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
Custom Block HTR #5219
Custom Block HTR #5219
Conversation
nisdas
commented
Mar 26, 2020
•
edited
edited
- Adds a custom block hash tree root method.
- Add a custom hash tree root method for block bodies.
- Add basic sanity tests.
- Add benchmarks between the custom method and generic ssz method.
- Gate this behind feature flag.
Codecov Report
@@ Coverage Diff @@
## master #5219 +/- ##
=========================================
Coverage ? 56.13%
=========================================
Files ? 289
Lines ? 22590
Branches ? 0
=========================================
Hits ? 12682
Misses ? 8131
Partials ? 1777 |
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.
Looks good to me. Couple feedback
1.) Can you post the benchmark result?
2.) A few comments on clarity of naming
3.) A bit odd Custom block HTR and attestation HTR is under /state/stateutil
pkg. Seems like a better place for them will be under /block/blockutil
return bitwiseMerkleizeArrays(fieldRoots, uint64(len(fieldRoots)), uint64(len(fieldRoots))) | ||
} | ||
|
||
func blockAttestationRoot(atts []*ethpb.Attestation) ([32]byte, error) { |
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.
Prefer naming it attestationsRoot
as it doesn't need to be constrained with block
, the function can be extensible to any object that needs a hash tree root of a list of attestations
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.
we use the max block attestation capacity here, so this will only apply for beacon block attestations. If we use attestations which are larger than 128 in length, this root will be incorrect.
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.
makes sense 👍
@@ -32,6 +33,88 @@ func BlockHeaderRoot(header *ethpb.BeaconBlockHeader) ([32]byte, error) { | |||
return bitwiseMerkleize(fieldRoots, uint64(len(fieldRoots)), uint64(len(fieldRoots))) | |||
} | |||
|
|||
// BlockRoot returns the block hash tree root of the provided block. | |||
func BlockRoot(blk *ethpb.BeaconBlock) ([32]byte, error) { |
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 a bit torn on the naming. BlockRoot
sounds a pure getter and its retrieving the the root within the block with no real work. Should we be consistent with HashTreeRootState
and name it HashTreeRootBlock
? This applies to attestations as well
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 was trying to put int more in line to how naming was done in this package, all the function names are basically data_structure
Root. Maybe we need to standardize naming here, although that will have to be in another pr
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.
Are you saying HashTreeRootState
should be named StateRoot
?
I'm ok with that, as long as the 2 are consistent
Co-Authored-By: terence tsao <terence@prysmaticlabs.com>
Co-Authored-By: terence tsao <terence@prysmaticlabs.com>
@terencechain
package. Maybe we should refactor and put all these in |
Sounds good, do you mind opening an issue since we likely won't get to that this PR? |
fieldRoots := make([][32]byte, 3) | ||
|
||
// Bitfield. | ||
aggregationRoot, err := bitlistRoot(att.AggregationBits, 2048) |
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.
Instead of hard coding 2048, better to use params.BeaconConfig.MaxValidatorsPerCommittee
It changes to 1024 and it'll take next person a while to discover this is the issue :)
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.
ah nice, catch. changing it now