@@ -104,10 +104,15 @@ type StrategyParams struct {
104
104
}
105
105
106
106
// 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)
107
109
var 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 },
111
116
}
112
117
113
118
// NewLayer2Relayer will return a new instance of Layer2RelayerClient
@@ -147,6 +152,11 @@ func NewLayer2Relayer(ctx context.Context, l2Client *ethclient.Client, db *gorm.
147
152
return nil , fmt .Errorf ("invalid service type for l2_relayer: %v" , serviceType )
148
153
}
149
154
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
+
150
160
layer2Relayer := & Layer2Relayer {
151
161
ctx : ctx ,
152
162
db : db ,
@@ -164,7 +174,7 @@ func NewLayer2Relayer(ctx context.Context, l2Client *ethclient.Client, db *gorm.
164
174
l1RollupABI : bridgeAbi .ScrollChainABI ,
165
175
166
176
l2GasOracleABI : bridgeAbi .L2GasPriceOracleABI ,
167
- batchStrategy : bestParams [ uint64 ( cfg . BatchSubmission . TimeoutSec )] ,
177
+ batchStrategy : strategy ,
168
178
cfg : cfg ,
169
179
chainCfg : chainCfg ,
170
180
}
@@ -271,11 +281,11 @@ func (r *Layer2Relayer) commitGenesisBatch(batchHash string, batchHeader []byte,
271
281
}
272
282
273
283
// 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 )
275
285
if err != nil {
276
286
return fmt .Errorf ("failed to send import genesis batch tx to L1, error: %v" , err )
277
287
}
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 )
279
289
280
290
// wait for confirmation
281
291
// we assume that no other transactions are sent before initializeGenesis completes
@@ -336,11 +346,11 @@ func (r *Layer2Relayer) ProcessPendingBatches() {
336
346
var forceSubmit bool
337
347
338
348
startChunk , err := r .chunkOrm .GetChunkByIndex (r .ctx , dbBatches [0 ].StartChunkIndex )
339
- oldestBlockTimestamp := time .Unix (int64 (startChunk .StartBlockTime ), 0 )
340
349
if err != nil {
341
350
log .Error ("failed to get first chunk" , "err" , err , "batch index" , dbBatches [0 ].Index , "chunk index" , dbBatches [0 ].StartChunkIndex )
342
351
return
343
352
}
353
+ oldestBlockTimestamp := time .Unix (int64 (startChunk .StartBlockTime ), 0 )
344
354
345
355
// if the batch with the oldest index is too old, we force submit all batches that we have so far in the next step
346
356
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() {
467
477
return
468
478
}
469
479
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 )
471
481
if err != nil {
472
482
if errors .Is (err , sender .ErrTooManyPendingBlobTxs ) {
473
483
r .metrics .rollupL2RelayerProcessPendingBatchErrTooManyPendingBlobTxsTotal .Inc ()
@@ -508,6 +518,7 @@ func (r *Layer2Relayer) ProcessPendingBatches() {
508
518
r .metrics .rollupL2RelayerProcessPendingBatchSuccessTotal .Add (float64 (len (batchesToSubmit )))
509
519
r .metrics .rollupL2RelayerProcessBatchesPerTxCount .Set (float64 (len (batchesToSubmit )))
510
520
r .metrics .rollupL2RelayerCommitLatency .Set (time .Since (oldestBlockTimestamp ).Seconds ())
521
+ r .metrics .rollupL2RelayerCommitPrice .Set (float64 (blobBaseFee ))
511
522
512
523
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 ())
513
524
}
@@ -691,7 +702,7 @@ func (r *Layer2Relayer) finalizeBundle(bundle *orm.Bundle, withProof bool) error
691
702
return fmt .Errorf ("unsupported codec version in finalizeBundle, bundle index: %v, version: %d" , bundle .Index , bundle .CodecVersion )
692
703
}
693
704
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 )
695
706
if err != nil {
696
707
log .Error ("finalizeBundle in layer1 failed" , "with proof" , withProof , "index" , bundle .Index ,
697
708
"start batch index" , bundle .StartBatchIndex , "end batch index" , bundle .EndBatchIndex ,
0 commit comments