Skip to content

Commit 1d04436

Browse files
calberaclaude
andauthored
feat(deposits): Migration to EIP-6110 style processing (#2794)
Signed-off-by: Cal Bera <calbera@berachain.com> Co-authored-by: Claude <noreply@anthropic.com>
1 parent 9ab5f95 commit 1d04436

44 files changed

Lines changed: 1347 additions & 307 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

beacon/blockchain/deposit.go

Lines changed: 0 additions & 125 deletions
This file was deleted.

beacon/blockchain/finalize_block.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"fmt"
2626
"time"
2727

28+
"github.com/berachain/beacon-kit/beacon/deposits"
2829
ctypes "github.com/berachain/beacon-kit/consensus-types/types"
2930
"github.com/berachain/beacon-kit/consensus/types"
3031
datypes "github.com/berachain/beacon-kit/da/types"
@@ -126,9 +127,10 @@ func (s *Service) PostFinalizeBlockOps(ctx sdk.Context, blk *ctypes.BeaconBlock)
126127
// TODO: consider extracting LatestExecutionPayloadHeader instead of using state here
127128
st := s.storageBackend.StateFromContext(ctx)
128129

129-
// Fetch and store the deposit for the block.
130-
blockNum := blk.GetBody().GetExecutionPayload().GetNumber()
131-
s.depositFetcher(ctx, blockNum)
130+
// Before Fulu, deposits must be fetched from the EL (at the eth1 follow distance).
131+
deposits.FetchPreviousDepositsPreFulu(
132+
ctx, s.depositContract, blk, s.eth1FollowDistance, s.storageBackend.DepositStore(), s.logger,
133+
)
132134

133135
// Store the finalized block in the KVStore.
134136
slot := blk.GetSlot()
@@ -169,6 +171,13 @@ func (s *Service) finalizeBeaconBlock(
169171
return nil, ErrNilBlk
170172
}
171173

174+
// If on the first block of Fulu, catchup the previous block's deposits.
175+
if err := deposits.CatchupFuluDeposits(
176+
ctx, s.depositContract, st, beaconBlk, s.chainSpec, s.storageBackend.DepositStore(), s.logger,
177+
); err != nil {
178+
return nil, err
179+
}
180+
172181
valUpdates, err := s.executeStateTransition(ctx, st, blk)
173182
if err != nil {
174183
return nil, err

beacon/blockchain/interfaces.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,4 +198,5 @@ type ServiceChainSpec interface {
198198
EpochsPerHistoricalVector() uint64
199199
SlotToEpoch(slot math.Slot) math.Epoch
200200
Eth1FollowDistance() uint64
201+
MaxDepositsPerBlock() uint64
201202
}

beacon/blockchain/process_proposal.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"slices"
2929
"time"
3030

31+
"github.com/berachain/beacon-kit/beacon/deposits"
3132
ctypes "github.com/berachain/beacon-kit/consensus-types/types"
3233
"github.com/berachain/beacon-kit/consensus/cometbft/service/cache"
3334
"github.com/berachain/beacon-kit/consensus/types"
@@ -328,6 +329,13 @@ func (s *Service) VerifyIncomingBlock(
328329
}
329330
}
330331

332+
// If on the first block of Fulu, catchup the previous block's deposits.
333+
if err = deposits.CatchupFuluDeposits(
334+
ctx, s.depositContract, state, beaconBlk, s.chainSpec, s.storageBackend.DepositStore(), s.logger,
335+
); err != nil {
336+
return nil, err
337+
}
338+
331339
// Verify the state root of the incoming block.
332340
valUpdates, err := s.verifyStateRoot(ctx, state, blk)
333341
if err != nil {

beacon/blockchain/service.go

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,11 @@ type Service struct {
4343
depositContract deposit.Contract
4444
// eth1FollowDistance is the follow distance for Ethereum 1.0 blocks.
4545
eth1FollowDistance math.U64
46-
// failedBlocksMu protects failedBlocks for concurrent access.
47-
failedBlocksMu sync.RWMutex
48-
// failedBlocks is a map of blocks that failed to be processed
49-
// and should be retried.
50-
failedBlocks map[math.U64]struct{}
5146
// logger is used for logging messages in the service.
5247
logger log.Logger
5348
// chainSpec holds the chain specifications.
5449
chainSpec ServiceChainSpec
5550
// executionEngine is the execution engine responsible for processing
56-
//
5751
// execution payloads.
5852
executionEngine ExecutionEngine
5953
// localBuilder is a local builder for constructing new beacon states.
@@ -64,7 +58,6 @@ type Service struct {
6458
metrics *chainMetrics
6559
// forceStartupSyncOnce is used to force a sync of the startup head.
6660
forceStartupSyncOnce *sync.Once
67-
6861
// latestFcuReq holds a copy of the latest FCU sent to the execution layer.
6962
// It helps avoid resending the same FCU data (and spares a network call)
7063
// in case optimistic block building is active
@@ -88,7 +81,6 @@ func NewService(
8881
blobProcessor: blobProcessor,
8982
depositContract: depositContract,
9083
eth1FollowDistance: math.U64(chainSpec.Eth1FollowDistance()),
91-
failedBlocks: make(map[math.Slot]struct{}),
9284
logger: logger,
9385
chainSpec: chainSpec,
9486
executionEngine: executionEngine,
@@ -105,10 +97,7 @@ func (s *Service) Name() string {
10597
}
10698

10799
// Start starts the blockchain service.
108-
func (s *Service) Start(ctx context.Context) error {
109-
// Catchup deposits for failed blocks. TODO: remove.
110-
go s.depositCatchupFetcher(ctx)
111-
100+
func (s *Service) Start(context.Context) error {
112101
return nil
113102
}
114103

0 commit comments

Comments
 (0)