Skip to content

Commit 47b1a03

Browse files
authored
Fix bug sequencer submission strategy and log commit price (#1664)
Co-authored-by: ranchalp <ranchalp@users.noreply.github.com>
1 parent ae34020 commit 47b1a03

File tree

6 files changed

+50
-34
lines changed

6 files changed

+50
-34
lines changed

common/version/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"runtime/debug"
66
)
77

8-
var tag = "v4.5.16"
8+
var tag = "v4.5.17"
99

1010
var commit = func() string {
1111
if info, ok := debug.ReadBuildInfo(); ok {

rollup/internal/controller/relayer/l1_relayer.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,13 @@ func (r *Layer1Relayer) ProcessGasPriceOracle() {
179179
return
180180
}
181181

182-
hash, err := r.gasOracleSender.SendTransaction(block.Hash, &r.cfg.GasPriceOracleContractAddress, data, nil)
182+
txHash, _, err := r.gasOracleSender.SendTransaction(block.Hash, &r.cfg.GasPriceOracleContractAddress, data, nil)
183183
if err != nil {
184184
log.Error("Failed to send gas oracle update tx to layer2", "block.Hash", block.Hash, "block.Height", block.Number, "block.BaseFee", baseFee, "block.BlobBaseFee", blobBaseFee, "err", err)
185185
return
186186
}
187187

188-
err = r.l1BlockOrm.UpdateL1GasOracleStatusAndOracleTxHash(r.ctx, block.Hash, types.GasOracleImporting, hash.String())
188+
err = r.l1BlockOrm.UpdateL1GasOracleStatusAndOracleTxHash(r.ctx, block.Hash, types.GasOracleImporting, txHash.String())
189189
if err != nil {
190190
log.Error("UpdateGasOracleStatusAndOracleTxHash failed", "block.Hash", block.Hash, "block.Height", block.Number, "err", err)
191191
return
@@ -195,7 +195,7 @@ func (r *Layer1Relayer) ProcessGasPriceOracle() {
195195
r.lastBlobBaseFee = blobBaseFee
196196
r.metrics.rollupL1RelayerLatestBaseFee.Set(float64(r.lastBaseFee))
197197
r.metrics.rollupL1RelayerLatestBlobBaseFee.Set(float64(r.lastBlobBaseFee))
198-
log.Info("Update l1 base fee", "txHash", hash.String(), "baseFee", baseFee, "blobBaseFee", blobBaseFee)
198+
log.Info("Update l1 base fee", "txHash", txHash.String(), "baseFee", baseFee, "blobBaseFee", blobBaseFee)
199199
}
200200
}
201201
}

rollup/internal/controller/relayer/l2_relayer.go

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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)
107109
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},
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,

rollup/internal/controller/relayer/l2_relayer_metrics.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ type l2RelayerMetrics struct {
3131
rollupL2RelayerTargetBlobPrice prometheus.Gauge
3232
rollupL2RelayerCommitLatency prometheus.Gauge
3333
rollupL2RelayerBacklogCounts prometheus.Gauge
34+
rollupL2RelayerCommitPrice prometheus.Gauge
3435
}
3536

3637
var (
@@ -125,6 +126,10 @@ func initL2RelayerMetrics(reg prometheus.Registerer) *l2RelayerMetrics {
125126
Name: "rollup_l2_relayer_backlog_counts",
126127
Help: "The number of pending batches in the backlog",
127128
}),
129+
rollupL2RelayerCommitPrice: promauto.With(reg).NewGauge(prometheus.GaugeOpts{
130+
Name: "rollup_l2_relayer_commit_price",
131+
Help: "The commit price for the L2 relayer's submission strategy",
132+
}),
128133
}
129134
})
130135
return l2RelayerMetric

rollup/internal/controller/sender/sender.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ func (s *Sender) getFeeData(target *common.Address, data []byte, sidecar *gethTy
171171
}
172172

