Skip to content
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

Merged
merged 11 commits into from Mar 26, 2020
Merged

Custom Block HTR #5219

merged 11 commits into from Mar 26, 2020

Conversation

nisdas
Copy link
Member

@nisdas nisdas commented Mar 26, 2020

  • 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
Copy link

codecov bot commented Mar 26, 2020

Codecov Report

❗ No coverage uploaded for pull request base (master@4118fa5). Click here to learn what that means.
The diff coverage is 13.82%.

@@            Coverage Diff            @@
##             master    #5219   +/-   ##
=========================================
  Coverage          ?   56.13%           
=========================================
  Files             ?      289           
  Lines             ?    22590           
  Branches          ?        0           
=========================================
  Hits              ?    12682           
  Misses            ?     8131           
  Partials          ?     1777

@nisdas nisdas marked this pull request as ready for review March 26, 2020 11:58
@nisdas nisdas added the Ready For Review A pull request ready for code review label Mar 26, 2020
Copy link
Member

@terencechain terencechain left a 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

beacon-chain/blockchain/process_block.go Outdated Show resolved Hide resolved
beacon-chain/blockchain/receive_block.go Outdated Show resolved Hide resolved
return bitwiseMerkleizeArrays(fieldRoots, uint64(len(fieldRoots)), uint64(len(fieldRoots)))
}

func blockAttestationRoot(atts []*ethpb.Attestation) ([32]byte, error) {
Copy link
Member

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

Copy link
Member Author

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.

Copy link
Member

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) {
Copy link
Member

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

Copy link
Member Author

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_structureRoot. Maybe we need to standardize naming here, although that will have to be in another pr

Copy link
Member

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

nisdas and others added 2 commits March 26, 2020 22:08
Co-Authored-By: terence tsao <terence@prysmaticlabs.com>
Co-Authored-By: terence tsao <terence@prysmaticlabs.com>
@nisdas
Copy link
Member Author

nisdas commented Mar 26, 2020

@terencechain
for

  1. The benchmark results were the same for both ssz and custom ssz, this is explained by the ssz cache used in our generic ssz library and that we basically have the same attestation , 128 times in the block. I was unable to use the testutil to generate unique attestations so that is why the benchmark isn't wholly correct. I haven't found a way to switch off the cache in go-ssz

  2. Agree with that , however the methods created in this PR basically use a lot of things from the

stateutils

package. Maybe we should refactor and put all these in /shared/sszutils or something.

@terencechain
Copy link
Member

@terencechain
for

  1. The benchmark results were the same for both ssz and custom ssz, this is explained by the ssz cache used in our generic ssz library and that we basically have the same attestation , 128 times in the block. I was unable to use the testutil to generate unique attestations so that is why the benchmark isn't wholly correct. I haven't found a way to switch off the cache in go-ssz
  2. Agree with that , however the methods created in this PR basically use a lot of things from the
stateutils

package. Maybe we should refactor and put all these in /shared/sszutils or something.

Sounds good, do you mind opening an issue since we likely won't get to that this PR?

terencechain
terencechain previously approved these changes Mar 26, 2020
fieldRoots := make([][32]byte, 3)

// Bitfield.
aggregationRoot, err := bitlistRoot(att.AggregationBits, 2048)
Copy link
Member

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 :)

Copy link
Member Author

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

@rauljordan rauljordan merged commit cdac3d6 into master Mar 26, 2020
@rauljordan rauljordan deleted the customBlockHTR branch March 26, 2020 18:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ready For Review A pull request ready for code review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants