@@ -204,47 +204,58 @@ func isBatchPreconfirmed(
204
204
txListBytes []byte ,
205
205
parent * types.Header ,
206
206
) (* types.Header , error ) {
207
+ var (
208
+ headers = make ([]* types.Header , len (metadata .Pacaya ().GetBlocks ()))
209
+ g = new (errgroup.Group )
210
+ )
211
+
207
212
// Check each block in the batch, and if the all blocks are preconfirmed, return the header of the last block.
208
213
for i := 0 ; i < len (metadata .Pacaya ().GetBlocks ()); i ++ {
209
- createExecutionPayloadsMetaData , anchorTx , err := assembleCreateExecutionPayloadMetaPacaya (
210
- ctx ,
211
- rpc ,
212
- anchorConstructor ,
213
- metadata ,
214
- allTxs ,
215
- parent ,
216
- i ,
217
- )
218
- if err != nil {
219
- return nil , fmt .Errorf ("failed to assemble execution payload creation metadata: %w" , err )
220
- }
214
+ g .Go (func () error {
215
+ parentHeader , err := rpc .L2 .HeaderByNumber (ctx , new (big.Int ).SetUint64 (parent .Number .Uint64 ()+ uint64 (i )))
216
+ if err != nil {
217
+ return fmt .Errorf ("failed to get parent block by number %d: %w" , parent .Number .Uint64 ()+ uint64 (i ), err )
218
+ }
221
219
222
- b , err := rlp .EncodeToBytes (append ([]* types.Transaction {anchorTx }, createExecutionPayloadsMetaData .Txs ... ))
223
- if err != nil {
224
- return nil , fmt .Errorf ("failed to RLP encode tx list: %w" , err )
225
- }
220
+ createExecutionPayloadsMetaData , anchorTx , err := assembleCreateExecutionPayloadMetaPacaya (
221
+ ctx ,
222
+ rpc ,
223
+ anchorConstructor ,
224
+ metadata ,
225
+ allTxs ,
226
+ parentHeader ,
227
+ i ,
228
+ )
229
+ if err != nil {
230
+ return fmt .Errorf ("failed to assemble execution payload creation metadata: %w" , err )
231
+ }
226
232
227
- header , err := isBlockPreconfirmed (
228
- ctx ,
229
- rpc ,
230
- & createPayloadAndSetHeadMetaData {
231
- createExecutionPayloadsMetaData : createExecutionPayloadsMetaData ,
232
- AnchorBlockID : new (big.Int ).SetUint64 (metadata .Pacaya ().GetAnchorBlockID ()),
233
- AnchorBlockHash : metadata .Pacaya ().GetAnchorBlockHash (),
234
- BaseFeeConfig : metadata .Pacaya ().GetBaseFeeConfig (),
235
- Parent : parent ,
236
- },
237
- b ,
238
- anchorTx ,
239
- )
240
- if err != nil {
241
- return nil , fmt .Errorf ("failed to check if block is preconfirmed: %w" , err )
242
- }
233
+ b , err := rlp .EncodeToBytes (append ([]* types.Transaction {anchorTx }, createExecutionPayloadsMetaData .Txs ... ))
234
+ if err != nil {
235
+ return fmt .Errorf ("failed to RLP encode tx list: %w" , err )
236
+ }
237
+
238
+ if headers [i ], err = isBlockPreconfirmed (
239
+ ctx ,
240
+ rpc ,
241
+ & createPayloadAndSetHeadMetaData {
242
+ createExecutionPayloadsMetaData : createExecutionPayloadsMetaData ,
243
+ AnchorBlockID : new (big.Int ).SetUint64 (metadata .Pacaya ().GetAnchorBlockID ()),
244
+ AnchorBlockHash : metadata .Pacaya ().GetAnchorBlockHash (),
245
+ BaseFeeConfig : metadata .Pacaya ().GetBaseFeeConfig (),
246
+ Parent : parentHeader ,
247
+ },
248
+ b ,
249
+ anchorTx ,
250
+ ); err != nil {
251
+ return fmt .Errorf ("failed to check if block is preconfirmed: %w" , err )
252
+ }
243
253
244
- parent = header
254
+ return nil
255
+ })
245
256
}
246
257
247
- return parent , nil
258
+ return headers [ len ( headers ) - 1 ], g . Wait ()
248
259
}
249
260
250
261
// isBlockPreconfirmed checks if the block is preconfirmed.
0 commit comments