Skip to content

Commit

Permalink
update miner/worker.go
Browse files Browse the repository at this point in the history
  • Loading branch information
0xmountaintop committed Nov 28, 2023
1 parent 4b9173b commit 0ff0275
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 0ff0275

Please sign in to comment.