mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-24 20:37:17 +00:00
Fix Justified and Finalized Retrieval in Genesis (#6861)
* fix * fix tests * add test
This commit is contained in:
parent
6af950f001
commit
daedb7411c
@ -176,7 +176,7 @@ func (s *Service) Start() {
|
||||
|
||||
// Resume fork choice.
|
||||
s.justifiedCheckpt = stateTrie.CopyCheckpoint(justifiedCheckpoint)
|
||||
if err := s.cacheJustifiedStateBalances(s.ctx, bytesutil.ToBytes32(s.justifiedCheckpt.Root)); err != nil {
|
||||
if err := s.cacheJustifiedStateBalances(s.ctx, s.ensureRootNotZeros(bytesutil.ToBytes32(s.justifiedCheckpt.Root))); err != nil {
|
||||
log.Fatalf("Could not cache justified state balances: %v", err)
|
||||
}
|
||||
s.prevJustifiedCheckpt = stateTrie.CopyCheckpoint(justifiedCheckpoint)
|
||||
|
@ -198,6 +198,31 @@ func TestChainService_InitializeBeaconChain(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestChainService_CorrectGenesisRoots(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, sc := testDB.SetupDB(t)
|
||||
|
||||
chainService := setupBeaconChain(t, db, sc)
|
||||
|
||||
genesisBlk := testutil.NewBeaconBlock()
|
||||
blkRoot, err := stateutil.BlockRoot(genesisBlk.Block)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, db.SaveBlock(ctx, genesisBlk))
|
||||
s := testutil.NewBeaconState()
|
||||
require.NoError(t, s.SetSlot(0))
|
||||
require.NoError(t, db.SaveState(ctx, s, blkRoot))
|
||||
require.NoError(t, db.SaveHeadBlockRoot(ctx, blkRoot))
|
||||
require.NoError(t, db.SaveGenesisBlockRoot(ctx, blkRoot))
|
||||
// Test the start function.
|
||||
chainService.Start()
|
||||
|
||||
require.DeepEqual(t, params.BeaconConfig().ZeroHash[:], chainService.finalizedCheckpt.Root, "Finalize Checkpoint root is incorrect")
|
||||
require.DeepEqual(t, params.BeaconConfig().ZeroHash[:], chainService.justifiedCheckpt.Root, "Justified Checkpoint root is incorrect")
|
||||
|
||||
require.NoError(t, chainService.Stop(), "Unable to stop chain service")
|
||||
|
||||
}
|
||||
|
||||
func TestChainService_InitializeChainInfo(t *testing.T) {
|
||||
db, sc := testDB.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
bolt "go.etcd.io/bbolt"
|
||||
"go.opencensus.io/trace"
|
||||
)
|
||||
@ -21,9 +22,7 @@ func (kv *Store) JustifiedCheckpoint(ctx context.Context) (*ethpb.Checkpoint, er
|
||||
bkt := tx.Bucket(checkpointBucket)
|
||||
enc := bkt.Get(justifiedCheckpointKey)
|
||||
if enc == nil {
|
||||
blockBucket := tx.Bucket(blocksBucket)
|
||||
genesisRoot := blockBucket.Get(genesisBlockRootKey)
|
||||
checkpoint = ðpb.Checkpoint{Root: genesisRoot}
|
||||
checkpoint = ðpb.Checkpoint{Root: params.BeaconConfig().ZeroHash[:]}
|
||||
return nil
|
||||
}
|
||||
checkpoint = ðpb.Checkpoint{}
|
||||
@ -41,9 +40,7 @@ func (kv *Store) FinalizedCheckpoint(ctx context.Context) (*ethpb.Checkpoint, er
|
||||
bkt := tx.Bucket(checkpointBucket)
|
||||
enc := bkt.Get(finalizedCheckpointKey)
|
||||
if enc == nil {
|
||||
blockBucket := tx.Bucket(blocksBucket)
|
||||
genesisRoot := blockBucket.Get(genesisBlockRootKey)
|
||||
checkpoint = ðpb.Checkpoint{Root: genesisRoot}
|
||||
checkpoint = ðpb.Checkpoint{Root: params.BeaconConfig().ZeroHash[:]}
|
||||
return nil
|
||||
}
|
||||
checkpoint = ðpb.Checkpoint{}
|
||||
|
@ -9,6 +9,7 @@ import (
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil"
|
||||
)
|
||||
|
||||
@ -94,16 +95,11 @@ func TestStore_FinalizedCheckpoint_CanSaveRetrieve(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestStore_JustifiedCheckpoint_DefaultCantBeNil(t *testing.T) {
|
||||
func TestStore_JustifiedCheckpoint_DefaultIsZeroHash(t *testing.T) {
|
||||
db := setupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
genesisRoot := [32]byte{'A'}
|
||||
if err := db.SaveGenesisBlockRoot(ctx, genesisRoot); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
cp := ðpb.Checkpoint{Root: genesisRoot[:]}
|
||||
cp := ðpb.Checkpoint{Root: params.BeaconConfig().ZeroHash[:]}
|
||||
retrieved, err := db.JustifiedCheckpoint(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@ -113,16 +109,11 @@ func TestStore_JustifiedCheckpoint_DefaultCantBeNil(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestStore_FinalizedCheckpoint_DefaultCantBeNil(t *testing.T) {
|
||||
func TestStore_FinalizedCheckpoint_DefaultIsZeroHash(t *testing.T) {
|
||||
db := setupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
genesisRoot := [32]byte{'B'}
|
||||
if err := db.SaveGenesisBlockRoot(ctx, genesisRoot); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
cp := ðpb.Checkpoint{Root: genesisRoot[:]}
|
||||
cp := ðpb.Checkpoint{Root: params.BeaconConfig().ZeroHash[:]}
|
||||
retrieved, err := db.FinalizedCheckpoint(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
Loading…
Reference in New Issue
Block a user