Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tx-submitter): optimize rollup transaction processing #680

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion tx-submitter/services/rollup.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,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
Expand All @@ -233,6 +235,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 {
Expand All @@ -241,9 +252,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.ParseParentBatchIndex(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())
Expand Down
Loading