mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 12:57:18 +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.
|
// Resume fork choice.
|
||||||
s.justifiedCheckpt = stateTrie.CopyCheckpoint(justifiedCheckpoint)
|
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)
|
log.Fatalf("Could not cache justified state balances: %v", err)
|
||||||
}
|
}
|
||||||
s.prevJustifiedCheckpt = stateTrie.CopyCheckpoint(justifiedCheckpoint)
|
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) {
|
func TestChainService_InitializeChainInfo(t *testing.T) {
|
||||||
db, sc := testDB.SetupDB(t)
|
db, sc := testDB.SetupDB(t)
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
|
|
||||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||||
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
||||||
|
"github.com/prysmaticlabs/prysm/shared/params"
|
||||||
bolt "go.etcd.io/bbolt"
|
bolt "go.etcd.io/bbolt"
|
||||||
"go.opencensus.io/trace"
|
"go.opencensus.io/trace"
|
||||||
)
|
)
|
||||||
@ -21,9 +22,7 @@ func (kv *Store) JustifiedCheckpoint(ctx context.Context) (*ethpb.Checkpoint, er
|
|||||||
bkt := tx.Bucket(checkpointBucket)
|
bkt := tx.Bucket(checkpointBucket)
|
||||||
enc := bkt.Get(justifiedCheckpointKey)
|
enc := bkt.Get(justifiedCheckpointKey)
|
||||||
if enc == nil {
|
if enc == nil {
|
||||||
blockBucket := tx.Bucket(blocksBucket)
|
checkpoint = ðpb.Checkpoint{Root: params.BeaconConfig().ZeroHash[:]}
|
||||||
genesisRoot := blockBucket.Get(genesisBlockRootKey)
|
|
||||||
checkpoint = ðpb.Checkpoint{Root: genesisRoot}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
checkpoint = ðpb.Checkpoint{}
|
checkpoint = ðpb.Checkpoint{}
|
||||||
@ -41,9 +40,7 @@ func (kv *Store) FinalizedCheckpoint(ctx context.Context) (*ethpb.Checkpoint, er
|
|||||||
bkt := tx.Bucket(checkpointBucket)
|
bkt := tx.Bucket(checkpointBucket)
|
||||||
enc := bkt.Get(finalizedCheckpointKey)
|
enc := bkt.Get(finalizedCheckpointKey)
|
||||||
if enc == nil {
|
if enc == nil {
|
||||||
blockBucket := tx.Bucket(blocksBucket)
|
checkpoint = ðpb.Checkpoint{Root: params.BeaconConfig().ZeroHash[:]}
|
||||||
genesisRoot := blockBucket.Get(genesisBlockRootKey)
|
|
||||||
checkpoint = ðpb.Checkpoint{Root: genesisRoot}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
checkpoint = ðpb.Checkpoint{}
|
checkpoint = ðpb.Checkpoint{}
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||||
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
|
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
|
||||||
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
||||||
|
"github.com/prysmaticlabs/prysm/shared/params"
|
||||||
"github.com/prysmaticlabs/prysm/shared/testutil"
|
"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)
|
db := setupDB(t)
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
genesisRoot := [32]byte{'A'}
|
cp := ðpb.Checkpoint{Root: params.BeaconConfig().ZeroHash[:]}
|
||||||
if err := db.SaveGenesisBlockRoot(ctx, genesisRoot); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
cp := ðpb.Checkpoint{Root: genesisRoot[:]}
|
|
||||||
retrieved, err := db.JustifiedCheckpoint(ctx)
|
retrieved, err := db.JustifiedCheckpoint(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
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)
|
db := setupDB(t)
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
genesisRoot := [32]byte{'B'}
|
cp := ðpb.Checkpoint{Root: params.BeaconConfig().ZeroHash[:]}
|
||||||
if err := db.SaveGenesisBlockRoot(ctx, genesisRoot); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
cp := ðpb.Checkpoint{Root: genesisRoot[:]}
|
|
||||||
retrieved, err := db.FinalizedCheckpoint(ctx)
|
retrieved, err := db.FinalizedCheckpoint(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
Loading…
Reference in New Issue
Block a user