Skip to content

Commit f981f59

Browse files
davidtaikochamask-ppYoGhurt111cyberhorseyCopilot
authored
feat(taiko-client): introduce payloadQueue for P2P gossip messages (#19195)
Co-authored-by: maskpp <[email protected]> Co-authored-by: Gavin Yu <[email protected]> Co-authored-by: Jeffery Walsh <[email protected]> Co-authored-by: jeff <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent 7f2556b commit f981f59

File tree

12 files changed

+721
-117
lines changed

12 files changed

+721
-117
lines changed

packages/taiko-client/bindings/encoding/struct.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ func TransitionContestedEventToV2(
150150
}
151151
}
152152

153-
// BlockVerifiedEventToV2 converts a *ontakeBindings.OntakeClients.TaikoL1ClientBlockVerified to *ontakeBindings.OntakeClients.TaikoL1ClientBlockVerifiedV2.
153+
// BlockVerifiedEventToV2 converts a *ontakeBindings.OntakeClients.TaikoL1ClientBlockVerified
154+
// to *ontakeBindings.OntakeClients.TaikoL1ClientBlockVerifiedV2.
154155
func BlockVerifiedEventToV2(e *ontakeBindings.TaikoL1ClientBlockVerified) *ontakeBindings.TaikoL1ClientBlockVerifiedV2 {
155156
return &ontakeBindings.TaikoL1ClientBlockVerifiedV2{
156157
BlockId: e.BlockId,

packages/taiko-client/driver/chain_syncer/blob/blocks_inserter/common.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,6 @@ func assembleCreateExecutionPayloadMetaPacaya(
449449
}, anchorTx, nil
450450
}
451451

452-
// updateL1OriginForBatch updates the each block's L1 origin in the given batch.
453452
func updateL1OriginForBatch(
454453
ctx context.Context,
455454
rpc *rpc.Client,
@@ -466,26 +465,32 @@ func updateL1OriginForBatch(
466465

467466
for i := 0; i < len(meta.GetBlocks()); i++ {
468467
g.Go(func() error {
469-
blockID := new(big.Int).SetUint64(meta.GetLastBlockID() - uint64(i))
468+
blockID := new(big.Int).SetUint64(meta.GetLastBlockID() - uint64(len(meta.GetBlocks())-1-i))
469+
470470
header, err := rpc.L2.HeaderByNumber(ctx, blockID)
471471
if err != nil {
472472
return fmt.Errorf("failed to get block by number %d: %w", blockID, err)
473473
}
474+
474475
l1Origin := &rawdb.L1Origin{
475476
BlockID: blockID,
476477
L2BlockHash: header.Hash(),
477478
L1BlockHeight: meta.GetRawBlockHeight(),
478479
L1BlockHash: meta.GetRawBlockHash(),
479480
}
480-
// Update the l1Origin and headL1Origin cursor for that preconfirmed block.
481+
481482
if _, err := rpc.L2Engine.UpdateL1Origin(ctx, l1Origin); err != nil {
482483
return fmt.Errorf("failed to update L1 origin: %w", err)
483484
}
485+
486+
// If this is the most recent block, update the HeadL1Origin.
484487
if i == len(meta.GetBlocks())-1 {
488+
log.Info("Update head L1 origin", "blockID", blockID, "l1Origin", l1Origin)
485489
if _, err := rpc.L2Engine.SetHeadL1Origin(ctx, l1Origin.BlockID); err != nil {
486490
return fmt.Errorf("failed to write head L1 origin: %w", err)
487491
}
488492
}
493+
489494
return nil
490495
})
491496
}

packages/taiko-client/driver/chain_syncer/blob/blocks_inserter/pacaya.go

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,15 +195,24 @@ func (i *BlocksInserterPacaya) InsertBlocks(
195195

196196
log.Debug("Payload data", "hash", lastPayloadData.BlockHash, "txs", len(lastPayloadData.Transactions))
197197

198+
// Wait till the corresponding L2 header to be existed in the L2 EE.
199+
if _, err := i.rpc.WaitL2Header(ctx, new(big.Int).SetUint64(lastPayloadData.Number)); err != nil {
200+
return fmt.Errorf("failed to wait for L2 header (%d): %w", lastPayloadData.Number, err)
201+
}
202+
198203
log.Info(
199204
"🔗 New L2 block inserted",
200205
"blockID", lastPayloadData.Number,
201206
"hash", lastPayloadData.BlockHash,
207+
"coinbase", lastPayloadData.FeeRecipient.Hex(),
202208
"transactions", len(lastPayloadData.Transactions),
203209
"timestamp", lastPayloadData.Timestamp,
204210
"baseFee", utils.WeiToGWei(lastPayloadData.BaseFeePerGas),
205211
"withdrawals", len(lastPayloadData.Withdrawals),
206212
"batchID", meta.GetBatchID(),
213+
"gasLimit", lastPayloadData.GasLimit,
214+
"gasUsed", lastPayloadData.GasUsed,
215+
"parentHash", lastPayloadData.ParentHash,
207216
"indexInBatch", j,
208217
)
209218

@@ -213,14 +222,31 @@ func (i *BlocksInserterPacaya) InsertBlocks(
213222
return nil
214223
}
215224

216-
// InsertPreconfBlockFromExecutionPayload inserts a preconf block from the given execution payload.
217-
func (i *BlocksInserterPacaya) InsertPreconfBlockFromExecutionPayload(
225+
// InsertPreconfBlocksFromExecutionPayloads inserts preconf blocks from the given execution payloads.
226+
func (i *BlocksInserterPacaya) InsertPreconfBlocksFromExecutionPayloads(
218227
ctx context.Context,
219-
executableData *eth.ExecutionPayload,
220-
) (*types.Header, error) {
228+
executionPayloads []*eth.ExecutionPayload,
229+
) ([]*types.Header, error) {
221230
i.mutex.Lock()
222231
defer i.mutex.Unlock()
223232

233+
headers := make([]*types.Header, len(executionPayloads))
234+
for j, executableData := range executionPayloads {
235+
header, err := i.insertPreconfBlockFromExecutionPayload(ctx, executableData)
236+
if err != nil {
237+
return nil, fmt.Errorf("failed to insert preconf block: %w", err)
238+
}
239+
headers[j] = header
240+
}
241+
242+
return headers, nil
243+
}
244+
245+
// insertPreconfBlockFromExecutionPayload the inner method to insert a preconf block from the given execution payload.
246+
func (i *BlocksInserterPacaya) insertPreconfBlockFromExecutionPayload(
247+
ctx context.Context,
248+
executableData *eth.ExecutionPayload,
249+
) (*types.Header, error) {
224250
// Ensure the preconfirmation block number is greater than the current head L1 origin block ID.
225251
headL1Origin, err := i.rpc.L2.HeadL1Origin(ctx)
226252
if err != nil && err.Error() != ethereum.NotFound.Error() {
@@ -231,7 +257,7 @@ func (i *BlocksInserterPacaya) InsertPreconfBlockFromExecutionPayload(
231257
if headL1Origin != nil {
232258
if uint64(executableData.BlockNumber) <= headL1Origin.BlockID.Uint64() {
233259
return nil, fmt.Errorf(
234-
"preconfirmation block number (%d) is less than or equal to the current head L1 origin block ID (%d)",
260+
"preconfirmation block ID (%d) is less than or equal to the current head L1 origin block ID (%d)",
235261
executableData.BlockNumber,
236262
headL1Origin.BlockID,
237263
)
@@ -242,6 +268,11 @@ func (i *BlocksInserterPacaya) InsertPreconfBlockFromExecutionPayload(
242268
return nil, fmt.Errorf("no transactions data in the payload")
243269
}
244270

271+
// Decompress the transactions list.
272+
if executableData.Transactions[0], err = utils.DecompressPacaya(executableData.Transactions[0]); err != nil {
273+
return nil, fmt.Errorf("failed to decompress transactions list bytes: %w", err)
274+
}
275+
245276
var u256BaseFee = uint256.Int(executableData.BaseFeePerGas)
246277
payload, err := createExecutionPayloadsAndSetHead(
247278
ctx,

packages/taiko-client/driver/chain_syncer/chain_syncer.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,7 @@ func New(
4747
go tracker.Track(ctx)
4848

4949
beaconSyncer := beaconsync.NewSyncer(ctx, rpc, state, tracker)
50-
blobSyncer, err := blob.NewSyncer(
51-
ctx,
52-
rpc,
53-
state,
54-
tracker,
55-
blobServerEndpoint,
56-
)
50+
blobSyncer, err := blob.NewSyncer(ctx, rpc, state, tracker, blobServerEndpoint)
5751
if err != nil {
5852
return nil, err
5953
}

packages/taiko-client/driver/driver.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ func (d *Driver) InitFromConfig(ctx context.Context, cfg *Config) (err error) {
117117
if d.preconfBlockServer, err = preconfBlocks.New(
118118
d.PreconfBlockServerCORSOrigins,
119119
d.PreconfBlockServerJWTSecret,
120+
d.TaikoL2Address,
120121
d.l2ChainSyncer.BlobSyncer().BlocksInserterPacaya(),
121122
d.rpc,
122123
); err != nil {

0 commit comments

Comments
 (0)