Skip to content

Commit

Permalink
Reset proposer root if the root is getting removed in store (#11053)
Browse files Browse the repository at this point in the history
* Reset proposer root if the root is getting removed in store

* Potuz feedback

* Fix root

* unit test

Co-authored-by: Potuz <potuz@prysmaticlabs.com>
  • Loading branch information
terencechain and potuz authored Jul 18, 2022
1 parent 6a74dcf commit 97dc9eb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
18 changes: 18 additions & 0 deletions beacon-chain/forkchoice/doubly-linked-tree/proposer_boost_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,3 +478,21 @@ func TestForkChoice_computeProposerBoostScore(t *testing.T) {
require.Equal(t, uint64(8), score)
})
}

// Regression test (11053)
func TestForkChoice_missingPreviousProposerBoost(t *testing.T) {
ctx := context.Background()
f := setup(1, 1)
balances := make([]uint64, 64) // 64 active validators.
for i := 0; i < len(balances); i++ {
balances[i] = 10
}
driftGenesisTime(f, 1, 0)
st, root, err := prepareForkchoiceState(ctx, 1, [32]byte{'r'}, [32]byte{}, [32]byte{}, 1, 1)
require.NoError(t, err)
require.NoError(t, f.InsertNode(ctx, st, root))

f.store.previousProposerBoostRoot = [32]byte{'p'}
_, err = f.Head(ctx, balances)
require.NoError(t, err)
}
8 changes: 6 additions & 2 deletions beacon-chain/forkchoice/doubly-linked-tree/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,19 @@ func (s *Store) applyProposerBoostScore(newBalances []uint64) error {
if s.previousProposerBoostRoot != params.BeaconConfig().ZeroHash {
previousNode, ok := s.nodeByRoot[s.previousProposerBoostRoot]
if !ok || previousNode == nil {
return errInvalidProposerBoostRoot
s.previousProposerBoostRoot = [32]byte{}
log.WithError(errInvalidProposerBoostRoot).Errorf(fmt.Sprintf("invalid prev root %#x", s.previousProposerBoostRoot))
return nil
}
previousNode.balance -= s.previousProposerBoostScore
}

if s.proposerBoostRoot != params.BeaconConfig().ZeroHash {
currentNode, ok := s.nodeByRoot[s.proposerBoostRoot]
if !ok || currentNode == nil {
return errInvalidProposerBoostRoot
s.proposerBoostRoot = [32]byte{}
log.WithError(errInvalidProposerBoostRoot).Errorf(fmt.Sprintf("invalid current root %#x", s.proposerBoostRoot))
return nil
}
proposerScore, err = computeProposerBoostScore(newBalances)
if err != nil {
Expand Down

0 comments on commit 97dc9eb

Please sign in to comment.