mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-03 08:37:37 +00:00
Add justified block insertion to forkchoice when missed (#7520)
* Add justified block insertion to fork choice when missed * Add regression test
This commit is contained in:
parent
b742511193
commit
9e712e4598
@ -51,6 +51,22 @@ func (s *Service) updateHead(ctx context.Context, balances []uint64) error {
|
|||||||
if headStartRoot == params.BeaconConfig().ZeroHash {
|
if headStartRoot == params.BeaconConfig().ZeroHash {
|
||||||
headStartRoot = s.genesisRoot
|
headStartRoot = s.genesisRoot
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// In order to process head, fork choice store requires justified info.
|
||||||
|
// If the fork choice store is missing justified block info, a node should
|
||||||
|
// re-initiate fork choice store using the latest justified info.
|
||||||
|
// This recovers a fatal condition and should not happen in run time.
|
||||||
|
if !s.forkChoiceStore.HasNode(headStartRoot) {
|
||||||
|
jb, err := s.beaconDB.Block(ctx, headStartRoot)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
s.forkChoiceStore = protoarray.New(j.Epoch, f.Epoch, bytesutil.ToBytes32(f.Root))
|
||||||
|
if err := s.insertBlockToForkChoiceStore(ctx, jb.Block, headStartRoot, f, j); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
headRoot, err := s.forkChoiceStore.Head(ctx, j.Epoch, headStartRoot, balances, f.Epoch)
|
headRoot, err := s.forkChoiceStore.Head(ctx, j.Epoch, headStartRoot, balances, f.Epoch)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||||
testDB "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
|
testDB "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
|
||||||
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||||
"github.com/prysmaticlabs/prysm/shared/testutil"
|
"github.com/prysmaticlabs/prysm/shared/testutil"
|
||||||
@ -137,3 +138,19 @@ func TestCacheJustifiedStateBalances_CanCache(t *testing.T) {
|
|||||||
require.NoError(t, service.cacheJustifiedStateBalances(context.Background(), r))
|
require.NoError(t, service.cacheJustifiedStateBalances(context.Background(), r))
|
||||||
require.DeepEqual(t, service.getJustifiedBalances(), state.Balances(), "Incorrect justified balances")
|
require.DeepEqual(t, service.getJustifiedBalances(), state.Balances(), "Incorrect justified balances")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestUpdateHead_MissingJustifiedRoot(t *testing.T) {
|
||||||
|
db, sc := testDB.SetupDB(t)
|
||||||
|
service := setupBeaconChain(t, db, sc)
|
||||||
|
|
||||||
|
b := testutil.NewBeaconBlock()
|
||||||
|
require.NoError(t, service.beaconDB.SaveBlock(context.Background(), b))
|
||||||
|
r, err := b.Block.HashTreeRoot()
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
service.justifiedCheckpt = ðpb.Checkpoint{Root: r[:]}
|
||||||
|
service.finalizedCheckpt = ðpb.Checkpoint{}
|
||||||
|
service.bestJustifiedCheckpt = ðpb.Checkpoint{}
|
||||||
|
|
||||||
|
require.NoError(t, service.updateHead(context.Background(), []uint64{}))
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user