mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-08 18:51:19 +00:00
Fetch Non Finalized Deposits Better (#10505)
This commit is contained in:
parent
ca5adbf7e4
commit
00b92e01d3
@ -36,7 +36,7 @@ type DepositFetcher interface {
|
|||||||
DepositByPubkey(ctx context.Context, pubKey []byte) (*ethpb.Deposit, *big.Int)
|
DepositByPubkey(ctx context.Context, pubKey []byte) (*ethpb.Deposit, *big.Int)
|
||||||
DepositsNumberAndRootAtHeight(ctx context.Context, blockHeight *big.Int) (uint64, [32]byte)
|
DepositsNumberAndRootAtHeight(ctx context.Context, blockHeight *big.Int) (uint64, [32]byte)
|
||||||
FinalizedDeposits(ctx context.Context) *FinalizedDeposits
|
FinalizedDeposits(ctx context.Context) *FinalizedDeposits
|
||||||
NonFinalizedDeposits(ctx context.Context, untilBlk *big.Int) []*ethpb.Deposit
|
NonFinalizedDeposits(ctx context.Context, lastFinalizedIndex int64, untilBlk *big.Int) []*ethpb.Deposit
|
||||||
}
|
}
|
||||||
|
|
||||||
// FinalizedDeposits stores the trie of deposits that have been included
|
// FinalizedDeposits stores the trie of deposits that have been included
|
||||||
@ -246,7 +246,7 @@ func (dc *DepositCache) FinalizedDeposits(ctx context.Context) *FinalizedDeposit
|
|||||||
|
|
||||||
// NonFinalizedDeposits returns the list of non-finalized deposits until the given block number (inclusive).
|
// NonFinalizedDeposits returns the list of non-finalized deposits until the given block number (inclusive).
|
||||||
// If no block is specified then this method returns all non-finalized deposits.
|
// If no block is specified then this method returns all non-finalized deposits.
|
||||||
func (dc *DepositCache) NonFinalizedDeposits(ctx context.Context, untilBlk *big.Int) []*ethpb.Deposit {
|
func (dc *DepositCache) NonFinalizedDeposits(ctx context.Context, lastFinalizedIndex int64, untilBlk *big.Int) []*ethpb.Deposit {
|
||||||
ctx, span := trace.StartSpan(ctx, "DepositsCache.NonFinalizedDeposits")
|
ctx, span := trace.StartSpan(ctx, "DepositsCache.NonFinalizedDeposits")
|
||||||
defer span.End()
|
defer span.End()
|
||||||
dc.depositsLock.RLock()
|
dc.depositsLock.RLock()
|
||||||
@ -256,10 +256,9 @@ func (dc *DepositCache) NonFinalizedDeposits(ctx context.Context, untilBlk *big.
|
|||||||
return dc.allDeposits(untilBlk)
|
return dc.allDeposits(untilBlk)
|
||||||
}
|
}
|
||||||
|
|
||||||
lastFinalizedDepositIndex := dc.finalizedDeposits.MerkleTrieIndex
|
|
||||||
var deposits []*ethpb.Deposit
|
var deposits []*ethpb.Deposit
|
||||||
for _, d := range dc.deposits {
|
for _, d := range dc.deposits {
|
||||||
if (d.Index > lastFinalizedDepositIndex) && (untilBlk == nil || untilBlk.Uint64() >= d.Eth1BlockHeight) {
|
if (d.Index > lastFinalizedIndex) && (untilBlk == nil || untilBlk.Uint64() >= d.Eth1BlockHeight) {
|
||||||
deposits = append(deposits, d.Deposit)
|
deposits = append(deposits, d.Deposit)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -554,7 +554,7 @@ func TestNonFinalizedDeposits_ReturnsAllNonFinalizedDeposits(t *testing.T) {
|
|||||||
})
|
})
|
||||||
dc.InsertFinalizedDeposits(context.Background(), 1)
|
dc.InsertFinalizedDeposits(context.Background(), 1)
|
||||||
|
|
||||||
deps := dc.NonFinalizedDeposits(context.Background(), nil)
|
deps := dc.NonFinalizedDeposits(context.Background(), 1, nil)
|
||||||
assert.Equal(t, 2, len(deps))
|
assert.Equal(t, 2, len(deps))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -611,7 +611,7 @@ func TestNonFinalizedDeposits_ReturnsNonFinalizedDepositsUpToBlockNumber(t *test
|
|||||||
})
|
})
|
||||||
dc.InsertFinalizedDeposits(context.Background(), 1)
|
dc.InsertFinalizedDeposits(context.Background(), 1)
|
||||||
|
|
||||||
deps := dc.NonFinalizedDeposits(context.Background(), big.NewInt(10))
|
deps := dc.NonFinalizedDeposits(context.Background(), 1, big.NewInt(10))
|
||||||
assert.Equal(t, 1, len(deps))
|
assert.Equal(t, 1, len(deps))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,7 +155,7 @@ func (_ *Service) FinalizedDeposits(_ context.Context) *depositcache.FinalizedDe
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NonFinalizedDeposits mocks out the deposit cache functionality for interop.
|
// NonFinalizedDeposits mocks out the deposit cache functionality for interop.
|
||||||
func (_ *Service) NonFinalizedDeposits(_ context.Context, _ *big.Int) []*ethpb.Deposit {
|
func (_ *Service) NonFinalizedDeposits(_ context.Context, _ int64, _ *big.Int) []*ethpb.Deposit {
|
||||||
return []*ethpb.Deposit{}
|
return []*ethpb.Deposit{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -480,8 +480,8 @@ func TestInitDepositCacheWithFinalization_OK(t *testing.T) {
|
|||||||
|
|
||||||
s.chainStartData.Chainstarted = true
|
s.chainStartData.Chainstarted = true
|
||||||
require.NoError(t, s.initDepositCaches(context.Background(), ctrs))
|
require.NoError(t, s.initDepositCaches(context.Background(), ctrs))
|
||||||
|
fDeposits := s.cfg.depositCache.FinalizedDeposits(ctx)
|
||||||
deps := s.cfg.depositCache.NonFinalizedDeposits(context.Background(), nil)
|
deps := s.cfg.depositCache.NonFinalizedDeposits(context.Background(), fDeposits.MerkleTrieIndex, nil)
|
||||||
assert.Equal(t, 0, len(deps))
|
assert.Equal(t, 0, len(deps))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,7 +161,7 @@ func (vs *Server) depositTrie(ctx context.Context, canonicalEth1Data *ethpb.Eth1
|
|||||||
|
|
||||||
finalizedDeposits := vs.DepositFetcher.FinalizedDeposits(ctx)
|
finalizedDeposits := vs.DepositFetcher.FinalizedDeposits(ctx)
|
||||||
depositTrie = finalizedDeposits.Deposits
|
depositTrie = finalizedDeposits.Deposits
|
||||||
upToEth1DataDeposits := vs.DepositFetcher.NonFinalizedDeposits(ctx, canonicalEth1DataHeight)
|
upToEth1DataDeposits := vs.DepositFetcher.NonFinalizedDeposits(ctx, finalizedDeposits.MerkleTrieIndex, canonicalEth1DataHeight)
|
||||||
insertIndex := finalizedDeposits.MerkleTrieIndex + 1
|
insertIndex := finalizedDeposits.MerkleTrieIndex + 1
|
||||||
|
|
||||||
for _, dep := range upToEth1DataDeposits {
|
for _, dep := range upToEth1DataDeposits {
|
||||||
|
Loading…
Reference in New Issue
Block a user