From 361f3ad561c016c1eddd1d287b863ca0be32644b Mon Sep 17 00:00:00 2001 From: David Date: Wed, 12 Jun 2024 22:06:10 +0700 Subject: [PATCH] feat(miner): count last oversized transaction (#273) --- miner/taiko_worker.go | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/miner/taiko_worker.go b/miner/taiko_worker.go index 3e17abd0970b..872fb49ba8ad 100644 --- a/miner/taiko_worker.go +++ b/miner/taiko_worker.go @@ -72,7 +72,7 @@ func (w *worker) BuildTransactionsLists( localTxs, remoteTxs = w.getPendingTxs(localAccounts, baseFee) ) - commitTxs := func() (*PreBuiltTxList, error) { + commitTxs := func(firstTransaction *types.Transaction) (*types.Transaction, *PreBuiltTxList, error) { env.tcount = 0 env.txs = []*types.Transaction{} env.gasPool = new(core.GasPool).AddGas(blockMaxGasLimit) @@ -90,8 +90,9 @@ func (w *worker) BuildTransactionsLists( remotes[address] = txs } - w.commitL2Transactions( + lastTransaction := w.commitL2Transactions( env, + firstTransaction, newTransactionsByPriceAndNonce(signer, locals, baseFee), newTransactionsByPriceAndNonce(signer, remotes, baseFee), maxBytesPerTxList, @@ -99,19 +100,22 @@ func (w *worker) BuildTransactionsLists( b, err := encodeAndComporeessTxList(env.txs) if err != nil { - return nil, err + return nil, nil, err } - return &PreBuiltTxList{ + return lastTransaction, &PreBuiltTxList{ TxList: env.txs, EstimatedGasUsed: env.header.GasLimit - env.gasPool.Gas(), BytesLength: uint64(len(b)), }, nil } + var ( + lastTx *types.Transaction + res *PreBuiltTxList + ) for i := 0; i < int(maxTransactionsLists); i++ { - res, err := commitTxs() - if err != nil { + if lastTx, res, err = commitTxs(lastTx); err != nil { return nil, err } @@ -230,15 +234,21 @@ func (w *worker) getPendingTxs(localAccounts []string, baseFee *big.Int) ( // commitL2Transactions tries to commit the transactions into the given state. func (w *worker) commitL2Transactions( env *environment, + firstTransaction *types.Transaction, txsLocal *transactionsByPriceAndNonce, txsRemote *transactionsByPriceAndNonce, maxBytesPerTxList uint64, -) { +) *types.Transaction { var ( - txs = txsLocal - isLocal = true + txs = txsLocal + isLocal = true + lastTransaction *types.Transaction ) + if firstTransaction != nil { + env.txs = append(env.txs, firstTransaction) + } + for { // If we don't have enough gas for any further transactions then we're done. if env.gasPool.Gas() < params.TxGas { @@ -319,10 +329,13 @@ func (w *worker) commitL2Transactions( continue } if len(b) > int(maxBytesPerTxList) { + lastTransaction = env.txs[env.tcount-1] env.txs = env.txs[0 : env.tcount-1] break } } + + return lastTransaction } // encodeAndComporeessTxList encodes and compresses the given transactions list.