173173
// SendTransaction send a signed L2tL1 transaction.
174-
func (s *Sender) SendTransaction(contextID string, target *common.Address, data []byte, blobs []*kzg4844.Blob) (common.Hash, error) {
174+
func (s *Sender) SendTransaction(contextID string, target *common.Address, data []byte, blobs []*kzg4844.Blob) (common.Hash, uint64, error) {
175175
s.metrics.sendTransactionTotal.WithLabelValues(s.service, s.name).Inc()
176176
var (
177177
feeData *FeeData
@@ -190,52 +190,52 @@ func (s *Sender) SendTransaction(contextID string, target *common.Address, data
190190
numPendingTransactions, err = s.pendingTransactionOrm.GetCountPendingTransactionsBySenderType(s.ctx, s.senderType)
191191
if err != nil {
192192
log.Error("failed to count pending transactions", "err: %w", err)
193-
return common.Hash{}, fmt.Errorf("failed to count pending transactions, err: %w", err)
193+
return common.Hash{}, 0, fmt.Errorf("failed to count pending transactions, err: %w", err)
194194
}
195195
if numPendingTransactions >= s.config.MaxPendingBlobTxs {
196-
return common.Hash{}, ErrTooManyPendingBlobTxs
196+
return common.Hash{}, 0, ErrTooManyPendingBlobTxs
197197
}
198198

199199
}
200200
sidecar, err = makeSidecar(blobs)
201201
if err != nil {
202202
log.Error("failed to make sidecar for blob transaction", "error", err)
203-
return common.Hash{}, fmt.Errorf("failed to make sidecar for blob transaction, err: %w", err)
203+
return common.Hash{}, 0, fmt.Errorf("failed to make sidecar for blob transaction, err: %w", err)
204204
}
205205
}
206206

207207
blockNumber, baseFee, blobBaseFee, err := s.getBlockNumberAndBaseFeeAndBlobFee(s.ctx)
208208
if err != nil {
209209
log.Error("failed to get block number and base fee", "error", err)
210-
return common.Hash{}, fmt.Errorf("failed to get block number and base fee, err: %w", err)
210+
return common.Hash{}, 0, fmt.Errorf("failed to get block number and base fee, err: %w", err)
211211
}
212212

213213
if feeData, err = s.getFeeData(target, data, sidecar, baseFee, blobBaseFee); err != nil {
214214
s.metrics.sendTransactionFailureGetFee.WithLabelValues(s.service, s.name).Inc()
215215
log.Error("failed to get fee data", "from", s.transactionSigner.GetAddr().String(), "nonce", s.transactionSigner.GetNonce(), "err", err)
216-
return common.Hash{}, fmt.Errorf("failed to get fee data, err: %w", err)
216+
return common.Hash{}, 0, fmt.Errorf("failed to get fee data, err: %w", err)
217217
}
218218

219219
signedTx, err := s.createTx(feeData, target, data, sidecar, s.transactionSigner.GetNonce())
220220
if err != nil {
221221
s.metrics.sendTransactionFailureSendTx.WithLabelValues(s.service, s.name).Inc()
222222
log.Error("failed to create signed tx (non-resubmit case)", "from", s.transactionSigner.GetAddr().String(), "nonce", s.transactionSigner.GetNonce(), "err", err)
223-
return common.Hash{}, fmt.Errorf("failed to create signed transaction, err: %w", err)
223+
return common.Hash{}, 0, fmt.Errorf("failed to create signed transaction, err: %w", err)
224224
}
225225

226226
// Insert the transaction into the pending transaction table.
227227
// A corner case is that the transaction is inserted into the table but not sent to the chain, because the server is stopped in the middle.
228228
// This case will be handled by the checkPendingTransaction function.
229229
if err = s.pendingTransactionOrm.InsertPendingTransaction(s.ctx, contextID, s.getSenderMeta(), signedTx, blockNumber); err != nil {
230230
log.Error("failed to insert transaction", "from", s.transactionSigner.GetAddr().String(), "nonce", s.transactionSigner.GetNonce(), "err", err)
231-
return common.Hash{}, fmt.Errorf("failed to insert transaction, err: %w", err)
231+
return common.Hash{}, 0, fmt.Errorf("failed to insert transaction, err: %w", err)
232232
}
233233

234234
if err := s.client.SendTransaction(s.ctx, signedTx); err != nil {
235235
// Delete the transaction from the pending transaction table if it fails to send.
236236
if updateErr := s.pendingTransactionOrm.DeleteTransactionByTxHash(s.ctx, signedTx.Hash()); updateErr != nil {
237237
log.Error("failed to delete transaction", "tx hash", signedTx.Hash().String(), "from", s.transactionSigner.GetAddr().String(), "nonce", signedTx.Nonce(), "err", updateErr)
238-
return common.Hash{}, fmt.Errorf("failed to delete transaction, err: %w", updateErr)
238+
return common.Hash{}, 0, fmt.Errorf("failed to delete transaction, err: %w", updateErr)
239239
}
240240

241241
log.Error("failed to send tx", "tx hash", signedTx.Hash().String(), "from", s.transactionSigner.GetAddr().String(), "nonce", signedTx.Nonce(), "err", err)
@@ -244,12 +244,12 @@ func (s *Sender) SendTransaction(contextID string, target *common.Address, data
244244
if strings.Contains(err.Error(), "nonce too low") {
245245
s.resetNonce(context.Background())
246246
}
247-
return common.Hash{}, fmt.Errorf("failed to send transaction, err: %w", err)
247+
return common.Hash{}, 0, fmt.Errorf("failed to send transaction, err: %w", err)
248248
}
249249

250250
s.transactionSigner.SetNonce(signedTx.Nonce() + 1)
251251

252-
return signedTx.Hash(), nil
252+
return signedTx.Hash(), blobBaseFee, nil
253253
}
254254

255255
func (s *Sender) createTx(feeData *FeeData, target *common.Address, data []byte, sidecar *gethTypes.BlobTxSidecar, nonce uint64) (*gethTypes.Transaction, error) {

rollup/internal/controller/sender/sender_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ func testSendAndRetrieveTransaction(t *testing.T) {
187187
if txBlob[i] != nil {
188188
blobs = []*kzg4844.Blob{txBlob[i]}
189189
}
190-
hash, err := s.SendTransaction("0", &common.Address{}, nil, blobs)
190+
hash, _, err := s.SendTransaction("0", &common.Address{}, nil, blobs)
191191
assert.NoError(t, err)
192192
txs, err := s.pendingTransactionOrm.GetPendingOrReplacedTransactionsBySenderType(context.Background(), s.senderType, 1)
193193
assert.NoError(t, err)
@@ -545,10 +545,10 @@ func testResubmitNonceGappedTransaction(t *testing.T) {
545545
if txBlob[i] != nil {
546546
blobs = []*kzg4844.Blob{txBlob[i]}
547547
}
548-
_, err = s.SendTransaction("test-1", &common.Address{}, nil, blobs)
548+
_, _, err = s.SendTransaction("test-1", &common.Address{}, nil, blobs)
549549
assert.NoError(t, err)
550550

551-
_, err = s.SendTransaction("test-2", &common.Address{}, nil, blobs)
551+
_, _, err = s.SendTransaction("test-2", &common.Address{}, nil, blobs)
552552
assert.NoError(t, err)
553553

554554
s.checkPendingTransaction()
@@ -589,7 +589,7 @@ func testCheckPendingTransactionTxConfirmed(t *testing.T) {
589589
return nil
590590
})
591591

592-
_, err = s.SendTransaction("test", &common.Address{}, nil, randBlobs(1))
592+
_, _, err = s.SendTransaction("test", &common.Address{}, nil, randBlobs(1))
593593
assert.NoError(t, err)
594594

595595
txs, err := s.pendingTransactionOrm.GetPendingOrReplacedTransactionsBySenderType(context.Background(), s.senderType, 1)
@@ -631,7 +631,7 @@ func testCheckPendingTransactionResubmitTxConfirmed(t *testing.T) {
631631
return nil
632632
})
633633

634-
originTxHash, err := s.SendTransaction("test", &common.Address{}, nil, randBlobs(1))
634+
originTxHash, _, err := s.SendTransaction("test", &common.Address{}, nil, randBlobs(1))
635635
assert.NoError(t, err)
636636

637637
txs, err := s.pendingTransactionOrm.GetPendingOrReplacedTransactionsBySenderType(context.Background(), s.senderType, 1)
@@ -691,7 +691,7 @@ func testCheckPendingTransactionReplacedTxConfirmed(t *testing.T) {
691691
return nil
692692
})
693693

694-
txHash, err := s.SendTransaction("test", &common.Address{}, nil, randBlobs(1))
694+
txHash, _, err := s.SendTransaction("test", &common.Address{}, nil, randBlobs(1))
695695
assert.NoError(t, err)
696696

697697
txs, err := s.pendingTransactionOrm.GetPendingOrReplacedTransactionsBySenderType(context.Background(), s.senderType, 1)
@@ -761,7 +761,7 @@ func testCheckPendingTransactionTxMultipleTimesWithOnlyOneTxPending(t *testing.T
761761
return nil
762762
})
763763

764-
_, err = s.SendTransaction("test", &common.Address{}, nil, randBlobs(1))
764+
_, _, err = s.SendTransaction("test", &common.Address{}, nil, randBlobs(1))
765765
assert.NoError(t, err)
766766

767767
txs, err := s.pendingTransactionOrm.GetPendingOrReplacedTransactionsBySenderType(context.Background(), s.senderType, 1)
@@ -835,7 +835,7 @@ func testBlobTransactionWithBlobhashOpContractCall(t *testing.T) {
835835
assert.NoError(t, err)
836836
defer s.Stop()
837837

838-
_, err = s.SendTransaction("0", &testContractsAddress, data, blobs)
838+
_, _, err = s.SendTransaction("0", &testContractsAddress, data, blobs)
839839
assert.NoError(t, err)
840840

841841
var txHash common.Hash
@@ -893,10 +893,10 @@ func testSendBlobCarryingTxOverLimit(t *testing.T) {
893893
assert.NoError(t, err)
894894

895895
for i := 0; i < int(cfgCopy.MaxPendingBlobTxs); i++ {
896-
_, err = s.SendTransaction("0", &common.Address{}, nil, randBlobs(1))
896+
_, _, err = s.SendTransaction("0", &common.Address{}, nil, randBlobs(1))
897897
assert.NoError(t, err)
898898
}
899-
_, err = s.SendTransaction("0", &common.Address{}, nil, randBlobs(1))
899+
_, _, err = s.SendTransaction("0", &common.Address{}, nil, randBlobs(1))
900900
assert.ErrorIs(t, err, ErrTooManyPendingBlobTxs)
901901
s.Stop()
902902
}

0 commit comments

Comments
 (0)