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

Add back State To ComputeProposerIndex #5674

Merged
merged 9 commits into from
Apr 29, 2020
Merged

Conversation

nisdas
Copy link
Member

@nisdas nisdas commented Apr 29, 2020

Previously we passed in validators as an argument to ComputeProposerIndex however with how our new state is structured, this is an expensive operation as we copy the whole validator set. It would instead be better to pass in our state object directly and use read only instances of validators to perform any operation in the function.

For support of our archival methods, I did keep the old method as ComputeProposerIndexWithValidators .

@nisdas nisdas requested a review from a team as a code owner April 29, 2020 09:40
@codecov
Copy link

codecov bot commented Apr 29, 2020

Codecov Report

Merging #5674 into master will increase coverage by 51.72%.
The diff coverage is 80.00%.

@@             Coverage Diff             @@
##           master    #5674       +/-   ##
===========================================
+ Coverage    1.46%   53.19%   +51.72%     
===========================================
  Files          69      308      +239     
  Lines        6548    25512    +18964     
===========================================
+ Hits           96    13571    +13475     
- Misses       6443     9911     +3468     
- Partials        9     2030     +2021     

Copy link
Contributor

@shayzluf shayzluf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

had one comment about testing

shayzluf
shayzluf previously approved these changes Apr 29, 2020
Copy link
Contributor

@shayzluf shayzluf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@shayzluf
Copy link
Contributor

nice improvement. thanks

@@ -179,11 +179,60 @@ func BeaconProposerIndex(state *stateTrie.BeaconState) (uint64, error) {
return 0, errors.Wrap(err, "could not update committee cache")
}

return ComputeProposerIndex(state.Validators(), indices, seedWithSlotHash)
return ComputeProposerIndex(state, indices, seedWithSlotHash)
}

// ComputeProposerIndex returns the index sampled by effective balance, which is used to calculate proposer.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somewhere in the comment, can you please mention:
1.) This is faster than ComputeProposerIndexWithValidators
2.) It uses read only validator set from beacon state

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright done @terencechain

@@ -202,7 +251,7 @@ func BeaconProposerIndex(state *stateTrie.BeaconState) (uint64, error) {
// if effective_balance * MAX_RANDOM_BYTE >= MAX_EFFECTIVE_BALANCE * random_byte:
// return ValidatorIndex(candidate_index)
// i += 1
func ComputeProposerIndex(validators []*ethpb.Validator, activeIndices []uint64, seed [32]byte) (uint64, error) {
func ComputeProposerIndexWithValidators(validators []*ethpb.Validator, activeIndices []uint64, seed [32]byte) (uint64, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need this? Can it be marked as deprecated?

Suggested change
func ComputeProposerIndexWithValidators(validators []*ethpb.Validator, activeIndices []uint64, seed [32]byte) (uint64, error) {
//
// Deprecated: Prefer using the beacon state with ComputeProposerIndex to avoid an unnecessary copy of the validator set.
func ComputeProposerIndexWithValidators(validators []*ethpb.Validator, activeIndices []uint64, seed [32]byte) (uint64, error) {

If deprecated is not appropriate, please still put a message somewhere that users should prefer the other method whenever possible.Otherwise we could still see misuse with ComputeProposerIndexWithValidators(state.Validators(), ...)

Copy link
Member Author

@nisdas nisdas Apr 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think deprecated would be appropriate here. This is only still there because an archival method requires this, but that archival method is going to be deprecated anyway

@@ -202,7 +251,7 @@ func BeaconProposerIndex(state *stateTrie.BeaconState) (uint64, error) {
// if effective_balance * MAX_RANDOM_BYTE >= MAX_EFFECTIVE_BALANCE * random_byte:
// return ValidatorIndex(candidate_index)
// i += 1
func ComputeProposerIndex(validators []*ethpb.Validator, activeIndices []uint64, seed [32]byte) (uint64, error) {
func ComputeProposerIndexWithValidators(validators []*ethpb.Validator, activeIndices []uint64, seed [32]byte) (uint64, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make sure this method is tested as well?

@prylabs-bulldozer prylabs-bulldozer bot merged commit 81a7bc7 into master Apr 29, 2020
@delete-merged-branch delete-merged-branch bot deleted the addBackState branch April 29, 2020 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants