From 817b842f20cf980a844eba97da7460ac33d2f62e Mon Sep 17 00:00:00 2001 From: WorldDogs <33647825+WorldDogs@users.noreply.github.com> Date: Mon, 9 Dec 2024 10:44:23 +0800 Subject: [PATCH 1/2] feat(tx-submitter): optimize rollup transaction processing - Add logic to handle committed batches and remove them from the local pool - Implement turn-based transaction processing for submitters - Enhance the transaction query process to check for already committed batches --- tx-submitter/services/rollup.go | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/tx-submitter/services/rollup.go b/tx-submitter/services/rollup.go index 2ca77a03..ce5b091c 100644 --- a/tx-submitter/services/rollup.go +++ b/tx-submitter/services/rollup.go @@ -221,6 +221,8 @@ func (r *Rollup) Start() error { func (r *Rollup) ProcessTx() error { + // case 0: batch has committed + // -> remove from local pool // case 1: in mempool // -> check timeout // case 2: no in mempool @@ -229,6 +231,15 @@ func (r *Rollup) ProcessTx() error { // case 2.3: tx included -> failed // -> reset index to failed index + // if this submitter work + cur, err := r.rotator.CurrentSubmitter(r.L2Clients, r.Staking) + if err != nil { + return fmt.Errorf("rollup: get current submitter err, %w", err) + } + if cur.Hex() != r.WalletAddr().Hex() { + log.Info("wait my turn to process tx") + return nil + } // get all local txs txRecords := r.pendingTxs.GetAll() if len(txRecords) == 0 { @@ -237,9 +248,27 @@ func (r *Rollup) ProcessTx() error { // query tx status for _, txRecord := range txRecords { - + // parse tx rtx := txRecord.tx method := utils.ParseMethod(rtx, r.abi) + if method == "commitBatch" { + // get latest rolluped batch index + cindexBig, err := r.Rollup.LastCommittedBatchIndex(nil) + if err != nil { + return fmt.Errorf("get last committed batch index error:%v", err) + } + batchIndex := utils.ParseBatchIndex(method, rtx.Data()) + if batchIndex <= cindexBig.Uint64() { + log.Info("batch has committed remove batch tx from local pool", + "cur_batch_index", batchIndex, + "latest_committed_batch_index", cindexBig, + ) + r.pendingTxs.Remove(rtx.Hash()) + continue + } + + } + log.Info("process tx", "hash", rtx.Hash().String(), "nonce", rtx.Nonce(), "method", method) // query tx _, ispending, err := r.L1Client.TransactionByHash(context.Background(), txRecord.tx.Hash()) From 5da995de0d2885f3020f3c8f4967ab219d2458f2 Mon Sep 17 00:00:00 2001 From: WorldDogs <33647825+WorldDogs@users.noreply.github.com> Date: Wed, 18 Dec 2024 16:07:20 +0800 Subject: [PATCH 2/2] fix(tx-submitter): Replace `utils.ParseBatchIndex` with `utils.ParseParentBatchIndex` to parse batchindex in batchheader --- tx-submitter/services/rollup.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tx-submitter/services/rollup.go b/tx-submitter/services/rollup.go index 46514adb..96e9c78a 100644 --- a/tx-submitter/services/rollup.go +++ b/tx-submitter/services/rollup.go @@ -261,7 +261,7 @@ func (r *Rollup) ProcessTx() error { if err != nil { return fmt.Errorf("get last committed batch index error:%v", err) } - batchIndex := utils.ParseBatchIndex(method, rtx.Data()) + batchIndex := utils.ParseParentBatchIndex(rtx.Data()) if batchIndex <= cindexBig.Uint64() { log.Info("batch has committed remove batch tx from local pool", "cur_batch_index", batchIndex,