feat(miner): count last oversized transaction (#273)

This commit is contained in:
David 2024-06-12 22:06:10 +07:00 committed by GitHub
parent 89b3fdd74c
commit 451a668d79
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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.