-
Notifications
You must be signed in to change notification settings - Fork 745
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BooleanBitfield needs to be made sane #22
Comments
What exactly does "unbounded" mean? Is there more info in the spec you could point me to? Is the idea that there is a bitvector but its size can change (up to) every incoming network message? |
Hey, thanks for jumping on this one :) For background, this was one of the first things built in the repo before it had aspirations of becoming a client. A lot has changed since then so I'm totally to a re-design it. If you can come up with a cleaner/more-standard API I have no objections to changing it. Unbounded (I think) was me trying to express that it's dynamically extendable, not based on some fixed array. Now that I know more about the spec, I don't think dynamically growing it is so important. Here are the primary use-cases for it:
I've considered making the For resources:
AFAIK there are no other resources. I've been trying to generate specification documents if they don't exist -- up to you if you're interested in that :) FYI I am about to merge some changes to the bitfield crate onto I hope this helps, let me know if I can help :) |
FYI, I have merged those changes onto master. I'll leave the bitfield crate alone now :) |
Great -- So it seems like there are two cases to consider before we can specify the nature of this bitfield:
from looking at the spec, there is a minimum committee size and there seems to be a maximum (as the total number of validators is capped) but it's not immediately clear how that backs into a maximum committee size. I would suggest we use a BigInteger type like this https://github.com/rust-num/num-bigint so we don't have to think about overflows and stuff. It can always be replaced with a more optimized impl if its a bottleneck. Thoughts on this approach? |
yep, the client can derive the committee size by looking at
|
Hey, I'm not exactly sure what the limit for a committee is, but I believe it's larger than @ralexstokes I would also be tempted to use a Another reason that I think a byte-backed impl would be useful is that we need to do some checks on the actual byte-array when processing a block. We need to know:
FYI, both of these conditions are required so that the hash of a If it helps, here an example of a bitfield being using in the wild: lighthouse/beacon_chain/validation/src/attestation_validation.rs Lines 124 to 143 in 49737fb
Presently I'm leaning towards the bitfield implementation containing two things:
(1) would allow us to deal with existing byte arrays without performing a memory copy. (2) would allow us to re-use the code from (1) whilst neatly storing the actual bytes somewhere. Thoughts? Happy to jump on a call if that is an easier method of comms? Thanks! |
Oh whoops, I missed a digit! I got 4096 validators per committee. I'm assuming 2²² maximum validators and 2⁶ slots per cycle. In addition, there are 2⁴ ( 2²² / 2⁶ / 2⁴ = 2¹² = 4096 validators. |
Ah cool, good to know!
…On Tue, 2 Oct 2018 at 6:44 pm, Yutaro Mori ***@***.***> wrote:
Oh whoops, I missed a digit! I got 4096 validators per committee.
I'm assuming 2²² maximum validators and 2⁶ slots per cycle. In addition,
there are 2⁴ (SHARD_COUNT // CYCLE_LENGTH) max committees per slot.
2²² / 2⁶ / 2⁴ = 2¹² = 4096 validators.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#22 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AGWiNKw9APsnPmOWSEkwMLZofk43-W41ks5ugyd9gaJpZM4W1FrM>
.
|
Thanks @paulhauner and @rawfalafel for the input. I have a pretty straightforward translation of the Python implementation you can see in this playground: https://play.rust-lang.org/?gist=01e011922837f2ca057244bfdeb28558&version=stable&mode=debug&edition=2015 If we like this, then I can add a wrapper type that owns a Vec and uses the BitFieldView to get/set bits. From there, you can wrap a higher-level type that manages "voting" like in the Python implementation but I'll leave that for a different issue. |
@paulhauner looking over the use cases you mentioned above, i'll need to change the linked gist a bit but its straightforward to do can you highlight which methods from the existing crate we want to keep as the external API? seems like we want to be able to get and (possibly) set bits, count the number of set bits and record the expected length of the attester set... i'm imaging a fairly immutable usage where this code is essentially just a nice wrapper over some bytes we either compute or get off the wire -- in this case we wouldn't be setting bits, resizing the backing array or needing to compute the length on demand (it is known at construction time). if there is some use case i'm not aware of plz fill me in |
Cool, looks good! Sorry if this is obvious, but we'll have to return I updated this issue description with a list of functions. I'm not attached to any of the variable names used there -- I just used them because they were short. I like your use of Re: I agree that we don't need to support re-sizing the backing array. Let's assume that number of bits is known at initialization time and that the vec is initialized to the minimum amount of bytes required to store those bits, with all bytes set to I hope this helps, happy to answer more questions! :) |
@paulhauner so I wasn't thinking far enough ahead and the It seems we have two cases: 1. we want to make a zeroed bitfield and allocate storage and 2. we want to use the bitfield logic but refer to an already allocated storage e.g. from bytes off the wire. You have any thoughts on what this looks like in legal Rust? It seems like the straightforward thing is that we have two different structs for each case (and perhaps pull the common logic out into common functions). This seems fine but if you can think of a way to avoid the duplication I'm all for it. Thoughts? |
@paulhauner the idea w/ My question now is -- how do you want to handle a panic on out of bounds access? If we don't check the index ahead of time like I have it, then the code will just panic on the invalid array access to |
You raised an excellent point about read/write structs. I just went on a rather long and magical journey across the internet and found std::borrow::Cow. CoW is copy-on-write. In a nutshell, reference whilst reading and then copy once a write is required. A.K.A lazy-copy. Check out my example: Great question about panics. I think we should make If you The Thanks!!! |
Also, I forgot to mention: that binary notation with the underscores is cool. I didn't know that. |
Yeah I think you can use them in any numeric literal -- helps when there
are a lot of zeros in the mix ;)
…On Sun, Oct 14, 2018 at 6:02 PM Paul Hauner ***@***.***> wrote:
Also, I forgot to mention: that binary notation with the underscores is
cool. I didn't know that.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#22 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AC-DNXEBaxTIodkTCMxIQ7faJ8U0rdmmks5uk96sgaJpZM4W1FrM>
.
|
Issue Status: 1. Open 2. Started 3. Submitted 4. Done Work has been started. These users each claimed they can complete the work by 7 months, 1 week from now. 1) ralexstokes has been approved to start work. Happy to discuss alternatives but I have already started work on this issue and would like to collect the bounty if there is one we are adding... Paul and I have been talking through various options and we feel like we have a good direction to go in -- I was going to author that as a PR in the next few days... Learn more on the Gitcoin Issue Details page. |
@ralexstokes you have been approved to work on this bounty, please submit the PR at your earliest convenience. Thanks! |
@ralexstokes Hello from Gitcoin Core - are you still working on this issue? Please submit a WIP PR or comment back within the next 3 days or you will be removed from this ticket and it will be returned to an ‘Open’ status. Please let us know if you have questions!
Funders only: Snooze warnings for 1 day | 3 days | 5 days | 10 days | 100 days |
@gitcoinbot there is an open PR at #62 . |
@ralexstokes Hello from Gitcoin Core - are you still working on this issue? Please submit a WIP PR or comment back within the next 3 days or you will be removed from this ticket and it will be returned to an ‘Open’ status. Please let us know if you have questions!
Funders only: Snooze warnings for 1 day | 3 days | 5 days | 10 days | 100 days |
@gitcoinbot there is an open PR at #62. we are all busy at devcon ;) |
@ralexstokes Hello from Gitcoin Core - are you still working on this issue? Please submit a WIP PR or comment back within the next 3 days or you will be removed from this ticket and it will be returned to an ‘Open’ status. Please let us know if you have questions!
Funders only: Snooze warnings for 1 day | 3 days | 5 days | 10 days | 100 days |
@gitcoinbot there is an open PR at #62. |
@ralexstokes Hello from Gitcoin Core - are you still working on this issue? Please submit a WIP PR or comment back within the next 3 days or you will be removed from this ticket and it will be returned to an ‘Open’ status. Please let us know if you have questions!
Funders only: Snooze warnings for 1 day | 3 days | 5 days | 10 days | 100 days |
@gitcoinbot there is an open PR at #62. |
@ralexstokes Hello from Gitcoin Core - are you still working on this issue? Please submit a WIP PR or comment back within the next 3 days or you will be removed from this ticket and it will be returned to an ‘Open’ status. Please let us know if you have questions!
Funders only: Snooze warnings for 1 day | 3 days | 5 days | 10 days | 100 days |
@gitcoinbot there is an open PR at #62 |
@ralexstokes Hello from Gitcoin Core - are you still working on this issue? Please submit a WIP PR or comment back within the next 3 days or you will be removed from this ticket and it will be returned to an ‘Open’ status. Please let us know if you have questions!
Funders only: Snooze warnings for 1 day | 3 days | 5 days | 10 days | 100 days |
@gitcoinbot after talking through some design decisions, i just need to wrangle a few more tests in #62 |
Great, thanks for the update @ralexstokes! |
@gitcoinbot this has been completed! Bounty can be paid out. Thank you :) |
@ralexstokes Hello from Gitcoin Core - are you still working on this issue? Please submit a WIP PR or comment back within the next 3 days or you will be removed from this ticket and it will be returned to an ‘Open’ status. Please let us know if you have questions!
Funders only: Snooze warnings for 1 day | 3 days | 5 days | 10 days | 100 days |
1 similar comment
@ralexstokes Hello from Gitcoin Core - are you still working on this issue? Please submit a WIP PR or comment back within the next 3 days or you will be removed from this ticket and it will be returned to an ‘Open’ status. Please let us know if you have questions!
Funders only: Snooze warnings for 1 day | 3 days | 5 days | 10 days | 100 days |
@gitcoinbot this issue has been resolved and the PR merged. see this comment: #22 (comment) |
⚡️ A tip worth 480.00000 DAI (480.0 USD @ $1.0/DAI) has been granted to @ralexstokes for this issue from @. ⚡️ Nice work @ralexstokes! Your tip has automatically been deposited in the ETH address we have on file.
|
@ralexstokes you have been paid out, sorry about the delay. Thanks! |
Issue Status: 1. Open 2. Started 3. Submitted 4. Done This Bounty has been completed. Additional Tips for this Bounty:
|
toy skelleton of sync changes
There is an implementation of a Boolean Bitfield here:
https://github.com/sigp/lighthouse/tree/master/boolean-bitfield
It (kinda) does the job for now, but it really needs some work done. If you spend some time looking at it I think you'll soon find out what I mean. As an example;
usize
, however there can theoretically beusize
number of bytes meaning we can have8 * usize
bits.On top of these two points, there's likely many chances for optimization.
Required Functionality
Get
Get value at index
n
.Error if bit out-of-bounds (OOB) of underlying bytes.
Set
Set bit at index
n
. Returns the previous value if successful.Error if bit is OOB of underlying bytes.
Highest Set Bit
Returns the index of the highest set bit.
Some(n)
if a bit set set,None
otherwise.Note: this is useful because we need to reject messages if an unnecessary bit is set (e.g. if there are 10 voters and the 11th bit is set
Number of Underlying Bytes
Returns the length of the underlying bytes.
_Note: useful to reject bitfields that are larger than required (e.g., if there are eight voters and two bytes -- only one byte is necessary). _
Number of Set Bits
Returns the total number of set bits (i.e., how many peeps voted).
Note: I'm not 100% sure we'll use this but I suspect we will.
The text was updated successfully, but these errors were encountered: