@@ -551,32 +551,6 @@ func (l *L2OutputSubmitter) sendTransaction(ctx context.Context, output *eth.Out
551
551
return nil
552
552
}
553
553
554
- // sendCheckpointTransaction sends a transaction to checkpoint the blockhash corresponding to `blockNumber` on the L2OO contract.
555
- func (l * L2OutputSubmitter ) sendCheckpointTransaction (ctx context.Context , blockNumber * big.Int ) error {
556
- var receipt * types.Receipt
557
- data , err := l .CheckpointBlockHashTxData (blockNumber )
558
- if err != nil {
559
- return err
560
- }
561
- // TODO: This currently blocks the loop while it waits for the transaction to be confirmed. Up to 3 minutes.
562
- receipt , err = l .Txmgr .Send (ctx , txmgr.TxCandidate {
563
- TxData : data ,
564
- To : l .Cfg .L2OutputOracleAddr ,
565
- GasLimit : 0 ,
566
- })
567
- if err != nil {
568
- return err
569
- }
570
-
571
- if receipt .Status == types .ReceiptStatusFailed {
572
- l .Log .Error ("checkpoint blockhash tx successfully published but reverted" , "tx_hash" , receipt .TxHash )
573
- } else {
574
- l .Log .Info ("checkpoint blockhash tx successfully published" ,
575
- "tx_hash" , receipt .TxHash )
576
- }
577
- return nil
578
- }
579
-
580
554
// loop is responsible for creating & submitting the next outputs
581
555
// TODO: Look into adding a transaction cache so the loop isn't waiting for the transaction to confirm. This sometimes takes up to 30s.
582
556
func (l * L2OutputSubmitter ) loop () {
@@ -744,9 +718,43 @@ func (l *L2OutputSubmitter) checkpointBlockHash(ctx context.Context) (uint64, co
744
718
blockHash := header .Hash ()
745
719
blockNumber := header .Number
746
720
747
- err = l .sendCheckpointTransaction (cCtx , blockNumber )
721
+ // Check if the block hash has ALREADY been checkpointed on the L2OO contract.
722
+ // If it has, we can skip the checkpointing step.
723
+ contract , err := opsuccinctbindings .NewOPSuccinctL2OutputOracleCaller (* l .Cfg .L2OutputOracleAddr , l .L1Client )
748
724
if err != nil {
749
725
return 0 , common.Hash {}, err
750
726
}
727
+ maybeBlockHash , err := contract .HistoricBlockHashes (& bind.CallOpts {Context : cCtx }, blockNumber )
728
+ if err != nil {
729
+ return 0 , common.Hash {}, err
730
+ }
731
+ if maybeBlockHash != (common.Hash {}) {
732
+ l .Log .Info ("Block hash already checkpointed on L2OO contract" , "block_number" , blockNumber , "block_hash" , blockHash )
733
+ return blockNumber .Uint64 (), blockHash , nil
734
+ }
735
+
736
+ // If not, send a transaction to checkpoint the blockhash on the L2OO contract.
737
+ var receipt * types.Receipt
738
+ data , err := l .CheckpointBlockHashTxData (blockNumber )
739
+ if err != nil {
740
+ return 0 , common.Hash {}, err
741
+ }
742
+
743
+ // TODO: This currently blocks the loop while it waits for the transaction to be confirmed. Up to 3 minutes.
744
+ receipt , err = l .Txmgr .Send (ctx , txmgr.TxCandidate {
745
+ TxData : data ,
746
+ To : l .Cfg .L2OutputOracleAddr ,
747
+ GasLimit : 0 ,
748
+ })
749
+ if err != nil {
750
+ return 0 , common.Hash {}, err
751
+ }
752
+
753
+ if receipt .Status == types .ReceiptStatusFailed {
754
+ l .Log .Error ("checkpoint blockhash tx successfully published but reverted" , "tx_hash" , receipt .TxHash )
755
+ } else {
756
+ l .Log .Info ("checkpoint blockhash tx successfully published" ,
757
+ "tx_hash" , receipt .TxHash )
758
+ }
751
759
return blockNumber .Uint64 (), blockHash , nil
752
760
}
0 commit comments