-
Notifications
You must be signed in to change notification settings - Fork 1k
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
QSP10, QSP11 - Add proper locking #6350
Conversation
Perhaps consider #6326 instead of the proposed changes to the state here, as they cover a wider range of fixes. |
It seems like #6326 will be taking longer to merge and maybe experimental. (e.g. feature flag was requested) I say we merge this first (lower risk) then default to #6326 after more testing there |
@@ -345,6 +352,10 @@ func (b *BeaconState) Eth1DataVotes() []*ethpb.Eth1Data { | |||
if b.state.Eth1DataVotes == nil { | |||
return 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.
This needs to go before we read b.state.Eth1DataVotes
@@ -413,13 +428,13 @@ func (b *BeaconState) ValidatorAtIndex(idx uint64) (*ethpb.Validator, error) { | |||
if b.state.Validators == nil { | |||
return ðpb.Validator{}, nil | |||
} | |||
if uint64(len(b.state.Validators)) <= idx { | |||
return nil, fmt.Errorf("index %d out of range", idx) | |||
} | |||
|
|||
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.
This needs to go before we read b.state.Validators
.
@@ -155,11 +155,11 @@ func (b *BeaconState) UpdateStateRootAtIndex(idx uint64, stateRoot [32]byte) err | |||
if !b.HasInnerState() { | |||
return ErrNilInnerState | |||
} | |||
b.lock.RLock() | |||
if len(b.state.StateRoots) <= int(idx) { | |||
return errors.Errorf("invalid index provided %d", idx) |
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.
You need to unlock in this branch now
beacon-chain/state/setters.go
Outdated
@@ -174,7 +175,6 @@ func (b *BeaconState) UpdateStateRootAtIndex(idx uint64, stateRoot [32]byte) err | |||
ref.MinusRef() | |||
b.sharedFieldReferences[stateRoots] = &reference{refs: 1} | |||
} | |||
b.lock.RUnlock() |
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 should stay here
What type of PR is this?
What does this PR do? Why is it needed?
Addressed locking related feedbacks from Audit report. They are qsp10 and qsp11
Which issues(s) does this PR fix?
Part of #6327