-
Notifications
You must be signed in to change notification settings - Fork 997
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
Use custom types in data structures and constants #695
Conversation
specs/core/0_beacon-chain.md
Outdated
# Withdrawal credentials | ||
'withdrawal_credentials': 'bytes32', | ||
'withdrawal_credentials': Hash, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JustinDrake
Should it be Bytes32
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Already returned it back to Bytes32
in this commit a693737
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But there are two withdrawal_credentials
s: one is in DepositInput
and another one is in Validator
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, my bad.
Sure this one should also be Bytes32
Thanks for spotting this!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm tempted to nuke Bytes32
(which is semantically redundant with bytes32
) and use Hash
everywhere. After all, withdrawal_crendentials
fits with the definition: "result of hashing and its derivatives"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with it. Committed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After all,
withdrawal_crendentials
fits with the definition: "result of hashing and its derivatives"
Technically the first byte is a version number, but hashes have had built-in version numbers before (see ipfs multi hash) so that's not too terrible...
…put.withdrawal_credentials)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a net positive. Is there any hangup on merge at this point?
I’m inclined to have custom types cover all elements. Compromise: define a general |
IMHO, defining aliases for types which are used just in a couple of places in the spec wouldn't make the spec clearer. |
# Conflicts: # specs/core/0_beacon-chain.md
Hmm, I think this PR would break CI tests... @Nashatyrev could you rebase it and then let's see how to fix it in |
# Conflicts: # specs/core/0_beacon-chain.md
@hwwhww rebased. Let me know if I can help you with CI tests |
* Remove unnecessary per-field comments, focus on field grouping * Group `Validator` fields relevant to light-clients together (small optimisation for light clients) * Rework grouping of `BeaconState` fields * `deposit_index` => `eth1_deposit_index` Do not merge before: * #695 which specifies custom types for individual container fields, offsetting the removal of comments in some instances * #896 and #843 so that we don't have to continuously maintain the genesis `BeaconState` * #874 which introduces `current_crosslinks` and `previous_crosslinks`
|
I'm very pro adding aliases for readability. Do you want to go ahead @protolambda and fix whatever needs fixing? We can then merge. |
I think we addressed most of the typing ideas with #1077. We can go further with it and use NewType here and there to describe some things in addition to typing them (e.g. 👏 for bringing this up so early, and apologies from us all that typing didn't make it into the spec so quick, I hope the new more complete typing support makes up for it. |
Original issue: #667
The goal is to improve Spec readability by using alias custom types in data structures and as constant units instead of generic types.
What was done
Hash
andBitfield
custom types. TheHash
type is treated as a result of any 256-bit cryptographic hash function or its derivative preserving hash properties (likexor
ing two hashes)What else can be done
Time
,ForkVersion
,Bitfield64
) which are now referred at 1-2 places in the Spec'validator_balances': [ValidatorIndex => Gwei]
)