@@ -196,7 +196,7 @@ func (s *RollupSyncService) parseAndUpdateRollupEventLogs(logs []types.Log, endB
196
196
197
197
chunkBlockRanges , err := s .getChunkRanges (batchIndex , & vLog )
198
198
if err != nil {
199
- return fmt .Errorf ("failed to get chunk ranges, err: %w" , err )
199
+ return fmt .Errorf ("failed to get chunk ranges, batch index: %v, err: %w" , batchIndex , err )
200
200
}
201
201
rawdb .WriteBatchChunkRanges (s .db , batchIndex , chunkBlockRanges )
202
202
@@ -311,9 +311,26 @@ func (s *RollupSyncService) getChunkRanges(batchIndex uint64, vLog *types.Log) (
311
311
return []* rawdb.ChunkBlockRange {{StartBlockNumber : 0 , EndBlockNumber : 0 }}, nil
312
312
}
313
313
314
- tx , _ , err := s .client .client .TransactionByHash (context . Background () , vLog .TxHash )
314
+ tx , _ , err := s .client .client .TransactionByHash (s . ctx , vLog .TxHash )
315
315
if err != nil {
316
- return nil , fmt .Errorf ("failed to get transaction, err: %w" , err )
316
+ log .Debug ("failed to get transaction by hash, probably an unindexed transaction, fetching the whole block to get the transaction" ,
317
+ "tx hash" , vLog .TxHash .Hex (), "block number" , vLog .BlockNumber , "block hash" , vLog .BlockHash .Hex (), "err" , err )
318
+ block , err := s .client .client .BlockByHash (s .ctx , vLog .BlockHash )
319
+ if err != nil {
320
+ return nil , fmt .Errorf ("failed to get block by hash, block number: %v, block hash: %v, err: %w" , vLog .BlockNumber , vLog .BlockHash .Hex (), err )
321
+ }
322
+
323
+ found := false
324
+ for _ , txInBlock := range block .Transactions () {
325
+ if txInBlock .Hash () == vLog .TxHash {
326
+ tx = txInBlock
327
+ found = true
328
+ break
329
+ }
330
+ }
331
+ if ! found {
332
+ return nil , fmt .Errorf ("transaction not found in the block, tx hash: %v, block number: %v, block hash: %v" , vLog .TxHash .Hex (), vLog .BlockNumber , vLog .BlockHash .Hex ())
333
+ }
317
334
}
318
335
319
336
return s .decodeChunkBlockRanges (tx .Data ())
@@ -323,17 +340,17 @@ func (s *RollupSyncService) getChunkRanges(batchIndex uint64, vLog *types.Log) (
323
340
func (s * RollupSyncService ) decodeChunkBlockRanges (txData []byte ) ([]* rawdb.ChunkBlockRange , error ) {
324
341
const methodIDLength = 4
325
342
if len (txData ) < methodIDLength {
326
- return nil , fmt .Errorf ("transaction data is too short" )
343
+ return nil , fmt .Errorf ("transaction data is too short, length of tx data: %v, minimum length required: %v" , len ( txData ), methodIDLength )
327
344
}
328
345
329
346
method , err := s .scrollChainABI .MethodById (txData [:methodIDLength ])
330
347
if err != nil {
331
- return nil , fmt .Errorf ("failed to get method by ID, ID: %v, err: %w" , txData [:4 ], err )
348
+ return nil , fmt .Errorf ("failed to get method by ID, ID: %v, err: %w" , txData [:methodIDLength ], err )
332
349
}
333
350
334
351
values , err := method .Inputs .Unpack (txData [methodIDLength :])
335
352
if err != nil {
336
- return nil , fmt .Errorf ("failed to unpack transaction data using ABI: %v" , err )
353
+ return nil , fmt .Errorf ("failed to unpack transaction data using ABI, tx data : %v, err: %w" , txData , err )
337
354
}
338
355
339
356
type commitBatchArgs struct {
@@ -345,11 +362,11 @@ func (s *RollupSyncService) decodeChunkBlockRanges(txData []byte) ([]*rawdb.Chun
345
362
var args commitBatchArgs
346
363
err = method .Inputs .Copy (& args , values )
347
364
if err != nil {
348
- return nil , fmt .Errorf ("failed to decode calldata into commitBatch args, err: %w" , err )
365
+ return nil , fmt .Errorf ("failed to decode calldata into commitBatch args, values: %+v, err: %w" , values , err )
349
366
}
350
367
351
368
if args .Version != batchHeaderVersion {
352
- return nil , fmt .Errorf ("unexpected batch version, expected: %d , got: %v" , batchHeaderVersion , args .Version )
369
+ return nil , fmt .Errorf ("unexpected batch version, expected: %v , got: %v" , batchHeaderVersion , args .Version )
353
370
}
354
371
355
372
return DecodeChunkBlockRanges (args .Chunks )
@@ -360,18 +377,18 @@ func (s *RollupSyncService) decodeChunkBlockRanges(txData []byte) ([]*rawdb.Chun
360
377
// It returns the number of the end block, a finalized batch meta data, and an error if any.
361
378
func validateBatch (event * L1FinalizeBatchEvent , parentBatchMeta * rawdb.FinalizedBatchMeta , chunks []* Chunk ) (uint64 , * rawdb.FinalizedBatchMeta , error ) {
362
379
if len (chunks ) == 0 {
363
- return 0 , nil , fmt .Errorf ("invalid argument: length of chunks is 0" )
380
+ return 0 , nil , fmt .Errorf ("invalid argument: length of chunks is 0, batch index: %v" , event . BatchIndex . Uint64 () )
364
381
}
365
382
366
383
startChunk := chunks [0 ]
367
384
if len (startChunk .Blocks ) == 0 {
368
- return 0 , nil , fmt .Errorf ("invalid argument: block count of start chunk is 0" )
385
+ return 0 , nil , fmt .Errorf ("invalid argument: block count of start chunk is 0, batch index: %v" , event . BatchIndex . Uint64 () )
369
386
}
370
387
startBlock := startChunk .Blocks [0 ]
371
388
372
389
endChunk := chunks [len (chunks )- 1 ]
373
390
if len (endChunk .Blocks ) == 0 {
374
- return 0 , nil , fmt .Errorf ("invalid argument: block count of end chunk is 0" )
391
+ return 0 , nil , fmt .Errorf ("invalid argument: block count of end chunk is 0, batch index: %v" , event . BatchIndex . Uint64 () )
375
392
}
376
393
endBlock := endChunk .Blocks [len (endChunk .Blocks )- 1 ]
377
394
@@ -392,15 +409,18 @@ func validateBatch(event *L1FinalizeBatchEvent, parentBatchMeta *rawdb.Finalized
392
409
// Note: All params for NewBatchHeader are calculated locally based on the block data.
393
410
batchHeader , err := NewBatchHeader (batchHeaderVersion , event .BatchIndex .Uint64 (), parentBatchMeta .TotalL1MessagePopped , parentBatchMeta .BatchHash , chunks )
394
411
if err != nil {
395
- return 0 , nil , fmt .Errorf ("failed to construct batch header, err: %w" , err )
412
+ return 0 , nil , fmt .Errorf ("failed to construct batch header, batch index: %v, err: %w" , event . BatchIndex . Uint64 () , err )
396
413
}
397
414
398
415
// Note: If the batch headers match, this ensures the consistency of blocks and transactions
399
416
// (including skipped transactions) between L1 and L2.
400
417
localBatchHash := batchHeader .Hash ()
401
418
if localBatchHash != event .BatchHash {
402
419
log .Error ("Batch hash mismatch" , "batch index" , event .BatchIndex .Uint64 (), "start block" , startBlock .Header .Number .Uint64 (), "end block" , endBlock .Header .Number .Uint64 (), "parent batch hash" , parentBatchMeta .BatchHash .Hex (), "parent TotalL1MessagePopped" , parentBatchMeta .TotalL1MessagePopped , "l1 finalized batch hash" , event .BatchHash .Hex (), "l2 batch hash" , localBatchHash .Hex ())
403
- chunksJson , _ := json .Marshal (chunks )
420
+ chunksJson , err := json .Marshal (chunks )
421
+ if err != nil {
422
+ log .Error ("marshal chunks failed" , "err" , err )
423
+ }
404
424
log .Error ("Chunks" , "chunks" , string (chunksJson ))
405
425
syscall .Kill (os .Getpid (), syscall .SIGTERM )
406
426
return 0 , nil , fmt .Errorf ("batch hash mismatch" )
0 commit comments