mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 15:37:56 -05:00
Move state summary cache to DB (#8101)
This commit is contained in:
@@ -11,7 +11,7 @@ import (
|
||||
)
|
||||
|
||||
func TestHeadSlot_DataRace(t *testing.T) {
|
||||
db, _ := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
s := &Service{
|
||||
beaconDB: db,
|
||||
}
|
||||
@@ -22,11 +22,11 @@ func TestHeadSlot_DataRace(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestHeadRoot_DataRace(t *testing.T) {
|
||||
db, sc := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
s := &Service{
|
||||
beaconDB: db,
|
||||
head: &head{root: [32]byte{'A'}},
|
||||
stateGen: stategen.New(db, sc),
|
||||
stateGen: stategen.New(db),
|
||||
}
|
||||
go func() {
|
||||
require.NoError(t, s.saveHead(context.Background(), [32]byte{}))
|
||||
@@ -36,11 +36,11 @@ func TestHeadRoot_DataRace(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestHeadBlock_DataRace(t *testing.T) {
|
||||
db, sc := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
s := &Service{
|
||||
beaconDB: db,
|
||||
head: &head{block: ðpb.SignedBeaconBlock{}},
|
||||
stateGen: stategen.New(db, sc),
|
||||
stateGen: stategen.New(db),
|
||||
}
|
||||
go func() {
|
||||
require.NoError(t, s.saveHead(context.Background(), [32]byte{}))
|
||||
@@ -50,10 +50,10 @@ func TestHeadBlock_DataRace(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestHeadState_DataRace(t *testing.T) {
|
||||
db, sc := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
s := &Service{
|
||||
beaconDB: db,
|
||||
stateGen: stategen.New(db, sc),
|
||||
stateGen: stategen.New(db),
|
||||
}
|
||||
go func() {
|
||||
require.NoError(t, s.saveHead(context.Background(), [32]byte{}))
|
||||
|
||||
@@ -25,44 +25,44 @@ var _ TimeFetcher = (*Service)(nil)
|
||||
var _ ForkFetcher = (*Service)(nil)
|
||||
|
||||
func TestFinalizedCheckpt_Nil(t *testing.T) {
|
||||
db, sc := testDB.SetupDB(t)
|
||||
c := setupBeaconChain(t, db, sc)
|
||||
db := testDB.SetupDB(t)
|
||||
c := setupBeaconChain(t, db)
|
||||
assert.DeepEqual(t, params.BeaconConfig().ZeroHash[:], c.FinalizedCheckpt().Root, "Incorrect pre chain start value")
|
||||
}
|
||||
|
||||
func TestHeadRoot_Nil(t *testing.T) {
|
||||
db, sc := testDB.SetupDB(t)
|
||||
c := setupBeaconChain(t, db, sc)
|
||||
db := testDB.SetupDB(t)
|
||||
c := setupBeaconChain(t, db)
|
||||
headRoot, err := c.HeadRoot(context.Background())
|
||||
require.NoError(t, err)
|
||||
assert.DeepEqual(t, params.BeaconConfig().ZeroHash[:], headRoot, "Incorrect pre chain start value")
|
||||
}
|
||||
|
||||
func TestFinalizedCheckpt_CanRetrieve(t *testing.T) {
|
||||
db, sc := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
|
||||
cp := ðpb.Checkpoint{Epoch: 5, Root: bytesutil.PadTo([]byte("foo"), 32)}
|
||||
c := setupBeaconChain(t, db, sc)
|
||||
c := setupBeaconChain(t, db)
|
||||
c.finalizedCheckpt = cp
|
||||
|
||||
assert.Equal(t, cp.Epoch, c.FinalizedCheckpt().Epoch, "Unexpected finalized epoch")
|
||||
}
|
||||
|
||||
func TestFinalizedCheckpt_GenesisRootOk(t *testing.T) {
|
||||
db, sc := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
|
||||
genesisRoot := [32]byte{'A'}
|
||||
cp := ðpb.Checkpoint{Root: genesisRoot[:]}
|
||||
c := setupBeaconChain(t, db, sc)
|
||||
c := setupBeaconChain(t, db)
|
||||
c.finalizedCheckpt = cp
|
||||
c.genesisRoot = genesisRoot
|
||||
assert.DeepEqual(t, c.genesisRoot[:], c.FinalizedCheckpt().Root)
|
||||
}
|
||||
|
||||
func TestCurrentJustifiedCheckpt_CanRetrieve(t *testing.T) {
|
||||
db, sc := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
|
||||
c := setupBeaconChain(t, db, sc)
|
||||
c := setupBeaconChain(t, db)
|
||||
assert.Equal(t, params.BeaconConfig().ZeroHash, bytesutil.ToBytes32(c.CurrentJustifiedCheckpt().Root), "Unexpected justified epoch")
|
||||
cp := ðpb.Checkpoint{Epoch: 6, Root: bytesutil.PadTo([]byte("foo"), 32)}
|
||||
c.justifiedCheckpt = cp
|
||||
@@ -70,9 +70,9 @@ func TestCurrentJustifiedCheckpt_CanRetrieve(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestJustifiedCheckpt_GenesisRootOk(t *testing.T) {
|
||||
db, sc := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
|
||||
c := setupBeaconChain(t, db, sc)
|
||||
c := setupBeaconChain(t, db)
|
||||
genesisRoot := [32]byte{'B'}
|
||||
cp := ðpb.Checkpoint{Root: genesisRoot[:]}
|
||||
c.justifiedCheckpt = cp
|
||||
@@ -81,21 +81,21 @@ func TestJustifiedCheckpt_GenesisRootOk(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPreviousJustifiedCheckpt_CanRetrieve(t *testing.T) {
|
||||
db, sc := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
|
||||
cp := ðpb.Checkpoint{Epoch: 7, Root: bytesutil.PadTo([]byte("foo"), 32)}
|
||||
c := setupBeaconChain(t, db, sc)
|
||||
c := setupBeaconChain(t, db)
|
||||
assert.Equal(t, params.BeaconConfig().ZeroHash, bytesutil.ToBytes32(c.CurrentJustifiedCheckpt().Root), "Unexpected justified epoch")
|
||||
c.prevJustifiedCheckpt = cp
|
||||
assert.Equal(t, cp.Epoch, c.PreviousJustifiedCheckpt().Epoch, "Unexpected previous justified epoch")
|
||||
}
|
||||
|
||||
func TestPrevJustifiedCheckpt_GenesisRootOk(t *testing.T) {
|
||||
db, sc := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
|
||||
genesisRoot := [32]byte{'C'}
|
||||
cp := ðpb.Checkpoint{Root: genesisRoot[:]}
|
||||
c := setupBeaconChain(t, db, sc)
|
||||
c := setupBeaconChain(t, db)
|
||||
c.prevJustifiedCheckpt = cp
|
||||
c.genesisRoot = genesisRoot
|
||||
assert.DeepEqual(t, c.genesisRoot[:], c.PreviousJustifiedCheckpt().Root)
|
||||
@@ -118,7 +118,7 @@ func TestHeadRoot_CanRetrieve(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestHeadRoot_UseDB(t *testing.T) {
|
||||
db, _ := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
c := &Service{beaconDB: db}
|
||||
c.head = &head{root: params.BeaconConfig().ZeroHash}
|
||||
b := testutil.NewBeaconBlock()
|
||||
@@ -195,8 +195,8 @@ func TestGenesisValidatorRoot_CanRetrieve(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestHeadETH1Data_Nil(t *testing.T) {
|
||||
db, sc := testDB.SetupDB(t)
|
||||
c := setupBeaconChain(t, db, sc)
|
||||
db := testDB.SetupDB(t)
|
||||
c := setupBeaconChain(t, db)
|
||||
assert.DeepEqual(t, ðpb.Eth1Data{}, c.HeadETH1Data(), "Incorrect pre chain start value")
|
||||
}
|
||||
|
||||
@@ -213,8 +213,8 @@ func TestHeadETH1Data_CanRetrieve(t *testing.T) {
|
||||
|
||||
func TestIsCanonical_Ok(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, sc := testDB.SetupDB(t)
|
||||
c := setupBeaconChain(t, db, sc)
|
||||
db := testDB.SetupDB(t)
|
||||
c := setupBeaconChain(t, db)
|
||||
|
||||
blk := testutil.NewBeaconBlock()
|
||||
blk.Block.Slot = 0
|
||||
|
||||
@@ -93,7 +93,7 @@ func (s *Service) saveHead(ctx context.Context, headRoot [32]byte) error {
|
||||
|
||||
// If the head state is not available, just return nil.
|
||||
// There's nothing to cache
|
||||
if !s.stateGen.StateSummaryExists(ctx, headRoot) {
|
||||
if !s.beaconDB.HasStateSummary(ctx, headRoot) {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -15,8 +15,8 @@ import (
|
||||
)
|
||||
|
||||
func TestSaveHead_Same(t *testing.T) {
|
||||
db, sc := testDB.SetupDB(t)
|
||||
service := setupBeaconChain(t, db, sc)
|
||||
db := testDB.SetupDB(t)
|
||||
service := setupBeaconChain(t, db)
|
||||
|
||||
r := [32]byte{'A'}
|
||||
service.head = &head{slot: 0, root: r}
|
||||
@@ -28,8 +28,8 @@ func TestSaveHead_Same(t *testing.T) {
|
||||
|
||||
func TestSaveHead_Different(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, sc := testDB.SetupDB(t)
|
||||
service := setupBeaconChain(t, db, sc)
|
||||
db := testDB.SetupDB(t)
|
||||
service := setupBeaconChain(t, db)
|
||||
|
||||
oldRoot := [32]byte{'A'}
|
||||
service.head = &head{slot: 0, root: oldRoot}
|
||||
@@ -61,8 +61,8 @@ func TestSaveHead_Different(t *testing.T) {
|
||||
func TestSaveHead_Different_Reorg(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
hook := logTest.NewGlobal()
|
||||
db, sc := testDB.SetupDB(t)
|
||||
service := setupBeaconChain(t, db, sc)
|
||||
db := testDB.SetupDB(t)
|
||||
service := setupBeaconChain(t, db)
|
||||
|
||||
oldRoot := [32]byte{'A'}
|
||||
service.head = &head{slot: 0, root: oldRoot}
|
||||
@@ -95,8 +95,8 @@ func TestSaveHead_Different_Reorg(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCacheJustifiedStateBalances_CanCache(t *testing.T) {
|
||||
db, sc := testDB.SetupDB(t)
|
||||
service := setupBeaconChain(t, db, sc)
|
||||
db := testDB.SetupDB(t)
|
||||
service := setupBeaconChain(t, db)
|
||||
|
||||
state, _ := testutil.DeterministicGenesisState(t, 100)
|
||||
r := [32]byte{'a'}
|
||||
@@ -107,8 +107,8 @@ func TestCacheJustifiedStateBalances_CanCache(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUpdateHead_MissingJustifiedRoot(t *testing.T) {
|
||||
db, sc := testDB.SetupDB(t)
|
||||
service := setupBeaconChain(t, db, sc)
|
||||
db := testDB.SetupDB(t)
|
||||
service := setupBeaconChain(t, db)
|
||||
|
||||
b := testutil.NewBeaconBlock()
|
||||
require.NoError(t, service.beaconDB.SaveBlock(context.Background(), b))
|
||||
|
||||
@@ -20,7 +20,7 @@ func TestService_TreeHandler(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
ctx := context.Background()
|
||||
db, sCache := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
headState := testutil.NewBeaconState()
|
||||
require.NoError(t, headState.SetBalances([]uint64{params.BeaconConfig().GweiPerEth}))
|
||||
cfg := &Config{
|
||||
@@ -30,7 +30,7 @@ func TestService_TreeHandler(t *testing.T) {
|
||||
0, // finalizedEpoch
|
||||
[32]byte{'a'},
|
||||
),
|
||||
StateGen: stategen.New(db, sCache),
|
||||
StateGen: stategen.New(db),
|
||||
}
|
||||
s, err := NewService(ctx, cfg)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -21,12 +21,12 @@ import (
|
||||
|
||||
func TestStore_OnAttestation(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, sc := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
|
||||
cfg := &Config{
|
||||
BeaconDB: db,
|
||||
ForkChoiceStore: protoarray.New(0, 0, [32]byte{}),
|
||||
StateGen: stategen.New(db, sc),
|
||||
StateGen: stategen.New(db),
|
||||
}
|
||||
service, err := NewService(ctx, cfg)
|
||||
require.NoError(t, err)
|
||||
@@ -130,11 +130,11 @@ func TestStore_OnAttestation(t *testing.T) {
|
||||
|
||||
func TestStore_SaveCheckpointState(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, sc := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
|
||||
cfg := &Config{
|
||||
BeaconDB: db,
|
||||
StateGen: stategen.New(db, sc),
|
||||
StateGen: stategen.New(db),
|
||||
}
|
||||
service, err := NewService(ctx, cfg)
|
||||
require.NoError(t, err)
|
||||
@@ -201,11 +201,11 @@ func TestStore_SaveCheckpointState(t *testing.T) {
|
||||
|
||||
func TestStore_UpdateCheckpointState(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, sc := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
|
||||
cfg := &Config{
|
||||
BeaconDB: db,
|
||||
StateGen: stategen.New(db, sc),
|
||||
StateGen: stategen.New(db),
|
||||
}
|
||||
service, err := NewService(ctx, cfg)
|
||||
require.NoError(t, err)
|
||||
@@ -242,7 +242,7 @@ func TestStore_UpdateCheckpointState(t *testing.T) {
|
||||
|
||||
func TestAttEpoch_MatchPrevEpoch(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, _ := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
|
||||
cfg := &Config{BeaconDB: db}
|
||||
service, err := NewService(ctx, cfg)
|
||||
@@ -254,7 +254,7 @@ func TestAttEpoch_MatchPrevEpoch(t *testing.T) {
|
||||
|
||||
func TestAttEpoch_MatchCurrentEpoch(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, _ := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
|
||||
cfg := &Config{BeaconDB: db}
|
||||
service, err := NewService(ctx, cfg)
|
||||
@@ -266,7 +266,7 @@ func TestAttEpoch_MatchCurrentEpoch(t *testing.T) {
|
||||
|
||||
func TestAttEpoch_NotMatch(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, _ := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
|
||||
cfg := &Config{BeaconDB: db}
|
||||
service, err := NewService(ctx, cfg)
|
||||
@@ -279,7 +279,7 @@ func TestAttEpoch_NotMatch(t *testing.T) {
|
||||
|
||||
func TestVerifyBeaconBlock_NoBlock(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, _ := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
|
||||
cfg := &Config{BeaconDB: db}
|
||||
service, err := NewService(ctx, cfg)
|
||||
@@ -295,7 +295,7 @@ func TestVerifyBeaconBlock_NoBlock(t *testing.T) {
|
||||
|
||||
func TestVerifyBeaconBlock_futureBlock(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, _ := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
|
||||
cfg := &Config{BeaconDB: db}
|
||||
service, err := NewService(ctx, cfg)
|
||||
@@ -313,7 +313,7 @@ func TestVerifyBeaconBlock_futureBlock(t *testing.T) {
|
||||
|
||||
func TestVerifyBeaconBlock_OK(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, _ := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
|
||||
cfg := &Config{BeaconDB: db}
|
||||
service, err := NewService(ctx, cfg)
|
||||
@@ -331,7 +331,7 @@ func TestVerifyBeaconBlock_OK(t *testing.T) {
|
||||
|
||||
func TestVerifyLMDFFGConsistent_NotOK(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, _ := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
|
||||
cfg := &Config{BeaconDB: db, ForkChoiceStore: protoarray.New(0, 0, [32]byte{})}
|
||||
service, err := NewService(ctx, cfg)
|
||||
@@ -355,7 +355,7 @@ func TestVerifyLMDFFGConsistent_NotOK(t *testing.T) {
|
||||
|
||||
func TestVerifyLMDFFGConsistent_OK(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, _ := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
|
||||
cfg := &Config{BeaconDB: db, ForkChoiceStore: protoarray.New(0, 0, [32]byte{})}
|
||||
service, err := NewService(ctx, cfg)
|
||||
@@ -379,7 +379,7 @@ func TestVerifyLMDFFGConsistent_OK(t *testing.T) {
|
||||
|
||||
func TestVerifyFinalizedConsistency_InconsistentRoot(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, _ := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
|
||||
cfg := &Config{BeaconDB: db, ForkChoiceStore: protoarray.New(0, 0, [32]byte{})}
|
||||
service, err := NewService(ctx, cfg)
|
||||
@@ -406,7 +406,7 @@ func TestVerifyFinalizedConsistency_InconsistentRoot(t *testing.T) {
|
||||
|
||||
func TestVerifyFinalizedConsistency_OK(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, _ := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
|
||||
cfg := &Config{BeaconDB: db, ForkChoiceStore: protoarray.New(0, 0, [32]byte{})}
|
||||
service, err := NewService(ctx, cfg)
|
||||
@@ -433,7 +433,7 @@ func TestVerifyFinalizedConsistency_OK(t *testing.T) {
|
||||
|
||||
func TestVerifyFinalizedConsistency_IsCanonical(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, _ := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
|
||||
cfg := &Config{BeaconDB: db, ForkChoiceStore: protoarray.New(0, 0, [32]byte{})}
|
||||
service, err := NewService(ctx, cfg)
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/state"
|
||||
stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state"
|
||||
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||
"github.com/prysmaticlabs/prysm/shared/attestationutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/bls"
|
||||
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
||||
@@ -303,7 +304,12 @@ func (s *Service) handleBlockAfterBatchVerify(ctx context.Context, signed *ethpb
|
||||
if err := s.insertBlockToForkChoiceStore(ctx, b, blockRoot, fCheckpoint, jCheckpoint); err != nil {
|
||||
return err
|
||||
}
|
||||
s.stateGen.SaveStateSummary(ctx, signed, blockRoot)
|
||||
if err := s.beaconDB.SaveStateSummary(ctx, &pb.StateSummary{
|
||||
Slot: signed.Block.Slot,
|
||||
Root: blockRoot[:],
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Rate limit how many blocks (2 epochs worth of blocks) a node keeps in the memory.
|
||||
if uint64(len(s.getInitSyncBlocks())) > initialSyncBlockCacheSize {
|
||||
|
||||
@@ -63,7 +63,7 @@ func (s *Service) verifyBlkPreState(ctx context.Context, b *ethpb.BeaconBlock) e
|
||||
// Loosen the check to HasBlock because state summary gets saved in batches
|
||||
// during initial syncing. There's no risk given a state summary object is just a
|
||||
// a subset of the block object.
|
||||
if !s.stateGen.StateSummaryExists(ctx, parentRoot) && !s.beaconDB.HasBlock(ctx, parentRoot) {
|
||||
if !s.beaconDB.HasStateSummary(ctx, parentRoot) && !s.beaconDB.HasBlock(ctx, parentRoot) {
|
||||
return errors.New("could not reconstruct parent state")
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
|
||||
"github.com/pkg/errors"
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/cache"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/state"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/db"
|
||||
@@ -28,11 +27,11 @@ import (
|
||||
|
||||
func TestStore_OnBlock(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, sc := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
|
||||
cfg := &Config{
|
||||
BeaconDB: db,
|
||||
StateGen: stategen.New(db, sc),
|
||||
StateGen: stategen.New(db),
|
||||
ForkChoiceStore: protoarray.New(0, 0, [32]byte{}),
|
||||
}
|
||||
service, err := NewService(ctx, cfg)
|
||||
@@ -123,11 +122,11 @@ func TestStore_OnBlock(t *testing.T) {
|
||||
|
||||
func TestStore_OnBlockBatch(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, sc := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
|
||||
cfg := &Config{
|
||||
BeaconDB: db,
|
||||
StateGen: stategen.New(db, sc),
|
||||
StateGen: stategen.New(db),
|
||||
}
|
||||
service, err := NewService(ctx, cfg)
|
||||
require.NoError(t, err)
|
||||
@@ -174,7 +173,7 @@ func TestStore_OnBlockBatch(t *testing.T) {
|
||||
|
||||
func TestRemoveStateSinceLastFinalized_EmptyStartSlot(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, _ := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
params.UseMinimalConfig()
|
||||
defer params.UseMainnetConfig()
|
||||
|
||||
@@ -208,7 +207,7 @@ func TestRemoveStateSinceLastFinalized_EmptyStartSlot(t *testing.T) {
|
||||
|
||||
func TestShouldUpdateJustified_ReturnFalse(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, _ := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
params.UseMinimalConfig()
|
||||
defer params.UseMainnetConfig()
|
||||
|
||||
@@ -237,11 +236,11 @@ func TestShouldUpdateJustified_ReturnFalse(t *testing.T) {
|
||||
|
||||
func TestCachedPreState_CanGetFromStateSummary(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, sc := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
|
||||
cfg := &Config{
|
||||
BeaconDB: db,
|
||||
StateGen: stategen.New(db, sc),
|
||||
StateGen: stategen.New(db),
|
||||
}
|
||||
service, err := NewService(ctx, cfg)
|
||||
require.NoError(t, err)
|
||||
@@ -270,11 +269,11 @@ func TestCachedPreState_CanGetFromStateSummary(t *testing.T) {
|
||||
|
||||
func TestCachedPreState_CanGetFromDB(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, sc := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
|
||||
cfg := &Config{
|
||||
BeaconDB: db,
|
||||
StateGen: stategen.New(db, sc),
|
||||
StateGen: stategen.New(db),
|
||||
}
|
||||
service, err := NewService(ctx, cfg)
|
||||
require.NoError(t, err)
|
||||
@@ -307,9 +306,9 @@ func TestCachedPreState_CanGetFromDB(t *testing.T) {
|
||||
|
||||
func TestUpdateJustified_CouldUpdateBest(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, _ := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
|
||||
cfg := &Config{BeaconDB: db, StateGen: stategen.New(db, cache.NewStateSummaryCache())}
|
||||
cfg := &Config{BeaconDB: db, StateGen: stategen.New(db)}
|
||||
service, err := NewService(ctx, cfg)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -338,7 +337,7 @@ func TestUpdateJustified_CouldUpdateBest(t *testing.T) {
|
||||
|
||||
func TestFillForkChoiceMissingBlocks_CanSave(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, _ := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
|
||||
cfg := &Config{BeaconDB: db}
|
||||
service, err := NewService(ctx, cfg)
|
||||
@@ -375,7 +374,7 @@ func TestFillForkChoiceMissingBlocks_CanSave(t *testing.T) {
|
||||
|
||||
func TestFillForkChoiceMissingBlocks_RootsMatch(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, _ := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
|
||||
cfg := &Config{BeaconDB: db}
|
||||
service, err := NewService(ctx, cfg)
|
||||
@@ -415,7 +414,7 @@ func TestFillForkChoiceMissingBlocks_RootsMatch(t *testing.T) {
|
||||
|
||||
func TestFillForkChoiceMissingBlocks_FilterFinalized(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, _ := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
|
||||
cfg := &Config{BeaconDB: db}
|
||||
service, err := NewService(ctx, cfg)
|
||||
@@ -568,7 +567,7 @@ func TestAncestorByDB_CtxErr(t *testing.T) {
|
||||
|
||||
func TestAncestor_HandleSkipSlot(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, _ := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
|
||||
cfg := &Config{BeaconDB: db, ForkChoiceStore: protoarray.New(0, 0, [32]byte{})}
|
||||
service, err := NewService(ctx, cfg)
|
||||
@@ -650,7 +649,7 @@ func TestAncestor_CanUseForkchoice(t *testing.T) {
|
||||
|
||||
func TestAncestor_CanUseDB(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, _ := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
|
||||
cfg := &Config{BeaconDB: db, ForkChoiceStore: protoarray.New(0, 0, [32]byte{})}
|
||||
service, err := NewService(ctx, cfg)
|
||||
@@ -702,7 +701,7 @@ func TestEnsureRootNotZeroHashes(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestFinalizedImpliesNewJustified(t *testing.T) {
|
||||
db, sc := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
type args struct {
|
||||
cachedCheckPoint *ethpb.Checkpoint
|
||||
@@ -743,7 +742,7 @@ func TestFinalizedImpliesNewJustified(t *testing.T) {
|
||||
for _, test := range tests {
|
||||
beaconState := testutil.NewBeaconState()
|
||||
require.NoError(t, beaconState.SetCurrentJustifiedCheckpoint(test.args.stateCheckPoint))
|
||||
service, err := NewService(ctx, &Config{BeaconDB: db, StateGen: stategen.New(db, sc), ForkChoiceStore: protoarray.New(0, 0, [32]byte{})})
|
||||
service, err := NewService(ctx, &Config{BeaconDB: db, StateGen: stategen.New(db), ForkChoiceStore: protoarray.New(0, 0, [32]byte{})})
|
||||
require.NoError(t, err)
|
||||
service.justifiedCheckpt = test.args.cachedCheckPoint
|
||||
require.NoError(t, service.beaconDB.SaveStateSummary(ctx, &pb.StateSummary{Root: bytesutil.PadTo(test.want.Root, 32)}))
|
||||
@@ -777,7 +776,7 @@ func TestFinalizedImpliesNewJustified(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestVerifyBlkDescendant(t *testing.T) {
|
||||
db, sc := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
b := testutil.NewBeaconBlock()
|
||||
@@ -834,7 +833,7 @@ func TestVerifyBlkDescendant(t *testing.T) {
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
service, err := NewService(ctx, &Config{BeaconDB: db, StateGen: stategen.New(db, sc), ForkChoiceStore: protoarray.New(0, 0, [32]byte{})})
|
||||
service, err := NewService(ctx, &Config{BeaconDB: db, StateGen: stategen.New(db), ForkChoiceStore: protoarray.New(0, 0, [32]byte{})})
|
||||
require.NoError(t, err)
|
||||
service.finalizedCheckpt = ðpb.Checkpoint{
|
||||
Root: tt.args.finalizedRoot[:],
|
||||
@@ -849,7 +848,7 @@ func TestVerifyBlkDescendant(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUpdateJustifiedInitSync(t *testing.T) {
|
||||
db, _ := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
cfg := &Config{BeaconDB: db}
|
||||
service, err := NewService(ctx, cfg)
|
||||
|
||||
@@ -125,7 +125,7 @@ func (s *Service) processAttestation(subscribedToStateEvents chan struct{}) {
|
||||
continue
|
||||
}
|
||||
|
||||
hasState := s.stateGen.StateSummaryExists(ctx, bytesutil.ToBytes32(a.Data.BeaconBlockRoot))
|
||||
hasState := s.beaconDB.HasStateSummary(ctx, bytesutil.ToBytes32(a.Data.BeaconBlockRoot))
|
||||
hasBlock := s.hasBlock(ctx, bytesutil.ToBytes32(a.Data.BeaconBlockRoot))
|
||||
if !(hasState && hasBlock) {
|
||||
continue
|
||||
|
||||
@@ -14,9 +14,9 @@ import (
|
||||
|
||||
func TestAttestationCheckPtState_FarFutureSlot(t *testing.T) {
|
||||
helpers.ClearCache()
|
||||
db, sc := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
|
||||
chainService := setupBeaconChain(t, db, sc)
|
||||
chainService := setupBeaconChain(t, db)
|
||||
chainService.genesisTime = time.Now()
|
||||
|
||||
e := helpers.MaxSlotBuffer/params.BeaconConfig().SlotsPerEpoch + 1
|
||||
|
||||
@@ -117,7 +117,7 @@ func TestService_ReceiveBlock(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
db, stateSummaryCache := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
genesisBlockRoot := bytesutil.ToBytes32(nil)
|
||||
require.NoError(t, db.SaveState(ctx, genesis, genesisBlockRoot))
|
||||
|
||||
@@ -131,7 +131,7 @@ func TestService_ReceiveBlock(t *testing.T) {
|
||||
AttPool: attestations.NewPool(),
|
||||
ExitPool: voluntaryexits.NewPool(),
|
||||
StateNotifier: &blockchainTesting.MockStateNotifier{RecordEvents: true},
|
||||
StateGen: stategen.New(db, stateSummaryCache),
|
||||
StateGen: stategen.New(db),
|
||||
}
|
||||
s, err := NewService(ctx, cfg)
|
||||
require.NoError(t, err)
|
||||
@@ -159,7 +159,7 @@ func TestService_ReceiveBlockUpdateHead(t *testing.T) {
|
||||
genesis, keys := testutil.DeterministicGenesisState(t, 64)
|
||||
b, err := testutil.GenerateFullBlock(genesis, keys, testutil.DefaultBlockGenConfig(), 1)
|
||||
assert.NoError(t, err)
|
||||
db, stateSummaryCache := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
genesisBlockRoot := bytesutil.ToBytes32(nil)
|
||||
require.NoError(t, db.SaveState(ctx, genesis, genesisBlockRoot))
|
||||
cfg := &Config{
|
||||
@@ -172,7 +172,7 @@ func TestService_ReceiveBlockUpdateHead(t *testing.T) {
|
||||
AttPool: attestations.NewPool(),
|
||||
ExitPool: voluntaryexits.NewPool(),
|
||||
StateNotifier: &blockchainTesting.MockStateNotifier{RecordEvents: true},
|
||||
StateGen: stategen.New(db, stateSummaryCache),
|
||||
StateGen: stategen.New(db),
|
||||
}
|
||||
s, err := NewService(ctx, cfg)
|
||||
require.NoError(t, err)
|
||||
@@ -242,7 +242,7 @@ func TestService_ReceiveBlockInitialSync(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
db, stateSummaryCache := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
genesisBlockRoot := bytesutil.ToBytes32(nil)
|
||||
|
||||
cfg := &Config{
|
||||
@@ -253,7 +253,7 @@ func TestService_ReceiveBlockInitialSync(t *testing.T) {
|
||||
genesisBlockRoot,
|
||||
),
|
||||
StateNotifier: &blockchainTesting.MockStateNotifier{RecordEvents: true},
|
||||
StateGen: stategen.New(db, stateSummaryCache),
|
||||
StateGen: stategen.New(db),
|
||||
}
|
||||
s, err := NewService(ctx, cfg)
|
||||
require.NoError(t, err)
|
||||
@@ -323,7 +323,7 @@ func TestService_ReceiveBlockBatch(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
db, stateSummaryCache := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
genesisBlockRoot, err := genesis.HashTreeRoot(ctx)
|
||||
require.NoError(t, err)
|
||||
cfg := &Config{
|
||||
@@ -334,7 +334,7 @@ func TestService_ReceiveBlockBatch(t *testing.T) {
|
||||
genesisBlockRoot,
|
||||
),
|
||||
StateNotifier: &blockchainTesting.MockStateNotifier{RecordEvents: true},
|
||||
StateGen: stategen.New(db, stateSummaryCache),
|
||||
StateGen: stategen.New(db),
|
||||
}
|
||||
s, err := NewService(ctx, cfg)
|
||||
require.NoError(t, err)
|
||||
@@ -375,9 +375,9 @@ func TestService_HasInitSyncBlock(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCheckSaveHotStateDB_Enabling(t *testing.T) {
|
||||
db, stateSummaryCache := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
hook := logTest.NewGlobal()
|
||||
s, err := NewService(context.Background(), &Config{StateGen: stategen.New(db, stateSummaryCache)})
|
||||
s, err := NewService(context.Background(), &Config{StateGen: stategen.New(db)})
|
||||
require.NoError(t, err)
|
||||
st := params.BeaconConfig().SlotsPerEpoch * uint64(epochsSinceFinalitySaveHotStateDB)
|
||||
s.genesisTime = time.Now().Add(time.Duration(-1*int64(st)*int64(params.BeaconConfig().SecondsPerSlot)) * time.Second)
|
||||
@@ -388,9 +388,9 @@ func TestCheckSaveHotStateDB_Enabling(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCheckSaveHotStateDB_Disabling(t *testing.T) {
|
||||
db, stateSummaryCache := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
hook := logTest.NewGlobal()
|
||||
s, err := NewService(context.Background(), &Config{StateGen: stategen.New(db, stateSummaryCache)})
|
||||
s, err := NewService(context.Background(), &Config{StateGen: stategen.New(db)})
|
||||
require.NoError(t, err)
|
||||
s.finalizedCheckpt = ðpb.Checkpoint{}
|
||||
require.NoError(t, s.checkSaveHotStateDB(context.Background()))
|
||||
@@ -401,9 +401,9 @@ func TestCheckSaveHotStateDB_Disabling(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCheckSaveHotStateDB_Overflow(t *testing.T) {
|
||||
db, stateSummaryCache := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
hook := logTest.NewGlobal()
|
||||
s, err := NewService(context.Background(), &Config{StateGen: stategen.New(db, stateSummaryCache)})
|
||||
s, err := NewService(context.Background(), &Config{StateGen: stategen.New(db)})
|
||||
require.NoError(t, err)
|
||||
s.finalizedCheckpt = ðpb.Checkpoint{Epoch: 10000000}
|
||||
s.genesisTime = time.Now()
|
||||
|
||||
@@ -342,11 +342,6 @@ func (s *Service) Stop() error {
|
||||
}
|
||||
}
|
||||
|
||||
// Save cached state summaries to the DB before stop.
|
||||
if err := s.stateGen.SaveStateSummariesToDB(s.ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Save initial sync cached blocks to the DB before stop.
|
||||
return s.beaconDB.SaveBlocks(s.ctx, s.getInitSyncBlocks())
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ func init() {
|
||||
}
|
||||
|
||||
func TestChainService_SaveHead_DataRace(t *testing.T) {
|
||||
db, _ := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
s := &Service{
|
||||
beaconDB: db,
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/gogo/protobuf/proto"
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/cache"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/cache/depositcache"
|
||||
b "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
||||
@@ -63,7 +62,7 @@ func (mb *mockBroadcaster) BroadcastAttestation(_ context.Context, _ uint64, _ *
|
||||
|
||||
var _ p2p.Broadcaster = (*mockBroadcaster)(nil)
|
||||
|
||||
func setupBeaconChain(t *testing.T, beaconDB db.Database, sc *cache.StateSummaryCache) *Service {
|
||||
func setupBeaconChain(t *testing.T, beaconDB db.Database) *Service {
|
||||
endpoint := "http://127.0.0.1"
|
||||
ctx := context.Background()
|
||||
var web3Service *powchain.Service
|
||||
@@ -106,7 +105,7 @@ func setupBeaconChain(t *testing.T, beaconDB db.Database, sc *cache.StateSummary
|
||||
P2p: &mockBroadcaster{},
|
||||
StateNotifier: &mockBeaconNode{},
|
||||
AttPool: attestations.NewPool(),
|
||||
StateGen: stategen.New(beaconDB, sc),
|
||||
StateGen: stategen.New(beaconDB),
|
||||
ForkChoiceStore: protoarray.New(0, 0, params.BeaconConfig().ZeroHash),
|
||||
OpsService: opsService,
|
||||
}
|
||||
@@ -124,9 +123,9 @@ func setupBeaconChain(t *testing.T, beaconDB db.Database, sc *cache.StateSummary
|
||||
func TestChainStartStop_Initialized(t *testing.T) {
|
||||
hook := logTest.NewGlobal()
|
||||
ctx := context.Background()
|
||||
db, sc := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
|
||||
chainService := setupBeaconChain(t, db, sc)
|
||||
chainService := setupBeaconChain(t, db)
|
||||
|
||||
genesisBlk := testutil.NewBeaconBlock()
|
||||
blkRoot, err := genesisBlk.Block.HashTreeRoot()
|
||||
@@ -153,9 +152,9 @@ func TestChainStartStop_Initialized(t *testing.T) {
|
||||
func TestChainStartStop_GenesisZeroHashes(t *testing.T) {
|
||||
hook := logTest.NewGlobal()
|
||||
ctx := context.Background()
|
||||
db, sc := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
|
||||
chainService := setupBeaconChain(t, db, sc)
|
||||
chainService := setupBeaconChain(t, db)
|
||||
|
||||
genesisBlk := testutil.NewBeaconBlock()
|
||||
blkRoot, err := genesisBlk.Block.HashTreeRoot()
|
||||
@@ -178,10 +177,10 @@ func TestChainStartStop_GenesisZeroHashes(t *testing.T) {
|
||||
|
||||
func TestChainService_InitializeBeaconChain(t *testing.T) {
|
||||
helpers.ClearCache()
|
||||
db, sc := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
bc := setupBeaconChain(t, db, sc)
|
||||
bc := setupBeaconChain(t, db)
|
||||
var err error
|
||||
|
||||
// Set up 10 deposits pre chain start for validators to register
|
||||
@@ -221,9 +220,9 @@ func TestChainService_InitializeBeaconChain(t *testing.T) {
|
||||
|
||||
func TestChainService_CorrectGenesisRoots(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, sc := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
|
||||
chainService := setupBeaconChain(t, db, sc)
|
||||
chainService := setupBeaconChain(t, db)
|
||||
|
||||
genesisBlk := testutil.NewBeaconBlock()
|
||||
blkRoot, err := genesisBlk.Block.HashTreeRoot()
|
||||
@@ -247,7 +246,7 @@ func TestChainService_CorrectGenesisRoots(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestChainService_InitializeChainInfo(t *testing.T) {
|
||||
db, sc := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
genesis := testutil.NewBeaconBlock()
|
||||
@@ -269,7 +268,7 @@ func TestChainService_InitializeChainInfo(t *testing.T) {
|
||||
require.NoError(t, db.SaveState(ctx, headState, genesisRoot))
|
||||
require.NoError(t, db.SaveBlock(ctx, headBlock))
|
||||
require.NoError(t, db.SaveFinalizedCheckpoint(ctx, ðpb.Checkpoint{Epoch: helpers.SlotToEpoch(finalizedSlot), Root: headRoot[:]}))
|
||||
c := &Service{beaconDB: db, stateGen: stategen.New(db, sc)}
|
||||
c := &Service{beaconDB: db, stateGen: stategen.New(db)}
|
||||
require.NoError(t, c.initializeChainInfo(ctx))
|
||||
headBlk, err := c.HeadBlock(ctx)
|
||||
require.NoError(t, err)
|
||||
@@ -287,7 +286,7 @@ func TestChainService_InitializeChainInfo(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestChainService_InitializeChainInfo_SetHeadAtGenesis(t *testing.T) {
|
||||
db, sc := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
genesis := testutil.NewBeaconBlock()
|
||||
@@ -308,7 +307,7 @@ func TestChainService_InitializeChainInfo_SetHeadAtGenesis(t *testing.T) {
|
||||
require.NoError(t, db.SaveState(ctx, headState, headRoot))
|
||||
require.NoError(t, db.SaveState(ctx, headState, genesisRoot))
|
||||
require.NoError(t, db.SaveBlock(ctx, headBlock))
|
||||
c := &Service{beaconDB: db, stateGen: stategen.New(db, sc)}
|
||||
c := &Service{beaconDB: db, stateGen: stategen.New(db)}
|
||||
require.NoError(t, c.initializeChainInfo(ctx))
|
||||
s, err := c.HeadState(ctx)
|
||||
require.NoError(t, err)
|
||||
@@ -328,7 +327,7 @@ func TestChainService_InitializeChainInfo_HeadSync(t *testing.T) {
|
||||
|
||||
hook := logTest.NewGlobal()
|
||||
finalizedSlot := params.BeaconConfig().SlotsPerEpoch*2 + 1
|
||||
db, sc := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
genesisBlock := testutil.NewBeaconBlock()
|
||||
@@ -364,7 +363,7 @@ func TestChainService_InitializeChainInfo_HeadSync(t *testing.T) {
|
||||
Root: finalizedRoot[:],
|
||||
}))
|
||||
|
||||
c := &Service{beaconDB: db, stateGen: stategen.New(db, sc)}
|
||||
c := &Service{beaconDB: db, stateGen: stategen.New(db)}
|
||||
|
||||
require.NoError(t, c.initializeChainInfo(ctx))
|
||||
s, err := c.HeadState(ctx)
|
||||
@@ -399,11 +398,11 @@ func TestChainService_InitializeChainInfo_HeadSync(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestChainService_SaveHeadNoDB(t *testing.T) {
|
||||
db, sc := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
s := &Service{
|
||||
beaconDB: db,
|
||||
stateGen: stategen.New(db, sc),
|
||||
stateGen: stategen.New(db),
|
||||
}
|
||||
b := testutil.NewBeaconBlock()
|
||||
b.Block.Slot = 1
|
||||
@@ -422,7 +421,7 @@ func TestChainService_SaveHeadNoDB(t *testing.T) {
|
||||
|
||||
func TestHasBlock_ForkChoiceAndDB(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, _ := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
s := &Service{
|
||||
forkChoiceStore: protoarray.New(0, 0, [32]byte{}),
|
||||
finalizedCheckpt: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
@@ -440,13 +439,13 @@ func TestHasBlock_ForkChoiceAndDB(t *testing.T) {
|
||||
|
||||
func TestServiceStop_SaveCachedBlocks(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
db, _ := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
s := &Service{
|
||||
ctx: ctx,
|
||||
cancel: cancel,
|
||||
beaconDB: db,
|
||||
initSyncBlocks: make(map[[32]byte]*ethpb.SignedBeaconBlock),
|
||||
stateGen: stategen.New(db, cache.NewStateSummaryCache()),
|
||||
stateGen: stategen.New(db),
|
||||
}
|
||||
b := testutil.NewBeaconBlock()
|
||||
r, err := b.Block.HashTreeRoot()
|
||||
@@ -456,27 +455,8 @@ func TestServiceStop_SaveCachedBlocks(t *testing.T) {
|
||||
require.Equal(t, true, s.beaconDB.HasBlock(ctx, r))
|
||||
}
|
||||
|
||||
func TestServiceStop_SaveCachedStateSummaries(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
db, _ := testDB.SetupDB(t)
|
||||
c := cache.NewStateSummaryCache()
|
||||
s := &Service{
|
||||
ctx: ctx,
|
||||
cancel: cancel,
|
||||
beaconDB: db,
|
||||
initSyncBlocks: make(map[[32]byte]*ethpb.SignedBeaconBlock),
|
||||
stateGen: stategen.New(db, c),
|
||||
}
|
||||
|
||||
r := [32]byte{'a'}
|
||||
ss := &pb.StateSummary{Root: r[:], Slot: 1}
|
||||
c.Put(r, ss)
|
||||
require.NoError(t, s.Stop())
|
||||
require.Equal(t, true, s.beaconDB.HasStateSummary(ctx, r))
|
||||
}
|
||||
|
||||
func BenchmarkHasBlockDB(b *testing.B) {
|
||||
db, _ := testDB.SetupDB(b)
|
||||
db := testDB.SetupDB(b)
|
||||
ctx := context.Background()
|
||||
s := &Service{
|
||||
beaconDB: db,
|
||||
@@ -494,7 +474,7 @@ func BenchmarkHasBlockDB(b *testing.B) {
|
||||
|
||||
func BenchmarkHasBlockForkChoiceStore(b *testing.B) {
|
||||
ctx := context.Background()
|
||||
db, _ := testDB.SetupDB(b)
|
||||
db := testDB.SetupDB(b)
|
||||
s := &Service{
|
||||
forkChoiceStore: protoarray.New(0, 0, [32]byte{}),
|
||||
finalizedCheckpt: ðpb.Checkpoint{Root: make([]byte, 32)},
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
)
|
||||
|
||||
func TestService_VerifyWeakSubjectivityRoot(t *testing.T) {
|
||||
db, _ := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
|
||||
b := testutil.NewBeaconBlock()
|
||||
b.Block.Slot = 32
|
||||
|
||||
1
beacon-chain/cache/BUILD.bazel
vendored
1
beacon-chain/cache/BUILD.bazel
vendored
@@ -13,7 +13,6 @@ go_library(
|
||||
"doc.go",
|
||||
"hot_state_cache.go",
|
||||
"skip_slot_cache.go",
|
||||
"state_summary.go",
|
||||
"subnet_ids.go",
|
||||
"proposer_indices_type.go",
|
||||
] + select({
|
||||
|
||||
@@ -5,11 +5,10 @@ package db
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/cache"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/db/kv"
|
||||
)
|
||||
|
||||
// NewDB initializes a new DB.
|
||||
func NewDB(ctx context.Context, dirPath string, stateSummaryCache *cache.StateSummaryCache) (Database, error) {
|
||||
return kv.NewKVStore(ctx, dirPath, stateSummaryCache)
|
||||
func NewDB(ctx context.Context, dirPath string) (Database, error) {
|
||||
return kv.NewKVStore(ctx, dirPath)
|
||||
}
|
||||
|
||||
@@ -3,13 +3,12 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/cache"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/db/kafka"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/db/kv"
|
||||
)
|
||||
|
||||
// NewDB initializes a new DB with kafka wrapper.
|
||||
func NewDB(dirPath string, stateSummaryCache *cache.StateSummaryCache) (Database, error) {
|
||||
func NewDB(dirPath string, stateSummaryCache *kv.stateSummaryCache) (Database, error) {
|
||||
db, err := kv.NewKVStore(dirPath, stateSummaryCache)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -21,12 +21,12 @@ go_library(
|
||||
"slashings.go",
|
||||
"state.go",
|
||||
"state_summary.go",
|
||||
"state_summary_cache.go",
|
||||
"utils.go",
|
||||
],
|
||||
importpath = "github.com/prysmaticlabs/prysm/beacon-chain/db/kv",
|
||||
visibility = ["//beacon-chain:__subpackages__"],
|
||||
deps = [
|
||||
"//beacon-chain/cache:go_default_library",
|
||||
"//beacon-chain/core/helpers:go_default_library",
|
||||
"//beacon-chain/db/filters:go_default_library",
|
||||
"//beacon-chain/db/iface:go_default_library",
|
||||
@@ -75,7 +75,6 @@ go_test(
|
||||
],
|
||||
embed = [":go_default_library"],
|
||||
deps = [
|
||||
"//beacon-chain/cache:go_default_library",
|
||||
"//beacon-chain/db/filters:go_default_library",
|
||||
"//beacon-chain/state:go_default_library",
|
||||
"//proto/beacon/db:go_default_library",
|
||||
|
||||
@@ -12,7 +12,8 @@ import (
|
||||
)
|
||||
|
||||
func TestStore_Backup(t *testing.T) {
|
||||
db := setupDB(t)
|
||||
db, err := NewKVStore(context.Background(), t.TempDir())
|
||||
require.NoError(t, err, "Failed to instantiate DB")
|
||||
ctx := context.Background()
|
||||
|
||||
head := testutil.NewBeaconBlock()
|
||||
@@ -39,7 +40,7 @@ func TestStore_Backup(t *testing.T) {
|
||||
// our NewKVStore function expects when opening a database.
|
||||
require.NoError(t, os.Rename(oldFilePath, newFilePath))
|
||||
|
||||
backedDB, err := NewKVStore(ctx, backupsPath, nil)
|
||||
backedDB, err := NewKVStore(ctx, backupsPath)
|
||||
require.NoError(t, err, "Failed to instantiate DB")
|
||||
t.Cleanup(func() {
|
||||
require.NoError(t, backedDB.Close(), "Failed to close database")
|
||||
|
||||
@@ -240,10 +240,9 @@ func (s *Store) SaveHeadBlockRoot(ctx context.Context, blockRoot [32]byte) error
|
||||
ctx, span := trace.StartSpan(ctx, "BeaconDB.SaveHeadBlockRoot")
|
||||
defer span.End()
|
||||
return s.db.Update(func(tx *bolt.Tx) error {
|
||||
hasStateSummaryInCache := s.stateSummaryCache.Has(blockRoot)
|
||||
hasStateSummaryInDB := tx.Bucket(stateSummaryBucket).Get(blockRoot[:]) != nil
|
||||
hasStateSummaryInDB := s.HasStateSummary(ctx, blockRoot)
|
||||
hasStateInDB := tx.Bucket(stateBucket).Get(blockRoot[:]) != nil
|
||||
if !(hasStateInDB || hasStateSummaryInDB || hasStateSummaryInCache) {
|
||||
if !(hasStateInDB || hasStateSummaryInDB) {
|
||||
return errors.New("no state or state summary found with head block root")
|
||||
}
|
||||
|
||||
|
||||
@@ -60,10 +60,9 @@ func (s *Store) SaveJustifiedCheckpoint(ctx context.Context, checkpoint *ethpb.C
|
||||
}
|
||||
return s.db.Update(func(tx *bolt.Tx) error {
|
||||
bucket := tx.Bucket(checkpointBucket)
|
||||
hasStateSummaryInDB := tx.Bucket(stateSummaryBucket).Get(checkpoint.Root) != nil
|
||||
hasStateSummaryInCache := s.stateSummaryCache.Has(bytesutil.ToBytes32(checkpoint.Root))
|
||||
hasStateSummaryInDB := s.HasStateSummary(ctx, bytesutil.ToBytes32(checkpoint.Root))
|
||||
hasStateInDB := tx.Bucket(stateBucket).Get(checkpoint.Root) != nil
|
||||
if !(hasStateInDB || hasStateSummaryInDB || hasStateSummaryInCache) {
|
||||
if !(hasStateInDB || hasStateSummaryInDB) {
|
||||
return errMissingStateForCheckpoint
|
||||
}
|
||||
return bucket.Put(justifiedCheckpointKey, enc)
|
||||
@@ -81,10 +80,9 @@ func (s *Store) SaveFinalizedCheckpoint(ctx context.Context, checkpoint *ethpb.C
|
||||
}
|
||||
return s.db.Update(func(tx *bolt.Tx) error {
|
||||
bucket := tx.Bucket(checkpointBucket)
|
||||
hasStateSummaryInDB := tx.Bucket(stateSummaryBucket).Get(checkpoint.Root) != nil
|
||||
hasStateSummaryInCache := s.stateSummaryCache.Has(bytesutil.ToBytes32(checkpoint.Root))
|
||||
hasStateSummaryInDB := s.HasStateSummary(ctx, bytesutil.ToBytes32(checkpoint.Root))
|
||||
hasStateInDB := tx.Bucket(stateBucket).Get(checkpoint.Root) != nil
|
||||
if !(hasStateInDB || hasStateSummaryInDB || hasStateSummaryInCache) {
|
||||
if !(hasStateInDB || hasStateSummaryInDB) {
|
||||
return errMissingStateForCheckpoint
|
||||
}
|
||||
if err := bucket.Put(finalizedCheckpointKey, enc); err != nil {
|
||||
|
||||
@@ -12,7 +12,6 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
prombolt "github.com/prysmaticlabs/prombbolt"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/cache"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/db/iface"
|
||||
"github.com/prysmaticlabs/prysm/shared/fileutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
@@ -45,14 +44,14 @@ type Store struct {
|
||||
databasePath string
|
||||
blockCache *ristretto.Cache
|
||||
validatorIndexCache *ristretto.Cache
|
||||
stateSummaryCache *cache.StateSummaryCache
|
||||
stateSummaryCache *stateSummaryCache
|
||||
ctx context.Context
|
||||
}
|
||||
|
||||
// NewKVStore initializes a new boltDB key-value store at the directory
|
||||
// path specified, creates the kv-buckets based on the schema, and stores
|
||||
// an open connection db object as a property of the Store struct.
|
||||
func NewKVStore(ctx context.Context, dirPath string, stateSummaryCache *cache.StateSummaryCache) (*Store, error) {
|
||||
func NewKVStore(ctx context.Context, dirPath string) (*Store, error) {
|
||||
hasDir, err := fileutil.HasDir(dirPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -94,7 +93,7 @@ func NewKVStore(ctx context.Context, dirPath string, stateSummaryCache *cache.St
|
||||
databasePath: dirPath,
|
||||
blockCache: blockCache,
|
||||
validatorIndexCache: validatorCache,
|
||||
stateSummaryCache: stateSummaryCache,
|
||||
stateSummaryCache: newStateSummaryCache(),
|
||||
ctx: ctx,
|
||||
}
|
||||
|
||||
@@ -150,6 +149,12 @@ func (s *Store) ClearDB() error {
|
||||
// Close closes the underlying BoltDB database.
|
||||
func (s *Store) Close() error {
|
||||
prometheus.Unregister(createBoltCollector(s.db))
|
||||
|
||||
// Before DB closes, we should dump the cached state summary objects to DB.
|
||||
if err := s.saveCachedStateSummariesDB(s.ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return s.db.Close()
|
||||
}
|
||||
|
||||
|
||||
@@ -4,13 +4,12 @@ import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/cache"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
||||
)
|
||||
|
||||
// setupDB instantiates and returns a Store instance.
|
||||
func setupDB(t testing.TB) *Store {
|
||||
db, err := NewKVStore(context.Background(), t.TempDir(), cache.NewStateSummaryCache())
|
||||
db, err := NewKVStore(context.Background(), t.TempDir())
|
||||
require.NoError(t, err, "Failed to instantiate DB")
|
||||
t.Cleanup(func() {
|
||||
require.NoError(t, db.Close(), "Failed to close database")
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
|
||||
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
||||
bolt "go.etcd.io/bbolt"
|
||||
"go.opencensus.io/trace"
|
||||
)
|
||||
@@ -21,25 +22,30 @@ func (s *Store) SaveStateSummaries(ctx context.Context, summaries []*pb.StateSum
|
||||
ctx, span := trace.StartSpan(ctx, "BeaconDB.SaveStateSummaries")
|
||||
defer span.End()
|
||||
|
||||
return s.db.Update(func(tx *bolt.Tx) error {
|
||||
bucket := tx.Bucket(stateSummaryBucket)
|
||||
for _, summary := range summaries {
|
||||
enc, err := encode(ctx, summary)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := bucket.Put(summary.Root, enc); err != nil {
|
||||
return err
|
||||
}
|
||||
// When we reach the state summary cache prune count,
|
||||
// dump the cached state summaries to the DB.
|
||||
if s.stateSummaryCache.len() >= stateSummaryCachePruneCount {
|
||||
if err := s.saveCachedStateSummariesDB(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
for _, ss := range summaries {
|
||||
s.stateSummaryCache.put(bytesutil.ToBytes32(ss.Root), ss)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// StateSummary returns the state summary object from the db using input block root.
|
||||
func (s *Store) StateSummary(ctx context.Context, blockRoot [32]byte) (*pb.StateSummary, error) {
|
||||
ctx, span := trace.StartSpan(ctx, "BeaconDB.StateSummary")
|
||||
defer span.End()
|
||||
|
||||
if s.stateSummaryCache.has(blockRoot) {
|
||||
return s.stateSummaryCache.get(blockRoot), nil
|
||||
}
|
||||
|
||||
enc, err := s.stateSummaryBytes(ctx, blockRoot)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -58,6 +64,11 @@ func (s *Store) StateSummary(ctx context.Context, blockRoot [32]byte) (*pb.State
|
||||
func (s *Store) HasStateSummary(ctx context.Context, blockRoot [32]byte) bool {
|
||||
ctx, span := trace.StartSpan(ctx, "BeaconDB.HasStateSummary")
|
||||
defer span.End()
|
||||
|
||||
if s.stateSummaryCache.has(blockRoot) {
|
||||
return true
|
||||
}
|
||||
|
||||
enc, err := s.stateSummaryBytes(ctx, blockRoot)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -78,3 +89,29 @@ func (s *Store) stateSummaryBytes(ctx context.Context, blockRoot [32]byte) ([]by
|
||||
|
||||
return enc, err
|
||||
}
|
||||
|
||||
// This saves all cached state summary objects to DB, and clears up the cache.
|
||||
func (s *Store) saveCachedStateSummariesDB(ctx context.Context) error {
|
||||
summaries := s.stateSummaryCache.getAll()
|
||||
encs := make([][]byte, len(summaries))
|
||||
for i, s := range summaries {
|
||||
enc, err := encode(ctx, s)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
encs[i] = enc
|
||||
}
|
||||
if err := s.db.Update(func(tx *bolt.Tx) error {
|
||||
bucket := tx.Bucket(stateSummaryBucket)
|
||||
for i, s := range summaries {
|
||||
if err := bucket.Put(s.Root, encs[i]); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
s.stateSummaryCache.clear()
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package cache
|
||||
package kv
|
||||
|
||||
import (
|
||||
"sync"
|
||||
@@ -6,47 +6,56 @@ import (
|
||||
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||
)
|
||||
|
||||
// StateSummaryCache caches state summary object.
|
||||
type StateSummaryCache struct {
|
||||
const stateSummaryCachePruneCount = 128
|
||||
|
||||
// stateSummaryCache caches state summary object.
|
||||
type stateSummaryCache struct {
|
||||
initSyncStateSummaries map[[32]byte]*pb.StateSummary
|
||||
initSyncStateSummariesLock sync.RWMutex
|
||||
}
|
||||
|
||||
// NewStateSummaryCache creates a new state summary cache.
|
||||
func NewStateSummaryCache() *StateSummaryCache {
|
||||
return &StateSummaryCache{
|
||||
// newStateSummaryCache creates a new state summary cache.
|
||||
func newStateSummaryCache() *stateSummaryCache {
|
||||
return &stateSummaryCache{
|
||||
initSyncStateSummaries: make(map[[32]byte]*pb.StateSummary),
|
||||
}
|
||||
}
|
||||
|
||||
// Put saves a state summary to the initial sync state summaries cache.
|
||||
func (s *StateSummaryCache) Put(r [32]byte, b *pb.StateSummary) {
|
||||
// put saves a state summary to the initial sync state summaries cache.
|
||||
func (s *stateSummaryCache) put(r [32]byte, b *pb.StateSummary) {
|
||||
s.initSyncStateSummariesLock.Lock()
|
||||
defer s.initSyncStateSummariesLock.Unlock()
|
||||
s.initSyncStateSummaries[r] = b
|
||||
}
|
||||
|
||||
// Has checks if a state summary exists in the initial sync state summaries cache using the root
|
||||
// has checks if a state summary exists in the initial sync state summaries cache using the root
|
||||
// of the block.
|
||||
func (s *StateSummaryCache) Has(r [32]byte) bool {
|
||||
func (s *stateSummaryCache) has(r [32]byte) bool {
|
||||
s.initSyncStateSummariesLock.RLock()
|
||||
defer s.initSyncStateSummariesLock.RUnlock()
|
||||
_, ok := s.initSyncStateSummaries[r]
|
||||
return ok
|
||||
}
|
||||
|
||||
// Get retrieves a state summary from the initial sync state summaries cache using the root of
|
||||
// get retrieves a state summary from the initial sync state summaries cache using the root of
|
||||
// the block.
|
||||
func (s *StateSummaryCache) Get(r [32]byte) *pb.StateSummary {
|
||||
func (s *stateSummaryCache) get(r [32]byte) *pb.StateSummary {
|
||||
s.initSyncStateSummariesLock.RLock()
|
||||
defer s.initSyncStateSummariesLock.RUnlock()
|
||||
b := s.initSyncStateSummaries[r]
|
||||
return b
|
||||
}
|
||||
|
||||
// len retrieves the state summary count from the state summaries cache.
|
||||
func (s *stateSummaryCache) len() int {
|
||||
s.initSyncStateSummariesLock.RLock()
|
||||
defer s.initSyncStateSummariesLock.RUnlock()
|
||||
return len(s.initSyncStateSummaries)
|
||||
}
|
||||
|
||||
// GetAll retrieves all the beacon state summaries from the initial sync state summaries cache, the returned
|
||||
// state summaries are unordered.
|
||||
func (s *StateSummaryCache) GetAll() []*pb.StateSummary {
|
||||
func (s *stateSummaryCache) getAll() []*pb.StateSummary {
|
||||
s.initSyncStateSummariesLock.RLock()
|
||||
defer s.initSyncStateSummariesLock.RUnlock()
|
||||
|
||||
@@ -58,7 +67,7 @@ func (s *StateSummaryCache) GetAll() []*pb.StateSummary {
|
||||
}
|
||||
|
||||
// Clear clears out the initial sync state summaries cache.
|
||||
func (s *StateSummaryCache) Clear() {
|
||||
func (s *stateSummaryCache) clear() {
|
||||
s.initSyncStateSummariesLock.Lock()
|
||||
defer s.initSyncStateSummariesLock.Unlock()
|
||||
s.initSyncStateSummaries = make(map[[32]byte]*pb.StateSummary)
|
||||
@@ -38,3 +38,26 @@ func TestStateSummary_CanSaveRretrieve(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
assert.DeepEqual(t, s2, saved, "State summary does not equal")
|
||||
}
|
||||
|
||||
func TestStateSummary_CacheToDB(t *testing.T) {
|
||||
db := setupDB(t)
|
||||
|
||||
summaries := make([]*pb.StateSummary, stateSummaryCachePruneCount-1)
|
||||
for i := range summaries {
|
||||
summaries[i] = &pb.StateSummary{Slot: uint64(i), Root: bytesutil.PadTo(bytesutil.Uint64ToBytesLittleEndian(uint64(i)), 32)}
|
||||
}
|
||||
|
||||
require.NoError(t, db.SaveStateSummaries(context.Background(), summaries))
|
||||
require.Equal(t, db.stateSummaryCache.len(), stateSummaryCachePruneCount-1)
|
||||
|
||||
require.NoError(t, db.SaveStateSummary(context.Background(), &pb.StateSummary{Slot: 1000, Root: []byte{'a', 'b'}}))
|
||||
require.Equal(t, db.stateSummaryCache.len(), stateSummaryCachePruneCount)
|
||||
|
||||
require.NoError(t, db.SaveStateSummary(context.Background(), &pb.StateSummary{Slot: 1001, Root: []byte{'c', 'd'}}))
|
||||
require.Equal(t, db.stateSummaryCache.len(), 1)
|
||||
|
||||
for i := range summaries {
|
||||
r := bytesutil.Uint64ToBytesLittleEndian(uint64(i))
|
||||
require.Equal(t, true, db.HasStateSummary(context.Background(), bytesutil.ToBytes32(r)))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/cache"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/db/kv"
|
||||
"github.com/prysmaticlabs/prysm/shared/cmd"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil"
|
||||
@@ -22,7 +21,7 @@ func TestRestore(t *testing.T) {
|
||||
logHook := logTest.NewGlobal()
|
||||
ctx := context.Background()
|
||||
|
||||
backupDb, err := kv.NewKVStore(context.Background(), t.TempDir(), cache.NewStateSummaryCache())
|
||||
backupDb, err := kv.NewKVStore(context.Background(), t.TempDir())
|
||||
defer func() {
|
||||
require.NoError(t, backupDb.Close())
|
||||
}()
|
||||
@@ -58,7 +57,7 @@ func TestRestore(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 1, len(files))
|
||||
assert.Equal(t, kv.DatabaseFileName, files[0].Name())
|
||||
restoredDb, err := kv.NewKVStore(context.Background(), path.Join(restoreDir, kv.BeaconNodeDbDirName), nil)
|
||||
restoredDb, err := kv.NewKVStore(context.Background(), path.Join(restoreDir, kv.BeaconNodeDbDirName))
|
||||
defer func() {
|
||||
require.NoError(t, restoredDb.Close())
|
||||
}()
|
||||
|
||||
@@ -7,7 +7,6 @@ go_library(
|
||||
importpath = "github.com/prysmaticlabs/prysm/beacon-chain/db/testing",
|
||||
visibility = ["//beacon-chain:__subpackages__"],
|
||||
deps = [
|
||||
"//beacon-chain/cache:go_default_library",
|
||||
"//beacon-chain/db:go_default_library",
|
||||
"//beacon-chain/db/kv:go_default_library",
|
||||
],
|
||||
|
||||
@@ -6,15 +6,13 @@ import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/cache"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/db"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/db/kv"
|
||||
)
|
||||
|
||||
// SetupDB instantiates and returns database backed by key value store.
|
||||
func SetupDB(t testing.TB) (db.Database, *cache.StateSummaryCache) {
|
||||
sc := cache.NewStateSummaryCache()
|
||||
s, err := kv.NewKVStore(context.Background(), t.TempDir(), sc)
|
||||
func SetupDB(t testing.TB) db.Database {
|
||||
s, err := kv.NewKVStore(context.Background(), t.TempDir())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -23,5 +21,5 @@ func SetupDB(t testing.TB) (db.Database, *cache.StateSummaryCache) {
|
||||
t.Fatalf("failed to close database: %v", err)
|
||||
}
|
||||
})
|
||||
return s, sc
|
||||
return s
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ go_library(
|
||||
visibility = ["//beacon-chain:__subpackages__"],
|
||||
deps = [
|
||||
"//beacon-chain/blockchain:go_default_library",
|
||||
"//beacon-chain/cache:go_default_library",
|
||||
"//beacon-chain/cache/depositcache:go_default_library",
|
||||
"//beacon-chain/db:go_default_library",
|
||||
"//beacon-chain/db/kv:go_default_library",
|
||||
|
||||
@@ -18,7 +18,6 @@ import (
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/blockchain"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/cache"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/cache/depositcache"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/db"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/db/kv"
|
||||
@@ -61,22 +60,21 @@ const testSkipPowFlag = "test-skip-pow"
|
||||
// full PoS node. It handles the lifecycle of the entire system and registers
|
||||
// services to a service registry.
|
||||
type BeaconNode struct {
|
||||
cliCtx *cli.Context
|
||||
ctx context.Context
|
||||
services *shared.ServiceRegistry
|
||||
lock sync.RWMutex
|
||||
stop chan struct{} // Channel to wait for termination notifications.
|
||||
db db.Database
|
||||
stateSummaryCache *cache.StateSummaryCache
|
||||
attestationPool attestations.Pool
|
||||
exitPool *voluntaryexits.Pool
|
||||
slashingsPool *slashings.Pool
|
||||
depositCache *depositcache.DepositCache
|
||||
stateFeed *event.Feed
|
||||
blockFeed *event.Feed
|
||||
opFeed *event.Feed
|
||||
forkChoiceStore forkchoice.ForkChoicer
|
||||
stateGen *stategen.State
|
||||
cliCtx *cli.Context
|
||||
ctx context.Context
|
||||
services *shared.ServiceRegistry
|
||||
lock sync.RWMutex
|
||||
stop chan struct{} // Channel to wait for termination notifications.
|
||||
db db.Database
|
||||
attestationPool attestations.Pool
|
||||
exitPool *voluntaryexits.Pool
|
||||
slashingsPool *slashings.Pool
|
||||
depositCache *depositcache.DepositCache
|
||||
stateFeed *event.Feed
|
||||
blockFeed *event.Feed
|
||||
opFeed *event.Feed
|
||||
forkChoiceStore forkchoice.ForkChoicer
|
||||
stateGen *stategen.State
|
||||
}
|
||||
|
||||
// NewBeaconNode creates a new node instance, sets up configuration options, and registers
|
||||
@@ -156,17 +154,16 @@ func NewBeaconNode(cliCtx *cli.Context) (*BeaconNode, error) {
|
||||
registry := shared.NewServiceRegistry()
|
||||
|
||||
beacon := &BeaconNode{
|
||||
cliCtx: cliCtx,
|
||||
ctx: cliCtx.Context,
|
||||
services: registry,
|
||||
stop: make(chan struct{}),
|
||||
stateFeed: new(event.Feed),
|
||||
blockFeed: new(event.Feed),
|
||||
opFeed: new(event.Feed),
|
||||
attestationPool: attestations.NewPool(),
|
||||
exitPool: voluntaryexits.NewPool(),
|
||||
slashingsPool: slashings.NewPool(),
|
||||
stateSummaryCache: cache.NewStateSummaryCache(),
|
||||
cliCtx: cliCtx,
|
||||
ctx: cliCtx.Context,
|
||||
services: registry,
|
||||
stop: make(chan struct{}),
|
||||
stateFeed: new(event.Feed),
|
||||
blockFeed: new(event.Feed),
|
||||
opFeed: new(event.Feed),
|
||||
attestationPool: attestations.NewPool(),
|
||||
exitPool: voluntaryexits.NewPool(),
|
||||
slashingsPool: slashings.NewPool(),
|
||||
}
|
||||
|
||||
if err := beacon.startDB(cliCtx); err != nil {
|
||||
@@ -297,7 +294,7 @@ func (b *BeaconNode) startDB(cliCtx *cli.Context) error {
|
||||
|
||||
log.WithField("database-path", dbPath).Info("Checking DB")
|
||||
|
||||
d, err := db.NewDB(b.ctx, dbPath, b.stateSummaryCache)
|
||||
d, err := db.NewDB(b.ctx, dbPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -319,7 +316,7 @@ func (b *BeaconNode) startDB(cliCtx *cli.Context) error {
|
||||
if err := d.ClearDB(); err != nil {
|
||||
return errors.Wrap(err, "could not clear database")
|
||||
}
|
||||
d, err = db.NewDB(b.ctx, dbPath, b.stateSummaryCache)
|
||||
d, err = db.NewDB(b.ctx, dbPath)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not create new database")
|
||||
}
|
||||
@@ -341,7 +338,7 @@ func (b *BeaconNode) startDB(cliCtx *cli.Context) error {
|
||||
}
|
||||
|
||||
func (b *BeaconNode) startStateGen() {
|
||||
b.stateGen = stategen.New(b.db, b.stateSummaryCache)
|
||||
b.stateGen = stategen.New(b.db)
|
||||
}
|
||||
|
||||
func readbootNodes(fileName string) ([]string, error) {
|
||||
@@ -548,7 +545,6 @@ func (b *BeaconNode) registerSyncService() error {
|
||||
AttPool: b.attestationPool,
|
||||
ExitPool: b.exitPool,
|
||||
SlashingPool: b.slashingsPool,
|
||||
StateSummaryCache: b.stateSummaryCache,
|
||||
StateGen: b.stateGen,
|
||||
})
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ func TestLatestMainchainInfo_OK(t *testing.T) {
|
||||
testAcc, err := contracts.Setup()
|
||||
require.NoError(t, err, "Unable to set up simulated backend")
|
||||
|
||||
beaconDB, _ := dbutil.SetupDB(t)
|
||||
beaconDB := dbutil.SetupDB(t)
|
||||
web3Service, err := NewService(context.Background(), &Web3ServiceConfig{
|
||||
HTTPEndpoints: []string{endpoint},
|
||||
DepositContract: testAcc.ContractAddr,
|
||||
@@ -68,7 +68,7 @@ func TestLatestMainchainInfo_OK(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestBlockHashByHeight_ReturnsHash(t *testing.T) {
|
||||
beaconDB, _ := dbutil.SetupDB(t)
|
||||
beaconDB := dbutil.SetupDB(t)
|
||||
web3Service, err := NewService(context.Background(), &Web3ServiceConfig{
|
||||
HTTPEndpoints: []string{endpoint},
|
||||
BeaconDB: beaconDB,
|
||||
@@ -95,7 +95,7 @@ func TestBlockHashByHeight_ReturnsHash(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestBlockHashByHeight_ReturnsError_WhenNoEth1Client(t *testing.T) {
|
||||
beaconDB, _ := dbutil.SetupDB(t)
|
||||
beaconDB := dbutil.SetupDB(t)
|
||||
web3Service, err := NewService(context.Background(), &Web3ServiceConfig{
|
||||
HTTPEndpoints: []string{endpoint},
|
||||
BeaconDB: beaconDB,
|
||||
@@ -111,7 +111,7 @@ func TestBlockHashByHeight_ReturnsError_WhenNoEth1Client(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestBlockExists_ValidHash(t *testing.T) {
|
||||
beaconDB, _ := dbutil.SetupDB(t)
|
||||
beaconDB := dbutil.SetupDB(t)
|
||||
web3Service, err := NewService(context.Background(), &Web3ServiceConfig{
|
||||
HTTPEndpoints: []string{endpoint},
|
||||
BeaconDB: beaconDB,
|
||||
@@ -142,7 +142,7 @@ func TestBlockExists_ValidHash(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestBlockExists_InvalidHash(t *testing.T) {
|
||||
beaconDB, _ := dbutil.SetupDB(t)
|
||||
beaconDB := dbutil.SetupDB(t)
|
||||
web3Service, err := NewService(context.Background(), &Web3ServiceConfig{
|
||||
HTTPEndpoints: []string{endpoint},
|
||||
BeaconDB: beaconDB,
|
||||
@@ -156,7 +156,7 @@ func TestBlockExists_InvalidHash(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestBlockExists_UsesCachedBlockInfo(t *testing.T) {
|
||||
beaconDB, _ := dbutil.SetupDB(t)
|
||||
beaconDB := dbutil.SetupDB(t)
|
||||
web3Service, err := NewService(context.Background(), &Web3ServiceConfig{
|
||||
HTTPEndpoints: []string{endpoint},
|
||||
BeaconDB: beaconDB,
|
||||
@@ -179,7 +179,7 @@ func TestBlockExists_UsesCachedBlockInfo(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestBlockExistsWithCache_UsesCachedHeaderInfo(t *testing.T) {
|
||||
beaconDB, _ := dbutil.SetupDB(t)
|
||||
beaconDB := dbutil.SetupDB(t)
|
||||
web3Service, err := NewService(context.Background(), &Web3ServiceConfig{
|
||||
HTTPEndpoints: []string{endpoint},
|
||||
BeaconDB: beaconDB,
|
||||
@@ -200,7 +200,7 @@ func TestBlockExistsWithCache_UsesCachedHeaderInfo(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestBlockExistsWithCache_HeaderNotCached(t *testing.T) {
|
||||
beaconDB, _ := dbutil.SetupDB(t)
|
||||
beaconDB := dbutil.SetupDB(t)
|
||||
web3Service, err := NewService(context.Background(), &Web3ServiceConfig{
|
||||
HTTPEndpoints: []string{endpoint},
|
||||
BeaconDB: beaconDB,
|
||||
@@ -214,7 +214,7 @@ func TestBlockExistsWithCache_HeaderNotCached(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestService_BlockNumberByTimestamp(t *testing.T) {
|
||||
beaconDB, _ := dbutil.SetupDB(t)
|
||||
beaconDB := dbutil.SetupDB(t)
|
||||
testAcc, err := contracts.Setup()
|
||||
require.NoError(t, err, "Unable to set up simulated backend")
|
||||
web3Service, err := NewService(context.Background(), &Web3ServiceConfig{
|
||||
@@ -241,7 +241,7 @@ func TestService_BlockNumberByTimestamp(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestService_BlockNumberByTimestampLessTargetTime(t *testing.T) {
|
||||
beaconDB, _ := dbutil.SetupDB(t)
|
||||
beaconDB := dbutil.SetupDB(t)
|
||||
testAcc, err := contracts.Setup()
|
||||
require.NoError(t, err, "Unable to set up simulated backend")
|
||||
web3Service, err := NewService(context.Background(), &Web3ServiceConfig{
|
||||
@@ -274,7 +274,7 @@ func TestService_BlockNumberByTimestampLessTargetTime(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestService_BlockNumberByTimestampMoreTargetTime(t *testing.T) {
|
||||
beaconDB, _ := dbutil.SetupDB(t)
|
||||
beaconDB := dbutil.SetupDB(t)
|
||||
testAcc, err := contracts.Setup()
|
||||
require.NoError(t, err, "Unable to set up simulated backend")
|
||||
web3Service, err := NewService(context.Background(), &Web3ServiceConfig{
|
||||
@@ -307,7 +307,7 @@ func TestService_BlockNumberByTimestampMoreTargetTime(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestService_BlockTimeByHeight_ReturnsError_WhenNoEth1Client(t *testing.T) {
|
||||
beaconDB, _ := dbutil.SetupDB(t)
|
||||
beaconDB := dbutil.SetupDB(t)
|
||||
web3Service, err := NewService(context.Background(), &Web3ServiceConfig{
|
||||
HTTPEndpoints: []string{endpoint},
|
||||
BeaconDB: beaconDB,
|
||||
|
||||
@@ -21,7 +21,7 @@ import (
|
||||
const pubKeyErr = "could not convert bytes to public key"
|
||||
|
||||
func TestProcessDeposit_OK(t *testing.T) {
|
||||
beaconDB, _ := testDB.SetupDB(t)
|
||||
beaconDB := testDB.SetupDB(t)
|
||||
web3Service, err := NewService(context.Background(), &Web3ServiceConfig{
|
||||
HTTPEndpoints: []string{endpoint},
|
||||
BeaconDB: beaconDB,
|
||||
@@ -45,7 +45,7 @@ func TestProcessDeposit_OK(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestProcessDeposit_InvalidMerkleBranch(t *testing.T) {
|
||||
beaconDB, _ := testDB.SetupDB(t)
|
||||
beaconDB := testDB.SetupDB(t)
|
||||
web3Service, err := NewService(context.Background(), &Web3ServiceConfig{
|
||||
HTTPEndpoints: []string{endpoint},
|
||||
BeaconDB: beaconDB,
|
||||
@@ -71,7 +71,7 @@ func TestProcessDeposit_InvalidMerkleBranch(t *testing.T) {
|
||||
|
||||
func TestProcessDeposit_InvalidPublicKey(t *testing.T) {
|
||||
hook := logTest.NewGlobal()
|
||||
beaconDB, _ := testDB.SetupDB(t)
|
||||
beaconDB := testDB.SetupDB(t)
|
||||
web3Service, err := NewService(context.Background(), &Web3ServiceConfig{
|
||||
HTTPEndpoints: []string{endpoint},
|
||||
BeaconDB: beaconDB,
|
||||
@@ -107,7 +107,7 @@ func TestProcessDeposit_InvalidPublicKey(t *testing.T) {
|
||||
|
||||
func TestProcessDeposit_InvalidSignature(t *testing.T) {
|
||||
hook := logTest.NewGlobal()
|
||||
beaconDB, _ := testDB.SetupDB(t)
|
||||
beaconDB := testDB.SetupDB(t)
|
||||
web3Service, err := NewService(context.Background(), &Web3ServiceConfig{
|
||||
HTTPEndpoints: []string{endpoint},
|
||||
BeaconDB: beaconDB,
|
||||
@@ -142,7 +142,7 @@ func TestProcessDeposit_InvalidSignature(t *testing.T) {
|
||||
|
||||
func TestProcessDeposit_UnableToVerify(t *testing.T) {
|
||||
hook := logTest.NewGlobal()
|
||||
beaconDB, _ := testDB.SetupDB(t)
|
||||
beaconDB := testDB.SetupDB(t)
|
||||
web3Service, err := NewService(context.Background(), &Web3ServiceConfig{
|
||||
HTTPEndpoints: []string{endpoint},
|
||||
BeaconDB: beaconDB,
|
||||
@@ -175,7 +175,7 @@ func TestProcessDeposit_UnableToVerify(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestProcessDeposit_IncompleteDeposit(t *testing.T) {
|
||||
beaconDB, _ := testDB.SetupDB(t)
|
||||
beaconDB := testDB.SetupDB(t)
|
||||
web3Service, err := NewService(context.Background(), &Web3ServiceConfig{
|
||||
HTTPEndpoints: []string{endpoint},
|
||||
BeaconDB: beaconDB,
|
||||
@@ -236,7 +236,7 @@ func TestProcessDeposit_IncompleteDeposit(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestProcessDeposit_AllDepositedSuccessfully(t *testing.T) {
|
||||
beaconDB, _ := testDB.SetupDB(t)
|
||||
beaconDB := testDB.SetupDB(t)
|
||||
web3Service, err := NewService(context.Background(), &Web3ServiceConfig{
|
||||
HTTPEndpoints: []string{endpoint},
|
||||
BeaconDB: beaconDB,
|
||||
|
||||
@@ -35,7 +35,7 @@ func TestProcessDepositLog_OK(t *testing.T) {
|
||||
testAcc, err := contracts.Setup()
|
||||
require.NoError(t, err, "Unable to set up simulated backend")
|
||||
|
||||
beaconDB, _ := testDB.SetupDB(t)
|
||||
beaconDB := testDB.SetupDB(t)
|
||||
depositCache, err := depositcache.New()
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -99,7 +99,7 @@ func TestProcessDepositLog_InsertsPendingDeposit(t *testing.T) {
|
||||
hook := logTest.NewGlobal()
|
||||
testAcc, err := contracts.Setup()
|
||||
require.NoError(t, err, "Unable to set up simulated backend")
|
||||
beaconDB, _ := testDB.SetupDB(t)
|
||||
beaconDB := testDB.SetupDB(t)
|
||||
depositCache, err := depositcache.New()
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -159,7 +159,7 @@ func TestProcessDepositLog_InsertsPendingDeposit(t *testing.T) {
|
||||
func TestUnpackDepositLogData_OK(t *testing.T) {
|
||||
testAcc, err := contracts.Setup()
|
||||
require.NoError(t, err, "Unable to set up simulated backend")
|
||||
beaconDB, _ := testDB.SetupDB(t)
|
||||
beaconDB := testDB.SetupDB(t)
|
||||
web3Service, err := NewService(context.Background(), &Web3ServiceConfig{
|
||||
HTTPEndpoints: []string{endpoint},
|
||||
BeaconDB: beaconDB,
|
||||
@@ -207,7 +207,7 @@ func TestProcessETH2GenesisLog_8DuplicatePubkeys(t *testing.T) {
|
||||
hook := logTest.NewGlobal()
|
||||
testAcc, err := contracts.Setup()
|
||||
require.NoError(t, err, "Unable to set up simulated backend")
|
||||
beaconDB, _ := testDB.SetupDB(t)
|
||||
beaconDB := testDB.SetupDB(t)
|
||||
depositCache, err := depositcache.New()
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -278,7 +278,7 @@ func TestProcessETH2GenesisLog(t *testing.T) {
|
||||
hook := logTest.NewGlobal()
|
||||
testAcc, err := contracts.Setup()
|
||||
require.NoError(t, err, "Unable to set up simulated backend")
|
||||
beaconDB, _ := testDB.SetupDB(t)
|
||||
beaconDB := testDB.SetupDB(t)
|
||||
depositCache, err := depositcache.New()
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -365,7 +365,7 @@ func TestProcessETH2GenesisLog_CorrectNumOfDeposits(t *testing.T) {
|
||||
hook := logTest.NewGlobal()
|
||||
testAcc, err := contracts.Setup()
|
||||
require.NoError(t, err, "Unable to set up simulated backend")
|
||||
kvStore, _ := testDB.SetupDB(t)
|
||||
kvStore := testDB.SetupDB(t)
|
||||
depositCache, err := depositcache.New()
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -458,7 +458,7 @@ func TestProcessETH2GenesisLog_LargePeriodOfNoLogs(t *testing.T) {
|
||||
hook := logTest.NewGlobal()
|
||||
testAcc, err := contracts.Setup()
|
||||
require.NoError(t, err, "Unable to set up simulated backend")
|
||||
kvStore, _ := testDB.SetupDB(t)
|
||||
kvStore := testDB.SetupDB(t)
|
||||
depositCache, err := depositcache.New()
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -561,7 +561,7 @@ func TestWeb3ServiceProcessDepositLog_RequestMissedDeposits(t *testing.T) {
|
||||
hook := logTest.NewGlobal()
|
||||
testAcc, err := contracts.Setup()
|
||||
require.NoError(t, err, "Unable to set up simulated backend")
|
||||
beaconDB, _ := testDB.SetupDB(t)
|
||||
beaconDB := testDB.SetupDB(t)
|
||||
depositCache, err := depositcache.New()
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -647,7 +647,7 @@ func TestConsistentGenesisState(t *testing.T) {
|
||||
t.Skip("Incorrect test setup")
|
||||
testAcc, err := contracts.Setup()
|
||||
require.NoError(t, err, "Unable to set up simulated backend")
|
||||
beaconDB, _ := testDB.SetupDB(t)
|
||||
beaconDB := testDB.SetupDB(t)
|
||||
web3Service := newPowchainService(t, testAcc, beaconDB)
|
||||
|
||||
testAcc.Backend.Commit()
|
||||
@@ -689,7 +689,7 @@ func TestConsistentGenesisState(t *testing.T) {
|
||||
}
|
||||
|
||||
// New db to prevent registration error.
|
||||
newBeaconDB, _ := testDB.SetupDB(t)
|
||||
newBeaconDB := testDB.SetupDB(t)
|
||||
|
||||
newWeb3Service := newPowchainService(t, testAcc, newBeaconDB)
|
||||
go newWeb3Service.run(ctx.Done())
|
||||
@@ -707,7 +707,7 @@ func TestCheckForChainstart_NoValidator(t *testing.T) {
|
||||
hook := logTest.NewGlobal()
|
||||
testAcc, err := contracts.Setup()
|
||||
require.NoError(t, err, "Unable to set up simulated backend")
|
||||
beaconDB, _ := testDB.SetupDB(t)
|
||||
beaconDB := testDB.SetupDB(t)
|
||||
s := newPowchainService(t, testAcc, beaconDB)
|
||||
s.checkForChainstart([32]byte{}, nil, 0)
|
||||
require.LogsDoNotContain(t, hook, "Could not determine active validator count from pre genesis state")
|
||||
|
||||
@@ -120,7 +120,7 @@ var depositsReqForChainStart = 64
|
||||
|
||||
func TestStart_OK(t *testing.T) {
|
||||
hook := logTest.NewGlobal()
|
||||
beaconDB, _ := dbutil.SetupDB(t)
|
||||
beaconDB := dbutil.SetupDB(t)
|
||||
testAcc, err := contracts.Setup()
|
||||
require.NoError(t, err, "Unable to set up simulated backend")
|
||||
web3Service, err := NewService(context.Background(), &Web3ServiceConfig{
|
||||
@@ -149,7 +149,7 @@ func TestStart_OK(t *testing.T) {
|
||||
|
||||
func TestStart_NoHTTPEndpointDefinedFails_WithoutChainStarted(t *testing.T) {
|
||||
hook := logTest.NewGlobal()
|
||||
beaconDB, _ := dbutil.SetupDB(t)
|
||||
beaconDB := dbutil.SetupDB(t)
|
||||
testAcc, err := contracts.Setup()
|
||||
require.NoError(t, err, "Unable to set up simulated backend")
|
||||
s, err := NewService(context.Background(), &Web3ServiceConfig{
|
||||
@@ -184,7 +184,7 @@ func TestStart_NoHTTPEndpointDefinedFails_WithoutChainStarted(t *testing.T) {
|
||||
|
||||
func TestStart_NoHTTPEndpointDefinedSucceeds_WithGenesisState(t *testing.T) {
|
||||
hook := logTest.NewGlobal()
|
||||
beaconDB, _ := dbutil.SetupDB(t)
|
||||
beaconDB := dbutil.SetupDB(t)
|
||||
testAcc, err := contracts.Setup()
|
||||
require.NoError(t, err, "Unable to set up simulated backend")
|
||||
st, _ := testutil.DeterministicGenesisState(t, 10)
|
||||
@@ -215,7 +215,7 @@ func TestStart_NoHTTPEndpointDefinedSucceeds_WithGenesisState(t *testing.T) {
|
||||
|
||||
func TestStart_NoHTTPEndpointDefinedSucceeds_WithChainStarted(t *testing.T) {
|
||||
hook := logTest.NewGlobal()
|
||||
beaconDB, _ := dbutil.SetupDB(t)
|
||||
beaconDB := dbutil.SetupDB(t)
|
||||
testAcc, err := contracts.Setup()
|
||||
require.NoError(t, err, "Unable to set up simulated backend")
|
||||
|
||||
@@ -239,7 +239,7 @@ func TestStop_OK(t *testing.T) {
|
||||
hook := logTest.NewGlobal()
|
||||
testAcc, err := contracts.Setup()
|
||||
require.NoError(t, err, "Unable to set up simulated backend")
|
||||
beaconDB, _ := dbutil.SetupDB(t)
|
||||
beaconDB := dbutil.SetupDB(t)
|
||||
web3Service, err := NewService(context.Background(), &Web3ServiceConfig{
|
||||
HTTPEndpoints: []string{endpoint},
|
||||
DepositContract: testAcc.ContractAddr,
|
||||
@@ -264,7 +264,7 @@ func TestStop_OK(t *testing.T) {
|
||||
func TestService_Eth1Synced(t *testing.T) {
|
||||
testAcc, err := contracts.Setup()
|
||||
require.NoError(t, err, "Unable to set up simulated backend")
|
||||
beaconDB, _ := dbutil.SetupDB(t)
|
||||
beaconDB := dbutil.SetupDB(t)
|
||||
web3Service, err := NewService(context.Background(), &Web3ServiceConfig{
|
||||
HTTPEndpoints: []string{endpoint},
|
||||
DepositContract: testAcc.ContractAddr,
|
||||
@@ -285,7 +285,7 @@ func TestService_Eth1Synced(t *testing.T) {
|
||||
func TestFollowBlock_OK(t *testing.T) {
|
||||
testAcc, err := contracts.Setup()
|
||||
require.NoError(t, err, "Unable to set up simulated backend")
|
||||
beaconDB, _ := dbutil.SetupDB(t)
|
||||
beaconDB := dbutil.SetupDB(t)
|
||||
web3Service, err := NewService(context.Background(), &Web3ServiceConfig{
|
||||
HTTPEndpoints: []string{endpoint},
|
||||
DepositContract: testAcc.ContractAddr,
|
||||
@@ -360,7 +360,7 @@ func TestStatus(t *testing.T) {
|
||||
|
||||
func TestHandlePanic_OK(t *testing.T) {
|
||||
hook := logTest.NewGlobal()
|
||||
beaconDB, _ := dbutil.SetupDB(t)
|
||||
beaconDB := dbutil.SetupDB(t)
|
||||
web3Service, err := NewService(context.Background(), &Web3ServiceConfig{
|
||||
HTTPEndpoints: []string{endpoint},
|
||||
BeaconDB: beaconDB,
|
||||
@@ -399,7 +399,7 @@ func TestLogTillGenesis_OK(t *testing.T) {
|
||||
hook := logTest.NewGlobal()
|
||||
testAcc, err := contracts.Setup()
|
||||
require.NoError(t, err, "Unable to set up simulated backend")
|
||||
beaconDB, _ := dbutil.SetupDB(t)
|
||||
beaconDB := dbutil.SetupDB(t)
|
||||
web3Service, err := NewService(context.Background(), &Web3ServiceConfig{
|
||||
HTTPEndpoints: []string{endpoint},
|
||||
DepositContract: testAcc.ContractAddr,
|
||||
@@ -431,7 +431,7 @@ func TestInitDepositCache_OK(t *testing.T) {
|
||||
{Index: 1, Eth1BlockHeight: 4, Deposit: ðpb.Deposit{Proof: [][]byte{[]byte("B")}}},
|
||||
{Index: 2, Eth1BlockHeight: 6, Deposit: ðpb.Deposit{Proof: [][]byte{[]byte("c")}}},
|
||||
}
|
||||
beaconDB, _ := dbutil.SetupDB(t)
|
||||
beaconDB := dbutil.SetupDB(t)
|
||||
s := &Service{
|
||||
chainStartData: &protodb.ChainStartData{Chainstarted: false},
|
||||
beaconDB: beaconDB,
|
||||
@@ -456,7 +456,7 @@ func TestInitDepositCache_OK(t *testing.T) {
|
||||
func TestNewService_EarliestVotingBlock(t *testing.T) {
|
||||
testAcc, err := contracts.Setup()
|
||||
require.NoError(t, err, "Unable to set up simulated backend")
|
||||
beaconDB, _ := dbutil.SetupDB(t)
|
||||
beaconDB := dbutil.SetupDB(t)
|
||||
web3Service, err := NewService(context.Background(), &Web3ServiceConfig{
|
||||
HTTPEndpoints: []string{endpoint},
|
||||
DepositContract: testAcc.ContractAddr,
|
||||
@@ -508,7 +508,7 @@ func TestNewService_EarliestVotingBlock(t *testing.T) {
|
||||
func TestNewService_Eth1HeaderRequLimit(t *testing.T) {
|
||||
testAcc, err := contracts.Setup()
|
||||
require.NoError(t, err, "Unable to set up simulated backend")
|
||||
beaconDB, _ := dbutil.SetupDB(t)
|
||||
beaconDB := dbutil.SetupDB(t)
|
||||
|
||||
s1, err := NewService(context.Background(), &Web3ServiceConfig{
|
||||
HTTPEndpoints: []string{endpoint},
|
||||
@@ -534,7 +534,7 @@ func TestServiceFallbackCorrectly(t *testing.T) {
|
||||
|
||||
testAcc, err := contracts.Setup()
|
||||
require.NoError(t, err, "Unable to set up simulated backend")
|
||||
beaconDB, _ := dbutil.SetupDB(t)
|
||||
beaconDB := dbutil.SetupDB(t)
|
||||
|
||||
s1, err := NewService(context.Background(), &Web3ServiceConfig{
|
||||
HTTPEndpoints: []string{firstEndpoint},
|
||||
|
||||
@@ -75,7 +75,6 @@ go_test(
|
||||
shard_count = 4,
|
||||
deps = [
|
||||
"//beacon-chain/blockchain/testing:go_default_library",
|
||||
"//beacon-chain/cache:go_default_library",
|
||||
"//beacon-chain/core/epoch/precompute:go_default_library",
|
||||
"//beacon-chain/core/feed:go_default_library",
|
||||
"//beacon-chain/core/feed/block:go_default_library",
|
||||
|
||||
@@ -22,7 +22,7 @@ import (
|
||||
|
||||
func TestServer_ListAssignments_CannotRequestFutureEpoch(t *testing.T) {
|
||||
|
||||
db, _ := dbTest.SetupDB(t)
|
||||
db := dbTest.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
bs := &Server{
|
||||
BeaconDB: db,
|
||||
@@ -43,7 +43,7 @@ func TestServer_ListAssignments_CannotRequestFutureEpoch(t *testing.T) {
|
||||
|
||||
func TestServer_ListAssignments_NoResults(t *testing.T) {
|
||||
|
||||
db, sc := dbTest.SetupDB(t)
|
||||
db := dbTest.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
st := testutil.NewBeaconState()
|
||||
|
||||
@@ -57,7 +57,7 @@ func TestServer_ListAssignments_NoResults(t *testing.T) {
|
||||
bs := &Server{
|
||||
BeaconDB: db,
|
||||
GenesisTimeFetcher: &mock.ChainService{},
|
||||
StateGen: stategen.New(db, sc),
|
||||
StateGen: stategen.New(db),
|
||||
}
|
||||
wanted := ðpb.ValidatorAssignments{
|
||||
Assignments: make([]*ethpb.ValidatorAssignments_CommitteeAssignment, 0),
|
||||
@@ -80,7 +80,7 @@ func TestServer_ListAssignments_NoResults(t *testing.T) {
|
||||
|
||||
func TestServer_ListAssignments_Pagination_InputOutOfRange(t *testing.T) {
|
||||
helpers.ClearCache()
|
||||
db, sc := dbTest.SetupDB(t)
|
||||
db := dbTest.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
count := 100
|
||||
validators := make([]*ethpb.Validator, 0, count)
|
||||
@@ -117,7 +117,7 @@ func TestServer_ListAssignments_Pagination_InputOutOfRange(t *testing.T) {
|
||||
},
|
||||
},
|
||||
GenesisTimeFetcher: &mock.ChainService{},
|
||||
StateGen: stategen.New(db, sc),
|
||||
StateGen: stategen.New(db),
|
||||
}
|
||||
|
||||
wanted := fmt.Sprintf("page start %d >= list %d", 500, count)
|
||||
@@ -143,7 +143,7 @@ func TestServer_ListAssignments_Pagination_ExceedsMaxPageSize(t *testing.T) {
|
||||
|
||||
func TestServer_ListAssignments_Pagination_DefaultPageSize_NoArchive(t *testing.T) {
|
||||
helpers.ClearCache()
|
||||
db, sc := dbTest.SetupDB(t)
|
||||
db := dbTest.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
count := 500
|
||||
validators := make([]*ethpb.Validator, 0, count)
|
||||
@@ -191,7 +191,7 @@ func TestServer_ListAssignments_Pagination_DefaultPageSize_NoArchive(t *testing.
|
||||
},
|
||||
},
|
||||
GenesisTimeFetcher: &mock.ChainService{},
|
||||
StateGen: stategen.New(db, sc),
|
||||
StateGen: stategen.New(db),
|
||||
}
|
||||
|
||||
res, err := bs.ListValidatorAssignments(context.Background(), ðpb.ListValidatorAssignmentsRequest{
|
||||
@@ -223,7 +223,7 @@ func TestServer_ListAssignments_Pagination_DefaultPageSize_NoArchive(t *testing.
|
||||
|
||||
func TestServer_ListAssignments_FilterPubkeysIndices_NoPagination(t *testing.T) {
|
||||
helpers.ClearCache()
|
||||
db, sc := dbTest.SetupDB(t)
|
||||
db := dbTest.SetupDB(t)
|
||||
|
||||
ctx := context.Background()
|
||||
count := 100
|
||||
@@ -256,7 +256,7 @@ func TestServer_ListAssignments_FilterPubkeysIndices_NoPagination(t *testing.T)
|
||||
},
|
||||
},
|
||||
GenesisTimeFetcher: &mock.ChainService{},
|
||||
StateGen: stategen.New(db, sc),
|
||||
StateGen: stategen.New(db),
|
||||
}
|
||||
|
||||
pubKey1 := make([]byte, params.BeaconConfig().BLSPubkeyLength)
|
||||
@@ -292,7 +292,7 @@ func TestServer_ListAssignments_FilterPubkeysIndices_NoPagination(t *testing.T)
|
||||
|
||||
func TestServer_ListAssignments_CanFilterPubkeysIndices_WithPagination(t *testing.T) {
|
||||
helpers.ClearCache()
|
||||
db, sc := dbTest.SetupDB(t)
|
||||
db := dbTest.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
count := 100
|
||||
validators := make([]*ethpb.Validator, 0, count)
|
||||
@@ -324,7 +324,7 @@ func TestServer_ListAssignments_CanFilterPubkeysIndices_WithPagination(t *testin
|
||||
},
|
||||
},
|
||||
GenesisTimeFetcher: &mock.ChainService{},
|
||||
StateGen: stategen.New(db, sc),
|
||||
StateGen: stategen.New(db),
|
||||
}
|
||||
|
||||
req := ðpb.ListValidatorAssignmentsRequest{Indices: []uint64{1, 2, 3, 4, 5, 6}, PageSize: 2, PageToken: "1"}
|
||||
|
||||
@@ -34,7 +34,7 @@ import (
|
||||
)
|
||||
|
||||
func TestServer_ListAttestations_NoResults(t *testing.T) {
|
||||
db, _ := dbTest.SetupDB(t)
|
||||
db := dbTest.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
st, err := stateTrie.InitializeFromProto(&pbp2p.BeaconState{
|
||||
@@ -62,7 +62,7 @@ func TestServer_ListAttestations_NoResults(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestServer_ListAttestations_Genesis(t *testing.T) {
|
||||
db, _ := dbTest.SetupDB(t)
|
||||
db := dbTest.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
st, err := stateTrie.InitializeFromProto(&pbp2p.BeaconState{
|
||||
@@ -112,7 +112,7 @@ func TestServer_ListAttestations_Genesis(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestServer_ListAttestations_NoPagination(t *testing.T) {
|
||||
db, _ := dbTest.SetupDB(t)
|
||||
db := dbTest.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
count := uint64(8)
|
||||
@@ -149,7 +149,7 @@ func TestServer_ListAttestations_NoPagination(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestServer_ListAttestations_FiltersCorrectly(t *testing.T) {
|
||||
db, _ := dbTest.SetupDB(t)
|
||||
db := dbTest.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
someRoot := [32]byte{1, 2, 3}
|
||||
@@ -282,7 +282,7 @@ func TestServer_ListAttestations_FiltersCorrectly(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestServer_ListAttestations_Pagination_CustomPageParameters(t *testing.T) {
|
||||
db, _ := dbTest.SetupDB(t)
|
||||
db := dbTest.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
count := params.BeaconConfig().SlotsPerEpoch * 4
|
||||
@@ -391,7 +391,7 @@ func TestServer_ListAttestations_Pagination_CustomPageParameters(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestServer_ListAttestations_Pagination_OutOfRange(t *testing.T) {
|
||||
db, _ := dbTest.SetupDB(t)
|
||||
db := dbTest.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
testutil.NewBeaconBlock()
|
||||
count := uint64(1)
|
||||
@@ -456,7 +456,7 @@ func TestServer_ListAttestations_Pagination_ExceedsMaxPageSize(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestServer_ListAttestations_Pagination_DefaultPageSize(t *testing.T) {
|
||||
db, _ := dbTest.SetupDB(t)
|
||||
db := dbTest.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
count := uint64(params.BeaconConfig().DefaultPageSize)
|
||||
@@ -529,7 +529,7 @@ func TestServer_mapAttestationToTargetRoot(t *testing.T) {
|
||||
|
||||
func TestServer_ListIndexedAttestations_GenesisEpoch(t *testing.T) {
|
||||
params.UseMainnetConfig()
|
||||
db, sc := dbTest.SetupDB(t)
|
||||
db := dbTest.SetupDB(t)
|
||||
helpers.ClearCache()
|
||||
ctx := context.Background()
|
||||
targetRoot1 := bytesutil.ToBytes32([]byte("root"))
|
||||
@@ -600,7 +600,7 @@ func TestServer_ListIndexedAttestations_GenesisEpoch(t *testing.T) {
|
||||
BeaconDB: db,
|
||||
GenesisTimeFetcher: &chainMock.ChainService{State: state},
|
||||
HeadFetcher: &chainMock.ChainService{State: state},
|
||||
StateGen: stategen.New(db, sc),
|
||||
StateGen: stategen.New(db),
|
||||
}
|
||||
err := db.SaveStateSummary(ctx, &pbp2p.StateSummary{
|
||||
Root: targetRoot1[:],
|
||||
@@ -637,7 +637,7 @@ func TestServer_ListIndexedAttestations_GenesisEpoch(t *testing.T) {
|
||||
func TestServer_ListIndexedAttestations_OldEpoch(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
params.OverrideBeaconConfig(params.MainnetConfig())
|
||||
db, sc := dbTest.SetupDB(t)
|
||||
db := dbTest.SetupDB(t)
|
||||
helpers.ClearCache()
|
||||
ctx := context.Background()
|
||||
|
||||
@@ -700,7 +700,7 @@ func TestServer_ListIndexedAttestations_OldEpoch(t *testing.T) {
|
||||
GenesisTimeFetcher: &chainMock.ChainService{
|
||||
Genesis: time.Now(),
|
||||
},
|
||||
StateGen: stategen.New(db, sc),
|
||||
StateGen: stategen.New(db),
|
||||
}
|
||||
err = db.SaveStateSummary(ctx, &pbp2p.StateSummary{
|
||||
Root: blockRoot[:],
|
||||
@@ -884,7 +884,7 @@ func TestServer_StreamIndexedAttestations_ContextCanceled(t *testing.T) {
|
||||
func TestServer_StreamIndexedAttestations_OK(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
params.OverrideBeaconConfig(params.MainnetConfig())
|
||||
db, sc := dbTest.SetupDB(t)
|
||||
db := dbTest.SetupDB(t)
|
||||
exitRoutine := make(chan bool)
|
||||
ctrl := gomock.NewController(t)
|
||||
defer ctrl.Finish()
|
||||
@@ -971,7 +971,7 @@ func TestServer_StreamIndexedAttestations_OK(t *testing.T) {
|
||||
},
|
||||
AttestationNotifier: chainService.OperationNotifier(),
|
||||
CollectedAttestationsBuffer: make(chan []*ethpb.Attestation, 1),
|
||||
StateGen: stategen.New(db, sc),
|
||||
StateGen: stategen.New(db),
|
||||
}
|
||||
|
||||
for dataRoot, sameDataAtts := range atts {
|
||||
|
||||
@@ -11,7 +11,6 @@ import (
|
||||
"github.com/golang/mock/gomock"
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
chainMock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/cache"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/feed"
|
||||
blockfeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/block"
|
||||
statefeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/state"
|
||||
@@ -30,7 +29,7 @@ import (
|
||||
)
|
||||
|
||||
func TestServer_ListBlocks_NoResults(t *testing.T) {
|
||||
db, _ := dbTest.SetupDB(t)
|
||||
db := dbTest.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
bs := &Server{
|
||||
@@ -71,7 +70,7 @@ func TestServer_ListBlocks_NoResults(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestServer_ListBlocks_Genesis(t *testing.T) {
|
||||
db, _ := dbTest.SetupDB(t)
|
||||
db := dbTest.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
bs := &Server{
|
||||
@@ -116,7 +115,7 @@ func TestServer_ListBlocks_Genesis(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestServer_ListBlocks_Genesis_MultiBlocks(t *testing.T) {
|
||||
db, _ := dbTest.SetupDB(t)
|
||||
db := dbTest.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
bs := &Server{
|
||||
@@ -154,7 +153,7 @@ func TestServer_ListBlocks_Genesis_MultiBlocks(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestServer_ListBlocks_Pagination(t *testing.T) {
|
||||
db, _ := dbTest.SetupDB(t)
|
||||
db := dbTest.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
count := uint64(100)
|
||||
@@ -288,7 +287,7 @@ func TestServer_ListBlocks_Pagination(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestServer_ListBlocks_Errors(t *testing.T) {
|
||||
db, _ := dbTest.SetupDB(t)
|
||||
db := dbTest.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
bs := &Server{BeaconDB: db}
|
||||
@@ -330,7 +329,7 @@ func TestServer_ListBlocks_Errors(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestServer_GetChainHead_NoFinalizedBlock(t *testing.T) {
|
||||
db, _ := dbTest.SetupDB(t)
|
||||
db := dbTest.SetupDB(t)
|
||||
|
||||
s := testutil.NewBeaconState()
|
||||
require.NoError(t, s.SetSlot(1))
|
||||
@@ -367,7 +366,7 @@ func TestServer_GetChainHead_NoHeadBlock(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestServer_GetChainHead(t *testing.T) {
|
||||
db, _ := dbTest.SetupDB(t)
|
||||
db := dbTest.SetupDB(t)
|
||||
|
||||
genBlock := testutil.NewBeaconBlock()
|
||||
genBlock.Block.ParentRoot = bytesutil.PadTo([]byte{'G'}, 32)
|
||||
@@ -432,7 +431,7 @@ func TestServer_GetChainHead(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestServer_StreamChainHead_ContextCanceled(t *testing.T) {
|
||||
db, _ := dbTest.SetupDB(t)
|
||||
db := dbTest.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
@@ -457,7 +456,7 @@ func TestServer_StreamChainHead_ContextCanceled(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestServer_StreamChainHead_OnHeadUpdated(t *testing.T) {
|
||||
db, _ := dbTest.SetupDB(t)
|
||||
db := dbTest.SetupDB(t)
|
||||
params.UseMainnetConfig()
|
||||
genBlock := testutil.NewBeaconBlock()
|
||||
genBlock.Block.ParentRoot = bytesutil.PadTo([]byte{'G'}, 32)
|
||||
@@ -553,7 +552,7 @@ func TestServer_StreamChainHead_OnHeadUpdated(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestServer_StreamBlocks_ContextCanceled(t *testing.T) {
|
||||
db, _ := dbTest.SetupDB(t)
|
||||
db := dbTest.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
chainService := &chainMock.ChainService{}
|
||||
@@ -615,7 +614,7 @@ func TestServer_StreamBlocks_OnHeadUpdated(t *testing.T) {
|
||||
func TestServer_GetWeakSubjectivityCheckpoint(t *testing.T) {
|
||||
params.UseMainnetConfig()
|
||||
|
||||
db, _ := dbTest.SetupDB(t)
|
||||
db := dbTest.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
beaconState := testutil.NewBeaconState()
|
||||
b := testutil.NewBeaconBlock()
|
||||
@@ -630,7 +629,7 @@ func TestServer_GetWeakSubjectivityCheckpoint(t *testing.T) {
|
||||
BlockNotifier: chainService.BlockNotifier(),
|
||||
HeadFetcher: chainService,
|
||||
BeaconDB: db,
|
||||
StateGen: stategen.New(db, cache.NewStateSummaryCache()),
|
||||
StateGen: stategen.New(db),
|
||||
}
|
||||
|
||||
c, err := server.GetWeakSubjectivityCheckpoint(ctx, &ptypes.Empty{})
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
"github.com/gogo/protobuf/proto"
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/cache"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
||||
dbTest "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
|
||||
stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state"
|
||||
@@ -24,7 +23,7 @@ import (
|
||||
)
|
||||
|
||||
func TestServer_ListBeaconCommittees_CurrentEpoch(t *testing.T) {
|
||||
db, sc := dbTest.SetupDB(t)
|
||||
db := dbTest.SetupDB(t)
|
||||
helpers.ClearCache()
|
||||
|
||||
numValidators := 128
|
||||
@@ -37,7 +36,7 @@ func TestServer_ListBeaconCommittees_CurrentEpoch(t *testing.T) {
|
||||
bs := &Server{
|
||||
HeadFetcher: m,
|
||||
GenesisTimeFetcher: m,
|
||||
StateGen: stategen.New(db, sc),
|
||||
StateGen: stategen.New(db),
|
||||
}
|
||||
b := testutil.NewBeaconBlock()
|
||||
require.NoError(t, db.SaveBlock(ctx, b))
|
||||
@@ -71,7 +70,7 @@ func TestServer_ListBeaconCommittees_PreviousEpoch(t *testing.T) {
|
||||
params.UseMainnetConfig()
|
||||
ctx := context.Background()
|
||||
|
||||
db, _ := dbTest.SetupDB(t)
|
||||
db := dbTest.SetupDB(t)
|
||||
helpers.ClearCache()
|
||||
|
||||
numValidators := 128
|
||||
@@ -98,7 +97,7 @@ func TestServer_ListBeaconCommittees_PreviousEpoch(t *testing.T) {
|
||||
bs := &Server{
|
||||
HeadFetcher: m,
|
||||
GenesisTimeFetcher: m,
|
||||
StateGen: stategen.New(db, cache.NewStateSummaryCache()),
|
||||
StateGen: stategen.New(db),
|
||||
}
|
||||
|
||||
activeIndices, err := helpers.ActiveValidatorIndices(headState, 1)
|
||||
@@ -138,7 +137,7 @@ func TestServer_ListBeaconCommittees_PreviousEpoch(t *testing.T) {
|
||||
|
||||
func TestRetrieveCommitteesForRoot(t *testing.T) {
|
||||
|
||||
db, sc := dbTest.SetupDB(t)
|
||||
db := dbTest.SetupDB(t)
|
||||
helpers.ClearCache()
|
||||
ctx := context.Background()
|
||||
|
||||
@@ -151,7 +150,7 @@ func TestRetrieveCommitteesForRoot(t *testing.T) {
|
||||
bs := &Server{
|
||||
HeadFetcher: m,
|
||||
GenesisTimeFetcher: m,
|
||||
StateGen: stategen.New(db, sc),
|
||||
StateGen: stategen.New(db),
|
||||
}
|
||||
b := testutil.NewBeaconBlock()
|
||||
require.NoError(t, db.SaveBlock(ctx, b))
|
||||
|
||||
@@ -14,7 +14,6 @@ import (
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/go-bitfield"
|
||||
mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/cache"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/epoch/precompute"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/db"
|
||||
@@ -33,7 +32,7 @@ import (
|
||||
)
|
||||
|
||||
func TestServer_GetValidatorActiveSetChanges_CannotRequestFutureEpoch(t *testing.T) {
|
||||
db, _ := dbTest.SetupDB(t)
|
||||
db := dbTest.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
st := testutil.NewBeaconState()
|
||||
require.NoError(t, st.SetSlot(0))
|
||||
@@ -58,7 +57,7 @@ func TestServer_GetValidatorActiveSetChanges_CannotRequestFutureEpoch(t *testing
|
||||
}
|
||||
|
||||
func TestServer_ListValidatorBalances_CannotRequestFutureEpoch(t *testing.T) {
|
||||
db, _ := dbTest.SetupDB(t)
|
||||
db := dbTest.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
st := testutil.NewBeaconState()
|
||||
@@ -84,14 +83,14 @@ func TestServer_ListValidatorBalances_CannotRequestFutureEpoch(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestServer_ListValidatorBalances_NoResults(t *testing.T) {
|
||||
db, sc := dbTest.SetupDB(t)
|
||||
db := dbTest.SetupDB(t)
|
||||
|
||||
ctx := context.Background()
|
||||
st := testutil.NewBeaconState()
|
||||
require.NoError(t, st.SetSlot(0))
|
||||
bs := &Server{
|
||||
GenesisTimeFetcher: &mock.ChainService{},
|
||||
StateGen: stategen.New(db, sc),
|
||||
StateGen: stategen.New(db),
|
||||
}
|
||||
|
||||
headState := testutil.NewBeaconState()
|
||||
@@ -122,7 +121,7 @@ func TestServer_ListValidatorBalances_NoResults(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestServer_ListValidatorBalances_DefaultResponse_NoArchive(t *testing.T) {
|
||||
db, sc := dbTest.SetupDB(t)
|
||||
db := dbTest.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
numItems := 100
|
||||
@@ -154,7 +153,7 @@ func TestServer_ListValidatorBalances_DefaultResponse_NoArchive(t *testing.T) {
|
||||
require.NoError(t, db.SaveState(ctx, st, gRoot))
|
||||
bs := &Server{
|
||||
GenesisTimeFetcher: &mock.ChainService{},
|
||||
StateGen: stategen.New(db, sc),
|
||||
StateGen: stategen.New(db),
|
||||
HeadFetcher: &mock.ChainService{
|
||||
State: st,
|
||||
},
|
||||
@@ -170,7 +169,7 @@ func TestServer_ListValidatorBalances_DefaultResponse_NoArchive(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestServer_ListValidatorBalances_PaginationOutOfRange(t *testing.T) {
|
||||
db, sc := dbTest.SetupDB(t)
|
||||
db := dbTest.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
_, _, headState := setupValidators(t, db, 100)
|
||||
@@ -182,7 +181,7 @@ func TestServer_ListValidatorBalances_PaginationOutOfRange(t *testing.T) {
|
||||
|
||||
bs := &Server{
|
||||
GenesisTimeFetcher: &mock.ChainService{},
|
||||
StateGen: stategen.New(db, sc),
|
||||
StateGen: stategen.New(db),
|
||||
HeadFetcher: &mock.ChainService{
|
||||
State: headState,
|
||||
},
|
||||
@@ -218,7 +217,7 @@ func pubKey(i uint64) []byte {
|
||||
}
|
||||
|
||||
func TestServer_ListValidatorBalances_Pagination_Default(t *testing.T) {
|
||||
db, sc := dbTest.SetupDB(t)
|
||||
db := dbTest.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
_, _, headState := setupValidators(t, db, 100)
|
||||
@@ -230,7 +229,7 @@ func TestServer_ListValidatorBalances_Pagination_Default(t *testing.T) {
|
||||
|
||||
bs := &Server{
|
||||
GenesisTimeFetcher: &mock.ChainService{},
|
||||
StateGen: stategen.New(db, sc),
|
||||
StateGen: stategen.New(db),
|
||||
HeadFetcher: &mock.ChainService{
|
||||
State: headState,
|
||||
},
|
||||
@@ -300,7 +299,7 @@ func TestServer_ListValidatorBalances_Pagination_Default(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestServer_ListValidatorBalances_Pagination_CustomPageSizes(t *testing.T) {
|
||||
db, sc := dbTest.SetupDB(t)
|
||||
db := dbTest.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
count := 1000
|
||||
@@ -313,7 +312,7 @@ func TestServer_ListValidatorBalances_Pagination_CustomPageSizes(t *testing.T) {
|
||||
|
||||
bs := &Server{
|
||||
GenesisTimeFetcher: &mock.ChainService{},
|
||||
StateGen: stategen.New(db, sc),
|
||||
StateGen: stategen.New(db),
|
||||
HeadFetcher: &mock.ChainService{
|
||||
State: headState,
|
||||
},
|
||||
@@ -368,7 +367,7 @@ func TestServer_ListValidatorBalances_Pagination_CustomPageSizes(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestServer_ListValidatorBalances_ResponseOutOfBound(t *testing.T) {
|
||||
db, sc := dbTest.SetupDB(t)
|
||||
db := dbTest.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
count := 10
|
||||
@@ -381,7 +380,7 @@ func TestServer_ListValidatorBalances_ResponseOutOfBound(t *testing.T) {
|
||||
|
||||
bs := &Server{
|
||||
GenesisTimeFetcher: &mock.ChainService{},
|
||||
StateGen: stategen.New(db, sc),
|
||||
StateGen: stategen.New(db),
|
||||
HeadFetcher: &mock.ChainService{
|
||||
State: headState,
|
||||
},
|
||||
@@ -393,7 +392,7 @@ func TestServer_ListValidatorBalances_ResponseOutOfBound(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestServer_ListValidatorBalances_OutOfRange(t *testing.T) {
|
||||
db, sc := dbTest.SetupDB(t)
|
||||
db := dbTest.SetupDB(t)
|
||||
|
||||
ctx := context.Background()
|
||||
_, _, headState := setupValidators(t, db, 1)
|
||||
@@ -405,7 +404,7 @@ func TestServer_ListValidatorBalances_OutOfRange(t *testing.T) {
|
||||
|
||||
bs := &Server{
|
||||
GenesisTimeFetcher: &mock.ChainService{},
|
||||
StateGen: stategen.New(db, sc),
|
||||
StateGen: stategen.New(db),
|
||||
HeadFetcher: &mock.ChainService{
|
||||
State: headState,
|
||||
},
|
||||
@@ -418,7 +417,7 @@ func TestServer_ListValidatorBalances_OutOfRange(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestServer_ListValidators_CannotRequestFutureEpoch(t *testing.T) {
|
||||
db, _ := dbTest.SetupDB(t)
|
||||
db := dbTest.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
st := testutil.NewBeaconState()
|
||||
@@ -447,7 +446,7 @@ func TestServer_ListValidators_CannotRequestFutureEpoch(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestServer_ListValidators_NoResults(t *testing.T) {
|
||||
db, _ := dbTest.SetupDB(t)
|
||||
db := dbTest.SetupDB(t)
|
||||
|
||||
ctx := context.Background()
|
||||
st := testutil.NewBeaconState()
|
||||
@@ -464,7 +463,7 @@ func TestServer_ListValidators_NoResults(t *testing.T) {
|
||||
HeadFetcher: &mock.ChainService{
|
||||
State: st,
|
||||
},
|
||||
StateGen: stategen.New(db, cache.NewStateSummaryCache()),
|
||||
StateGen: stategen.New(db),
|
||||
}
|
||||
wanted := ðpb.Validators{
|
||||
ValidatorList: make([]*ethpb.Validators_ValidatorContainer, 0),
|
||||
@@ -487,7 +486,7 @@ func TestServer_ListValidators_NoResults(t *testing.T) {
|
||||
|
||||
func TestServer_ListValidators_OnlyActiveValidators(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, _ := dbTest.SetupDB(t)
|
||||
db := dbTest.SetupDB(t)
|
||||
count := 100
|
||||
balances := make([]uint64, count)
|
||||
validators := make([]*ethpb.Validator, count)
|
||||
@@ -530,7 +529,7 @@ func TestServer_ListValidators_OnlyActiveValidators(t *testing.T) {
|
||||
// We are in epoch 0.
|
||||
Genesis: time.Now(),
|
||||
},
|
||||
StateGen: stategen.New(db, cache.NewStateSummaryCache()),
|
||||
StateGen: stategen.New(db),
|
||||
}
|
||||
|
||||
b := testutil.NewBeaconBlock()
|
||||
@@ -549,7 +548,7 @@ func TestServer_ListValidators_OnlyActiveValidators(t *testing.T) {
|
||||
|
||||
func TestServer_ListValidators_InactiveInTheMiddle(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, _ := dbTest.SetupDB(t)
|
||||
db := dbTest.SetupDB(t)
|
||||
count := 100
|
||||
balances := make([]uint64, count)
|
||||
validators := make([]*ethpb.Validator, count)
|
||||
@@ -597,7 +596,7 @@ func TestServer_ListValidators_InactiveInTheMiddle(t *testing.T) {
|
||||
// We are in epoch 0.
|
||||
Genesis: time.Now(),
|
||||
},
|
||||
StateGen: stategen.New(db, cache.NewStateSummaryCache()),
|
||||
StateGen: stategen.New(db),
|
||||
}
|
||||
|
||||
b := testutil.NewBeaconBlock()
|
||||
@@ -617,7 +616,7 @@ func TestServer_ListValidators_InactiveInTheMiddle(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestServer_ListValidators_NoPagination(t *testing.T) {
|
||||
db, _ := dbTest.SetupDB(t)
|
||||
db := dbTest.SetupDB(t)
|
||||
|
||||
validators, _, headState := setupValidators(t, db, 100)
|
||||
want := make([]*ethpb.Validators_ValidatorContainer, len(validators))
|
||||
@@ -641,7 +640,7 @@ func TestServer_ListValidators_NoPagination(t *testing.T) {
|
||||
Epoch: 0,
|
||||
},
|
||||
},
|
||||
StateGen: stategen.New(db, cache.NewStateSummaryCache()),
|
||||
StateGen: stategen.New(db),
|
||||
}
|
||||
|
||||
received, err := bs.ListValidators(context.Background(), ðpb.ListValidatorsRequest{})
|
||||
@@ -650,7 +649,7 @@ func TestServer_ListValidators_NoPagination(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestServer_ListValidators_StategenNotUsed(t *testing.T) {
|
||||
db, _ := dbTest.SetupDB(t)
|
||||
db := dbTest.SetupDB(t)
|
||||
|
||||
validators, _, headState := setupValidators(t, db, 100)
|
||||
want := make([]*ethpb.Validators_ValidatorContainer, len(validators))
|
||||
@@ -677,7 +676,7 @@ func TestServer_ListValidators_StategenNotUsed(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestServer_ListValidators_IndicesPubKeys(t *testing.T) {
|
||||
db, _ := dbTest.SetupDB(t)
|
||||
db := dbTest.SetupDB(t)
|
||||
|
||||
validators, _, headState := setupValidators(t, db, 100)
|
||||
indicesWanted := []uint64{2, 7, 11, 17}
|
||||
@@ -707,7 +706,7 @@ func TestServer_ListValidators_IndicesPubKeys(t *testing.T) {
|
||||
// We are in epoch 0.
|
||||
Genesis: time.Now(),
|
||||
},
|
||||
StateGen: stategen.New(db, cache.NewStateSummaryCache()),
|
||||
StateGen: stategen.New(db),
|
||||
}
|
||||
|
||||
pubKeysWanted := make([][]byte, len(pubkeyIndicesWanted))
|
||||
@@ -724,7 +723,7 @@ func TestServer_ListValidators_IndicesPubKeys(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestServer_ListValidators_Pagination(t *testing.T) {
|
||||
db, _ := dbTest.SetupDB(t)
|
||||
db := dbTest.SetupDB(t)
|
||||
|
||||
count := 100
|
||||
_, _, headState := setupValidators(t, db, count)
|
||||
@@ -743,7 +742,7 @@ func TestServer_ListValidators_Pagination(t *testing.T) {
|
||||
// We are in epoch 0.
|
||||
Genesis: time.Now(),
|
||||
},
|
||||
StateGen: stategen.New(db, cache.NewStateSummaryCache()),
|
||||
StateGen: stategen.New(db),
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
@@ -862,7 +861,7 @@ func TestServer_ListValidators_Pagination(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestServer_ListValidators_PaginationOutOfRange(t *testing.T) {
|
||||
db, _ := dbTest.SetupDB(t)
|
||||
db := dbTest.SetupDB(t)
|
||||
|
||||
count := 1
|
||||
validators, _, headState := setupValidators(t, db, count)
|
||||
@@ -880,7 +879,7 @@ func TestServer_ListValidators_PaginationOutOfRange(t *testing.T) {
|
||||
// We are in epoch 0.
|
||||
Genesis: time.Now(),
|
||||
},
|
||||
StateGen: stategen.New(db, cache.NewStateSummaryCache()),
|
||||
StateGen: stategen.New(db),
|
||||
}
|
||||
|
||||
req := ðpb.ListValidatorsRequest{PageToken: strconv.Itoa(1), PageSize: 100}
|
||||
@@ -900,7 +899,7 @@ func TestServer_ListValidators_ExceedsMaxPageSize(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestServer_ListValidators_DefaultPageSize(t *testing.T) {
|
||||
db, _ := dbTest.SetupDB(t)
|
||||
db := dbTest.SetupDB(t)
|
||||
|
||||
validators, _, headState := setupValidators(t, db, 1000)
|
||||
want := make([]*ethpb.Validators_ValidatorContainer, len(validators))
|
||||
@@ -924,7 +923,7 @@ func TestServer_ListValidators_DefaultPageSize(t *testing.T) {
|
||||
// We are in epoch 0.
|
||||
Genesis: time.Now(),
|
||||
},
|
||||
StateGen: stategen.New(db, cache.NewStateSummaryCache()),
|
||||
StateGen: stategen.New(db),
|
||||
}
|
||||
|
||||
req := ðpb.ListValidatorsRequest{}
|
||||
@@ -937,7 +936,7 @@ func TestServer_ListValidators_DefaultPageSize(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestServer_ListValidators_FromOldEpoch(t *testing.T) {
|
||||
db, _ := dbTest.SetupDB(t)
|
||||
db := dbTest.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
numEpochs := 30
|
||||
@@ -975,7 +974,7 @@ func TestServer_ListValidators_FromOldEpoch(t *testing.T) {
|
||||
// We are in epoch 30
|
||||
Genesis: time.Now().Add(time.Duration(-1*int64(30*secondsPerEpoch)) * time.Second),
|
||||
},
|
||||
StateGen: stategen.New(db, cache.NewStateSummaryCache()),
|
||||
StateGen: stategen.New(db),
|
||||
}
|
||||
|
||||
req := ðpb.ListValidatorsRequest{
|
||||
@@ -1000,7 +999,7 @@ func TestServer_ListValidators_FromOldEpoch(t *testing.T) {
|
||||
func TestServer_ListValidators_ProcessHeadStateSlots(t *testing.T) {
|
||||
params.UseMinimalConfig()
|
||||
|
||||
db, _ := dbTest.SetupDB(t)
|
||||
db := dbTest.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
headSlot := uint64(32)
|
||||
@@ -1042,7 +1041,7 @@ func TestServer_ListValidators_ProcessHeadStateSlots(t *testing.T) {
|
||||
GenesisTimeFetcher: &mock.ChainService{
|
||||
Genesis: time.Now().Add(time.Duration(-1*int64(secondsPerEpoch)) * time.Second),
|
||||
},
|
||||
StateGen: stategen.New(db, cache.NewStateSummaryCache()),
|
||||
StateGen: stategen.New(db),
|
||||
}
|
||||
|
||||
req := ðpb.ListValidatorsRequest{
|
||||
@@ -1139,7 +1138,7 @@ func TestServer_GetValidator(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestServer_GetValidatorActiveSetChanges(t *testing.T) {
|
||||
db, sc := dbTest.SetupDB(t)
|
||||
db := dbTest.SetupDB(t)
|
||||
|
||||
ctx := context.Background()
|
||||
validators := make([]*ethpb.Validator, 8)
|
||||
@@ -1193,7 +1192,7 @@ func TestServer_GetValidatorActiveSetChanges(t *testing.T) {
|
||||
FinalizedCheckPoint: ðpb.Checkpoint{Epoch: 0, Root: make([]byte, 32)},
|
||||
},
|
||||
GenesisTimeFetcher: &mock.ChainService{},
|
||||
StateGen: stategen.New(db, sc),
|
||||
StateGen: stategen.New(db),
|
||||
}
|
||||
res, err := bs.GetValidatorActiveSetChanges(ctx, ðpb.GetValidatorActiveSetChangesRequest{
|
||||
QueryFilter: ðpb.GetValidatorActiveSetChangesRequest_Genesis{Genesis: true},
|
||||
@@ -1384,7 +1383,7 @@ func TestServer_GetValidatorQueue_PendingExit(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestServer_GetValidatorParticipation_CannotRequestFutureEpoch(t *testing.T) {
|
||||
db, _ := dbTest.SetupDB(t)
|
||||
db := dbTest.SetupDB(t)
|
||||
|
||||
ctx := context.Background()
|
||||
headState := testutil.NewBeaconState()
|
||||
@@ -1395,7 +1394,7 @@ func TestServer_GetValidatorParticipation_CannotRequestFutureEpoch(t *testing.T)
|
||||
State: headState,
|
||||
},
|
||||
GenesisTimeFetcher: &mock.ChainService{},
|
||||
StateGen: stategen.New(db, cache.NewStateSummaryCache()),
|
||||
StateGen: stategen.New(db),
|
||||
}
|
||||
|
||||
wanted := "Cannot retrieve information about an epoch"
|
||||
@@ -1411,7 +1410,7 @@ func TestServer_GetValidatorParticipation_CannotRequestFutureEpoch(t *testing.T)
|
||||
}
|
||||
|
||||
func TestServer_GetValidatorParticipation_UnknownState(t *testing.T) {
|
||||
db, _ := dbTest.SetupDB(t)
|
||||
db := dbTest.SetupDB(t)
|
||||
|
||||
ctx := context.Background()
|
||||
headState := testutil.NewBeaconState()
|
||||
@@ -1426,7 +1425,7 @@ func TestServer_GetValidatorParticipation_UnknownState(t *testing.T) {
|
||||
GenesisTimeFetcher: &mock.ChainService{
|
||||
Genesis: time.Now().Add(time.Duration(-1*int64(slots)) * time.Second),
|
||||
},
|
||||
StateGen: stategen.New(db, cache.NewStateSummaryCache()),
|
||||
StateGen: stategen.New(db),
|
||||
}
|
||||
|
||||
wanted := "Could not get state: unknown state"
|
||||
@@ -1442,7 +1441,7 @@ func TestServer_GetValidatorParticipation_UnknownState(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestServer_GetValidatorParticipation_CurrentAndPrevEpoch(t *testing.T) {
|
||||
db, sc := dbTest.SetupDB(t)
|
||||
db := dbTest.SetupDB(t)
|
||||
|
||||
ctx := context.Background()
|
||||
validatorCount := uint64(100)
|
||||
@@ -1492,7 +1491,7 @@ func TestServer_GetValidatorParticipation_CurrentAndPrevEpoch(t *testing.T) {
|
||||
bs := &Server{
|
||||
BeaconDB: db,
|
||||
HeadFetcher: m,
|
||||
StateGen: stategen.New(db, sc),
|
||||
StateGen: stategen.New(db),
|
||||
GenesisTimeFetcher: &mock.ChainService{
|
||||
Genesis: timeutils.Now().Add(time.Duration(-1*int64(params.BeaconConfig().SlotsPerEpoch*params.BeaconConfig().SecondsPerSlot)) * time.Second),
|
||||
},
|
||||
@@ -1749,7 +1748,7 @@ func TestGetValidatorPerformance_IndicesPubkeys(t *testing.T) {
|
||||
|
||||
func BenchmarkListValidatorBalances(b *testing.B) {
|
||||
b.StopTimer()
|
||||
db, _ := dbTest.SetupDB(b)
|
||||
db := dbTest.SetupDB(b)
|
||||
ctx := context.Background()
|
||||
|
||||
count := 1000
|
||||
@@ -1799,7 +1798,7 @@ func TestServer_GetIndividualVotes_ValidatorsDontExist(t *testing.T) {
|
||||
|
||||
params.UseMinimalConfig()
|
||||
defer params.UseMainnetConfig()
|
||||
db, sc := dbTest.SetupDB(t)
|
||||
db := dbTest.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
validators := uint64(64)
|
||||
@@ -1813,7 +1812,7 @@ func TestServer_GetIndividualVotes_ValidatorsDontExist(t *testing.T) {
|
||||
require.NoError(t, db.SaveBlock(ctx, b))
|
||||
gRoot, err := b.Block.HashTreeRoot()
|
||||
require.NoError(t, err)
|
||||
gen := stategen.New(db, sc)
|
||||
gen := stategen.New(db)
|
||||
require.NoError(t, gen.SaveState(ctx, gRoot, beaconState))
|
||||
require.NoError(t, db.SaveState(ctx, beaconState, gRoot))
|
||||
require.NoError(t, db.SaveGenesisBlockRoot(ctx, gRoot))
|
||||
@@ -1871,7 +1870,7 @@ func TestServer_GetIndividualVotes_Working(t *testing.T) {
|
||||
|
||||
params.UseMinimalConfig()
|
||||
defer params.UseMainnetConfig()
|
||||
db, sc := dbTest.SetupDB(t)
|
||||
db := dbTest.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
validators := uint64(64)
|
||||
@@ -1908,7 +1907,7 @@ func TestServer_GetIndividualVotes_Working(t *testing.T) {
|
||||
require.NoError(t, db.SaveBlock(ctx, b))
|
||||
gRoot, err := b.Block.HashTreeRoot()
|
||||
require.NoError(t, err)
|
||||
gen := stategen.New(db, sc)
|
||||
gen := stategen.New(db)
|
||||
require.NoError(t, gen.SaveState(ctx, gRoot, beaconState))
|
||||
require.NoError(t, db.SaveState(ctx, beaconState, gRoot))
|
||||
require.NoError(t, db.SaveGenesisBlockRoot(ctx, gRoot))
|
||||
|
||||
@@ -63,7 +63,7 @@ func fillDBTestBlocks(ctx context.Context, t *testing.T, db db.Database) (*ethpb
|
||||
}
|
||||
|
||||
func TestServer_GetBlockHeader(t *testing.T) {
|
||||
db, _ := dbTest.SetupDB(t)
|
||||
db := dbTest.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
genBlk, blkContainers := fillDBTestBlocks(ctx, t, db)
|
||||
@@ -160,7 +160,7 @@ func TestServer_GetBlockHeader(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestServer_ListBlockHeaders(t *testing.T) {
|
||||
db, _ := dbTest.SetupDB(t)
|
||||
db := dbTest.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
_, blkContainers := fillDBTestBlocks(ctx, t, db)
|
||||
@@ -241,7 +241,7 @@ func TestServer_ListBlockHeaders(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestServer_ProposeBlock_OK(t *testing.T) {
|
||||
db, _ := dbTest.SetupDB(t)
|
||||
db := dbTest.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
params.SetupTestConfigCleanup(t)
|
||||
params.OverrideBeaconConfig(params.MainnetConfig())
|
||||
@@ -281,7 +281,7 @@ func TestServer_ProposeBlock_OK(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestServer_GetBlock(t *testing.T) {
|
||||
db, _ := dbTest.SetupDB(t)
|
||||
db := dbTest.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
_, blkContainers := fillDBTestBlocks(ctx, t, db)
|
||||
@@ -394,7 +394,7 @@ func TestServer_GetBlock(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestServer_GetBlockRoot(t *testing.T) {
|
||||
db, _ := dbTest.SetupDB(t)
|
||||
db := dbTest.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
genBlk, blkContainers := fillDBTestBlocks(ctx, t, db)
|
||||
@@ -497,7 +497,7 @@ func TestServer_GetBlockRoot(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestServer_ListBlockAttestations(t *testing.T) {
|
||||
db, _ := dbTest.SetupDB(t)
|
||||
db := dbTest.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
_, blkContainers := fillDBTestBlocks(ctx, t, db)
|
||||
|
||||
@@ -19,7 +19,7 @@ import (
|
||||
)
|
||||
|
||||
func TestServer_GetBlock(t *testing.T) {
|
||||
db, _ := dbTest.SetupDB(t)
|
||||
db := dbTest.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
b := testutil.NewBeaconBlock()
|
||||
@@ -48,11 +48,11 @@ func TestServer_GetBlock(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestServer_GetAttestationInclusionSlot(t *testing.T) {
|
||||
db, sc := dbTest.SetupDB(t)
|
||||
db := dbTest.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
bs := &Server{
|
||||
BeaconDB: db,
|
||||
StateGen: stategen.New(db, sc),
|
||||
StateGen: stategen.New(db),
|
||||
GenesisTimeFetcher: &mock.ChainService{Genesis: time.Now().Add(time.Duration(-1*int64(
|
||||
2*params.BeaconConfig().SlotsPerEpoch*params.BeaconConfig().SecondsPerSlot)) * time.Second)},
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
|
||||
func TestServer_GetBeaconState(t *testing.T) {
|
||||
|
||||
db, sc := dbTest.SetupDB(t)
|
||||
db := dbTest.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
st := testutil.NewBeaconState()
|
||||
slot := uint64(100)
|
||||
@@ -25,7 +25,7 @@ func TestServer_GetBeaconState(t *testing.T) {
|
||||
require.NoError(t, db.SaveBlock(ctx, b))
|
||||
gRoot, err := b.Block.HashTreeRoot()
|
||||
require.NoError(t, err)
|
||||
gen := stategen.New(db, sc)
|
||||
gen := stategen.New(db)
|
||||
require.NoError(t, gen.SaveState(ctx, gRoot, st))
|
||||
require.NoError(t, db.SaveState(ctx, st, gRoot))
|
||||
bs := &Server{
|
||||
|
||||
@@ -40,7 +40,7 @@ func TestNodeServer_GetSyncStatus(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNodeServer_GetGenesis(t *testing.T) {
|
||||
db, _ := dbutil.SetupDB(t)
|
||||
db := dbutil.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
addr := common.Address{1, 2, 3}
|
||||
require.NoError(t, db.SaveDepositContractAddress(ctx, addr))
|
||||
|
||||
@@ -27,7 +27,7 @@ import (
|
||||
)
|
||||
|
||||
func TestSubmitAggregateAndProof_Syncing(t *testing.T) {
|
||||
db, _ := dbutil.SetupDB(t)
|
||||
db := dbutil.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
s := &beaconstate.BeaconState{}
|
||||
@@ -45,7 +45,7 @@ func TestSubmitAggregateAndProof_Syncing(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSubmitAggregateAndProof_CantFindValidatorIndex(t *testing.T) {
|
||||
db, _ := dbutil.SetupDB(t)
|
||||
db := dbutil.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
s, err := beaconstate.InitializeFromProto(&pbp2p.BeaconState{
|
||||
@@ -69,7 +69,7 @@ func TestSubmitAggregateAndProof_CantFindValidatorIndex(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSubmitAggregateAndProof_IsAggregatorAndNoAtts(t *testing.T) {
|
||||
db, _ := dbutil.SetupDB(t)
|
||||
db := dbutil.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
s, err := beaconstate.InitializeFromProto(&pbp2p.BeaconState{
|
||||
@@ -106,7 +106,7 @@ func TestSubmitAggregateAndProof_UnaggregateOk(t *testing.T) {
|
||||
c.TargetAggregatorsPerCommittee = 16
|
||||
params.OverrideBeaconConfig(c)
|
||||
|
||||
db, _ := dbutil.SetupDB(t)
|
||||
db := dbutil.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
beaconState, privKeys := testutil.DeterministicGenesisState(t, 32)
|
||||
@@ -142,7 +142,7 @@ func TestSubmitAggregateAndProof_AggregateOk(t *testing.T) {
|
||||
c.TargetAggregatorsPerCommittee = 16
|
||||
params.OverrideBeaconConfig(c)
|
||||
|
||||
db, _ := dbutil.SetupDB(t)
|
||||
db := dbutil.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
beaconState, privKeys := testutil.DeterministicGenesisState(t, 32)
|
||||
@@ -189,7 +189,7 @@ func TestSubmitAggregateAndProof_AggregateNotOk(t *testing.T) {
|
||||
c.TargetAggregatorsPerCommittee = 16
|
||||
params.OverrideBeaconConfig(c)
|
||||
|
||||
db, _ := dbutil.SetupDB(t)
|
||||
db := dbutil.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, 32)
|
||||
@@ -306,7 +306,7 @@ func TestSubmitAggregateAndProof_PreferOwnAttestation(t *testing.T) {
|
||||
c.TargetAggregatorsPerCommittee = 16
|
||||
params.OverrideBeaconConfig(c)
|
||||
|
||||
db, _ := dbutil.SetupDB(t)
|
||||
db := dbutil.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
// This test creates 3 attestations. 0 and 2 have the same attestation data and can be
|
||||
@@ -363,7 +363,7 @@ func TestSubmitAggregateAndProof_SelectsMostBitsWhenOwnAttestationNotPresent(t *
|
||||
c.TargetAggregatorsPerCommittee = 16
|
||||
params.OverrideBeaconConfig(c)
|
||||
|
||||
db, _ := dbutil.SetupDB(t)
|
||||
db := dbutil.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
// This test creates two distinct attestations, neither of which contain the validator's index,
|
||||
|
||||
@@ -31,7 +31,7 @@ func pubKey(i uint64) []byte {
|
||||
}
|
||||
|
||||
func TestGetDuties_OK(t *testing.T) {
|
||||
db, _ := dbutil.SetupDB(t)
|
||||
db := dbutil.SetupDB(t)
|
||||
|
||||
genesis := testutil.NewBeaconBlock()
|
||||
depChainStart := params.BeaconConfig().MinGenesisActiveValidatorCount
|
||||
@@ -102,7 +102,7 @@ func TestGetDuties_OK(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetDuties_CurrentEpoch_ShouldNotFail(t *testing.T) {
|
||||
db, _ := dbutil.SetupDB(t)
|
||||
db := dbutil.SetupDB(t)
|
||||
|
||||
genesis := testutil.NewBeaconBlock()
|
||||
depChainStart := params.BeaconConfig().MinGenesisActiveValidatorCount
|
||||
@@ -145,7 +145,7 @@ func TestGetDuties_CurrentEpoch_ShouldNotFail(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetDuties_MultipleKeys_OK(t *testing.T) {
|
||||
db, _ := dbutil.SetupDB(t)
|
||||
db := dbutil.SetupDB(t)
|
||||
|
||||
genesis := testutil.NewBeaconBlock()
|
||||
depChainStart := uint64(64)
|
||||
@@ -209,7 +209,7 @@ func TestStreamDuties_SyncNotReady(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestStreamDuties_OK(t *testing.T) {
|
||||
db, _ := dbutil.SetupDB(t)
|
||||
db := dbutil.SetupDB(t)
|
||||
|
||||
genesis := testutil.NewBeaconBlock()
|
||||
depChainStart := params.BeaconConfig().MinGenesisActiveValidatorCount
|
||||
@@ -268,7 +268,7 @@ func TestStreamDuties_OK(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestStreamDuties_OK_ChainReorg(t *testing.T) {
|
||||
db, _ := dbutil.SetupDB(t)
|
||||
db := dbutil.SetupDB(t)
|
||||
|
||||
genesis := testutil.NewBeaconBlock()
|
||||
depChainStart := params.BeaconConfig().MinGenesisActiveValidatorCount
|
||||
@@ -359,7 +359,7 @@ func TestAssignValidatorToSubnet(t *testing.T) {
|
||||
}
|
||||
|
||||
func BenchmarkCommitteeAssignment(b *testing.B) {
|
||||
db, _ := dbutil.SetupDB(b)
|
||||
db := dbutil.SetupDB(b)
|
||||
|
||||
genesis := testutil.NewBeaconBlock()
|
||||
depChainStart := uint64(8192 * 2)
|
||||
|
||||
@@ -29,7 +29,7 @@ import (
|
||||
)
|
||||
|
||||
func TestProposeAttestation_OK(t *testing.T) {
|
||||
db, _ := dbutil.SetupDB(t)
|
||||
db := dbutil.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
attesterServer := &Server{
|
||||
@@ -79,7 +79,7 @@ func TestProposeAttestation_OK(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestProposeAttestation_IncorrectSignature(t *testing.T) {
|
||||
db, _ := dbutil.SetupDB(t)
|
||||
db := dbutil.SetupDB(t)
|
||||
|
||||
attesterServer := &Server{
|
||||
HeadFetcher: &mock.ChainService{},
|
||||
@@ -105,7 +105,7 @@ func TestProposeAttestation_IncorrectSignature(t *testing.T) {
|
||||
|
||||
func TestGetAttestationData_OK(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, _ := dbutil.SetupDB(t)
|
||||
db := dbutil.SetupDB(t)
|
||||
|
||||
block := testutil.NewBeaconBlock()
|
||||
block.Block.Slot = 3*params.BeaconConfig().SlotsPerEpoch + 1
|
||||
@@ -198,7 +198,7 @@ func TestAttestationDataAtSlot_HandlesFarAwayJustifiedEpoch(t *testing.T) {
|
||||
//
|
||||
// More background: https://github.com/prysmaticlabs/prysm/issues/2153
|
||||
// This test breaks if it doesnt use mainnet config
|
||||
db, _ := dbutil.SetupDB(t)
|
||||
db := dbutil.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
// Ensure HistoricalRootsLimit matches scenario
|
||||
params.SetupTestConfigCleanup(t)
|
||||
@@ -354,7 +354,7 @@ func TestServer_GetAttestationData_HeadStateSlotGreaterThanRequestSlot(t *testin
|
||||
// attestation is referencing be less than or equal to the attestation data slot.
|
||||
// See: https://github.com/prysmaticlabs/prysm/issues/5164
|
||||
ctx := context.Background()
|
||||
db, sc := dbutil.SetupDB(t)
|
||||
db := dbutil.SetupDB(t)
|
||||
|
||||
slot := 3*params.BeaconConfig().SlotsPerEpoch + 1
|
||||
block := testutil.NewBeaconBlock()
|
||||
@@ -411,7 +411,7 @@ func TestServer_GetAttestationData_HeadStateSlotGreaterThanRequestSlot(t *testin
|
||||
FinalizationFetcher: &mock.ChainService{CurrentJustifiedCheckPoint: beaconState.CurrentJustifiedCheckpoint()},
|
||||
GenesisTimeFetcher: &mock.ChainService{Genesis: time.Now().Add(time.Duration(-1*int64(slot*params.BeaconConfig().SecondsPerSlot)) * time.Second)},
|
||||
StateNotifier: chainService.StateNotifier(),
|
||||
StateGen: stategen.New(db, sc),
|
||||
StateGen: stategen.New(db),
|
||||
}
|
||||
require.NoError(t, db.SaveState(ctx, beaconState, blockRoot))
|
||||
require.NoError(t, db.SaveBlock(ctx, block))
|
||||
@@ -444,7 +444,7 @@ func TestServer_GetAttestationData_HeadStateSlotGreaterThanRequestSlot(t *testin
|
||||
|
||||
func TestGetAttestationData_SucceedsInFirstEpoch(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, _ := dbutil.SetupDB(t)
|
||||
db := dbutil.SetupDB(t)
|
||||
|
||||
slot := uint64(5)
|
||||
block := testutil.NewBeaconBlock()
|
||||
@@ -519,7 +519,7 @@ func TestGetAttestationData_SucceedsInFirstEpoch(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestServer_SubscribeCommitteeSubnets_NoSlots(t *testing.T) {
|
||||
db, _ := dbutil.SetupDB(t)
|
||||
db := dbutil.SetupDB(t)
|
||||
|
||||
attesterServer := &Server{
|
||||
HeadFetcher: &mock.ChainService{},
|
||||
@@ -539,7 +539,7 @@ func TestServer_SubscribeCommitteeSubnets_NoSlots(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestServer_SubscribeCommitteeSubnets_DifferentLengthSlots(t *testing.T) {
|
||||
db, _ := dbutil.SetupDB(t)
|
||||
db := dbutil.SetupDB(t)
|
||||
|
||||
// fixed seed
|
||||
s := rand.NewSource(10)
|
||||
@@ -576,7 +576,7 @@ func TestServer_SubscribeCommitteeSubnets_DifferentLengthSlots(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestServer_SubscribeCommitteeSubnets_MultipleSlots(t *testing.T) {
|
||||
db, _ := dbutil.SetupDB(t)
|
||||
db := dbutil.SetupDB(t)
|
||||
// fixed seed
|
||||
s := rand.NewSource(10)
|
||||
randGen := rand.New(s)
|
||||
|
||||
@@ -23,7 +23,7 @@ import (
|
||||
)
|
||||
|
||||
func TestProposeExit_Notification(t *testing.T) {
|
||||
db, _ := dbutil.SetupDB(t)
|
||||
db := dbutil.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
testutil.ResetCache()
|
||||
deposits, keys, err := testutil.DeterministicDepositsAndKeys(params.BeaconConfig().MinGenesisActiveValidatorCount)
|
||||
@@ -93,7 +93,7 @@ func TestProposeExit_Notification(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestProposeExit_NoPanic(t *testing.T) {
|
||||
db, _ := dbutil.SetupDB(t)
|
||||
db := dbutil.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
testutil.ResetCache()
|
||||
deposits, keys, err := testutil.DeterministicDepositsAndKeys(params.BeaconConfig().MinGenesisActiveValidatorCount)
|
||||
|
||||
@@ -38,7 +38,7 @@ import (
|
||||
)
|
||||
|
||||
func TestProposer_GetBlock_OK(t *testing.T) {
|
||||
db, sc := dbutil.SetupDB(t)
|
||||
db := dbutil.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
testutil.ResetCache()
|
||||
@@ -69,7 +69,7 @@ func TestProposer_GetBlock_OK(t *testing.T) {
|
||||
AttPool: attestations.NewPool(),
|
||||
SlashingsPool: slashings.NewPool(),
|
||||
ExitPool: voluntaryexits.NewPool(),
|
||||
StateGen: stategen.New(db, sc),
|
||||
StateGen: stategen.New(db),
|
||||
}
|
||||
|
||||
randaoReveal, err := testutil.RandaoReveal(beaconState, 0, privKeys)
|
||||
@@ -121,7 +121,7 @@ func TestProposer_GetBlock_OK(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestProposer_GetBlock_AddsUnaggregatedAtts(t *testing.T) {
|
||||
db, sc := dbutil.SetupDB(t)
|
||||
db := dbutil.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
params.SetupTestConfigCleanup(t)
|
||||
@@ -151,7 +151,7 @@ func TestProposer_GetBlock_AddsUnaggregatedAtts(t *testing.T) {
|
||||
SlashingsPool: slashings.NewPool(),
|
||||
AttPool: attestations.NewPool(),
|
||||
ExitPool: voluntaryexits.NewPool(),
|
||||
StateGen: stategen.New(db, sc),
|
||||
StateGen: stategen.New(db),
|
||||
}
|
||||
|
||||
// Generate a bunch of random attestations at slot. These would be considered double votes, but
|
||||
@@ -208,7 +208,7 @@ func TestProposer_GetBlock_AddsUnaggregatedAtts(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestProposer_ProposeBlock_OK(t *testing.T) {
|
||||
db, _ := dbutil.SetupDB(t)
|
||||
db := dbutil.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
params.SetupTestConfigCleanup(t)
|
||||
params.OverrideBeaconConfig(params.MainnetConfig())
|
||||
@@ -244,7 +244,7 @@ func TestProposer_ProposeBlock_OK(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestProposer_ComputeStateRoot_OK(t *testing.T) {
|
||||
db, sc := dbutil.SetupDB(t)
|
||||
db := dbutil.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
params.SetupTestConfigCleanup(t)
|
||||
@@ -267,7 +267,7 @@ func TestProposer_ComputeStateRoot_OK(t *testing.T) {
|
||||
ChainStartFetcher: &mockPOW.POWChain{},
|
||||
Eth1InfoFetcher: &mockPOW.POWChain{},
|
||||
Eth1BlockFetcher: &mockPOW.POWChain{},
|
||||
StateGen: stategen.New(db, sc),
|
||||
StateGen: stategen.New(db),
|
||||
}
|
||||
req := testutil.NewBeaconBlock()
|
||||
req.Block.ProposerIndex = 21
|
||||
@@ -1190,7 +1190,7 @@ func TestProposer_Eth1Data_SmallerDepositCount(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestProposer_Eth1Data_MockEnabled(t *testing.T) {
|
||||
db, _ := dbutil.SetupDB(t)
|
||||
db := dbutil.SetupDB(t)
|
||||
// If a mock eth1 data votes is specified, we use the following for the
|
||||
// eth1data we provide to every proposer based on https://github.com/ethereum/eth2.0-pm/issues/62:
|
||||
//
|
||||
@@ -1790,7 +1790,7 @@ func TestProposer_Eth1Data_MajorityVote(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestProposer_FilterAttestation(t *testing.T) {
|
||||
db, _ := dbutil.SetupDB(t)
|
||||
db := dbutil.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
params.SetupTestConfigCleanup(t)
|
||||
|
||||
@@ -31,7 +31,7 @@ import (
|
||||
)
|
||||
|
||||
func TestValidatorIndex_OK(t *testing.T) {
|
||||
db, _ := dbutil.SetupDB(t)
|
||||
db := dbutil.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
st := testutil.NewBeaconState()
|
||||
require.NoError(t, db.SaveState(ctx, st.Copy(), [32]byte{}))
|
||||
@@ -54,7 +54,7 @@ func TestValidatorIndex_OK(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWaitForActivation_ContextClosed(t *testing.T) {
|
||||
db, _ := dbutil.SetupDB(t)
|
||||
db := dbutil.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
beaconState, err := stateTrie.InitializeFromProto(&pbp2p.BeaconState{
|
||||
@@ -102,7 +102,7 @@ func TestWaitForActivation_ContextClosed(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWaitForActivation_ValidatorOriginallyExists(t *testing.T) {
|
||||
db, _ := dbutil.SetupDB(t)
|
||||
db := dbutil.SetupDB(t)
|
||||
// This test breaks if it doesnt use mainnet config
|
||||
params.SetupTestConfigCleanup(t)
|
||||
params.OverrideBeaconConfig(params.MainnetConfig())
|
||||
@@ -195,7 +195,7 @@ func TestWaitForActivation_ValidatorOriginallyExists(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWaitForActivation_MultipleStatuses(t *testing.T) {
|
||||
db, _ := dbutil.SetupDB(t)
|
||||
db := dbutil.SetupDB(t)
|
||||
|
||||
priv1, err := bls.RandKey()
|
||||
require.NoError(t, err)
|
||||
@@ -285,7 +285,7 @@ func TestWaitForActivation_MultipleStatuses(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWaitForChainStart_ContextClosed(t *testing.T) {
|
||||
db, _ := dbutil.SetupDB(t)
|
||||
db := dbutil.SetupDB(t)
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
chainService := &mockChain.ChainService{}
|
||||
Server := &Server{
|
||||
@@ -313,7 +313,7 @@ func TestWaitForChainStart_ContextClosed(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWaitForChainStart_AlreadyStarted(t *testing.T) {
|
||||
db, _ := dbutil.SetupDB(t)
|
||||
db := dbutil.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
headBlockRoot := [32]byte{0x01, 0x02}
|
||||
trie := testutil.NewBeaconState()
|
||||
@@ -348,7 +348,7 @@ func TestWaitForChainStart_AlreadyStarted(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWaitForChainStart_HeadStateDoesNotExist(t *testing.T) {
|
||||
db, _ := dbutil.SetupDB(t)
|
||||
db := dbutil.SetupDB(t)
|
||||
genesisValidatorRoot := params.BeaconConfig().ZeroHash
|
||||
|
||||
// Set head state to nil
|
||||
@@ -387,7 +387,7 @@ func TestWaitForChainStart_HeadStateDoesNotExist(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWaitForChainStart_NotStartedThenLogFired(t *testing.T) {
|
||||
db, _ := dbutil.SetupDB(t)
|
||||
db := dbutil.SetupDB(t)
|
||||
hook := logTest.NewGlobal()
|
||||
|
||||
genesisValidatorsRoot := bytesutil.ToBytes32([]byte("validators"))
|
||||
|
||||
@@ -24,7 +24,7 @@ import (
|
||||
)
|
||||
|
||||
func TestValidatorStatus_DepositedEth1(t *testing.T) {
|
||||
db, _ := dbutil.SetupDB(t)
|
||||
db := dbutil.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
deposits, _, err := testutil.DeterministicDepositsAndKeys(1)
|
||||
require.NoError(t, err, "Could not generate deposits and keys")
|
||||
@@ -62,7 +62,7 @@ func TestValidatorStatus_DepositedEth1(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestValidatorStatus_Deposited(t *testing.T) {
|
||||
db, _ := dbutil.SetupDB(t)
|
||||
db := dbutil.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
pubKey1 := pubKey(1)
|
||||
@@ -114,7 +114,7 @@ func TestValidatorStatus_Deposited(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestValidatorStatus_PartiallyDeposited(t *testing.T) {
|
||||
db, _ := dbutil.SetupDB(t)
|
||||
db := dbutil.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
pubKey1 := pubKey(1)
|
||||
@@ -166,7 +166,7 @@ func TestValidatorStatus_PartiallyDeposited(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestValidatorStatus_Pending(t *testing.T) {
|
||||
db, _ := dbutil.SetupDB(t)
|
||||
db := dbutil.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
pubKey := pubKey(1)
|
||||
@@ -229,7 +229,7 @@ func TestValidatorStatus_Pending(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestValidatorStatus_Active(t *testing.T) {
|
||||
db, _ := dbutil.SetupDB(t)
|
||||
db := dbutil.SetupDB(t)
|
||||
// This test breaks if it doesnt use mainnet config
|
||||
params.SetupTestConfigCleanup(t)
|
||||
params.OverrideBeaconConfig(params.MainnetConfig())
|
||||
@@ -303,7 +303,7 @@ func TestValidatorStatus_Active(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestValidatorStatus_Exiting(t *testing.T) {
|
||||
db, _ := dbutil.SetupDB(t)
|
||||
db := dbutil.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
pubKey := pubKey(1)
|
||||
@@ -366,7 +366,7 @@ func TestValidatorStatus_Exiting(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestValidatorStatus_Slashing(t *testing.T) {
|
||||
db, _ := dbutil.SetupDB(t)
|
||||
db := dbutil.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
pubKey := pubKey(1)
|
||||
@@ -426,7 +426,7 @@ func TestValidatorStatus_Slashing(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestValidatorStatus_Exited(t *testing.T) {
|
||||
db, _ := dbutil.SetupDB(t)
|
||||
db := dbutil.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
pubKey := pubKey(1)
|
||||
@@ -490,7 +490,7 @@ func TestValidatorStatus_Exited(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestValidatorStatus_UnknownStatus(t *testing.T) {
|
||||
db, _ := dbutil.SetupDB(t)
|
||||
db := dbutil.SetupDB(t)
|
||||
pubKey := pubKey(1)
|
||||
depositCache, err := depositcache.New()
|
||||
require.NoError(t, err)
|
||||
@@ -516,7 +516,7 @@ func TestValidatorStatus_UnknownStatus(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestActivationStatus_OK(t *testing.T) {
|
||||
db, _ := dbutil.SetupDB(t)
|
||||
db := dbutil.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
deposits, _, err := testutil.DeterministicDepositsAndKeys(4)
|
||||
@@ -606,7 +606,7 @@ func TestActivationStatus_OK(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestValidatorStatus_CorrectActivationQueue(t *testing.T) {
|
||||
db, _ := dbutil.SetupDB(t)
|
||||
db := dbutil.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
pbKey := pubKey(5)
|
||||
@@ -709,7 +709,7 @@ func TestValidatorStatus_CorrectActivationQueue(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMultipleValidatorStatus_Pubkeys(t *testing.T) {
|
||||
db, _ := dbutil.SetupDB(t)
|
||||
db := dbutil.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
deposits, _, err := testutil.DeterministicDepositsAndKeys(6)
|
||||
@@ -820,7 +820,7 @@ func TestMultipleValidatorStatus_Pubkeys(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMultipleValidatorStatus_Indices(t *testing.T) {
|
||||
db, _ := dbutil.SetupDB(t)
|
||||
db := dbutil.SetupDB(t)
|
||||
slot := uint64(10000)
|
||||
epoch := helpers.SlotToEpoch(slot)
|
||||
pubKeys := [][]byte{pubKey(1), pubKey(2), pubKey(3), pubKey(4), pubKey(5), pubKey(6), pubKey(7)}
|
||||
@@ -918,7 +918,7 @@ func TestMultipleValidatorStatus_Indices(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestValidatorStatus_Invalid(t *testing.T) {
|
||||
db, _ := dbutil.SetupDB(t)
|
||||
db := dbutil.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
deposits, _, err := testutil.DeterministicDepositsAndKeys(1)
|
||||
require.NoError(t, err, "Could not generate deposits and keys")
|
||||
|
||||
@@ -51,7 +51,6 @@ go_test(
|
||||
],
|
||||
embed = [":go_default_library"],
|
||||
deps = [
|
||||
"//beacon-chain/cache:go_default_library",
|
||||
"//beacon-chain/core/blocks:go_default_library",
|
||||
"//beacon-chain/db:go_default_library",
|
||||
"//beacon-chain/db/testing:go_default_library",
|
||||
|
||||
@@ -108,28 +108,17 @@ func (s *State) StateBySlot(ctx context.Context, slot uint64) (*state.BeaconStat
|
||||
return s.loadStateBySlot(ctx, slot)
|
||||
}
|
||||
|
||||
// StateSummaryExists returns true if the corresponding state summary of the input block root either
|
||||
// exists in the DB or in the cache.
|
||||
func (s *State) StateSummaryExists(ctx context.Context, blockRoot [32]byte) bool {
|
||||
return s.stateSummaryCache.Has(blockRoot) || s.beaconDB.HasStateSummary(ctx, blockRoot)
|
||||
}
|
||||
|
||||
// This returns the state summary object of a given block root, it first checks the cache
|
||||
// then checks the DB. An error is returned if state summary object is nil.
|
||||
func (s *State) stateSummary(ctx context.Context, blockRoot [32]byte) (*pb.StateSummary, error) {
|
||||
var summary *pb.StateSummary
|
||||
var err error
|
||||
if s.stateSummaryCache == nil {
|
||||
return nil, errors.New("nil stateSummaryCache")
|
||||
}
|
||||
if s.stateSummaryCache.Has(blockRoot) {
|
||||
summary = s.stateSummaryCache.Get(blockRoot)
|
||||
} else {
|
||||
summary, err = s.beaconDB.StateSummary(ctx, blockRoot)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
summary, err = s.beaconDB.StateSummary(ctx, blockRoot)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if summary == nil {
|
||||
return s.RecoverStateSummary(ctx, blockRoot)
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
|
||||
"github.com/gogo/protobuf/proto"
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/cache"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
|
||||
testDB "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
|
||||
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||
@@ -19,9 +18,9 @@ import (
|
||||
|
||||
func TestStateByRoot_ColdState(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, _ := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
|
||||
service := New(db, cache.NewStateSummaryCache())
|
||||
service := New(db)
|
||||
service.finalizedInfo.slot = 2
|
||||
service.slotsPerArchivedPoint = 1
|
||||
|
||||
@@ -44,9 +43,9 @@ func TestStateByRoot_ColdState(t *testing.T) {
|
||||
|
||||
func TestStateByRoot_HotStateUsingEpochBoundaryCacheNoReplay(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, _ := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
|
||||
service := New(db, cache.NewStateSummaryCache())
|
||||
service := New(db)
|
||||
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, 32)
|
||||
require.NoError(t, beaconState.SetSlot(10))
|
||||
@@ -62,9 +61,9 @@ func TestStateByRoot_HotStateUsingEpochBoundaryCacheNoReplay(t *testing.T) {
|
||||
|
||||
func TestStateByRoot_HotStateUsingEpochBoundaryCacheWithReplay(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, ssc := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
|
||||
service := New(db, ssc)
|
||||
service := New(db)
|
||||
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, 32)
|
||||
blk := testutil.NewBeaconBlock()
|
||||
@@ -87,9 +86,9 @@ func TestStateByRoot_HotStateUsingEpochBoundaryCacheWithReplay(t *testing.T) {
|
||||
|
||||
func TestStateByRoot_HotStateCached(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, _ := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
|
||||
service := New(db, cache.NewStateSummaryCache())
|
||||
service := New(db)
|
||||
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, 32)
|
||||
r := [32]byte{'A'}
|
||||
@@ -105,9 +104,9 @@ func TestStateByRoot_HotStateCached(t *testing.T) {
|
||||
|
||||
func TestStateByRootInitialSync_UseEpochStateCache(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, ssc := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
|
||||
service := New(db, ssc)
|
||||
service := New(db)
|
||||
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, 32)
|
||||
targetSlot := uint64(10)
|
||||
@@ -123,9 +122,9 @@ func TestStateByRootInitialSync_UseEpochStateCache(t *testing.T) {
|
||||
|
||||
func TestStateByRootInitialSync_UseCache(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, _ := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
|
||||
service := New(db, cache.NewStateSummaryCache())
|
||||
service := New(db)
|
||||
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, 32)
|
||||
r := [32]byte{'A'}
|
||||
@@ -144,8 +143,8 @@ func TestStateByRootInitialSync_UseCache(t *testing.T) {
|
||||
|
||||
func TestStateByRootInitialSync_CanProcessUpTo(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, _ := testDB.SetupDB(t)
|
||||
service := New(db, cache.NewStateSummaryCache())
|
||||
db := testDB.SetupDB(t)
|
||||
service := New(db)
|
||||
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, 32)
|
||||
blk := testutil.NewBeaconBlock()
|
||||
@@ -168,9 +167,9 @@ func TestStateByRootInitialSync_CanProcessUpTo(t *testing.T) {
|
||||
|
||||
func TestStateBySlot_ColdState(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, _ := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
|
||||
service := New(db, cache.NewStateSummaryCache())
|
||||
service := New(db)
|
||||
service.slotsPerArchivedPoint = params.BeaconConfig().SlotsPerEpoch * 2
|
||||
service.finalizedInfo.slot = service.slotsPerArchivedPoint + 1
|
||||
|
||||
@@ -203,9 +202,9 @@ func TestStateBySlot_ColdState(t *testing.T) {
|
||||
|
||||
func TestStateBySlot_HotStateDB(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, _ := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
|
||||
service := New(db, cache.NewStateSummaryCache())
|
||||
service := New(db)
|
||||
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, 32)
|
||||
genesisStateRoot, err := beaconState.HashTreeRoot(ctx)
|
||||
@@ -223,41 +222,10 @@ func TestStateBySlot_HotStateDB(t *testing.T) {
|
||||
assert.Equal(t, slot, loadedState.Slot(), "Did not correctly load state")
|
||||
}
|
||||
|
||||
func TestStateSummary_CanGetFromCacheOrDB(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, _ := testDB.SetupDB(t)
|
||||
|
||||
service := New(db, cache.NewStateSummaryCache())
|
||||
|
||||
r := [32]byte{'a'}
|
||||
summary := &pb.StateSummary{Slot: 100}
|
||||
_, err := service.stateSummary(ctx, r)
|
||||
require.ErrorContains(t, "could not find block in DB", err)
|
||||
|
||||
service.stateSummaryCache.Put(r, summary)
|
||||
got, err := service.stateSummary(ctx, r)
|
||||
require.NoError(t, err)
|
||||
if !proto.Equal(got, summary) {
|
||||
t.Error("Did not get wanted summary")
|
||||
}
|
||||
|
||||
r = [32]byte{'b'}
|
||||
summary = &pb.StateSummary{Root: r[:], Slot: 101}
|
||||
_, err = service.stateSummary(ctx, r)
|
||||
require.ErrorContains(t, "could not find block in DB", err)
|
||||
|
||||
require.NoError(t, service.beaconDB.SaveStateSummary(ctx, summary))
|
||||
got, err = service.stateSummary(ctx, r)
|
||||
require.NoError(t, err)
|
||||
if !proto.Equal(got, summary) {
|
||||
t.Error("Did not get wanted summary")
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadeStateByRoot_Cached(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, _ := testDB.SetupDB(t)
|
||||
service := New(db, cache.NewStateSummaryCache())
|
||||
db := testDB.SetupDB(t)
|
||||
service := New(db)
|
||||
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, 32)
|
||||
r := [32]byte{'A'}
|
||||
@@ -274,8 +242,8 @@ func TestLoadeStateByRoot_Cached(t *testing.T) {
|
||||
|
||||
func TestLoadeStateByRoot_FinalizedState(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, _ := testDB.SetupDB(t)
|
||||
service := New(db, cache.NewStateSummaryCache())
|
||||
db := testDB.SetupDB(t)
|
||||
service := New(db)
|
||||
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, 32)
|
||||
genesisStateRoot, err := beaconState.HashTreeRoot(ctx)
|
||||
@@ -301,8 +269,8 @@ func TestLoadeStateByRoot_FinalizedState(t *testing.T) {
|
||||
|
||||
func TestLoadeStateByRoot_EpochBoundaryStateCanProcess(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, ssc := testDB.SetupDB(t)
|
||||
service := New(db, ssc)
|
||||
db := testDB.SetupDB(t)
|
||||
service := New(db)
|
||||
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, 32)
|
||||
gBlk := testutil.NewBeaconBlock()
|
||||
@@ -327,8 +295,8 @@ func TestLoadeStateByRoot_EpochBoundaryStateCanProcess(t *testing.T) {
|
||||
|
||||
func TestLoadeStateByRoot_FromDBBoundaryCase(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, ssc := testDB.SetupDB(t)
|
||||
service := New(db, ssc)
|
||||
db := testDB.SetupDB(t)
|
||||
service := New(db)
|
||||
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, 32)
|
||||
gBlk := testutil.NewBeaconBlock()
|
||||
@@ -353,8 +321,8 @@ func TestLoadeStateByRoot_FromDBBoundaryCase(t *testing.T) {
|
||||
|
||||
func TestLoadeStateBySlot_CanAdvanceSlotUsingDB(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, _ := testDB.SetupDB(t)
|
||||
service := New(db, cache.NewStateSummaryCache())
|
||||
db := testDB.SetupDB(t)
|
||||
service := New(db)
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, 32)
|
||||
b := testutil.NewBeaconBlock()
|
||||
require.NoError(t, service.beaconDB.SaveBlock(ctx, b))
|
||||
@@ -371,8 +339,8 @@ func TestLoadeStateBySlot_CanAdvanceSlotUsingDB(t *testing.T) {
|
||||
|
||||
func TestLoadeStateBySlot_CanReplayBlock(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, _ := testDB.SetupDB(t)
|
||||
service := New(db, cache.NewStateSummaryCache())
|
||||
db := testDB.SetupDB(t)
|
||||
service := New(db)
|
||||
genesis, keys := testutil.DeterministicGenesisState(t, 64)
|
||||
genesisBlockRoot := bytesutil.ToBytes32(nil)
|
||||
require.NoError(t, db.SaveState(ctx, genesis, genesisBlockRoot))
|
||||
@@ -399,8 +367,8 @@ func TestLoadeStateBySlot_CanReplayBlock(t *testing.T) {
|
||||
|
||||
func TestLastAncestorState_CanGetUsingDB(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, _ := testDB.SetupDB(t)
|
||||
service := New(db, cache.NewStateSummaryCache())
|
||||
db := testDB.SetupDB(t)
|
||||
service := New(db)
|
||||
|
||||
b0 := testutil.NewBeaconBlock()
|
||||
b0.Block.ParentRoot = bytesutil.PadTo([]byte{'a'}, 32)
|
||||
@@ -438,8 +406,8 @@ func TestLastAncestorState_CanGetUsingDB(t *testing.T) {
|
||||
|
||||
func TestLastAncestorState_CanGetUsingCache(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, _ := testDB.SetupDB(t)
|
||||
service := New(db, cache.NewStateSummaryCache())
|
||||
db := testDB.SetupDB(t)
|
||||
service := New(db)
|
||||
|
||||
b0 := testutil.NewBeaconBlock()
|
||||
b0.Block.ParentRoot = bytesutil.PadTo([]byte{'a'}, 32)
|
||||
@@ -477,8 +445,8 @@ func TestLastAncestorState_CanGetUsingCache(t *testing.T) {
|
||||
|
||||
func TestState_HasState(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, _ := testDB.SetupDB(t)
|
||||
service := New(db, cache.NewStateSummaryCache())
|
||||
db := testDB.SetupDB(t)
|
||||
service := New(db)
|
||||
s := testutil.NewBeaconState()
|
||||
rHit1 := [32]byte{1}
|
||||
rHit2 := [32]byte{2}
|
||||
@@ -508,8 +476,8 @@ func TestState_HasState(t *testing.T) {
|
||||
|
||||
func TestState_HasStateInCache(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, _ := testDB.SetupDB(t)
|
||||
service := New(db, cache.NewStateSummaryCache())
|
||||
db := testDB.SetupDB(t)
|
||||
service := New(db)
|
||||
s := testutil.NewBeaconState()
|
||||
rHit1 := [32]byte{1}
|
||||
rHit2 := [32]byte{2}
|
||||
|
||||
@@ -106,11 +106,6 @@ func (s *State) MigrateToCold(ctx context.Context, fRoot [32]byte) error {
|
||||
}
|
||||
}
|
||||
|
||||
// Migrate all state summary objects from state summary cache to DB.
|
||||
if err := s.SaveStateSummariesToDB(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Update finalized info in memory.
|
||||
fInfo, ok, err := s.epochBoundaryStateCache.getByRoot(fRoot)
|
||||
if err != nil {
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/cache"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
|
||||
testDB "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
|
||||
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||
@@ -16,8 +15,8 @@ import (
|
||||
|
||||
func TestMigrateToCold_CanSaveFinalizedInfo(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, c := testDB.SetupDB(t)
|
||||
service := New(db, c)
|
||||
db := testDB.SetupDB(t)
|
||||
service := New(db)
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, 32)
|
||||
b := testutil.NewBeaconBlock()
|
||||
b.Block.Slot = 1
|
||||
@@ -34,9 +33,9 @@ func TestMigrateToCold_CanSaveFinalizedInfo(t *testing.T) {
|
||||
func TestMigrateToCold_HappyPath(t *testing.T) {
|
||||
hook := logTest.NewGlobal()
|
||||
ctx := context.Background()
|
||||
db, _ := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
|
||||
service := New(db, cache.NewStateSummaryCache())
|
||||
service := New(db)
|
||||
service.slotsPerArchivedPoint = 1
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, 32)
|
||||
stateSlot := uint64(1)
|
||||
@@ -64,9 +63,9 @@ func TestMigrateToCold_HappyPath(t *testing.T) {
|
||||
func TestMigrateToCold_RegeneratePath(t *testing.T) {
|
||||
hook := logTest.NewGlobal()
|
||||
ctx := context.Background()
|
||||
db, _ := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
|
||||
service := New(db, cache.NewStateSummaryCache())
|
||||
service := New(db)
|
||||
service.slotsPerArchivedPoint = 1
|
||||
beaconState, pks := testutil.DeterministicGenesisState(t, 32)
|
||||
genesisStateRoot, err := beaconState.HashTreeRoot(ctx)
|
||||
@@ -114,9 +113,9 @@ func TestMigrateToCold_RegeneratePath(t *testing.T) {
|
||||
func TestMigrateToCold_StateExistsInDB(t *testing.T) {
|
||||
hook := logTest.NewGlobal()
|
||||
ctx := context.Background()
|
||||
db, _ := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
|
||||
service := New(db, cache.NewStateSummaryCache())
|
||||
service := New(db)
|
||||
service.slotsPerArchivedPoint = 1
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, 32)
|
||||
stateSlot := uint64(1)
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
|
||||
"github.com/gogo/protobuf/proto"
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/cache"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/db"
|
||||
testDB "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
|
||||
@@ -19,7 +18,7 @@ import (
|
||||
)
|
||||
|
||||
func TestReplayBlocks_AllSkipSlots(t *testing.T) {
|
||||
db, _ := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, 32)
|
||||
genesisBlock := blocks.NewGenesisBlock([]byte{})
|
||||
@@ -40,7 +39,7 @@ func TestReplayBlocks_AllSkipSlots(t *testing.T) {
|
||||
require.NoError(t, beaconState.SetCurrentJustifiedCheckpoint(cp))
|
||||
require.NoError(t, beaconState.SetCurrentEpochAttestations([]*pb.PendingAttestation{}))
|
||||
|
||||
service := New(db, cache.NewStateSummaryCache())
|
||||
service := New(db)
|
||||
targetSlot := params.BeaconConfig().SlotsPerEpoch - 1
|
||||
newState, err := service.ReplayBlocks(context.Background(), beaconState, []*ethpb.SignedBeaconBlock{}, targetSlot)
|
||||
require.NoError(t, err)
|
||||
@@ -48,7 +47,7 @@ func TestReplayBlocks_AllSkipSlots(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestReplayBlocks_SameSlot(t *testing.T) {
|
||||
db, _ := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, 32)
|
||||
genesisBlock := blocks.NewGenesisBlock([]byte{})
|
||||
@@ -69,7 +68,7 @@ func TestReplayBlocks_SameSlot(t *testing.T) {
|
||||
require.NoError(t, beaconState.SetCurrentJustifiedCheckpoint(cp))
|
||||
require.NoError(t, beaconState.SetCurrentEpochAttestations([]*pb.PendingAttestation{}))
|
||||
|
||||
service := New(db, cache.NewStateSummaryCache())
|
||||
service := New(db)
|
||||
targetSlot := beaconState.Slot()
|
||||
newState, err := service.ReplayBlocks(context.Background(), beaconState, []*ethpb.SignedBeaconBlock{}, targetSlot)
|
||||
require.NoError(t, err)
|
||||
@@ -77,7 +76,7 @@ func TestReplayBlocks_SameSlot(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestReplayBlocks_LowerSlotBlock(t *testing.T) {
|
||||
db, _ := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, 32)
|
||||
require.NoError(t, beaconState.SetSlot(1))
|
||||
@@ -99,7 +98,7 @@ func TestReplayBlocks_LowerSlotBlock(t *testing.T) {
|
||||
require.NoError(t, beaconState.SetCurrentJustifiedCheckpoint(cp))
|
||||
require.NoError(t, beaconState.SetCurrentEpochAttestations([]*pb.PendingAttestation{}))
|
||||
|
||||
service := New(db, cache.NewStateSummaryCache())
|
||||
service := New(db)
|
||||
targetSlot := beaconState.Slot()
|
||||
b := testutil.NewBeaconBlock()
|
||||
b.Block.Slot = beaconState.Slot() - 1
|
||||
@@ -109,7 +108,7 @@ func TestReplayBlocks_LowerSlotBlock(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLoadBlocks_FirstBranch(t *testing.T) {
|
||||
db, _ := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
s := &State{
|
||||
beaconDB: db,
|
||||
@@ -138,7 +137,7 @@ func TestLoadBlocks_FirstBranch(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLoadBlocks_SecondBranch(t *testing.T) {
|
||||
db, _ := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
s := &State{
|
||||
beaconDB: db,
|
||||
@@ -165,7 +164,7 @@ func TestLoadBlocks_SecondBranch(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLoadBlocks_ThirdBranch(t *testing.T) {
|
||||
db, _ := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
s := &State{
|
||||
beaconDB: db,
|
||||
@@ -194,7 +193,7 @@ func TestLoadBlocks_ThirdBranch(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLoadBlocks_SameSlots(t *testing.T) {
|
||||
db, _ := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
s := &State{
|
||||
beaconDB: db,
|
||||
@@ -221,7 +220,7 @@ func TestLoadBlocks_SameSlots(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLoadBlocks_SameEndSlots(t *testing.T) {
|
||||
db, _ := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
s := &State{
|
||||
beaconDB: db,
|
||||
@@ -247,7 +246,7 @@ func TestLoadBlocks_SameEndSlots(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLoadBlocks_SameEndSlotsWith2blocks(t *testing.T) {
|
||||
db, _ := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
s := &State{
|
||||
beaconDB: db,
|
||||
@@ -272,7 +271,7 @@ func TestLoadBlocks_SameEndSlotsWith2blocks(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLoadBlocks_BadStart(t *testing.T) {
|
||||
db, _ := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
s := &State{
|
||||
beaconDB: db,
|
||||
@@ -285,7 +284,7 @@ func TestLoadBlocks_BadStart(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLastSavedBlock_Genesis(t *testing.T) {
|
||||
db, _ := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
s := &State{
|
||||
beaconDB: db,
|
||||
@@ -305,7 +304,7 @@ func TestLastSavedBlock_Genesis(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLastSavedBlock_CanGet(t *testing.T) {
|
||||
db, _ := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
s := &State{
|
||||
beaconDB: db,
|
||||
@@ -331,7 +330,7 @@ func TestLastSavedBlock_CanGet(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLastSavedBlock_NoSavedBlock(t *testing.T) {
|
||||
db, _ := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
s := &State{
|
||||
beaconDB: db,
|
||||
@@ -346,7 +345,7 @@ func TestLastSavedBlock_NoSavedBlock(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLastSavedState_Genesis(t *testing.T) {
|
||||
db, _ := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
s := &State{
|
||||
beaconDB: db,
|
||||
@@ -367,7 +366,7 @@ func TestLastSavedState_Genesis(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLastSavedState_CanGet(t *testing.T) {
|
||||
db, _ := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
s := &State{
|
||||
beaconDB: db,
|
||||
@@ -398,7 +397,7 @@ func TestLastSavedState_CanGet(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLastSavedState_NoSavedBlockState(t *testing.T) {
|
||||
db, _ := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
s := &State{
|
||||
beaconDB: db,
|
||||
@@ -718,7 +717,7 @@ func tree4(db db.Database, genesisRoot []byte) ([][32]byte, []*ethpb.SignedBeaco
|
||||
}
|
||||
|
||||
func TestLoadFinalizedBlocks(t *testing.T) {
|
||||
db, _ := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
s := &State{
|
||||
beaconDB: db,
|
||||
|
||||
@@ -25,7 +25,6 @@ type State struct {
|
||||
slotsPerArchivedPoint uint64
|
||||
hotStateCache *cache.HotStateCache
|
||||
finalizedInfo *finalizedInfo
|
||||
stateSummaryCache *cache.StateSummaryCache
|
||||
epochBoundaryStateCache *epochBoundaryState
|
||||
saveHotStateDB *saveHotStateDbConfig
|
||||
}
|
||||
@@ -50,13 +49,12 @@ type finalizedInfo struct {
|
||||
}
|
||||
|
||||
// New returns a new state management object.
|
||||
func New(db db.NoHeadAccessDatabase, stateSummaryCache *cache.StateSummaryCache) *State {
|
||||
func New(db db.NoHeadAccessDatabase) *State {
|
||||
return &State{
|
||||
beaconDB: db,
|
||||
hotStateCache: cache.NewHotStateCache(),
|
||||
finalizedInfo: &finalizedInfo{slot: 0, root: params.BeaconConfig().ZeroHash},
|
||||
slotsPerArchivedPoint: params.BeaconConfig().SlotsPerArchivedPoint,
|
||||
stateSummaryCache: stateSummaryCache,
|
||||
epochBoundaryStateCache: newBoundaryStateCache(),
|
||||
saveHotStateDB: &saveHotStateDbConfig{
|
||||
duration: defaultHotStateDBInterval,
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
|
||||
"github.com/gogo/protobuf/proto"
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/cache"
|
||||
testDB "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil"
|
||||
@@ -16,9 +15,9 @@ import (
|
||||
|
||||
func TestResume(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, _ := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
|
||||
service := New(db, cache.NewStateSummaryCache())
|
||||
service := New(db)
|
||||
b := testutil.NewBeaconBlock()
|
||||
require.NoError(t, service.beaconDB.SaveBlock(ctx, b))
|
||||
root, err := b.Block.HashTreeRoot()
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"math"
|
||||
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/state"
|
||||
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||
@@ -43,27 +42,6 @@ func (s *State) ForceCheckpoint(ctx context.Context, root []byte) error {
|
||||
return s.beaconDB.SaveState(ctx, fs, root32)
|
||||
}
|
||||
|
||||
// SaveStateSummariesToDB saves cached state summaries to DB.
|
||||
func (s *State) SaveStateSummariesToDB(ctx context.Context) error {
|
||||
ctx, span := trace.StartSpan(ctx, "stateGen.SaveStateSummariesToDB")
|
||||
defer span.End()
|
||||
if err := s.beaconDB.SaveStateSummaries(ctx, s.stateSummaryCache.GetAll()); err != nil {
|
||||
return err
|
||||
}
|
||||
s.stateSummaryCache.Clear()
|
||||
return nil
|
||||
}
|
||||
|
||||
// SaveStateSummary saves the relevant state summary for a block and its corresponding state slot in the
|
||||
// state summary cache.
|
||||
func (s *State) SaveStateSummary(_ context.Context, blk *ethpb.SignedBeaconBlock, blockRoot [32]byte) {
|
||||
// Save State summary
|
||||
s.stateSummaryCache.Put(blockRoot, &pb.StateSummary{
|
||||
Slot: blk.Block.Slot,
|
||||
Root: blockRoot[:],
|
||||
})
|
||||
}
|
||||
|
||||
// This saves a post beacon state. On the epoch boundary,
|
||||
// it saves a full state. On an intermediate slot, it saves a back pointer to the
|
||||
// nearest epoch boundary state.
|
||||
@@ -101,11 +79,13 @@ func (s *State) saveStateByRoot(ctx context.Context, blockRoot [32]byte, state *
|
||||
}
|
||||
}
|
||||
|
||||
// On an intermediate slots, save the hot state summary.
|
||||
s.stateSummaryCache.Put(blockRoot, &pb.StateSummary{
|
||||
// On an intermediate slots, save state summary.
|
||||
if err := s.beaconDB.SaveStateSummary(ctx, &pb.StateSummary{
|
||||
Slot: state.Slot(),
|
||||
Root: blockRoot[:],
|
||||
})
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Store the copied state in the hot state cache.
|
||||
s.hotStateCache.Put(blockRoot, state)
|
||||
|
||||
@@ -4,9 +4,7 @@ import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/cache"
|
||||
testDB "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
|
||||
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
||||
@@ -16,9 +14,9 @@ import (
|
||||
|
||||
func TestSaveState_HotStateCanBeSaved(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, _ := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
|
||||
service := New(db, cache.NewStateSummaryCache())
|
||||
service := New(db)
|
||||
service.slotsPerArchivedPoint = 1
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, 32)
|
||||
// This goes to hot section, verify it can save on epoch boundary.
|
||||
@@ -31,15 +29,15 @@ func TestSaveState_HotStateCanBeSaved(t *testing.T) {
|
||||
_, ok, err := service.epochBoundaryStateCache.getByRoot(r)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, true, ok, "Should have saved the state")
|
||||
assert.Equal(t, true, service.stateSummaryCache.Has(r), "Should have saved the state summary")
|
||||
assert.Equal(t, true, service.beaconDB.HasStateSummary(ctx, r), "Should have saved the state summary")
|
||||
}
|
||||
|
||||
func TestSaveState_HotStateCached(t *testing.T) {
|
||||
hook := logTest.NewGlobal()
|
||||
ctx := context.Background()
|
||||
db, _ := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
|
||||
service := New(db, cache.NewStateSummaryCache())
|
||||
service := New(db)
|
||||
service.slotsPerArchivedPoint = 1
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, 32)
|
||||
require.NoError(t, beaconState.SetSlot(params.BeaconConfig().SlotsPerEpoch))
|
||||
@@ -57,9 +55,9 @@ func TestSaveState_HotStateCached(t *testing.T) {
|
||||
|
||||
func TestState_ForceCheckpoint_SavesStateToDatabase(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, ssc := testDB.SetupDB(t)
|
||||
db := testDB.SetupDB(t)
|
||||
|
||||
svc := New(db, ssc)
|
||||
svc := New(db)
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, 32)
|
||||
require.NoError(t, beaconState.SetSlot(params.BeaconConfig().SlotsPerEpoch))
|
||||
|
||||
@@ -77,8 +75,8 @@ func TestState_ForceCheckpoint_SavesStateToDatabase(t *testing.T) {
|
||||
func TestSaveState_AlreadyHas(t *testing.T) {
|
||||
hook := logTest.NewGlobal()
|
||||
ctx := context.Background()
|
||||
db, _ := testDB.SetupDB(t)
|
||||
service := New(db, cache.NewStateSummaryCache())
|
||||
db := testDB.SetupDB(t)
|
||||
service := New(db)
|
||||
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, 32)
|
||||
require.NoError(t, beaconState.SetSlot(params.BeaconConfig().SlotsPerEpoch))
|
||||
@@ -96,8 +94,8 @@ func TestSaveState_AlreadyHas(t *testing.T) {
|
||||
|
||||
func TestSaveState_CanSaveOnEpochBoundary(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, _ := testDB.SetupDB(t)
|
||||
service := New(db, cache.NewStateSummaryCache())
|
||||
db := testDB.SetupDB(t)
|
||||
service := New(db)
|
||||
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, 32)
|
||||
require.NoError(t, beaconState.SetSlot(params.BeaconConfig().SlotsPerEpoch))
|
||||
@@ -109,7 +107,7 @@ func TestSaveState_CanSaveOnEpochBoundary(t *testing.T) {
|
||||
_, ok, err := service.epochBoundaryStateCache.getByRoot(r)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, true, ok, "Did not save epoch boundary state")
|
||||
assert.Equal(t, true, service.stateSummaryCache.Has(r), "Should have saved the state summary")
|
||||
assert.Equal(t, true, service.beaconDB.HasStateSummary(ctx, r), "Should have saved the state summary")
|
||||
// Should have not been saved in DB.
|
||||
require.Equal(t, false, db.HasState(ctx, r))
|
||||
}
|
||||
@@ -117,8 +115,8 @@ func TestSaveState_CanSaveOnEpochBoundary(t *testing.T) {
|
||||
func TestSaveState_NoSaveNotEpochBoundary(t *testing.T) {
|
||||
hook := logTest.NewGlobal()
|
||||
ctx := context.Background()
|
||||
db, _ := testDB.SetupDB(t)
|
||||
service := New(db, cache.NewStateSummaryCache())
|
||||
db := testDB.SetupDB(t)
|
||||
service := New(db)
|
||||
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, 32)
|
||||
require.NoError(t, beaconState.SetSlot(params.BeaconConfig().SlotsPerEpoch-1))
|
||||
@@ -132,7 +130,7 @@ func TestSaveState_NoSaveNotEpochBoundary(t *testing.T) {
|
||||
|
||||
// Should only save state summary.
|
||||
assert.Equal(t, false, service.beaconDB.HasState(ctx, r), "Should not have saved the state")
|
||||
assert.Equal(t, true, service.stateSummaryCache.Has(r), "Should have saved the state summary")
|
||||
assert.Equal(t, true, service.beaconDB.HasStateSummary(ctx, r), "Should have saved the state summary")
|
||||
require.LogsDoNotContain(t, hook, "Saved full state on epoch boundary")
|
||||
// Should have not been saved in DB.
|
||||
require.Equal(t, false, db.HasState(ctx, r))
|
||||
@@ -141,8 +139,8 @@ func TestSaveState_NoSaveNotEpochBoundary(t *testing.T) {
|
||||
func TestSaveState_CanSaveHotStateToDB(t *testing.T) {
|
||||
hook := logTest.NewGlobal()
|
||||
ctx := context.Background()
|
||||
db, _ := testDB.SetupDB(t)
|
||||
service := New(db, cache.NewStateSummaryCache())
|
||||
db := testDB.SetupDB(t)
|
||||
service := New(db)
|
||||
service.EnableSaveHotStateToDB(ctx)
|
||||
beaconState, _ := testutil.DeterministicGenesisState(t, 32)
|
||||
require.NoError(t, beaconState.SetSlot(defaultHotStateDBInterval))
|
||||
@@ -158,8 +156,8 @@ func TestSaveState_CanSaveHotStateToDB(t *testing.T) {
|
||||
func TestEnableSaveHotStateToDB_Enabled(t *testing.T) {
|
||||
hook := logTest.NewGlobal()
|
||||
ctx := context.Background()
|
||||
db, _ := testDB.SetupDB(t)
|
||||
service := New(db, cache.NewStateSummaryCache())
|
||||
db := testDB.SetupDB(t)
|
||||
service := New(db)
|
||||
|
||||
service.EnableSaveHotStateToDB(ctx)
|
||||
require.LogsContain(t, hook, "Entering mode to save hot states in DB")
|
||||
@@ -169,8 +167,8 @@ func TestEnableSaveHotStateToDB_Enabled(t *testing.T) {
|
||||
func TestEnableSaveHotStateToDB_AlreadyEnabled(t *testing.T) {
|
||||
hook := logTest.NewGlobal()
|
||||
ctx := context.Background()
|
||||
db, _ := testDB.SetupDB(t)
|
||||
service := New(db, cache.NewStateSummaryCache())
|
||||
db := testDB.SetupDB(t)
|
||||
service := New(db)
|
||||
service.saveHotStateDB.enabled = true
|
||||
service.EnableSaveHotStateToDB(ctx)
|
||||
require.LogsDoNotContain(t, hook, "Entering mode to save hot states in DB")
|
||||
@@ -180,8 +178,8 @@ func TestEnableSaveHotStateToDB_AlreadyEnabled(t *testing.T) {
|
||||
func TestEnableSaveHotStateToDB_Disabled(t *testing.T) {
|
||||
hook := logTest.NewGlobal()
|
||||
ctx := context.Background()
|
||||
db, _ := testDB.SetupDB(t)
|
||||
service := New(db, cache.NewStateSummaryCache())
|
||||
db := testDB.SetupDB(t)
|
||||
service := New(db)
|
||||
service.saveHotStateDB.enabled = true
|
||||
b := testutil.NewBeaconBlock()
|
||||
require.NoError(t, db.SaveBlock(ctx, b))
|
||||
@@ -197,25 +195,9 @@ func TestEnableSaveHotStateToDB_Disabled(t *testing.T) {
|
||||
func TestEnableSaveHotStateToDB_AlreadyDisabled(t *testing.T) {
|
||||
hook := logTest.NewGlobal()
|
||||
ctx := context.Background()
|
||||
db, _ := testDB.SetupDB(t)
|
||||
service := New(db, cache.NewStateSummaryCache())
|
||||
db := testDB.SetupDB(t)
|
||||
service := New(db)
|
||||
require.NoError(t, service.DisableSaveHotStateToDB(ctx))
|
||||
require.LogsDoNotContain(t, hook, "Exiting mode to save hot states in DB")
|
||||
require.Equal(t, false, service.saveHotStateDB.enabled)
|
||||
}
|
||||
|
||||
func TestState_SaveStateSummariesToDB(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, _ := testDB.SetupDB(t)
|
||||
service := New(db, cache.NewStateSummaryCache())
|
||||
|
||||
r := [32]byte{'a'}
|
||||
s := &pb.StateSummary{Root: r[:], Slot: 1}
|
||||
service.stateSummaryCache.Put(r, s)
|
||||
require.Equal(t, false, service.beaconDB.HasStateSummary(ctx, r))
|
||||
require.Equal(t, true, service.stateSummaryCache.Has(r))
|
||||
|
||||
require.NoError(t, service.SaveStateSummariesToDB(ctx))
|
||||
require.Equal(t, true, service.beaconDB.HasStateSummary(ctx, r))
|
||||
require.Equal(t, false, service.stateSummaryCache.Has(r))
|
||||
}
|
||||
|
||||
@@ -135,12 +135,12 @@ go_test(
|
||||
shard_count = 4,
|
||||
deps = [
|
||||
"//beacon-chain/blockchain/testing:go_default_library",
|
||||
"//beacon-chain/cache:go_default_library",
|
||||
"//beacon-chain/core/feed:go_default_library",
|
||||
"//beacon-chain/core/feed/state:go_default_library",
|
||||
"//beacon-chain/core/helpers:go_default_library",
|
||||
"//beacon-chain/core/state:go_default_library",
|
||||
"//beacon-chain/db:go_default_library",
|
||||
"//beacon-chain/db/kv:go_default_library",
|
||||
"//beacon-chain/db/testing:go_default_library",
|
||||
"//beacon-chain/flags:go_default_library",
|
||||
"//beacon-chain/operations/attestations:go_default_library",
|
||||
|
||||
@@ -33,7 +33,6 @@ func NewRegularSyncFuzz(cfg *Config) *Service {
|
||||
blkRootToPendingAtts: make(map[[32]byte][]*ethpb.SignedAggregateAttestationAndProof),
|
||||
stateNotifier: cfg.StateNotifier,
|
||||
blockNotifier: cfg.BlockNotifier,
|
||||
stateSummaryCache: cfg.StateSummaryCache,
|
||||
stateGen: cfg.StateGen,
|
||||
rateLimiter: rLimiter,
|
||||
}
|
||||
|
||||
@@ -257,7 +257,7 @@ func TestBlocksFetcher_RoundRobin(t *testing.T) {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
cache.initializeRootCache(tt.expectedBlockSlots, t)
|
||||
|
||||
beaconDB, _ := dbtest.SetupDB(t)
|
||||
beaconDB := dbtest.SetupDB(t)
|
||||
|
||||
p := p2pt.NewTestP2P(t)
|
||||
connectPeers(t, p, tt.peers, p.Peers())
|
||||
|
||||
@@ -145,7 +145,7 @@ func TestBlocksFetcher_findFork(t *testing.T) {
|
||||
// - C'- D'- E'- F'- G'
|
||||
// Allow fetcher to proceed till E, then connect peer having alternative branch.
|
||||
// Test that G' slot can be reached i.e. fetcher can track back and explore alternative paths.
|
||||
beaconDB, _ := dbtest.SetupDB(t)
|
||||
beaconDB := dbtest.SetupDB(t)
|
||||
p2p := p2pt.NewTestP2P(t)
|
||||
|
||||
// Chain contains blocks from 8 epochs (from 0 to 7, 256 is the start slot of epoch8).
|
||||
@@ -298,7 +298,7 @@ func TestBlocksFetcher_findFork(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestBlocksFetcher_findForkWithPeer(t *testing.T) {
|
||||
beaconDB, _ := dbtest.SetupDB(t)
|
||||
beaconDB := dbtest.SetupDB(t)
|
||||
p1 := p2pt.NewTestP2P(t)
|
||||
|
||||
knownBlocks := extendBlockSequence(t, []*eth.SignedBeaconBlock{}, 128)
|
||||
@@ -404,7 +404,7 @@ func TestBlocksFetcher_findForkWithPeer(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestBlocksFetcher_findAncestor(t *testing.T) {
|
||||
beaconDB, _ := dbtest.SetupDB(t)
|
||||
beaconDB := dbtest.SetupDB(t)
|
||||
p2p := p2pt.NewTestP2P(t)
|
||||
|
||||
knownBlocks := extendBlockSequence(t, []*eth.SignedBeaconBlock{}, 128)
|
||||
|
||||
@@ -1029,7 +1029,7 @@ func TestBlocksQueue_stuckInUnfavourableFork(t *testing.T) {
|
||||
})
|
||||
defer resetCfg()
|
||||
|
||||
beaconDB, _ := dbtest.SetupDB(t)
|
||||
beaconDB := dbtest.SetupDB(t)
|
||||
p2p := p2pt.NewTestP2P(t)
|
||||
|
||||
// The chain1 contains 250 blocks and is a dead end.
|
||||
@@ -1231,7 +1231,7 @@ func TestBlocksQueue_stuckWhenHeadIsSetToOrphanedBlock(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
beaconDB, _ := dbtest.SetupDB(t)
|
||||
beaconDB := dbtest.SetupDB(t)
|
||||
p2p := p2pt.NewTestP2P(t)
|
||||
|
||||
chain := extendBlockSequence(t, []*eth.SignedBeaconBlock{}, 128)
|
||||
|
||||
@@ -73,7 +73,7 @@ func TestMain(m *testing.M) {
|
||||
|
||||
func initializeTestServices(t *testing.T, blocks []uint64, peers []*peerData) (*mock.ChainService, *p2pt.TestP2P, db.Database) {
|
||||
cache.initializeRootCache(blocks, t)
|
||||
beaconDB, _ := dbtest.SetupDB(t)
|
||||
beaconDB := dbtest.SetupDB(t)
|
||||
|
||||
p := p2pt.NewTestP2P(t)
|
||||
connectPeers(t, p, peers, p.Peers())
|
||||
|
||||
@@ -273,7 +273,7 @@ func TestService_roundRobinSync(t *testing.T) {
|
||||
cache.initializeRootCache(tt.availableBlockSlots, t)
|
||||
|
||||
p := p2pt.NewTestP2P(t)
|
||||
beaconDB, _ := dbtest.SetupDB(t)
|
||||
beaconDB := dbtest.SetupDB(t)
|
||||
|
||||
connectPeers(t, p, tt.peers, p.Peers())
|
||||
cache.RLock()
|
||||
@@ -318,7 +318,7 @@ func TestService_roundRobinSync(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestService_processBlock(t *testing.T) {
|
||||
beaconDB, _ := dbtest.SetupDB(t)
|
||||
beaconDB := dbtest.SetupDB(t)
|
||||
genesisBlk := testutil.NewBeaconBlock()
|
||||
genesisBlkRoot, err := genesisBlk.Block.HashTreeRoot()
|
||||
require.NoError(t, err)
|
||||
@@ -378,7 +378,7 @@ func TestService_processBlock(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestService_processBlockBatch(t *testing.T) {
|
||||
beaconDB, _ := dbtest.SetupDB(t)
|
||||
beaconDB := dbtest.SetupDB(t)
|
||||
genesisBlk := testutil.NewBeaconBlock()
|
||||
genesisBlkRoot, err := genesisBlk.Block.HashTreeRoot()
|
||||
require.NoError(t, err)
|
||||
@@ -478,7 +478,7 @@ func TestService_blockProviderScoring(t *testing.T) {
|
||||
cache.initializeRootCache(makeSequence(1, 640), t)
|
||||
|
||||
p := p2pt.NewTestP2P(t)
|
||||
beaconDB, _ := dbtest.SetupDB(t)
|
||||
beaconDB := dbtest.SetupDB(t)
|
||||
|
||||
peerData := []*peerData{
|
||||
{
|
||||
@@ -569,7 +569,7 @@ func TestService_syncToFinalizedEpoch(t *testing.T) {
|
||||
cache.initializeRootCache(makeSequence(1, 640), t)
|
||||
|
||||
p := p2pt.NewTestP2P(t)
|
||||
beaconDB, _ := dbtest.SetupDB(t)
|
||||
beaconDB := dbtest.SetupDB(t)
|
||||
cache.RLock()
|
||||
genesisRoot := cache.rootCache[0]
|
||||
cache.RUnlock()
|
||||
|
||||
@@ -367,7 +367,7 @@ func TestService_Resync(t *testing.T) {
|
||||
{blocks: makeSequence(1, 160), finalizedEpoch: 5, headSlot: 160},
|
||||
}, p.Peers())
|
||||
cache.initializeRootCache(makeSequence(1, 160), t)
|
||||
beaconDB, _ := dbtest.SetupDB(t)
|
||||
beaconDB := dbtest.SetupDB(t)
|
||||
err := beaconDB.SaveBlock(context.Background(), testutil.NewBeaconBlock())
|
||||
require.NoError(t, err)
|
||||
cache.RLock()
|
||||
|
||||
@@ -59,9 +59,8 @@ func (s *Service) processPendingAtts(ctx context.Context) error {
|
||||
s.pendingAttsLock.RLock()
|
||||
attestations := s.blkRootToPendingAtts[bRoot]
|
||||
s.pendingAttsLock.RUnlock()
|
||||
// Has the pending attestation's missing block arrived and the node processed block yet?
|
||||
hasStateSummary := s.db.HasStateSummary(ctx, bRoot) || s.stateSummaryCache.Has(bRoot)
|
||||
if s.db.HasBlock(ctx, bRoot) && (s.db.HasState(ctx, bRoot) || hasStateSummary) {
|
||||
// has the pending attestation's missing block arrived and the node processed block yet?
|
||||
if s.db.HasBlock(ctx, bRoot) && (s.db.HasState(ctx, bRoot) || s.db.HasStateSummary(ctx, bRoot)) {
|
||||
for _, signedAtt := range attestations {
|
||||
att := signedAtt.Message
|
||||
// The pending attestations can arrive in both aggregated and unaggregated forms,
|
||||
|
||||
@@ -11,7 +11,6 @@ import (
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/go-bitfield"
|
||||
mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/cache"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
||||
dbtest "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/operations/attestations"
|
||||
@@ -32,7 +31,7 @@ import (
|
||||
|
||||
func TestProcessPendingAtts_NoBlockRequestBlock(t *testing.T) {
|
||||
hook := logTest.NewGlobal()
|
||||
db, _ := dbtest.SetupDB(t)
|
||||
db := dbtest.SetupDB(t)
|
||||
p1 := p2ptest.NewTestP2P(t)
|
||||
p2 := p2ptest.NewTestP2P(t)
|
||||
p1.Connect(p2)
|
||||
@@ -46,7 +45,6 @@ func TestProcessPendingAtts_NoBlockRequestBlock(t *testing.T) {
|
||||
db: db,
|
||||
chain: &mock.ChainService{Genesis: timeutils.Now(), FinalizedCheckPoint: ðpb.Checkpoint{}},
|
||||
blkRootToPendingAtts: make(map[[32]byte][]*ethpb.SignedAggregateAttestationAndProof),
|
||||
stateSummaryCache: cache.NewStateSummaryCache(),
|
||||
chainStarted: abool.New(),
|
||||
}
|
||||
|
||||
@@ -58,7 +56,7 @@ func TestProcessPendingAtts_NoBlockRequestBlock(t *testing.T) {
|
||||
|
||||
func TestProcessPendingAtts_HasBlockSaveUnAggregatedAtt(t *testing.T) {
|
||||
hook := logTest.NewGlobal()
|
||||
db, _ := dbtest.SetupDB(t)
|
||||
db := dbtest.SetupDB(t)
|
||||
p1 := p2ptest.NewTestP2P(t)
|
||||
validators := uint64(256)
|
||||
testutil.ResetCache()
|
||||
@@ -119,7 +117,6 @@ func TestProcessPendingAtts_HasBlockSaveUnAggregatedAtt(t *testing.T) {
|
||||
}},
|
||||
blkRootToPendingAtts: make(map[[32]byte][]*ethpb.SignedAggregateAttestationAndProof),
|
||||
attPool: attestations.NewPool(),
|
||||
stateSummaryCache: cache.NewStateSummaryCache(),
|
||||
seenAttestationCache: c,
|
||||
}
|
||||
|
||||
@@ -142,7 +139,7 @@ func TestProcessPendingAtts_HasBlockSaveUnAggregatedAtt(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestProcessPendingAtts_NoBroadcastWithBadSignature(t *testing.T) {
|
||||
db, _ := dbtest.SetupDB(t)
|
||||
db := dbtest.SetupDB(t)
|
||||
p1 := p2ptest.NewTestP2P(t)
|
||||
|
||||
r := &Service{
|
||||
@@ -151,7 +148,6 @@ func TestProcessPendingAtts_NoBroadcastWithBadSignature(t *testing.T) {
|
||||
chain: &mock.ChainService{Genesis: timeutils.Now(), FinalizedCheckPoint: ðpb.Checkpoint{Root: make([]byte, 32)}},
|
||||
blkRootToPendingAtts: make(map[[32]byte][]*ethpb.SignedAggregateAttestationAndProof),
|
||||
attPool: attestations.NewPool(),
|
||||
stateSummaryCache: cache.NewStateSummaryCache(),
|
||||
}
|
||||
|
||||
priv, err := bls.RandKey()
|
||||
@@ -235,7 +231,6 @@ func TestProcessPendingAtts_NoBroadcastWithBadSignature(t *testing.T) {
|
||||
}},
|
||||
blkRootToPendingAtts: make(map[[32]byte][]*ethpb.SignedAggregateAttestationAndProof),
|
||||
attPool: attestations.NewPool(),
|
||||
stateSummaryCache: cache.NewStateSummaryCache(),
|
||||
seenAttestationCache: c,
|
||||
}
|
||||
|
||||
@@ -247,7 +242,7 @@ func TestProcessPendingAtts_NoBroadcastWithBadSignature(t *testing.T) {
|
||||
|
||||
func TestProcessPendingAtts_HasBlockSaveAggregatedAtt(t *testing.T) {
|
||||
hook := logTest.NewGlobal()
|
||||
db, _ := dbtest.SetupDB(t)
|
||||
db := dbtest.SetupDB(t)
|
||||
p1 := p2ptest.NewTestP2P(t)
|
||||
validators := uint64(256)
|
||||
testutil.ResetCache()
|
||||
@@ -312,7 +307,6 @@ func TestProcessPendingAtts_HasBlockSaveAggregatedAtt(t *testing.T) {
|
||||
}},
|
||||
blkRootToPendingAtts: make(map[[32]byte][]*ethpb.SignedAggregateAttestationAndProof),
|
||||
attPool: attestations.NewPool(),
|
||||
stateSummaryCache: cache.NewStateSummaryCache(),
|
||||
seenAttestationCache: c,
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ import (
|
||||
// \- b3
|
||||
// Test b1 was missing then received and we can process b0 -> b1 -> b2
|
||||
func TestRegularSyncBeaconBlockSubscriber_ProcessPendingBlocks1(t *testing.T) {
|
||||
db, stateSummaryCache := dbtest.SetupDB(t)
|
||||
db := dbtest.SetupDB(t)
|
||||
|
||||
p1 := p2ptest.NewTestP2P(t)
|
||||
r := &Service{
|
||||
@@ -44,8 +44,7 @@ func TestRegularSyncBeaconBlockSubscriber_ProcessPendingBlocks1(t *testing.T) {
|
||||
},
|
||||
slotToPendingBlocks: gcache.New(time.Second, 2*time.Second),
|
||||
seenPendingBlocks: make(map[[32]byte]bool),
|
||||
stateSummaryCache: stateSummaryCache,
|
||||
stateGen: stategen.New(db, stateSummaryCache),
|
||||
stateGen: stategen.New(db),
|
||||
}
|
||||
err := r.initCaches()
|
||||
require.NoError(t, err)
|
||||
@@ -92,7 +91,7 @@ func TestRegularSyncBeaconBlockSubscriber_ProcessPendingBlocks1(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRegularSync_InsertDuplicateBlocks(t *testing.T) {
|
||||
db, _ := dbtest.SetupDB(t)
|
||||
db := dbtest.SetupDB(t)
|
||||
|
||||
p1 := p2ptest.NewTestP2P(t)
|
||||
r := &Service{
|
||||
@@ -141,7 +140,7 @@ func TestRegularSync_InsertDuplicateBlocks(t *testing.T) {
|
||||
// \- b3 - b4
|
||||
// Test b2 and b3 were missed, after receiving them we can process 2 chains.
|
||||
func TestRegularSyncBeaconBlockSubscriber_ProcessPendingBlocks_2Chains(t *testing.T) {
|
||||
db, stateSummaryCache := dbtest.SetupDB(t)
|
||||
db := dbtest.SetupDB(t)
|
||||
p1 := p2ptest.NewTestP2P(t)
|
||||
p2 := p2ptest.NewTestP2P(t)
|
||||
p1.Connect(p2)
|
||||
@@ -173,8 +172,7 @@ func TestRegularSyncBeaconBlockSubscriber_ProcessPendingBlocks_2Chains(t *testin
|
||||
},
|
||||
slotToPendingBlocks: gcache.New(time.Second, 2*time.Second),
|
||||
seenPendingBlocks: make(map[[32]byte]bool),
|
||||
stateSummaryCache: stateSummaryCache,
|
||||
stateGen: stategen.New(db, stateSummaryCache),
|
||||
stateGen: stategen.New(db),
|
||||
}
|
||||
err := r.initCaches()
|
||||
require.NoError(t, err)
|
||||
@@ -247,7 +245,7 @@ func TestRegularSyncBeaconBlockSubscriber_ProcessPendingBlocks_2Chains(t *testin
|
||||
}
|
||||
|
||||
func TestRegularSyncBeaconBlockSubscriber_PruneOldPendingBlocks(t *testing.T) {
|
||||
db, _ := dbtest.SetupDB(t)
|
||||
db := dbtest.SetupDB(t)
|
||||
p1 := p2ptest.NewTestP2P(t)
|
||||
p2 := p2ptest.NewTestP2P(t)
|
||||
p1.Connect(p2)
|
||||
@@ -331,7 +329,7 @@ func TestService_sortedPendingSlots(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestService_BatchRootRequest(t *testing.T) {
|
||||
db, _ := dbtest.SetupDB(t)
|
||||
db := dbtest.SetupDB(t)
|
||||
p1 := p2ptest.NewTestP2P(t)
|
||||
p2 := p2ptest.NewTestP2P(t)
|
||||
p1.Connect(p2)
|
||||
|
||||
@@ -33,7 +33,7 @@ func TestRPCBeaconBlocksByRange_RPCHandlerReturnsBlocks(t *testing.T) {
|
||||
p2 := p2ptest.NewTestP2P(t)
|
||||
p1.Connect(p2)
|
||||
assert.Equal(t, 1, len(p1.BHost.Network().Peers()), "Expected peers to be connected")
|
||||
d, _ := db.SetupDB(t)
|
||||
d := db.SetupDB(t)
|
||||
|
||||
req := &pb.BeaconBlocksByRangeRequest{
|
||||
StartSlot: 100,
|
||||
@@ -88,7 +88,7 @@ func TestRPCBeaconBlocksByRange_ReturnCorrectNumberBack(t *testing.T) {
|
||||
p2 := p2ptest.NewTestP2P(t)
|
||||
p1.Connect(p2)
|
||||
assert.Equal(t, 1, len(p1.BHost.Network().Peers()), "Expected peers to be connected")
|
||||
d, _ := db.SetupDB(t)
|
||||
d := db.SetupDB(t)
|
||||
|
||||
req := &pb.BeaconBlocksByRangeRequest{
|
||||
StartSlot: 0,
|
||||
@@ -153,7 +153,7 @@ func TestRPCBeaconBlocksByRange_RPCHandlerReturnsSortedBlocks(t *testing.T) {
|
||||
p2 := p2ptest.NewTestP2P(t)
|
||||
p1.Connect(p2)
|
||||
assert.Equal(t, 1, len(p1.BHost.Network().Peers()), "Expected peers to be connected")
|
||||
d, _ := db.SetupDB(t)
|
||||
d := db.SetupDB(t)
|
||||
|
||||
req := &pb.BeaconBlocksByRangeRequest{
|
||||
StartSlot: 200,
|
||||
@@ -216,7 +216,7 @@ func TestRPCBeaconBlocksByRange_ReturnsGenesisBlock(t *testing.T) {
|
||||
p2 := p2ptest.NewTestP2P(t)
|
||||
p1.Connect(p2)
|
||||
assert.Equal(t, 1, len(p1.BHost.Network().Peers()), "Expected peers to be connected")
|
||||
d, _ := db.SetupDB(t)
|
||||
d := db.SetupDB(t)
|
||||
|
||||
req := &pb.BeaconBlocksByRangeRequest{
|
||||
StartSlot: 0,
|
||||
@@ -272,7 +272,7 @@ func TestRPCBeaconBlocksByRange_ReturnsGenesisBlock(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRPCBeaconBlocksByRange_RPCHandlerRateLimitOverflow(t *testing.T) {
|
||||
d, _ := db.SetupDB(t)
|
||||
d := db.SetupDB(t)
|
||||
saveBlocks := func(req *pb.BeaconBlocksByRangeRequest) {
|
||||
// Populate the database with blocks that would match the request.
|
||||
parentRoot := [32]byte{}
|
||||
@@ -527,7 +527,7 @@ func TestRPCBeaconBlocksByRange_validateRangeRequest(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRPCBeaconBlocksByRange_EnforceResponseInvariants(t *testing.T) {
|
||||
d, _ := db.SetupDB(t)
|
||||
d := db.SetupDB(t)
|
||||
hook := logTest.NewGlobal()
|
||||
saveBlocks := func(req *pb.BeaconBlocksByRangeRequest) {
|
||||
// Populate the database with blocks that would match the request.
|
||||
@@ -737,7 +737,7 @@ func TestRPCBeaconBlocksByRange_FilterBlocks(t *testing.T) {
|
||||
t.Run("process normal range", func(t *testing.T) {
|
||||
p1 := p2ptest.NewTestP2P(t)
|
||||
p2 := p2ptest.NewTestP2P(t)
|
||||
d, _ := db.SetupDB(t)
|
||||
d := db.SetupDB(t)
|
||||
|
||||
p1.Connect(p2)
|
||||
assert.Equal(t, 1, len(p1.BHost.Network().Peers()), "Expected peers to be connected")
|
||||
@@ -768,7 +768,7 @@ func TestRPCBeaconBlocksByRange_FilterBlocks(t *testing.T) {
|
||||
t.Run("process non linear blocks", func(t *testing.T) {
|
||||
p1 := p2ptest.NewTestP2P(t)
|
||||
p2 := p2ptest.NewTestP2P(t)
|
||||
d, _ := db.SetupDB(t)
|
||||
d := db.SetupDB(t)
|
||||
|
||||
p1.Connect(p2)
|
||||
assert.Equal(t, 1, len(p1.BHost.Network().Peers()), "Expected peers to be connected")
|
||||
@@ -803,7 +803,7 @@ func TestRPCBeaconBlocksByRange_FilterBlocks(t *testing.T) {
|
||||
t.Run("process non linear blocks with 2nd bad batch", func(t *testing.T) {
|
||||
p1 := p2ptest.NewTestP2P(t)
|
||||
p2 := p2ptest.NewTestP2P(t)
|
||||
d, _ := db.SetupDB(t)
|
||||
d := db.SetupDB(t)
|
||||
|
||||
p1.Connect(p2)
|
||||
assert.Equal(t, 1, len(p1.BHost.Network().Peers()), "Expected peers to be connected")
|
||||
@@ -838,7 +838,7 @@ func TestRPCBeaconBlocksByRange_FilterBlocks(t *testing.T) {
|
||||
t.Run("only return finalized blocks", func(t *testing.T) {
|
||||
p1 := p2ptest.NewTestP2P(t)
|
||||
p2 := p2ptest.NewTestP2P(t)
|
||||
d, _ := db.SetupDB(t)
|
||||
d := db.SetupDB(t)
|
||||
|
||||
p1.Connect(p2)
|
||||
assert.Equal(t, 1, len(p1.BHost.Network().Peers()), "Expected peers to be connected")
|
||||
@@ -878,7 +878,7 @@ func TestRPCBeaconBlocksByRange_FilterBlocks(t *testing.T) {
|
||||
t.Run("reject duplicate and non canonical blocks", func(t *testing.T) {
|
||||
p1 := p2ptest.NewTestP2P(t)
|
||||
p2 := p2ptest.NewTestP2P(t)
|
||||
d, _ := db.SetupDB(t)
|
||||
d := db.SetupDB(t)
|
||||
|
||||
p1.Connect(p2)
|
||||
assert.Equal(t, 1, len(p1.BHost.Network().Peers()), "Expected peers to be connected")
|
||||
|
||||
@@ -32,7 +32,7 @@ func TestRecentBeaconBlocksRPCHandler_ReturnsBlocks(t *testing.T) {
|
||||
p2 := p2ptest.NewTestP2P(t)
|
||||
p1.Connect(p2)
|
||||
assert.Equal(t, 1, len(p1.BHost.Network().Peers()), "Expected peers to be connected")
|
||||
d, _ := db.SetupDB(t)
|
||||
d := db.SetupDB(t)
|
||||
|
||||
var blkRoots p2pTypes.BeaconBlockByRootsReq
|
||||
// Populate the database with blocks that would match the request.
|
||||
@@ -147,7 +147,7 @@ func TestRecentBeaconBlocksRPCHandler_HandleZeroBlocks(t *testing.T) {
|
||||
p2 := p2ptest.NewTestP2P(t)
|
||||
p1.Connect(p2)
|
||||
assert.Equal(t, 1, len(p1.BHost.Network().Peers()), "Expected peers to be connected")
|
||||
d, _ := db.SetupDB(t)
|
||||
d := db.SetupDB(t)
|
||||
|
||||
r := &Service{p2p: p1, db: d, rateLimiter: newRateLimiter(p1)}
|
||||
pcl := protocol.ID("/testing")
|
||||
|
||||
@@ -24,7 +24,7 @@ func TestGoodByeRPCHandler_Disconnects_With_Peer(t *testing.T) {
|
||||
assert.Equal(t, 1, len(p1.BHost.Network().Peers()), "Expected peers to be connected")
|
||||
|
||||
// Set up a head state in the database with data we expect.
|
||||
d, _ := db.SetupDB(t)
|
||||
d := db.SetupDB(t)
|
||||
r := &Service{
|
||||
db: d,
|
||||
p2p: p1,
|
||||
@@ -67,7 +67,7 @@ func TestGoodByeRPCHandler_BackOffPeer(t *testing.T) {
|
||||
assert.Equal(t, 2, len(p1.BHost.Network().Peers()), "Expected peers to be connected")
|
||||
|
||||
// Set up a head state in the database with data we expect.
|
||||
d, _ := db.SetupDB(t)
|
||||
d := db.SetupDB(t)
|
||||
r := &Service{
|
||||
db: d,
|
||||
p2p: p1,
|
||||
@@ -140,7 +140,7 @@ func TestSendGoodbye_SendsMessage(t *testing.T) {
|
||||
assert.Equal(t, 1, len(p1.BHost.Network().Peers()), "Expected peers to be connected")
|
||||
|
||||
// Set up a head state in the database with data we expect.
|
||||
d, _ := db.SetupDB(t)
|
||||
d := db.SetupDB(t)
|
||||
r := &Service{
|
||||
db: d,
|
||||
p2p: p1,
|
||||
@@ -182,7 +182,7 @@ func TestSendGoodbye_DisconnectWithPeer(t *testing.T) {
|
||||
assert.Equal(t, 1, len(p1.BHost.Network().Peers()), "Expected peers to be connected")
|
||||
|
||||
// Set up a head state in the database with data we expect.
|
||||
d, _ := db.SetupDB(t)
|
||||
d := db.SetupDB(t)
|
||||
r := &Service{
|
||||
db: d,
|
||||
p2p: p1,
|
||||
|
||||
@@ -32,7 +32,7 @@ func TestMetaDataRPCHandler_ReceivesMetadata(t *testing.T) {
|
||||
}
|
||||
|
||||
// Set up a head state in the database with data we expect.
|
||||
d, _ := db.SetupDB(t)
|
||||
d := db.SetupDB(t)
|
||||
r := &Service{
|
||||
db: d,
|
||||
p2p: p1,
|
||||
@@ -79,7 +79,7 @@ func TestMetadataRPCHandler_SendsMetadata(t *testing.T) {
|
||||
}
|
||||
|
||||
// Set up a head state in the database with data we expect.
|
||||
d, _ := db.SetupDB(t)
|
||||
d := db.SetupDB(t)
|
||||
r := &Service{
|
||||
db: d,
|
||||
p2p: p1,
|
||||
|
||||
@@ -35,7 +35,7 @@ func TestPingRPCHandler_ReceivesPing(t *testing.T) {
|
||||
}
|
||||
|
||||
// Set up a head state in the database with data we expect.
|
||||
d, _ := db.SetupDB(t)
|
||||
d := db.SetupDB(t)
|
||||
r := &Service{
|
||||
db: d,
|
||||
p2p: p1,
|
||||
@@ -90,7 +90,7 @@ func TestPingRPCHandler_SendsPing(t *testing.T) {
|
||||
}
|
||||
|
||||
// Set up a head state in the database with data we expect.
|
||||
d, _ := db.SetupDB(t)
|
||||
d := db.SetupDB(t)
|
||||
r := &Service{
|
||||
db: d,
|
||||
p2p: p1,
|
||||
@@ -151,7 +151,7 @@ func TestPingRPCHandler_BadSequenceNumber(t *testing.T) {
|
||||
}
|
||||
|
||||
// Set up a head state in the database with data we expect.
|
||||
d, _ := db.SetupDB(t)
|
||||
d := db.SetupDB(t)
|
||||
r := &Service{
|
||||
db: d,
|
||||
p2p: p1,
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/state"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/db/kv"
|
||||
testingDB "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/p2p/peers"
|
||||
p2ptest "github.com/prysmaticlabs/prysm/beacon-chain/p2p/testing"
|
||||
@@ -154,7 +155,7 @@ func TestStatusRPCHandler_ReturnsHelloMessage(t *testing.T) {
|
||||
p2 := p2ptest.NewTestP2P(t)
|
||||
p1.Connect(p2)
|
||||
assert.Equal(t, 1, len(p1.BHost.Network().Peers()), "Expected peers to be connected")
|
||||
db, _ := testingDB.SetupDB(t)
|
||||
db := testingDB.SetupDB(t)
|
||||
|
||||
// Set up a head state with data we expect.
|
||||
head := testutil.NewBeaconBlock()
|
||||
@@ -240,7 +241,7 @@ func TestHandshakeHandlers_Roundtrip(t *testing.T) {
|
||||
// p2 disconnects and p1 should forget the handshake status.
|
||||
p1 := p2ptest.NewTestP2P(t)
|
||||
p2 := p2ptest.NewTestP2P(t)
|
||||
db, _ := testingDB.SetupDB(t)
|
||||
db := testingDB.SetupDB(t)
|
||||
|
||||
p1.LocalMetadata = &pb.MetaData{
|
||||
SeqNumber: 2,
|
||||
@@ -446,7 +447,7 @@ func TestStatusRPCRequest_RequestSent(t *testing.T) {
|
||||
func TestStatusRPCRequest_FinalizedBlockExists(t *testing.T) {
|
||||
p1 := p2ptest.NewTestP2P(t)
|
||||
p2 := p2ptest.NewTestP2P(t)
|
||||
db, _ := testingDB.SetupDB(t)
|
||||
db := testingDB.SetupDB(t)
|
||||
|
||||
// Set up a head state with data we expect.
|
||||
head := testutil.NewBeaconBlock()
|
||||
@@ -531,7 +532,8 @@ func TestStatusRPCRequest_FinalizedBlockExists(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestStatusRPCRequest_FinalizedBlockSkippedSlots(t *testing.T) {
|
||||
db, _ := testingDB.SetupDB(t)
|
||||
db, err := kv.NewKVStore(context.Background(), t.TempDir())
|
||||
require.NoError(t, err)
|
||||
bState, err := state.GenesisBeaconState(nil, 0, ðpb.Eth1Data{DepositRoot: make([]byte, 32), BlockHash: make([]byte, 32)})
|
||||
require.NoError(t, err)
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/blockchain"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/cache"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/feed"
|
||||
blockfeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/block"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/feed/operation"
|
||||
@@ -62,7 +61,6 @@ type Config struct {
|
||||
StateNotifier statefeed.Notifier
|
||||
BlockNotifier blockfeed.Notifier
|
||||
AttestationNotifier operation.Notifier
|
||||
StateSummaryCache *cache.StateSummaryCache
|
||||
StateGen *stategen.State
|
||||
}
|
||||
|
||||
@@ -113,7 +111,6 @@ type Service struct {
|
||||
seenAttesterSlashingCache *lru.Cache
|
||||
badBlockCache *lru.Cache
|
||||
badBlockLock sync.RWMutex
|
||||
stateSummaryCache *cache.StateSummaryCache
|
||||
stateGen *stategen.State
|
||||
}
|
||||
|
||||
@@ -140,7 +137,6 @@ func NewService(ctx context.Context, cfg *Config) *Service {
|
||||
blkRootToPendingAtts: make(map[[32]byte][]*ethpb.SignedAggregateAttestationAndProof),
|
||||
stateNotifier: cfg.StateNotifier,
|
||||
blockNotifier: cfg.BlockNotifier,
|
||||
stateSummaryCache: cfg.StateSummaryCache,
|
||||
stateGen: cfg.StateGen,
|
||||
rateLimiter: rLimiter,
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ func TestService_beaconBlockSubscriber(t *testing.T) {
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
db, _ := dbtest.SetupDB(t)
|
||||
db := dbtest.SetupDB(t)
|
||||
s := &Service{
|
||||
chain: &chainMock.ChainService{
|
||||
DB: db,
|
||||
|
||||
@@ -69,7 +69,7 @@ func TestSubscribe_ReceivesValidMessage(t *testing.T) {
|
||||
func TestSubscribe_ReceivesAttesterSlashing(t *testing.T) {
|
||||
p2p := p2ptest.NewTestP2P(t)
|
||||
ctx := context.Background()
|
||||
d, _ := db.SetupDB(t)
|
||||
d := db.SetupDB(t)
|
||||
chainService := &mockChain.ChainService{
|
||||
Genesis: time.Now(),
|
||||
ValidatorsRoot: [32]byte{'A'},
|
||||
@@ -125,7 +125,7 @@ func TestSubscribe_ReceivesProposerSlashing(t *testing.T) {
|
||||
ValidatorsRoot: [32]byte{'A'},
|
||||
Genesis: time.Now(),
|
||||
}
|
||||
d, _ := db.SetupDB(t)
|
||||
d := db.SetupDB(t)
|
||||
c, err := lru.New(10)
|
||||
require.NoError(t, err)
|
||||
r := Service{
|
||||
|
||||
@@ -13,7 +13,6 @@ import (
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/go-bitfield"
|
||||
mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/cache"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
||||
dbtest "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/operations/attestations"
|
||||
@@ -96,7 +95,7 @@ func TestVerifySelection_NotAnAggregator(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestValidateAggregateAndProof_NoBlock(t *testing.T) {
|
||||
db, _ := dbtest.SetupDB(t)
|
||||
db := dbtest.SetupDB(t)
|
||||
p := p2ptest.NewTestP2P(t)
|
||||
|
||||
att := ðpb.Attestation{
|
||||
@@ -124,7 +123,6 @@ func TestValidateAggregateAndProof_NoBlock(t *testing.T) {
|
||||
attPool: attestations.NewPool(),
|
||||
blkRootToPendingAtts: make(map[[32]byte][]*ethpb.SignedAggregateAttestationAndProof),
|
||||
seenAttestationCache: c,
|
||||
stateSummaryCache: cache.NewStateSummaryCache(),
|
||||
chain: &mock.ChainService{},
|
||||
}
|
||||
err = r.initCaches()
|
||||
@@ -148,7 +146,7 @@ func TestValidateAggregateAndProof_NoBlock(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestValidateAggregateAndProof_NotWithinSlotRange(t *testing.T) {
|
||||
db, _ := dbtest.SetupDB(t)
|
||||
db := dbtest.SetupDB(t)
|
||||
p := p2ptest.NewTestP2P(t)
|
||||
|
||||
validators := uint64(256)
|
||||
@@ -194,7 +192,6 @@ func TestValidateAggregateAndProof_NotWithinSlotRange(t *testing.T) {
|
||||
},
|
||||
attPool: attestations.NewPool(),
|
||||
seenAttestationCache: c,
|
||||
stateSummaryCache: cache.NewStateSummaryCache(),
|
||||
}
|
||||
err = r.initCaches()
|
||||
require.NoError(t, err)
|
||||
@@ -233,7 +230,7 @@ func TestValidateAggregateAndProof_NotWithinSlotRange(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestValidateAggregateAndProof_ExistedInPool(t *testing.T) {
|
||||
db, _ := dbtest.SetupDB(t)
|
||||
db := dbtest.SetupDB(t)
|
||||
p := p2ptest.NewTestP2P(t)
|
||||
|
||||
validators := uint64(256)
|
||||
@@ -298,7 +295,7 @@ func TestValidateAggregateAndProof_ExistedInPool(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestValidateAggregateAndProof_CanValidate(t *testing.T) {
|
||||
db, _ := dbtest.SetupDB(t)
|
||||
db := dbtest.SetupDB(t)
|
||||
p := p2ptest.NewTestP2P(t)
|
||||
|
||||
validators := uint64(256)
|
||||
@@ -364,7 +361,6 @@ func TestValidateAggregateAndProof_CanValidate(t *testing.T) {
|
||||
}},
|
||||
attPool: attestations.NewPool(),
|
||||
seenAttestationCache: c,
|
||||
stateSummaryCache: cache.NewStateSummaryCache(),
|
||||
}
|
||||
err = r.initCaches()
|
||||
require.NoError(t, err)
|
||||
@@ -386,7 +382,7 @@ func TestValidateAggregateAndProof_CanValidate(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestVerifyIndexInCommittee_SeenAggregatorEpoch(t *testing.T) {
|
||||
db, _ := dbtest.SetupDB(t)
|
||||
db := dbtest.SetupDB(t)
|
||||
p := p2ptest.NewTestP2P(t)
|
||||
|
||||
validators := uint64(256)
|
||||
@@ -453,7 +449,6 @@ func TestVerifyIndexInCommittee_SeenAggregatorEpoch(t *testing.T) {
|
||||
|
||||
attPool: attestations.NewPool(),
|
||||
seenAttestationCache: c,
|
||||
stateSummaryCache: cache.NewStateSummaryCache(),
|
||||
}
|
||||
err = r.initCaches()
|
||||
require.NoError(t, err)
|
||||
@@ -492,7 +487,7 @@ func TestVerifyIndexInCommittee_SeenAggregatorEpoch(t *testing.T) {
|
||||
|
||||
func TestValidateAggregateAndProof_BadBlock(t *testing.T) {
|
||||
|
||||
db, _ := dbtest.SetupDB(t)
|
||||
db := dbtest.SetupDB(t)
|
||||
p := p2ptest.NewTestP2P(t)
|
||||
|
||||
validators := uint64(256)
|
||||
@@ -557,7 +552,6 @@ func TestValidateAggregateAndProof_BadBlock(t *testing.T) {
|
||||
}},
|
||||
attPool: attestations.NewPool(),
|
||||
seenAttestationCache: c,
|
||||
stateSummaryCache: cache.NewStateSummaryCache(),
|
||||
}
|
||||
err = r.initCaches()
|
||||
require.NoError(t, err)
|
||||
@@ -579,7 +573,7 @@ func TestValidateAggregateAndProof_BadBlock(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestValidateAggregateAndProof_RejectWhenAttEpochDoesntEqualTargetEpoch(t *testing.T) {
|
||||
db, _ := dbtest.SetupDB(t)
|
||||
db := dbtest.SetupDB(t)
|
||||
p := p2ptest.NewTestP2P(t)
|
||||
|
||||
validators := uint64(256)
|
||||
@@ -645,7 +639,6 @@ func TestValidateAggregateAndProof_RejectWhenAttEpochDoesntEqualTargetEpoch(t *t
|
||||
}},
|
||||
attPool: attestations.NewPool(),
|
||||
seenAttestationCache: c,
|
||||
stateSummaryCache: cache.NewStateSummaryCache(),
|
||||
}
|
||||
err = r.initCaches()
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -214,7 +214,7 @@ func (s *Service) setSeenCommitteeIndicesSlot(slot, committeeID uint64, aggregat
|
||||
// hasBlockAndState returns true if the beacon node knows about a block and associated state in the
|
||||
// database or cache.
|
||||
func (s *Service) hasBlockAndState(ctx context.Context, blockRoot [32]byte) bool {
|
||||
hasStateSummary := s.stateSummaryCache.Has(blockRoot) || s.db.HasStateSummary(ctx, blockRoot)
|
||||
hasStateSummary := s.db.HasStateSummary(ctx, blockRoot)
|
||||
hasState := hasStateSummary || s.db.HasState(ctx, blockRoot)
|
||||
hasBlock := s.chain.HasInitSyncBlock(blockRoot) || s.db.HasBlock(ctx, blockRoot)
|
||||
return hasState && hasBlock
|
||||
|
||||
@@ -13,7 +13,6 @@ import (
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"github.com/prysmaticlabs/go-bitfield"
|
||||
mockChain "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/cache"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
||||
dbtest "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
|
||||
p2ptest "github.com/prysmaticlabs/prysm/beacon-chain/p2p/testing"
|
||||
@@ -27,7 +26,7 @@ import (
|
||||
func TestService_validateCommitteeIndexBeaconAttestation(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
p := p2ptest.NewTestP2P(t)
|
||||
db, _ := dbtest.SetupDB(t)
|
||||
db := dbtest.SetupDB(t)
|
||||
chain := &mockChain.ChainService{
|
||||
// 1 slot ago.
|
||||
Genesis: time.Now().Add(time.Duration(-1*int64(params.BeaconConfig().SecondsPerSlot)) * time.Second),
|
||||
@@ -44,7 +43,6 @@ func TestService_validateCommitteeIndexBeaconAttestation(t *testing.T) {
|
||||
chain: chain,
|
||||
blkRootToPendingAtts: make(map[[32]byte][]*ethpb.SignedAggregateAttestationAndProof),
|
||||
seenAttestationCache: c,
|
||||
stateSummaryCache: cache.NewStateSummaryCache(),
|
||||
}
|
||||
err = s.initCaches()
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -152,8 +152,7 @@ func (s *Service) validateBeaconBlock(ctx context.Context, blk *ethpb.SignedBeac
|
||||
}
|
||||
|
||||
hasStateSummaryDB := s.db.HasStateSummary(ctx, bytesutil.ToBytes32(blk.Block.ParentRoot))
|
||||
hasStateSummaryCache := s.stateSummaryCache.Has(bytesutil.ToBytes32(blk.Block.ParentRoot))
|
||||
if !hasStateSummaryDB && !hasStateSummaryCache {
|
||||
if !hasStateSummaryDB {
|
||||
_, err := s.stateGen.RecoverStateSummary(ctx, bytesutil.ToBytes32(blk.Block.ParentRoot))
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -14,7 +14,6 @@ import (
|
||||
gcache "github.com/patrickmn/go-cache"
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/cache"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/state"
|
||||
dbtest "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
|
||||
@@ -40,7 +39,7 @@ import (
|
||||
|
||||
func TestValidateBeaconBlockPubSub_InvalidSignature(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, _ := dbtest.SetupDB(t)
|
||||
db := dbtest.SetupDB(t)
|
||||
msg := testutil.NewBeaconBlock()
|
||||
msg.Block.Slot = 1
|
||||
msg.Block.ParentRoot = testutil.Random32Bytes(t)
|
||||
@@ -81,7 +80,7 @@ func TestValidateBeaconBlockPubSub_InvalidSignature(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestValidateBeaconBlockPubSub_BlockAlreadyPresentInDB(t *testing.T) {
|
||||
db, _ := dbtest.SetupDB(t)
|
||||
db := dbtest.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
p := p2ptest.NewTestP2P(t)
|
||||
@@ -96,14 +95,13 @@ func TestValidateBeaconBlockPubSub_BlockAlreadyPresentInDB(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
chainService := &mock.ChainService{Genesis: time.Now()}
|
||||
r := &Service{
|
||||
db: db,
|
||||
p2p: p,
|
||||
initialSync: &mockSync.Sync{IsSyncing: false},
|
||||
chain: chainService,
|
||||
seenBlockCache: c,
|
||||
badBlockCache: c2,
|
||||
stateSummaryCache: cache.NewStateSummaryCache(),
|
||||
blockNotifier: chainService.BlockNotifier(),
|
||||
db: db,
|
||||
p2p: p,
|
||||
initialSync: &mockSync.Sync{IsSyncing: false},
|
||||
chain: chainService,
|
||||
seenBlockCache: c,
|
||||
badBlockCache: c2,
|
||||
blockNotifier: chainService.BlockNotifier(),
|
||||
}
|
||||
|
||||
buf := new(bytes.Buffer)
|
||||
@@ -122,7 +120,7 @@ func TestValidateBeaconBlockPubSub_BlockAlreadyPresentInDB(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestValidateBeaconBlockPubSub_CanRecoverStateSummary(t *testing.T) {
|
||||
db, stateSummaryCache := dbtest.SetupDB(t)
|
||||
db := dbtest.SetupDB(t)
|
||||
p := p2ptest.NewTestP2P(t)
|
||||
ctx := context.Background()
|
||||
beaconState, privKeys := testutil.DeterministicGenesisState(t, 100)
|
||||
@@ -146,7 +144,7 @@ func TestValidateBeaconBlockPubSub_CanRecoverStateSummary(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
c2, err := lru.New(10)
|
||||
require.NoError(t, err)
|
||||
stateGen := stategen.New(db, stateSummaryCache)
|
||||
stateGen := stategen.New(db)
|
||||
chainService := &mock.ChainService{Genesis: time.Unix(time.Now().Unix()-int64(params.BeaconConfig().SecondsPerSlot), 0),
|
||||
State: beaconState,
|
||||
FinalizedCheckPoint: ðpb.Checkpoint{
|
||||
@@ -164,7 +162,6 @@ func TestValidateBeaconBlockPubSub_CanRecoverStateSummary(t *testing.T) {
|
||||
badBlockCache: c2,
|
||||
slotToPendingBlocks: gcache.New(time.Second, 2*time.Second),
|
||||
seenPendingBlocks: make(map[[32]byte]bool),
|
||||
stateSummaryCache: stateSummaryCache,
|
||||
stateGen: stateGen,
|
||||
}
|
||||
buf := new(bytes.Buffer)
|
||||
@@ -183,7 +180,7 @@ func TestValidateBeaconBlockPubSub_CanRecoverStateSummary(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestValidateBeaconBlockPubSub_ValidProposerSignature(t *testing.T) {
|
||||
db, stateSummaryCache := dbtest.SetupDB(t)
|
||||
db := dbtest.SetupDB(t)
|
||||
p := p2ptest.NewTestP2P(t)
|
||||
ctx := context.Background()
|
||||
beaconState, privKeys := testutil.DeterministicGenesisState(t, 100)
|
||||
@@ -208,7 +205,7 @@ func TestValidateBeaconBlockPubSub_ValidProposerSignature(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
c2, err := lru.New(10)
|
||||
require.NoError(t, err)
|
||||
stateGen := stategen.New(db, stateSummaryCache)
|
||||
stateGen := stategen.New(db)
|
||||
chainService := &mock.ChainService{Genesis: time.Unix(time.Now().Unix()-int64(params.BeaconConfig().SecondsPerSlot), 0),
|
||||
State: beaconState,
|
||||
FinalizedCheckPoint: ðpb.Checkpoint{
|
||||
@@ -226,7 +223,6 @@ func TestValidateBeaconBlockPubSub_ValidProposerSignature(t *testing.T) {
|
||||
badBlockCache: c2,
|
||||
slotToPendingBlocks: gcache.New(time.Second, 2*time.Second),
|
||||
seenPendingBlocks: make(map[[32]byte]bool),
|
||||
stateSummaryCache: stateSummaryCache,
|
||||
stateGen: stateGen,
|
||||
}
|
||||
buf := new(bytes.Buffer)
|
||||
@@ -245,7 +241,7 @@ func TestValidateBeaconBlockPubSub_ValidProposerSignature(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestValidateBeaconBlockPubSub_WithLookahead(t *testing.T) {
|
||||
db, stateSummaryCache := dbtest.SetupDB(t)
|
||||
db := dbtest.SetupDB(t)
|
||||
p := p2ptest.NewTestP2P(t)
|
||||
ctx := context.Background()
|
||||
beaconState, privKeys := testutil.DeterministicGenesisState(t, 100)
|
||||
@@ -273,7 +269,7 @@ func TestValidateBeaconBlockPubSub_WithLookahead(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
c2, err := lru.New(10)
|
||||
require.NoError(t, err)
|
||||
stateGen := stategen.New(db, stateSummaryCache)
|
||||
stateGen := stategen.New(db)
|
||||
chainService := &mock.ChainService{Genesis: time.Unix(time.Now().Unix()-int64(blkSlot*params.BeaconConfig().SecondsPerSlot), 0),
|
||||
State: beaconState,
|
||||
FinalizedCheckPoint: ðpb.Checkpoint{
|
||||
@@ -289,7 +285,6 @@ func TestValidateBeaconBlockPubSub_WithLookahead(t *testing.T) {
|
||||
badBlockCache: c2,
|
||||
slotToPendingBlocks: gcache.New(time.Second, 2*time.Second),
|
||||
seenPendingBlocks: make(map[[32]byte]bool),
|
||||
stateSummaryCache: stateSummaryCache,
|
||||
stateGen: stateGen,
|
||||
}
|
||||
buf := new(bytes.Buffer)
|
||||
@@ -308,7 +303,7 @@ func TestValidateBeaconBlockPubSub_WithLookahead(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestValidateBeaconBlockPubSub_AdvanceEpochsForState(t *testing.T) {
|
||||
db, stateSummaryCache := dbtest.SetupDB(t)
|
||||
db := dbtest.SetupDB(t)
|
||||
p := p2ptest.NewTestP2P(t)
|
||||
ctx := context.Background()
|
||||
beaconState, privKeys := testutil.DeterministicGenesisState(t, 100)
|
||||
@@ -336,7 +331,7 @@ func TestValidateBeaconBlockPubSub_AdvanceEpochsForState(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
c2, err := lru.New(10)
|
||||
require.NoError(t, err)
|
||||
stateGen := stategen.New(db, stateSummaryCache)
|
||||
stateGen := stategen.New(db)
|
||||
chainService := &mock.ChainService{Genesis: time.Unix(time.Now().Unix()-int64(blkSlot*params.BeaconConfig().SecondsPerSlot), 0),
|
||||
State: beaconState,
|
||||
FinalizedCheckPoint: ðpb.Checkpoint{
|
||||
@@ -352,8 +347,8 @@ func TestValidateBeaconBlockPubSub_AdvanceEpochsForState(t *testing.T) {
|
||||
badBlockCache: c2,
|
||||
slotToPendingBlocks: gcache.New(time.Second, 2*time.Second),
|
||||
seenPendingBlocks: make(map[[32]byte]bool),
|
||||
stateSummaryCache: stateSummaryCache,
|
||||
stateGen: stateGen,
|
||||
|
||||
stateGen: stateGen,
|
||||
}
|
||||
buf := new(bytes.Buffer)
|
||||
_, err = p.Encoding().EncodeGossip(buf, msg)
|
||||
@@ -371,7 +366,7 @@ func TestValidateBeaconBlockPubSub_AdvanceEpochsForState(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestValidateBeaconBlockPubSub_Syncing(t *testing.T) {
|
||||
db, _ := dbtest.SetupDB(t)
|
||||
db := dbtest.SetupDB(t)
|
||||
p := p2ptest.NewTestP2P(t)
|
||||
ctx := context.Background()
|
||||
b := []byte("sk")
|
||||
@@ -409,7 +404,7 @@ func TestValidateBeaconBlockPubSub_Syncing(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestValidateBeaconBlockPubSub_RejectBlocksFromFuture(t *testing.T) {
|
||||
db, _ := dbtest.SetupDB(t)
|
||||
db := dbtest.SetupDB(t)
|
||||
p := p2ptest.NewTestP2P(t)
|
||||
ctx := context.Background()
|
||||
b := []byte("sk")
|
||||
@@ -454,7 +449,7 @@ func TestValidateBeaconBlockPubSub_RejectBlocksFromFuture(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestValidateBeaconBlockPubSub_RejectBlocksFromThePast(t *testing.T) {
|
||||
db, _ := dbtest.SetupDB(t)
|
||||
db := dbtest.SetupDB(t)
|
||||
b := []byte("sk")
|
||||
b32 := bytesutil.ToBytes32(b)
|
||||
p := p2ptest.NewTestP2P(t)
|
||||
@@ -502,7 +497,7 @@ func TestValidateBeaconBlockPubSub_RejectBlocksFromThePast(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestValidateBeaconBlockPubSub_SeenProposerSlot(t *testing.T) {
|
||||
db, _ := dbtest.SetupDB(t)
|
||||
db := dbtest.SetupDB(t)
|
||||
p := p2ptest.NewTestP2P(t)
|
||||
ctx := context.Background()
|
||||
beaconState, privKeys := testutil.DeterministicGenesisState(t, 100)
|
||||
@@ -542,7 +537,6 @@ func TestValidateBeaconBlockPubSub_SeenProposerSlot(t *testing.T) {
|
||||
badBlockCache: c2,
|
||||
slotToPendingBlocks: gcache.New(time.Second, 2*time.Second),
|
||||
seenPendingBlocks: make(map[[32]byte]bool),
|
||||
stateSummaryCache: cache.NewStateSummaryCache(),
|
||||
}
|
||||
|
||||
buf := new(bytes.Buffer)
|
||||
@@ -563,7 +557,7 @@ func TestValidateBeaconBlockPubSub_SeenProposerSlot(t *testing.T) {
|
||||
|
||||
func TestValidateBeaconBlockPubSub_FilterByFinalizedEpoch(t *testing.T) {
|
||||
hook := logTest.NewGlobal()
|
||||
db, _ := dbtest.SetupDB(t)
|
||||
db := dbtest.SetupDB(t)
|
||||
p := p2ptest.NewTestP2P(t)
|
||||
|
||||
parent := testutil.NewBeaconBlock()
|
||||
@@ -622,7 +616,7 @@ func TestValidateBeaconBlockPubSub_FilterByFinalizedEpoch(t *testing.T) {
|
||||
|
||||
func TestValidateBeaconBlockPubSub_ParentNotFinalizedDescendant(t *testing.T) {
|
||||
hook := logTest.NewGlobal()
|
||||
db, stateSummaryCache := dbtest.SetupDB(t)
|
||||
db := dbtest.SetupDB(t)
|
||||
p := p2ptest.NewTestP2P(t)
|
||||
ctx := context.Background()
|
||||
beaconState, privKeys := testutil.DeterministicGenesisState(t, 100)
|
||||
@@ -647,7 +641,7 @@ func TestValidateBeaconBlockPubSub_ParentNotFinalizedDescendant(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
c2, err := lru.New(10)
|
||||
require.NoError(t, err)
|
||||
stateGen := stategen.New(db, stateSummaryCache)
|
||||
stateGen := stategen.New(db)
|
||||
chainService := &mock.ChainService{Genesis: time.Unix(time.Now().Unix()-int64(params.BeaconConfig().SecondsPerSlot), 0),
|
||||
State: beaconState,
|
||||
FinalizedCheckPoint: ðpb.Checkpoint{
|
||||
@@ -666,7 +660,6 @@ func TestValidateBeaconBlockPubSub_ParentNotFinalizedDescendant(t *testing.T) {
|
||||
badBlockCache: c2,
|
||||
slotToPendingBlocks: gcache.New(time.Second, 2*time.Second),
|
||||
seenPendingBlocks: make(map[[32]byte]bool),
|
||||
stateSummaryCache: stateSummaryCache,
|
||||
stateGen: stateGen,
|
||||
}
|
||||
buf := new(bytes.Buffer)
|
||||
@@ -684,7 +677,7 @@ func TestValidateBeaconBlockPubSub_ParentNotFinalizedDescendant(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestValidateBeaconBlockPubSub_InvalidParentBlock(t *testing.T) {
|
||||
db, stateSummaryCache := dbtest.SetupDB(t)
|
||||
db := dbtest.SetupDB(t)
|
||||
p := p2ptest.NewTestP2P(t)
|
||||
ctx := context.Background()
|
||||
beaconState, privKeys := testutil.DeterministicGenesisState(t, 100)
|
||||
@@ -714,7 +707,7 @@ func TestValidateBeaconBlockPubSub_InvalidParentBlock(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
c2, err := lru.New(10)
|
||||
require.NoError(t, err)
|
||||
stateGen := stategen.New(db, stateSummaryCache)
|
||||
stateGen := stategen.New(db)
|
||||
chainService := &mock.ChainService{Genesis: time.Unix(time.Now().Unix()-int64(params.BeaconConfig().SecondsPerSlot), 0),
|
||||
State: beaconState,
|
||||
FinalizedCheckPoint: ðpb.Checkpoint{
|
||||
@@ -730,7 +723,6 @@ func TestValidateBeaconBlockPubSub_InvalidParentBlock(t *testing.T) {
|
||||
badBlockCache: c2,
|
||||
slotToPendingBlocks: gcache.New(time.Second, 2*time.Second),
|
||||
seenPendingBlocks: make(map[[32]byte]bool),
|
||||
stateSummaryCache: stateSummaryCache,
|
||||
stateGen: stateGen,
|
||||
}
|
||||
buf := new(bytes.Buffer)
|
||||
@@ -771,7 +763,7 @@ func TestValidateBeaconBlockPubSub_InvalidParentBlock(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestValidateBeaconBlockPubSub_RejectEvilBlocksFromFuture(t *testing.T) {
|
||||
db, stateSummaryCache := dbtest.SetupDB(t)
|
||||
db := dbtest.SetupDB(t)
|
||||
p := p2ptest.NewTestP2P(t)
|
||||
ctx := context.Background()
|
||||
|
||||
@@ -813,7 +805,7 @@ func TestValidateBeaconBlockPubSub_RejectEvilBlocksFromFuture(t *testing.T) {
|
||||
c2, err := lru.New(10)
|
||||
require.NoError(t, err)
|
||||
|
||||
stateGen := stategen.New(db, stateSummaryCache)
|
||||
stateGen := stategen.New(db)
|
||||
chainService := &mock.ChainService{
|
||||
Genesis: time.Unix(genesisTime.Unix()-int64(slotsSinceGenesis*perSlot), 0),
|
||||
FinalizedCheckPoint: ðpb.Checkpoint{
|
||||
@@ -830,7 +822,6 @@ func TestValidateBeaconBlockPubSub_RejectEvilBlocksFromFuture(t *testing.T) {
|
||||
badBlockCache: c2,
|
||||
slotToPendingBlocks: gcache.New(time.Second, 2*time.Second),
|
||||
seenPendingBlocks: make(map[[32]byte]bool),
|
||||
stateSummaryCache: stateSummaryCache,
|
||||
stateGen: stateGen,
|
||||
}
|
||||
|
||||
|
||||
@@ -14,10 +14,8 @@ import (
|
||||
pubsub "github.com/libp2p/go-libp2p-pubsub"
|
||||
pubsub_pb "github.com/libp2p/go-libp2p-pubsub/pb"
|
||||
"github.com/prysmaticlabs/go-ssz"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/blockchain"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/cache"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/state"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/db"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/forkchoice/protoarray"
|
||||
@@ -39,7 +37,6 @@ import (
|
||||
const topic = p2p.BlockSubnetTopicFormat
|
||||
|
||||
var db1 db.Database
|
||||
var ssc *cache.StateSummaryCache
|
||||
var dbPath = path.Join(os.TempDir(), "fuzz_beacondb", randomHex(6))
|
||||
|
||||
func randomHex(n int) string {
|
||||
@@ -56,11 +53,9 @@ func init() {
|
||||
logrus.SetLevel(logrus.PanicLevel)
|
||||
logrus.SetOutput(ioutil.Discard)
|
||||
|
||||
ssc = cache.NewStateSummaryCache()
|
||||
|
||||
var err error
|
||||
|
||||
db1, err = db.NewDB(context.Background(), dbPath, ssc)
|
||||
db1, err = db.NewDB(context.Background(), dbPath)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -117,7 +112,7 @@ func BeaconFuzzBlock(b []byte) {
|
||||
setupDB()
|
||||
|
||||
p2p := p2pt.NewFuzzTestP2P()
|
||||
sgen := stategen.New(db1, ssc)
|
||||
sgen := stategen.New(db1)
|
||||
sn := &testing.MockStateNotifier{}
|
||||
bn := &testing.MockBlockNotifier{}
|
||||
an := &testing.MockOperationNotifier{}
|
||||
@@ -158,7 +153,6 @@ func BeaconFuzzBlock(b []byte) {
|
||||
AttPool: ap,
|
||||
ExitPool: ep,
|
||||
SlashingPool: sp,
|
||||
StateSummaryCache: ssc,
|
||||
StateGen: sgen,
|
||||
})
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/cache"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/p2p"
|
||||
regularsync "github.com/prysmaticlabs/prysm/beacon-chain/sync"
|
||||
mockSync "github.com/prysmaticlabs/prysm/beacon-chain/sync/initial-sync/testing"
|
||||
@@ -59,7 +58,6 @@ func init() {
|
||||
StateNotifier: (&mock.ChainService{}).StateNotifier(),
|
||||
AttestationNotifier: (&mock.ChainService{}).OperationNotifier(),
|
||||
InitialSync: &mockSync.Sync{IsSyncing: false},
|
||||
StateSummaryCache: cache.NewStateSummaryCache(),
|
||||
BlockNotifier: nil,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ func TestHasHistoryBlkHdr(t *testing.T) {
|
||||
}
|
||||
for _, tt := range tests {
|
||||
found := db.HasBlockHeader(ctx, tt.bh.Header.Slot, tt.bh.Header.ProposerIndex)
|
||||
require.Equal(t, false, found, "Has block header should return false for block headers that are not in db")
|
||||
require.Equal(t, false, found, "has block header should return false for block headers that are not in db")
|
||||
err := db.SaveBlockHeader(ctx, tt.bh)
|
||||
require.NoError(t, err, "Save block failed")
|
||||
}
|
||||
|
||||
@@ -672,7 +672,7 @@ func TestHasIndexedAttestation(t *testing.T) {
|
||||
for _, tt := range tests {
|
||||
exists, err := db.HasIndexedAttestation(ctx, tt.idxAtt)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, false, exists, "Has indexed attestation should return false for indexed attestations that are not in db")
|
||||
require.Equal(t, false, exists, "has indexed attestation should return false for indexed attestations that are not in db")
|
||||
|
||||
require.NoError(t, db.SaveIndexedAttestation(ctx, tt.idxAtt), "Save indexed attestation failed")
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ go_library(
|
||||
importpath = "github.com/prysmaticlabs/prysm/tools/blocktree",
|
||||
visibility = ["//visibility:private"],
|
||||
deps = [
|
||||
"//beacon-chain/cache:go_default_library",
|
||||
"//beacon-chain/db:go_default_library",
|
||||
"//beacon-chain/db/filters:go_default_library",
|
||||
"//shared/bytesutil:go_default_library",
|
||||
|
||||
@@ -16,7 +16,6 @@ import (
|
||||
"strconv"
|
||||
|
||||
"github.com/emicklei/dot"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/cache"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/db"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/db/filters"
|
||||
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
||||
@@ -38,7 +37,7 @@ type node struct {
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
db, err := db.NewDB(context.Background(), *datadir, cache.NewStateSummaryCache())
|
||||
db, err := db.NewDB(context.Background(), *datadir)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ go_library(
|
||||
importpath = "github.com/prysmaticlabs/prysm/tools/extractor",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//beacon-chain/cache:go_default_library",
|
||||
"//beacon-chain/core/state/interop:go_default_library",
|
||||
"//beacon-chain/db:go_default_library",
|
||||
"//beacon-chain/db/filters:go_default_library",
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"flag"
|
||||
"fmt"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/cache"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/state/interop"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/db"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/db/filters"
|
||||
@@ -24,7 +23,7 @@ func main() {
|
||||
defer resetCfg()
|
||||
flag.Parse()
|
||||
fmt.Println("Starting process...")
|
||||
d, err := db.NewDB(context.Background(), *datadir, cache.NewStateSummaryCache())
|
||||
d, err := db.NewDB(context.Background(), *datadir)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ go_library(
|
||||
importpath = "github.com/prysmaticlabs/prysm/tools/interop/export-genesis",
|
||||
visibility = ["//visibility:private"],
|
||||
deps = [
|
||||
"//beacon-chain/cache:go_default_library",
|
||||
"//beacon-chain/db:go_default_library",
|
||||
"//shared/fileutil:go_default_library",
|
||||
],
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/cache"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/db"
|
||||
"github.com/prysmaticlabs/prysm/shared/fileutil"
|
||||
)
|
||||
@@ -21,7 +20,7 @@ func main() {
|
||||
|
||||
fmt.Printf("Reading db at %s and writing ssz output to %s.\n", os.Args[1], os.Args[2])
|
||||
|
||||
d, err := db.NewDB(context.Background(), os.Args[1], cache.NewStateSummaryCache())
|
||||
d, err := db.NewDB(context.Background(), os.Args[1])
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user