mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-10 07:58:22 -05:00
Fixed nil pointer error in DepositCache (#6596)
This commit is contained in:
@@ -104,10 +104,14 @@ func setupBeaconChain(t *testing.T, beaconDB db.Database, sc *cache.StateSummary
|
||||
|
||||
opsService, err := attestations.NewService(ctx, &attestations.Config{Pool: attestations.NewPool()})
|
||||
require.NoError(t, err)
|
||||
|
||||
depositCache, err := depositcache.NewDepositCache()
|
||||
require.NoError(t, err)
|
||||
|
||||
cfg := &Config{
|
||||
BeaconBlockBuf: 0,
|
||||
BeaconDB: beaconDB,
|
||||
DepositCache: depositcache.NewDepositCache(),
|
||||
DepositCache: depositCache,
|
||||
ChainStartFetcher: web3Service,
|
||||
P2p: &mockBroadcaster{},
|
||||
StateNotifier: &mockBeaconNode{},
|
||||
|
||||
@@ -60,13 +60,21 @@ type DepositCache struct {
|
||||
}
|
||||
|
||||
// NewDepositCache instantiates a new deposit cache
|
||||
func NewDepositCache() *DepositCache {
|
||||
func NewDepositCache() (*DepositCache, error) {
|
||||
finalizedDepositsTrie, err := trieutil.NewTrie(int(params.BeaconConfig().DepositContractTreeDepth))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// finalizedDeposits.MerkleTrieIndex is initialized to -1 because it represents the index of the last trie item.
|
||||
// Inserting the first item into the trie will set the value of the index to 0.
|
||||
return &DepositCache{
|
||||
pendingDeposits: []*dbpb.DepositContainer{},
|
||||
deposits: []*dbpb.DepositContainer{},
|
||||
finalizedDeposits: &FinalizedDeposits{Deposits: finalizedDepositsTrie, MerkleTrieIndex: -1},
|
||||
chainStartPubkeys: make(map[string]bool),
|
||||
chainStartDeposits: make([]*ethpb.Deposit, 0),
|
||||
}
|
||||
}, nil
|
||||
}
|
||||
|
||||
// InsertDeposit into the database. If deposit or block number are nil
|
||||
@@ -104,54 +112,29 @@ func (dc *DepositCache) InsertDepositContainers(ctx context.Context, ctrs []*dbp
|
||||
historicalDepositsCount.Add(float64(len(ctrs)))
|
||||
}
|
||||
|
||||
// InsertFinalizedDeposits inserts deposits up to eth1DepositIndex (exclusive) into the finalized deposits cache.
|
||||
// InsertFinalizedDeposits inserts deposits up to eth1DepositIndex (inclusive) into the finalized deposits cache.
|
||||
func (dc *DepositCache) InsertFinalizedDeposits(ctx context.Context, eth1DepositIndex int64) {
|
||||
ctx, span := trace.StartSpan(ctx, "DepositsCache.InsertFinalizedDeposits")
|
||||
defer span.End()
|
||||
dc.depositsLock.Lock()
|
||||
defer dc.depositsLock.Unlock()
|
||||
|
||||
var depositTrie *trieutil.SparseMerkleTrie
|
||||
|
||||
if dc.finalizedDeposits != nil {
|
||||
depositTrie = dc.finalizedDeposits.Deposits
|
||||
|
||||
insertIndex := dc.finalizedDeposits.MerkleTrieIndex + 1
|
||||
for _, d := range dc.deposits {
|
||||
if d.Index <= dc.finalizedDeposits.MerkleTrieIndex {
|
||||
continue
|
||||
}
|
||||
if d.Index > eth1DepositIndex {
|
||||
break
|
||||
}
|
||||
depHash, err := ssz.HashTreeRoot(d.Deposit.Data)
|
||||
if err != nil {
|
||||
log.WithError(err).Error("Could not hash deposit data. Finalized deposit cache not updated.")
|
||||
return
|
||||
}
|
||||
depositTrie.Insert(depHash[:], int(insertIndex))
|
||||
insertIndex++
|
||||
depositTrie := dc.finalizedDeposits.Deposits
|
||||
insertIndex := dc.finalizedDeposits.MerkleTrieIndex + 1
|
||||
for _, d := range dc.deposits {
|
||||
if d.Index <= dc.finalizedDeposits.MerkleTrieIndex {
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
var finalizedDeposits [][]byte
|
||||
for _, d := range dc.deposits {
|
||||
if d.Index > eth1DepositIndex {
|
||||
break
|
||||
}
|
||||
hash, err := ssz.HashTreeRoot(d.Deposit.Data)
|
||||
if err != nil {
|
||||
log.WithError(err).Error("Could not hash deposit data. Finalized deposit cache not updated.")
|
||||
return
|
||||
}
|
||||
finalizedDeposits = append(finalizedDeposits, hash[:])
|
||||
if d.Index > eth1DepositIndex {
|
||||
break
|
||||
}
|
||||
|
||||
var err error
|
||||
depositTrie, err = trieutil.GenerateTrieFromItems(finalizedDeposits, int(params.BeaconConfig().DepositContractTreeDepth))
|
||||
depHash, err := ssz.HashTreeRoot(d.Deposit.Data)
|
||||
if err != nil {
|
||||
log.WithError(err).Error("Could not generate deposit trie. Finalized deposit cache not updated.")
|
||||
log.WithError(err).Error("Could not hash deposit data. Finalized deposit cache not updated.")
|
||||
return
|
||||
}
|
||||
depositTrie.Insert(depHash[:], int(insertIndex))
|
||||
insertIndex++
|
||||
}
|
||||
|
||||
dc.finalizedDeposits = &FinalizedDeposits{
|
||||
|
||||
@@ -24,7 +24,8 @@ var _ = DepositFetcher(&DepositCache{})
|
||||
|
||||
func TestInsertDeposit_LogsOnNilDepositInsertion(t *testing.T) {
|
||||
hook := logTest.NewGlobal()
|
||||
dc := DepositCache{}
|
||||
dc, err := NewDepositCache()
|
||||
require.NoError(t, err)
|
||||
|
||||
dc.InsertDeposit(context.Background(), nil, 1, 0, [32]byte{})
|
||||
|
||||
@@ -33,7 +34,8 @@ func TestInsertDeposit_LogsOnNilDepositInsertion(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestInsertDeposit_MaintainsSortedOrderByIndex(t *testing.T) {
|
||||
dc := DepositCache{}
|
||||
dc, err := NewDepositCache()
|
||||
require.NoError(t, err)
|
||||
|
||||
insertions := []struct {
|
||||
blkNum uint64
|
||||
@@ -74,7 +76,8 @@ func TestInsertDeposit_MaintainsSortedOrderByIndex(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAllDeposits_ReturnsAllDeposits(t *testing.T) {
|
||||
dc := DepositCache{}
|
||||
dc, err := NewDepositCache()
|
||||
require.NoError(t, err)
|
||||
|
||||
deposits := []*dbpb.DepositContainer{
|
||||
{
|
||||
@@ -113,7 +116,8 @@ func TestAllDeposits_ReturnsAllDeposits(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAllDeposits_FiltersDepositUpToAndIncludingBlockNumber(t *testing.T) {
|
||||
dc := DepositCache{}
|
||||
dc, err := NewDepositCache()
|
||||
require.NoError(t, err)
|
||||
|
||||
deposits := []*dbpb.DepositContainer{
|
||||
{
|
||||
@@ -152,7 +156,8 @@ func TestAllDeposits_FiltersDepositUpToAndIncludingBlockNumber(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDepositsNumberAndRootAtHeight_ReturnsAppropriateCountAndRoot(t *testing.T) {
|
||||
dc := DepositCache{}
|
||||
dc, err := NewDepositCache()
|
||||
require.NoError(t, err)
|
||||
|
||||
dc.deposits = []*dbpb.DepositContainer{
|
||||
{
|
||||
@@ -192,7 +197,8 @@ func TestDepositsNumberAndRootAtHeight_ReturnsAppropriateCountAndRoot(t *testing
|
||||
}
|
||||
|
||||
func TestDepositsNumberAndRootAtHeight_ReturnsEmptyTrieIfBlockHeightLessThanOldestDeposit(t *testing.T) {
|
||||
dc := DepositCache{}
|
||||
dc, err := NewDepositCache()
|
||||
require.NoError(t, err)
|
||||
|
||||
dc.deposits = []*dbpb.DepositContainer{
|
||||
{
|
||||
@@ -213,7 +219,8 @@ func TestDepositsNumberAndRootAtHeight_ReturnsEmptyTrieIfBlockHeightLessThanOlde
|
||||
}
|
||||
|
||||
func TestDepositByPubkey_ReturnsFirstMatchingDeposit(t *testing.T) {
|
||||
dc := DepositCache{}
|
||||
dc, err := NewDepositCache()
|
||||
require.NoError(t, err)
|
||||
|
||||
dc.deposits = []*dbpb.DepositContainer{
|
||||
{
|
||||
@@ -260,7 +267,8 @@ func TestDepositByPubkey_ReturnsFirstMatchingDeposit(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestFinalizedDeposits_DepositsCachedCorrectly(t *testing.T) {
|
||||
dc := DepositCache{}
|
||||
dc, err := NewDepositCache()
|
||||
require.NoError(t, err)
|
||||
|
||||
finalizedDeposits := []*dbpb.DepositContainer{
|
||||
{
|
||||
@@ -315,7 +323,8 @@ func TestFinalizedDeposits_DepositsCachedCorrectly(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestFinalizedDeposits_UtilizesPreviouslyCachedDeposits(t *testing.T) {
|
||||
dc := DepositCache{}
|
||||
dc, err := NewDepositCache()
|
||||
require.NoError(t, err)
|
||||
|
||||
oldFinalizedDeposits := []*dbpb.DepositContainer{
|
||||
{
|
||||
@@ -365,8 +374,19 @@ func TestFinalizedDeposits_UtilizesPreviouslyCachedDeposits(t *testing.T) {
|
||||
assert.Equal(t, trie.HashTreeRoot(), cachedDeposits.Deposits.HashTreeRoot())
|
||||
}
|
||||
|
||||
func TestFinalizedDeposits_InitializedCorrectly(t *testing.T) {
|
||||
dc, err := NewDepositCache()
|
||||
require.NoError(t, err)
|
||||
|
||||
finalizedDeposits := dc.finalizedDeposits
|
||||
assert.NotNil(t, finalizedDeposits)
|
||||
assert.NotNil(t, finalizedDeposits.Deposits)
|
||||
assert.Equal(t, int64(-1), finalizedDeposits.MerkleTrieIndex)
|
||||
}
|
||||
|
||||
func TestNonFinalizedDeposits_ReturnsAllNonFinalizedDeposits(t *testing.T) {
|
||||
dc := DepositCache{}
|
||||
dc, err := NewDepositCache()
|
||||
require.NoError(t, err)
|
||||
|
||||
finalizedDeposits := []*dbpb.DepositContainer{
|
||||
{
|
||||
@@ -414,7 +434,8 @@ func TestNonFinalizedDeposits_ReturnsAllNonFinalizedDeposits(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNonFinalizedDeposits_ReturnsNonFinalizedDepositsUpToBlockNumber(t *testing.T) {
|
||||
dc := DepositCache{}
|
||||
dc, err := NewDepositCache()
|
||||
require.NoError(t, err)
|
||||
|
||||
finalizedDeposits := []*dbpb.DepositContainer{
|
||||
{
|
||||
|
||||
@@ -301,7 +301,13 @@ func (b *BeaconNode) startDB(cliCtx *cli.Context) error {
|
||||
|
||||
log.WithField("database-path", dbPath).Info("Checking DB")
|
||||
b.db = d
|
||||
b.depositCache = depositcache.NewDepositCache()
|
||||
|
||||
depositCache, err := depositcache.NewDepositCache()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not create deposit cache")
|
||||
}
|
||||
|
||||
b.depositCache = depositCache
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -78,6 +78,7 @@ go_test(
|
||||
"//shared/event:go_default_library",
|
||||
"//shared/params:go_default_library",
|
||||
"//shared/testutil:go_default_library",
|
||||
"//shared/testutil/require:go_default_library",
|
||||
"//shared/trieutil:go_default_library",
|
||||
"@com_github_ethereum_go_ethereum//:go_default_library",
|
||||
"@com_github_ethereum_go_ethereum//accounts/abi/bind/backends:go_default_library",
|
||||
|
||||
@@ -24,6 +24,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/shared/cmd"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
||||
"github.com/prysmaticlabs/prysm/shared/trieutil"
|
||||
"github.com/sirupsen/logrus"
|
||||
logTest "github.com/sirupsen/logrus/hooks/test"
|
||||
@@ -43,11 +44,14 @@ func TestProcessDepositLog_OK(t *testing.T) {
|
||||
t.Fatalf("Unable to set up simulated backend %v", err)
|
||||
}
|
||||
beaconDB, _ := testDB.SetupDB(t)
|
||||
depositCache, err := depositcache.NewDepositCache()
|
||||
require.NoError(t, err)
|
||||
|
||||
web3Service, err := NewService(context.Background(), &Web3ServiceConfig{
|
||||
HTTPEndPoint: endpoint,
|
||||
DepositContract: testAcc.ContractAddr,
|
||||
BeaconDB: beaconDB,
|
||||
DepositCache: depositcache.NewDepositCache(),
|
||||
DepositCache: depositCache,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("unable to setup web3 ETH1.0 chain service: %v", err)
|
||||
@@ -117,11 +121,14 @@ func TestProcessDepositLog_InsertsPendingDeposit(t *testing.T) {
|
||||
t.Fatalf("Unable to set up simulated backend %v", err)
|
||||
}
|
||||
beaconDB, _ := testDB.SetupDB(t)
|
||||
depositCache, err := depositcache.NewDepositCache()
|
||||
require.NoError(t, err)
|
||||
|
||||
web3Service, err := NewService(context.Background(), &Web3ServiceConfig{
|
||||
HTTPEndPoint: endpoint,
|
||||
DepositContract: testAcc.ContractAddr,
|
||||
BeaconDB: beaconDB,
|
||||
DepositCache: depositcache.NewDepositCache(),
|
||||
DepositCache: depositCache,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("unable to setup web3 ETH1.0 chain service: %v", err)
|
||||
@@ -269,11 +276,14 @@ func TestProcessETH2GenesisLog_8DuplicatePubkeys(t *testing.T) {
|
||||
t.Fatalf("Unable to set up simulated backend %v", err)
|
||||
}
|
||||
beaconDB, _ := testDB.SetupDB(t)
|
||||
depositCache, err := depositcache.NewDepositCache()
|
||||
require.NoError(t, err)
|
||||
|
||||
web3Service, err := NewService(context.Background(), &Web3ServiceConfig{
|
||||
HTTPEndPoint: endpoint,
|
||||
DepositContract: testAcc.ContractAddr,
|
||||
BeaconDB: beaconDB,
|
||||
DepositCache: depositcache.NewDepositCache(),
|
||||
DepositCache: depositCache,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("unable to setup web3 ETH1.0 chain service: %v", err)
|
||||
@@ -354,11 +364,14 @@ func TestProcessETH2GenesisLog(t *testing.T) {
|
||||
t.Fatalf("Unable to set up simulated backend %v", err)
|
||||
}
|
||||
beaconDB, _ := testDB.SetupDB(t)
|
||||
depositCache, err := depositcache.NewDepositCache()
|
||||
require.NoError(t, err)
|
||||
|
||||
web3Service, err := NewService(context.Background(), &Web3ServiceConfig{
|
||||
HTTPEndPoint: endpoint,
|
||||
DepositContract: testAcc.ContractAddr,
|
||||
BeaconDB: beaconDB,
|
||||
DepositCache: depositcache.NewDepositCache(),
|
||||
DepositCache: depositCache,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("unable to setup web3 ETH1.0 chain service: %v", err)
|
||||
@@ -471,11 +484,14 @@ func TestProcessETH2GenesisLog_CorrectNumOfDeposits(t *testing.T) {
|
||||
t.Fatalf("Unable to set up simulated backend %v", err)
|
||||
}
|
||||
kvStore, _ := testDB.SetupDB(t)
|
||||
depositCache, err := depositcache.NewDepositCache()
|
||||
require.NoError(t, err)
|
||||
|
||||
web3Service, err := NewService(context.Background(), &Web3ServiceConfig{
|
||||
HTTPEndPoint: endpoint,
|
||||
DepositContract: testAcc.ContractAddr,
|
||||
BeaconDB: kvStore,
|
||||
DepositCache: depositcache.NewDepositCache(),
|
||||
DepositCache: depositCache,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("unable to setup web3 ETH1.0 chain service: %v", err)
|
||||
@@ -582,11 +598,14 @@ func TestWeb3ServiceProcessDepositLog_RequestMissedDeposits(t *testing.T) {
|
||||
t.Fatalf("Unable to set up simulated backend %v", err)
|
||||
}
|
||||
beaconDB, _ := testDB.SetupDB(t)
|
||||
depositCache, err := depositcache.NewDepositCache()
|
||||
require.NoError(t, err)
|
||||
|
||||
web3Service, err := NewService(context.Background(), &Web3ServiceConfig{
|
||||
HTTPEndPoint: endpoint,
|
||||
DepositContract: testAcc.ContractAddr,
|
||||
BeaconDB: beaconDB,
|
||||
DepositCache: depositcache.NewDepositCache(),
|
||||
DepositCache: depositCache,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("unable to setup web3 ETH1.0 chain service: %v", err)
|
||||
@@ -765,11 +784,14 @@ func TestConsistentGenesisState(t *testing.T) {
|
||||
}
|
||||
|
||||
func newPowchainService(t *testing.T, eth1Backend *contracts.TestAccount, beaconDB db.Database) *Service {
|
||||
depositCache, err := depositcache.NewDepositCache()
|
||||
require.NoError(t, err)
|
||||
|
||||
web3Service, err := NewService(context.Background(), &Web3ServiceConfig{
|
||||
HTTPEndPoint: endpoint,
|
||||
DepositContract: eth1Backend.ContractAddr,
|
||||
BeaconDB: beaconDB,
|
||||
DepositCache: depositcache.NewDepositCache(),
|
||||
DepositCache: depositCache,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("unable to setup web3 ETH1.0 chain service: %v", err)
|
||||
|
||||
@@ -106,6 +106,7 @@ go_test(
|
||||
"//shared/params:go_default_library",
|
||||
"//shared/roughtime:go_default_library",
|
||||
"//shared/testutil:go_default_library",
|
||||
"//shared/testutil/require:go_default_library",
|
||||
"//shared/trieutil:go_default_library",
|
||||
"@com_github_ferranbt_fastssz//:go_default_library",
|
||||
"@com_github_gogo_protobuf//proto:go_default_library",
|
||||
|
||||
@@ -26,6 +26,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/shared/mock"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
||||
)
|
||||
|
||||
// pubKey is a helper to generate a well-formed public key.
|
||||
@@ -55,12 +56,15 @@ func TestGetDuties_NextEpoch_CantFindValidatorIdx(t *testing.T) {
|
||||
chain := &mockChain.ChainService{
|
||||
State: beaconState, Root: genesisRoot[:], Genesis: time.Now(),
|
||||
}
|
||||
depositCache, err := depositcache.NewDepositCache()
|
||||
require.NoError(t, err)
|
||||
|
||||
vs := &Server{
|
||||
BeaconDB: db,
|
||||
HeadFetcher: chain,
|
||||
SyncChecker: &mockSync.Sync{IsSyncing: false},
|
||||
Eth1InfoFetcher: p,
|
||||
DepositFetcher: depositcache.NewDepositCache(),
|
||||
DepositFetcher: depositCache,
|
||||
GenesisTimeFetcher: chain,
|
||||
}
|
||||
|
||||
|
||||
@@ -361,23 +361,20 @@ func (vs *Server) depositTrie(ctx context.Context, canonicalEth1DataHeight *big.
|
||||
var finalizedDeposits *depositcache.FinalizedDeposits
|
||||
if featureconfig.Get().EnableFinalizedDepositsCache {
|
||||
finalizedDeposits = vs.DepositFetcher.FinalizedDeposits(ctx)
|
||||
depositTrie = finalizedDeposits.Deposits
|
||||
upToEth1DataDeposits := vs.DepositFetcher.NonFinalizedDeposits(ctx, canonicalEth1DataHeight)
|
||||
insertIndex := finalizedDeposits.MerkleTrieIndex + 1
|
||||
|
||||
if finalizedDeposits != nil {
|
||||
depositTrie = finalizedDeposits.Deposits
|
||||
|
||||
upToEth1DataDeposits := vs.DepositFetcher.NonFinalizedDeposits(ctx, canonicalEth1DataHeight)
|
||||
insertIndex := finalizedDeposits.MerkleTrieIndex + 1
|
||||
for _, dep := range upToEth1DataDeposits {
|
||||
depHash, err := ssz.HashTreeRoot(dep.Data)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not hash deposit data")
|
||||
}
|
||||
depositTrie.Insert(depHash[:], int(insertIndex))
|
||||
insertIndex++
|
||||
for _, dep := range upToEth1DataDeposits {
|
||||
depHash, err := ssz.HashTreeRoot(dep.Data)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not hash deposit data")
|
||||
}
|
||||
|
||||
return depositTrie, nil
|
||||
depositTrie.Insert(depHash[:], int(insertIndex))
|
||||
insertIndex++
|
||||
}
|
||||
|
||||
return depositTrie, nil
|
||||
}
|
||||
|
||||
upToEth1DataDeposits := vs.DepositFetcher.AllDeposits(ctx, canonicalEth1DataHeight)
|
||||
|
||||
@@ -36,6 +36,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/shared/hashutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
||||
"github.com/prysmaticlabs/prysm/shared/trieutil"
|
||||
)
|
||||
|
||||
@@ -583,7 +584,10 @@ func TestPendingDeposits_OutsideEth1FollowWindow(t *testing.T) {
|
||||
}},
|
||||
},
|
||||
}
|
||||
depositCache := depositcache.NewDepositCache()
|
||||
|
||||
depositCache, err := depositcache.NewDepositCache()
|
||||
require.NoError(t, err)
|
||||
|
||||
depositTrie, err := trieutil.NewTrie(int(params.BeaconConfig().DepositContractTreeDepth))
|
||||
if err != nil {
|
||||
t.Fatalf("could not setup deposit trie: %v", err)
|
||||
@@ -737,7 +741,10 @@ func TestPendingDeposits_FollowsCorrectEth1Block(t *testing.T) {
|
||||
}},
|
||||
},
|
||||
}
|
||||
depositCache := depositcache.NewDepositCache()
|
||||
|
||||
depositCache, err := depositcache.NewDepositCache()
|
||||
require.NoError(t, err)
|
||||
|
||||
depositTrie, err := trieutil.NewTrie(int(params.BeaconConfig().DepositContractTreeDepth))
|
||||
if err != nil {
|
||||
t.Fatalf("could not setup deposit trie: %v", err)
|
||||
@@ -858,7 +865,10 @@ func TestPendingDeposits_CantReturnBelowStateEth1DepositIndex(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("could not setup deposit trie: %v", err)
|
||||
}
|
||||
depositCache := depositcache.NewDepositCache()
|
||||
|
||||
depositCache, err := depositcache.NewDepositCache()
|
||||
require.NoError(t, err)
|
||||
|
||||
for _, dp := range append(readyDeposits, recentDeposits...) {
|
||||
depositHash, err := ssz.HashTreeRoot(dp.Deposit.Data)
|
||||
if err != nil {
|
||||
@@ -967,7 +977,10 @@ func TestPendingDeposits_CantReturnMoreThanMax(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("could not setup deposit trie: %v", err)
|
||||
}
|
||||
depositCache := depositcache.NewDepositCache()
|
||||
|
||||
depositCache, err := depositcache.NewDepositCache()
|
||||
require.NoError(t, err)
|
||||
|
||||
for _, dp := range append(readyDeposits, recentDeposits...) {
|
||||
depositHash, err := ssz.HashTreeRoot(dp.Deposit.Data)
|
||||
if err != nil {
|
||||
@@ -1074,7 +1087,10 @@ func TestPendingDeposits_CantReturnMoreThanDepositCount(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("could not setup deposit trie: %v", err)
|
||||
}
|
||||
depositCache := depositcache.NewDepositCache()
|
||||
|
||||
depositCache, err := depositcache.NewDepositCache()
|
||||
require.NoError(t, err)
|
||||
|
||||
for _, dp := range append(readyDeposits, recentDeposits...) {
|
||||
depositHash, err := ssz.HashTreeRoot(dp.Deposit.Data)
|
||||
if err != nil {
|
||||
@@ -1195,7 +1211,9 @@ func TestDepositTrie_UtilizesCachedFinalizedDeposits(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
depositCache := depositcache.NewDepositCache()
|
||||
depositCache, err := depositcache.NewDepositCache()
|
||||
require.NoError(t, err)
|
||||
|
||||
depositTrie, err := trieutil.NewTrie(int(params.BeaconConfig().DepositContractTreeDepth))
|
||||
if err != nil {
|
||||
t.Fatalf("could not setup deposit trie: %v", err)
|
||||
@@ -1291,7 +1309,10 @@ func TestDefaultEth1Data_NoBlockExists(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("could not setup deposit trie: %v", err)
|
||||
}
|
||||
depositCache := depositcache.NewDepositCache()
|
||||
|
||||
depositCache, err := depositcache.NewDepositCache()
|
||||
require.NoError(t, err)
|
||||
|
||||
for _, dp := range deps {
|
||||
depositCache.InsertDeposit(context.Background(), dp.Deposit, dp.Eth1BlockHeight, dp.Index, depositTrie.Root())
|
||||
}
|
||||
@@ -1348,11 +1369,14 @@ func TestEth1Data(t *testing.T) {
|
||||
if err := headState.SetEth1Data(ðpb.Eth1Data{DepositCount: 55}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
depositCache, err := depositcache.NewDepositCache()
|
||||
require.NoError(t, err)
|
||||
|
||||
ps := &Server{
|
||||
ChainStartFetcher: p,
|
||||
Eth1InfoFetcher: p,
|
||||
Eth1BlockFetcher: p,
|
||||
DepositFetcher: depositcache.NewDepositCache(),
|
||||
DepositFetcher: depositCache,
|
||||
HeadFetcher: &mock.ChainService{State: headState},
|
||||
}
|
||||
|
||||
@@ -1395,7 +1419,10 @@ func TestEth1Data_SmallerDepositCount(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("could not setup deposit trie: %v", err)
|
||||
}
|
||||
depositCache := depositcache.NewDepositCache()
|
||||
|
||||
depositCache, err := depositcache.NewDepositCache()
|
||||
require.NoError(t, err)
|
||||
|
||||
for _, dp := range deps {
|
||||
depositCache.InsertDeposit(context.Background(), dp.Deposit, dp.Eth1BlockHeight, dp.Index, depositTrie.Root())
|
||||
}
|
||||
@@ -1616,7 +1643,9 @@ func Benchmark_Eth1Data(b *testing.B) {
|
||||
},
|
||||
}
|
||||
|
||||
depositCache := depositcache.NewDepositCache()
|
||||
depositCache, err := depositcache.NewDepositCache()
|
||||
require.NoError(b, err)
|
||||
|
||||
for i, dp := range deposits {
|
||||
var root [32]byte
|
||||
copy(root[:], []byte{'d', 'e', 'p', 'o', 's', 'i', 't', byte(i)})
|
||||
@@ -1737,7 +1766,10 @@ func TestDeposits_ReturnsEmptyList_IfLatestEth1DataEqGenesisEth1Block(t *testing
|
||||
if err != nil {
|
||||
t.Fatalf("could not setup deposit trie: %v", err)
|
||||
}
|
||||
depositCache := depositcache.NewDepositCache()
|
||||
|
||||
depositCache, err := depositcache.NewDepositCache()
|
||||
require.NoError(t, err)
|
||||
|
||||
for _, dp := range append(readyDeposits, recentDeposits...) {
|
||||
depositHash, err := ssz.HashTreeRoot(dp.Deposit.Data)
|
||||
if err != nil {
|
||||
|
||||
@@ -26,6 +26,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/shared/mock"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
||||
"github.com/prysmaticlabs/prysm/shared/trieutil"
|
||||
logTest "github.com/sirupsen/logrus/hooks/test"
|
||||
)
|
||||
@@ -79,6 +80,9 @@ func TestWaitForActivation_ContextClosed(t *testing.T) {
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
depositCache, err := depositcache.NewDepositCache()
|
||||
require.NoError(t, err)
|
||||
|
||||
vs := &Server{
|
||||
BeaconDB: db,
|
||||
Ctx: ctx,
|
||||
@@ -86,7 +90,7 @@ func TestWaitForActivation_ContextClosed(t *testing.T) {
|
||||
BlockFetcher: &mockPOW.POWChain{},
|
||||
Eth1InfoFetcher: &mockPOW.POWChain{},
|
||||
CanonicalStateChan: make(chan *pbp2p.BeaconState, 1),
|
||||
DepositFetcher: depositcache.NewDepositCache(),
|
||||
DepositFetcher: depositCache,
|
||||
HeadFetcher: &mockChain.ChainService{State: beaconState, Root: genesisRoot[:]},
|
||||
}
|
||||
req := ðpb.ValidatorActivationRequest{
|
||||
@@ -160,7 +164,9 @@ func TestWaitForActivation_ValidatorOriginallyExists(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(fmt.Errorf("could not setup deposit trie: %v", err))
|
||||
}
|
||||
depositCache := depositcache.NewDepositCache()
|
||||
depositCache, err := depositcache.NewDepositCache()
|
||||
require.NoError(t, err)
|
||||
|
||||
depositCache.InsertDeposit(ctx, deposit, 10 /*blockNum*/, 0, depositTrie.Root())
|
||||
trie, err := stateTrie.InitializeFromProtoUnsafe(beaconState)
|
||||
if err != nil {
|
||||
|
||||
@@ -20,6 +20,7 @@ import (
|
||||
pbp2p "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/require"
|
||||
"github.com/prysmaticlabs/prysm/shared/trieutil"
|
||||
)
|
||||
|
||||
@@ -40,7 +41,9 @@ func TestValidatorStatus_DepositedEth1(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("Could not setup deposit trie: %v", err)
|
||||
}
|
||||
depositCache := depositcache.NewDepositCache()
|
||||
depositCache, err := depositcache.NewDepositCache()
|
||||
require.NoError(t, err)
|
||||
|
||||
depositCache.InsertDeposit(ctx, deposit, 0 /*blockNum*/, 0, depositTrie.Root())
|
||||
height := time.Unix(int64(params.BeaconConfig().Eth1FollowDistance), 0).Unix()
|
||||
p := &mockPOW.POWChain{
|
||||
@@ -90,7 +93,9 @@ func TestValidatorStatus_Deposited(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("Could not setup deposit trie: %v", err)
|
||||
}
|
||||
depositCache := depositcache.NewDepositCache()
|
||||
depositCache, err := depositcache.NewDepositCache()
|
||||
require.NoError(t, err)
|
||||
|
||||
depositCache.InsertDeposit(ctx, deposit, 0 /*blockNum*/, 0, depositTrie.Root())
|
||||
height := time.Unix(int64(params.BeaconConfig().Eth1FollowDistance), 0).Unix()
|
||||
p := &mockPOW.POWChain{
|
||||
@@ -178,7 +183,9 @@ func TestValidatorStatus_Pending(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("Could not setup deposit trie: %v", err)
|
||||
}
|
||||
depositCache := depositcache.NewDepositCache()
|
||||
depositCache, err := depositcache.NewDepositCache()
|
||||
require.NoError(t, err)
|
||||
|
||||
depositCache.InsertDeposit(ctx, deposit, 0 /*blockNum*/, 0, depositTrie.Root())
|
||||
|
||||
height := time.Unix(int64(params.BeaconConfig().Eth1FollowDistance), 0).Unix()
|
||||
@@ -229,7 +236,9 @@ func TestValidatorStatus_Active(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("Could not setup deposit trie: %v", err)
|
||||
}
|
||||
depositCache := depositcache.NewDepositCache()
|
||||
depositCache, err := depositcache.NewDepositCache()
|
||||
require.NoError(t, err)
|
||||
|
||||
depositCache.InsertDeposit(ctx, deposit, 0 /*blockNum*/, 0, depositTrie.Root())
|
||||
|
||||
// Active because activation epoch <= current epoch < exit epoch.
|
||||
@@ -334,7 +343,9 @@ func TestValidatorStatus_Exiting(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("Could not setup deposit trie: %v", err)
|
||||
}
|
||||
depositCache := depositcache.NewDepositCache()
|
||||
depositCache, err := depositcache.NewDepositCache()
|
||||
require.NoError(t, err)
|
||||
|
||||
depositCache.InsertDeposit(ctx, deposit, 0 /*blockNum*/, 0, depositTrie.Root())
|
||||
height := time.Unix(int64(params.BeaconConfig().Eth1FollowDistance), 0).Unix()
|
||||
p := &mockPOW.POWChain{
|
||||
@@ -404,7 +415,9 @@ func TestValidatorStatus_Slashing(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("Could not setup deposit trie: %v", err)
|
||||
}
|
||||
depositCache := depositcache.NewDepositCache()
|
||||
depositCache, err := depositcache.NewDepositCache()
|
||||
require.NoError(t, err)
|
||||
|
||||
depositCache.InsertDeposit(ctx, deposit, 0 /*blockNum*/, 0, depositTrie.Root())
|
||||
height := time.Unix(int64(params.BeaconConfig().Eth1FollowDistance), 0).Unix()
|
||||
p := &mockPOW.POWChain{
|
||||
@@ -482,7 +495,9 @@ func TestValidatorStatus_Exited(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("Could not setup deposit trie: %v", err)
|
||||
}
|
||||
depositCache := depositcache.NewDepositCache()
|
||||
depositCache, err := depositcache.NewDepositCache()
|
||||
require.NoError(t, err)
|
||||
|
||||
depositCache.InsertDeposit(ctx, deposit, 0 /*blockNum*/, 0, depositTrie.Root())
|
||||
height := time.Unix(int64(params.BeaconConfig().Eth1FollowDistance), 0).Unix()
|
||||
p := &mockPOW.POWChain{
|
||||
@@ -513,7 +528,9 @@ func TestValidatorStatus_Exited(t *testing.T) {
|
||||
func TestValidatorStatus_UnknownStatus(t *testing.T) {
|
||||
db, _ := dbutil.SetupDB(t)
|
||||
pubKey := pubKey(1)
|
||||
depositCache := depositcache.NewDepositCache()
|
||||
depositCache, err := depositcache.NewDepositCache()
|
||||
require.NoError(t, err)
|
||||
|
||||
stateObj, err := stateTrie.InitializeFromProtoUnsafe(&pbp2p.BeaconState{
|
||||
Slot: 0,
|
||||
})
|
||||
@@ -584,7 +601,9 @@ func TestActivationStatus_OK(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("Could not setup deposit trie: %v", err)
|
||||
}
|
||||
depositCache := depositcache.NewDepositCache()
|
||||
depositCache, err := depositcache.NewDepositCache()
|
||||
require.NoError(t, err)
|
||||
|
||||
depositCache.InsertDeposit(ctx, dep, 10 /*blockNum*/, 0, depositTrie.Root())
|
||||
depData = ðpb.Deposit_Data{
|
||||
PublicKey: pubKey(3),
|
||||
@@ -720,7 +739,8 @@ func TestValidatorStatus_CorrectActivationQueue(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("Could not setup deposit trie: %v", err)
|
||||
}
|
||||
depositCache := depositcache.NewDepositCache()
|
||||
depositCache, err := depositcache.NewDepositCache()
|
||||
require.NoError(t, err)
|
||||
|
||||
for i := 0; i < 6; i++ {
|
||||
depData := ðpb.Deposit_Data{
|
||||
@@ -784,7 +804,9 @@ func TestDepositBlockSlotAfterGenesisTime(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("Could not setup deposit trie: %v", err)
|
||||
}
|
||||
depositCache := depositcache.NewDepositCache()
|
||||
depositCache, err := depositcache.NewDepositCache()
|
||||
require.NoError(t, err)
|
||||
|
||||
depositCache.InsertDeposit(ctx, deposit, 0 /*blockNum*/, 0, depositTrie.Root())
|
||||
|
||||
timestamp := time.Unix(int64(params.BeaconConfig().Eth1FollowDistance), 0).Unix()
|
||||
@@ -859,7 +881,9 @@ func TestDepositBlockSlotBeforeGenesisTime(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("Could not setup deposit trie: %v", err)
|
||||
}
|
||||
depositCache := depositcache.NewDepositCache()
|
||||
depositCache, err := depositcache.NewDepositCache()
|
||||
require.NoError(t, err)
|
||||
|
||||
depositCache.InsertDeposit(ctx, deposit, 0 /*blockNum*/, 0, depositTrie.Root())
|
||||
|
||||
timestamp := time.Unix(int64(params.BeaconConfig().Eth1FollowDistance), 0).Unix()
|
||||
@@ -958,7 +982,9 @@ func TestMultipleValidatorStatus_Pubkeys(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("Could not setup deposit trie: %v", err)
|
||||
}
|
||||
depositCache := depositcache.NewDepositCache()
|
||||
depositCache, err := depositcache.NewDepositCache()
|
||||
require.NoError(t, err)
|
||||
|
||||
depositCache.InsertDeposit(ctx, dep, 10 /*blockNum*/, 0, depositTrie.Root())
|
||||
depData = ðpb.Deposit_Data{
|
||||
PublicKey: pubKey(3),
|
||||
|
||||
@@ -625,5 +625,5 @@ var E2EBeaconChainFlags = []string{
|
||||
"--check-head-state",
|
||||
"--attestation-aggregation-strategy=max_cover",
|
||||
"--dev",
|
||||
// "--enable-finalized-deposits-cache", // TODO(6588): Enable in e2e
|
||||
"--enable-finalized-deposits-cache",
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user