From 0ff027550316b083cd9ffda0d989417a6c82ad1d Mon Sep 17 00:00:00 2001 From: HAOYUatHZ Date: Tue, 28 Nov 2023 11:51:16 +0800 Subject: [PATCH] update miner/worker.go --- miner/worker.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/miner/worker.go b/miner/worker.go index f68070281454..7bfb2456babb 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -85,6 +85,7 @@ type environment struct { signer types.Signer state *state.StateDB // apply state changes here tcount int // tx count in cycle + blockSize uint64 // approximate size of tx payload in bytes gasPool *core.GasPool // available gas used to pack transactions coinbase common.Address @@ -722,6 +723,7 @@ func (w *worker) makeEnv(parent *types.Header, header *types.Header, coinbase co } // Keep track of transactions which return errors so they can be removed env.tcount = 0 + env.blockSize = 0 return env, nil } @@ -834,6 +836,17 @@ func (w *worker) commitTransactions(env *environment, txs *transactionsByPriceAn txs.Pop() continue } + // If we have collected enough transactions then we're done + // Originally we only limit l2txs count, but now strictly limit total txs number. + if !w.chainConfig.Scroll.IsValidTxCount(w.current.tcount + 1) { + log.Trace("Transaction count limit reached", "have", w.current.tcount, "want", w.chainConfig.Scroll.MaxTxPerBlock) + break + } + if !tx.IsL1MessageTx() && !w.chainConfig.Scroll.IsValidBlockSize(w.current.blockSize+tx.Size()) { + log.Trace("Block size limit reached", "have", w.current.blockSize, "want", w.chainConfig.Scroll.MaxTxPayloadBytesPerBlock, "tx", tx.Size()) + txs.Pop() // skip transactions from this account + continue + } // Error may be ignored here. The error has already been checked // during transaction acceptance is the transaction pool. from, _ := types.Sender(env.signer, tx) @@ -861,6 +874,12 @@ func (w *worker) commitTransactions(env *environment, txs *transactionsByPriceAn env.tcount++ txs.Shift() + if tx.IsL1MessageTx() { + } else { + // only consider block size limit for L2 transactions + w.current.blockSize += tx.Size() + } + default: // Transaction is regarded as invalid, drop all consecutive transactions from // the same sender because of `nonce-too-high` clause.