Dont return if proposer boost roots are missing (#11459)

* Dont return if proposer boost roots are missing

* move spectests to doublylinked tree

* unit test

Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
Potuz
2022-09-17 09:46:11 -03:00
committed by GitHub
parent 73443208a1
commit 588674f2fd
4 changed files with 25 additions and 15 deletions

View File

@@ -480,7 +480,7 @@ func TestForkChoice_computeProposerBoostScore(t *testing.T) {
}
// Regression test (11053)
func TestForkChoice_missingPreviousProposerBoost(t *testing.T) {
func TestForkChoice_missingProposerBoostRoots(t *testing.T) {
ctx := context.Background()
f := setup(1, 1)
balances := make([]uint64, 64) // 64 active validators.
@@ -493,6 +493,18 @@ func TestForkChoice_missingPreviousProposerBoost(t *testing.T) {
require.NoError(t, f.InsertNode(ctx, st, root))
f.store.previousProposerBoostRoot = [32]byte{'p'}
_, err = f.Head(ctx, balances)
headRoot, err := f.Head(ctx, balances)
require.NoError(t, err)
require.Equal(t, root, headRoot)
require.Equal(t, [32]byte{'r'}, f.store.proposerBoostRoot)
f.store.proposerBoostRoot = [32]byte{'p'}
driftGenesisTime(f, 3, 0)
st, root, err = prepareForkchoiceState(ctx, 2, [32]byte{'a'}, [32]byte{'r'}, [32]byte{}, 1, 1)
require.NoError(t, err)
require.NoError(t, f.InsertNode(ctx, st, root))
headRoot, err = f.Head(ctx, balances)
require.NoError(t, err)
require.Equal(t, root, headRoot)
require.Equal(t, [32]byte{'p'}, f.store.proposerBoostRoot)
}

View File

@@ -23,25 +23,23 @@ func (s *Store) applyProposerBoostScore(newBalances []uint64) error {
if s.previousProposerBoostRoot != params.BeaconConfig().ZeroHash {
previousNode, ok := s.nodeByRoot[s.previousProposerBoostRoot]
if !ok || previousNode == nil {
s.previousProposerBoostRoot = [32]byte{}
log.WithError(errInvalidProposerBoostRoot).Errorf(fmt.Sprintf("invalid prev root %#x", s.previousProposerBoostRoot))
return nil
} else {
previousNode.balance -= s.previousProposerBoostScore
}
previousNode.balance -= s.previousProposerBoostScore
}
if s.proposerBoostRoot != params.BeaconConfig().ZeroHash {
currentNode, ok := s.nodeByRoot[s.proposerBoostRoot]
if !ok || currentNode == nil {
s.proposerBoostRoot = [32]byte{}
log.WithError(errInvalidProposerBoostRoot).Errorf(fmt.Sprintf("invalid current root %#x", s.proposerBoostRoot))
return nil
} else {
proposerScore, err = computeProposerBoostScore(newBalances)
if err != nil {
return err
}
currentNode.balance += proposerScore
}
proposerScore, err = computeProposerBoostScore(newBalances)
if err != nil {
return err
}
currentNode.balance += proposerScore
}
s.previousProposerBoostRoot = s.proposerBoostRoot
s.previousProposerBoostScore = proposerScore

View File

@@ -20,7 +20,7 @@ go_library(
"//beacon-chain/core/transition:go_default_library",
"//beacon-chain/db/testing:go_default_library",
"//beacon-chain/execution:go_default_library",
"//beacon-chain/forkchoice/protoarray:go_default_library",
"//beacon-chain/forkchoice/doubly-linked-tree:go_default_library",
"//beacon-chain/operations/attestations:go_default_library",
"//beacon-chain/state:go_default_library",
"//beacon-chain/state/state-native:go_default_library",

View File

@@ -14,7 +14,7 @@ import (
"github.com/prysmaticlabs/prysm/v3/beacon-chain/cache/depositcache"
coreTime "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/time"
testDB "github.com/prysmaticlabs/prysm/v3/beacon-chain/db/testing"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/forkchoice/protoarray"
doublylinkedtree "github.com/prysmaticlabs/prysm/v3/beacon-chain/forkchoice/doubly-linked-tree"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/operations/attestations"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen"
@@ -57,7 +57,7 @@ func startChainService(t testing.TB,
blockchain.WithFinalizedStateAtStartUp(st),
blockchain.WithDatabase(db),
blockchain.WithAttestationService(attPool),
blockchain.WithForkChoiceStore(protoarray.New()),
blockchain.WithForkChoiceStore(doublylinkedtree.New()),
blockchain.WithStateGen(stategen.New(db)),
blockchain.WithStateNotifier(&mock.MockStateNotifier{}),
blockchain.WithAttestationPool(attestations.NewPool()),