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

QSP10, QSP11 - Add proper locking #6350

Merged
merged 23 commits into from
Jun 23, 2020
Merged

QSP10, QSP11 - Add proper locking #6350

merged 23 commits into from
Jun 23, 2020

Conversation

terencechain
Copy link
Member

What type of PR is this?

Code health improvements

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

@terencechain terencechain added Ready For Review A pull request ready for code review Audit labels Jun 22, 2020
@terencechain terencechain requested a review from a team as a code owner June 22, 2020 20:58
@terencechain terencechain self-assigned this Jun 22, 2020
@mcdee
Copy link
Contributor

mcdee commented Jun 22, 2020

Perhaps consider #6326 instead of the proposed changes to the state here, as they cover a wider range of fixes.

@terencechain
Copy link
Member Author

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

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 &ethpb.Validator{}, nil
}
if uint64(len(b.state.Validators)) <= idx {
return nil, fmt.Errorf("index %d out of range", idx)
}

b.lock.RLock()
Copy link
Member

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

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

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

Choose a reason for hiding this comment

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

This should stay here

@prylabs-bulldozer prylabs-bulldozer bot merged commit c3adde3 into master Jun 23, 2020
@delete-merged-branch delete-merged-branch bot deleted the qsp10-11 branch June 23, 2020 23:08
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.

3 participants