@@ -104,10 +104,15 @@ type StrategyParams struct {
104104}
105105
106106// bestParams maps your 2h/5h/12h windows to their best rules.
107+ // Timeouts are in seconds, 2, 5 and 12 hours (and same + 20 mins to account for
108+ // time to create batch currently roughly, as time is measured from block creation)
107109var bestParams = map [uint64 ]StrategyParams {
108- 2 * 3600 : {BaselineType : PctMin , BaselineParam : 0.10 , Gamma : 0.4 , Beta : 8 , RelaxType : Exponential },
109- 5 * 3600 : {BaselineType : PctMin , BaselineParam : 0.30 , Gamma : 0.6 , Beta : 20 , RelaxType : Sigmoid },
110- 12 * 3600 : {BaselineType : PctMin , BaselineParam : 0.50 , Gamma : 0.5 , Beta : 20 , RelaxType : Sigmoid },
110+ 7200 : {BaselineType : PctMin , BaselineParam : 0.10 , Gamma : 0.4 , Beta : 8 , RelaxType : Exponential },
111+ 8400 : {BaselineType : PctMin , BaselineParam : 0.10 , Gamma : 0.4 , Beta : 8 , RelaxType : Exponential },
112+ 18000 : {BaselineType : PctMin , BaselineParam : 0.30 , Gamma : 0.6 , Beta : 20 , RelaxType : Sigmoid },
113+ 19200 : {BaselineType : PctMin , BaselineParam : 0.30 , Gamma : 0.6 , Beta : 20 , RelaxType : Sigmoid },
114+ 42800 : {BaselineType : PctMin , BaselineParam : 0.50 , Gamma : 0.5 , Beta : 20 , RelaxType : Sigmoid },
115+ 44400 : {BaselineType : PctMin , BaselineParam : 0.50 , Gamma : 0.5 , Beta : 20 , RelaxType : Sigmoid },
111116}
112117
113118// NewLayer2Relayer will return a new instance of Layer2RelayerClient
@@ -147,6 +152,11 @@ func NewLayer2Relayer(ctx context.Context, l2Client *ethclient.Client, db *gorm.
147152 return nil , fmt .Errorf ("invalid service type for l2_relayer: %v" , serviceType )
148153 }
149154
155+ strategy , ok := bestParams [uint64 (cfg .BatchSubmission .TimeoutSec )]
156+ if ! ok {
157+ return nil , fmt .Errorf ("invalid timeout for batch submission: %v" , cfg .BatchSubmission .TimeoutSec )
158+ }
159+
150160 layer2Relayer := & Layer2Relayer {
151161 ctx : ctx ,
152162 db : db ,
@@ -164,7 +174,7 @@ func NewLayer2Relayer(ctx context.Context, l2Client *ethclient.Client, db *gorm.
164174 l1RollupABI : bridgeAbi .ScrollChainABI ,
165175
166176 l2GasOracleABI : bridgeAbi .L2GasPriceOracleABI ,
167- batchStrategy : bestParams [ uint64 ( cfg . BatchSubmission . TimeoutSec )] ,
177+ batchStrategy : strategy ,
168178 cfg : cfg ,
169179 chainCfg : chainCfg ,
170180 }
@@ -271,11 +281,11 @@ func (r *Layer2Relayer) commitGenesisBatch(batchHash string, batchHeader []byte,
271281 }
272282
273283 // submit genesis batch to L1 rollup contract
274- txHash , err := r .commitSender .SendTransaction (batchHash , & r .cfg .RollupContractAddress , calldata , nil )
284+ txHash , _ , err := r .commitSender .SendTransaction (batchHash , & r .cfg .RollupContractAddress , calldata , nil )
275285 if err != nil {
276286 return fmt .Errorf ("failed to send import genesis batch tx to L1, error: %v" , err )
277287 }
278- log .Info ("importGenesisBatch transaction sent" , "contract" , r .cfg .RollupContractAddress , "txHash" , txHash . String () , "batchHash" , batchHash )
288+ log .Info ("importGenesisBatch transaction sent" , "contract" , r .cfg .RollupContractAddress , "txHash" , txHash , "batchHash" , batchHash )
279289
280290 // wait for confirmation
281291 // we assume that no other transactions are sent before initializeGenesis completes
@@ -336,11 +346,11 @@ func (r *Layer2Relayer) ProcessPendingBatches() {
336346 var forceSubmit bool
337347
338348 startChunk , err := r .chunkOrm .GetChunkByIndex (r .ctx , dbBatches [0 ].StartChunkIndex )
339- oldestBlockTimestamp := time .Unix (int64 (startChunk .StartBlockTime ), 0 )
340349 if err != nil {
341350 log .Error ("failed to get first chunk" , "err" , err , "batch index" , dbBatches [0 ].Index , "chunk index" , dbBatches [0 ].StartChunkIndex )
342351 return
343352 }
353+ oldestBlockTimestamp := time .Unix (int64 (startChunk .StartBlockTime ), 0 )
344354
345355 // if the batch with the oldest index is too old, we force submit all batches that we have so far in the next step
346356 if r .cfg .BatchSubmission .TimeoutSec > 0 && time .Since (oldestBlockTimestamp ) > time .Duration (r .cfg .BatchSubmission .TimeoutSec )* time .Second {
@@ -467,7 +477,7 @@ func (r *Layer2Relayer) ProcessPendingBatches() {
467477 return
468478 }
469479
470- txHash , err := r .commitSender .SendTransaction (r .contextIDFromBatches (batchesToSubmit ), & r .cfg .RollupContractAddress , calldata , blobs )
480+ txHash , blobBaseFee , err := r .commitSender .SendTransaction (r .contextIDFromBatches (batchesToSubmit ), & r .cfg .RollupContractAddress , calldata , blobs )
471481 if err != nil {
472482 if errors .Is (err , sender .ErrTooManyPendingBlobTxs ) {
473483 r .metrics .rollupL2RelayerProcessPendingBatchErrTooManyPendingBlobTxsTotal .Inc ()
@@ -508,6 +518,7 @@ func (r *Layer2Relayer) ProcessPendingBatches() {
508518 r .metrics .rollupL2RelayerProcessPendingBatchSuccessTotal .Add (float64 (len (batchesToSubmit )))
509519 r .metrics .rollupL2RelayerProcessBatchesPerTxCount .Set (float64 (len (batchesToSubmit )))
510520 r .metrics .rollupL2RelayerCommitLatency .Set (time .Since (oldestBlockTimestamp ).Seconds ())
521+ r .metrics .rollupL2RelayerCommitPrice .Set (float64 (blobBaseFee ))
511522
512523 log .Info ("Sent the commitBatches tx to layer1" , "batches count" , len (batchesToSubmit ), "start index" , firstBatch .Index , "start hash" , firstBatch .Hash , "end index" , lastBatch .Index , "end hash" , lastBatch .Hash , "tx hash" , txHash .String ())
513524}
@@ -691,7 +702,7 @@ func (r *Layer2Relayer) finalizeBundle(bundle *orm.Bundle, withProof bool) error
691702 return fmt .Errorf ("unsupported codec version in finalizeBundle, bundle index: %v, version: %d" , bundle .Index , bundle .CodecVersion )
692703 }
693704
694- txHash , err := r .finalizeSender .SendTransaction ("finalizeBundle-" + bundle .Hash , & r .cfg .RollupContractAddress , calldata , nil )
705+ txHash , _ , err := r .finalizeSender .SendTransaction ("finalizeBundle-" + bundle .Hash , & r .cfg .RollupContractAddress , calldata , nil )
695706 if err != nil {
696707 log .Error ("finalizeBundle in layer1 failed" , "with proof" , withProof , "index" , bundle .Index ,
697708 "start batch index" , bundle .StartBatchIndex , "end batch index" , bundle .EndBatchIndex ,
0 commit comments