-
Notifications
You must be signed in to change notification settings - Fork 922
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 StateRoot as Key for Cache #7540
Conversation
} | ||
if proposerIndices != nil { | ||
return proposerIndices[state.Slot()%params.BeaconConfig().SlotsPerEpoch], nil | ||
} | ||
} | ||
if err := UpdateProposerIndicesInCache(state, e); err != nil { |
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.
Should we move UpdateProposerIndicesInCache
inside !bytes.Equal(r, params.BeaconConfig().ZeroHash[:])
as well?
return nil, nil | ||
} | ||
|
||
b.lock.RLock() |
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 the lock should be before b.state.StateRoots == nil
? It's a read there
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.
True, although this is a general pattern in all our getters which in hindsight looks incorrect. I can fix it in another pr.
return 0, errors.Wrap(err, "could not interface with committee cache") | ||
} | ||
if proposerIndices != nil { | ||
return proposerIndices[state.Slot()%params.BeaconConfig().SlotsPerEpoch], nil |
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.
Perhaps a length check here, just to be extra defensive even if it is unlikely to happen
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.
@rauljordan I think there is sufficient length check above. We know that len(proposerIndices) is exactly SlotsPerEpoch so when we do slot%SlotsPerEpoch, we know that there cannot be out of bounds since the max value of that operation would be the last value in the slice.
… into changeCacheKey
Codecov Report
@@ Coverage Diff @@
## master #7540 +/- ##
==========================================
- Coverage 61.70% 61.68% -0.03%
==========================================
Files 424 424
Lines 29884 29925 +41
==========================================
+ Hits 18441 18459 +18
- Misses 8484 8496 +12
- Partials 2959 2970 +11 |
@@ -348,9 +349,9 @@ func UpdateCommitteeCache(state *stateTrie.BeaconState, epoch uint64) error { | |||
|
|||
// UpdateProposerIndicesInCache updates proposer indices entry of the committee cache. | |||
func UpdateProposerIndicesInCache(state *stateTrie.BeaconState, epoch uint64) error { | |||
// The cache uses the block root at the last epoch slot as key. (e.g. for epoch 1, the key is root at slot 31) | |||
// The cache uses the state root at the last epoch slot as key. (e.g. for epoch 1, the key is root at slot 31) |
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.
This comment is still correct?
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.
Thanks will fix it tomorrow
if err != nil { | ||
return 0, errors.Wrap(err, "could not interface with committee cache") | ||
} | ||
if proposerIndices != nil && len(proposerIndices) == int(params.BeaconConfig().SlotsPerEpoch) { |
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 would argue that if length does not equal to slots per epoch, It should return an error here. The consumers should know why this fail and proposer cache is not working since there will be performance penalties
return 0, errors.Wrap(err, "could not interface with committee cache") | ||
} | ||
if proposerIndices != nil { | ||
return proposerIndices[state.Slot()%params.BeaconConfig().SlotsPerEpoch], nil |
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.
@rauljordan I think there is sufficient length check above. We know that len(proposerIndices) is exactly SlotsPerEpoch so when we do slot%SlotsPerEpoch, we know that there cannot be out of bounds since the max value of that operation would be the last value in the slice.
LGTM. We ran this PR in production environment for 12 hours without significant issue. |
What type of PR is this?
Feature Improvement
What does this PR do? Why is it needed?
Which issues(s) does this PR fix?
Other notes for review
cc @terencechain