@@ -173,14 +173,10 @@ func (f *L1FetcherLogic) getBlocksAndDetectReorg(ctx context.Context, from, to u
173173 return false , 0 , lastBlockHash , blocks , nil
174174}
175175
176- func (f * L1FetcherLogic ) getRevertedTxs (ctx context.Context , from , to uint64 , blocks []* types.Block ) (map [ uint64 ] uint64 , []* orm.CrossMessage , error ) {
176+ func (f * L1FetcherLogic ) getRevertedTxs (ctx context.Context , from , to uint64 , blocks []* types.Block ) ([]* orm.CrossMessage , error ) {
177177 var l1RevertedTxs []* orm.CrossMessage
178- blockTimestampsMap := make (map [uint64 ]uint64 )
179-
180178 for i := from ; i <= to ; i ++ {
181179 block := blocks [i - from ]
182- blockTimestampsMap [block .NumberU64 ()] = block .Time ()
183-
184180 for _ , tx := range block .Transactions () {
185181 // Gateways: L1 deposit.
186182 // Messenger: L1 deposit retry (replayMessage), L1 deposit refund (dropMessage), L2 withdrawal's claim (relayMessageWithProof).
@@ -192,7 +188,7 @@ func (f *L1FetcherLogic) getRevertedTxs(ctx context.Context, from, to uint64, bl
192188 receipt , receiptErr := f .client .TransactionReceipt (ctx , tx .Hash ())
193189 if receiptErr != nil {
194190 log .Error ("Failed to get transaction receipt" , "txHash" , tx .Hash ().String (), "err" , receiptErr )
195- return nil , nil , receiptErr
191+ return nil , receiptErr
196192 }
197193
198194 // Check if the transaction is failed
@@ -204,7 +200,7 @@ func (f *L1FetcherLogic) getRevertedTxs(ctx context.Context, from, to uint64, bl
204200 sender , senderErr := signer .Sender (tx )
205201 if senderErr != nil {
206202 log .Error ("get sender failed" , "chain id" , tx .ChainId ().Uint64 (), "tx hash" , tx .Hash ().String (), "err" , senderErr )
207- return nil , nil , senderErr
203+ return nil , senderErr
208204 }
209205
210206 l1RevertedTxs = append (l1RevertedTxs , & orm.CrossMessage {
@@ -218,7 +214,7 @@ func (f *L1FetcherLogic) getRevertedTxs(ctx context.Context, from, to uint64, bl
218214 })
219215 }
220216 }
221- return blockTimestampsMap , l1RevertedTxs , nil
217+ return l1RevertedTxs , nil
222218}
223219
224220func (f * L1FetcherLogic ) l1FetcherLogs (ctx context.Context , from , to uint64 ) ([]types.Log , error ) {
@@ -270,12 +266,18 @@ func (f *L1FetcherLogic) L1Fetcher(ctx context.Context, from, to uint64, lastBlo
270266 return isReorg , reorgHeight , blockHash , nil , nil
271267 }
272268
273- blockTimestampsMap , l1RevertedTxs , err := f .getRevertedTxs (ctx , from , to , blocks )
269+ l1RevertedTxs , err := f .getRevertedTxs (ctx , from , to , blocks )
274270 if err != nil {
275271 log .Error ("L1Fetcher getRevertedTxs failed" , "from" , from , "to" , to , "error" , err )
276272 return false , 0 , common.Hash {}, nil , err
277273 }
278274
275+ // Map block number to block timestamp to avoid fetching block header multiple times to get block timestamp.
276+ blockTimestampsMap := make (map [uint64 ]uint64 )
277+ for _ , block := range blocks {
278+ blockTimestampsMap [block .NumberU64 ()] = block .Time ()
279+ }
280+
279281 eventLogs , err := f .l1FetcherLogs (ctx , from , to )
280282 if err != nil {
281283 log .Error ("L1Fetcher l1FetcherLogs failed" , "from" , from , "to" , to , "error" , err )
@@ -288,7 +290,7 @@ func (f *L1FetcherLogic) L1Fetcher(ctx context.Context, from, to uint64, lastBlo
288290 return false , 0 , common.Hash {}, nil , err
289291 }
290292
291- l1BatchEvents , err := f .parser .ParseL1BatchEventLogs (ctx , eventLogs , f .client )
293+ l1BatchEvents , err := f .parser .ParseL1BatchEventLogs (ctx , eventLogs , f .client , blockTimestampsMap )
292294 if err != nil {
293295 log .Error ("failed to parse L1 batch event logs" , "from" , from , "to" , to , "err" , err )
294296 return false , 0 , common.Hash {}, nil , err
0 commit comments