mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-10 05:53:46 +00:00
feat(miner): count last oversized transaction (#273)
This commit is contained in:
parent
89b3fdd74c
commit
451a668d79
1 changed files with 22 additions and 9 deletions
|
|
@ -72,7 +72,7 @@ func (w *worker) BuildTransactionsLists(
|
||||||
localTxs, remoteTxs = w.getPendingTxs(localAccounts, baseFee)
|
localTxs, remoteTxs = w.getPendingTxs(localAccounts, baseFee)
|
||||||
)
|
)
|
||||||
|
|
||||||
commitTxs := func() (*PreBuiltTxList, error) {
|
commitTxs := func(firstTransaction *types.Transaction) (*types.Transaction, *PreBuiltTxList, error) {
|
||||||
env.tcount = 0
|
env.tcount = 0
|
||||||
env.txs = []*types.Transaction{}
|
env.txs = []*types.Transaction{}
|
||||||
env.gasPool = new(core.GasPool).AddGas(blockMaxGasLimit)
|
env.gasPool = new(core.GasPool).AddGas(blockMaxGasLimit)
|
||||||
|
|
@ -90,8 +90,9 @@ func (w *worker) BuildTransactionsLists(
|
||||||
remotes[address] = txs
|
remotes[address] = txs
|
||||||
}
|
}
|
||||||
|
|
||||||
w.commitL2Transactions(
|
lastTransaction := w.commitL2Transactions(
|
||||||
env,
|
env,
|
||||||
|
firstTransaction,
|
||||||
newTransactionsByPriceAndNonce(signer, locals, baseFee),
|
newTransactionsByPriceAndNonce(signer, locals, baseFee),
|
||||||
newTransactionsByPriceAndNonce(signer, remotes, baseFee),
|
newTransactionsByPriceAndNonce(signer, remotes, baseFee),
|
||||||
maxBytesPerTxList,
|
maxBytesPerTxList,
|
||||||
|
|
@ -99,19 +100,22 @@ func (w *worker) BuildTransactionsLists(
|
||||||
|
|
||||||
b, err := encodeAndComporeessTxList(env.txs)
|
b, err := encodeAndComporeessTxList(env.txs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &PreBuiltTxList{
|
return lastTransaction, &PreBuiltTxList{
|
||||||
TxList: env.txs,
|
TxList: env.txs,
|
||||||
EstimatedGasUsed: env.header.GasLimit - env.gasPool.Gas(),
|
EstimatedGasUsed: env.header.GasLimit - env.gasPool.Gas(),
|
||||||
BytesLength: uint64(len(b)),
|
BytesLength: uint64(len(b)),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
lastTx *types.Transaction
|
||||||
|
res *PreBuiltTxList
|
||||||
|
)
|
||||||
for i := 0; i < int(maxTransactionsLists); i++ {
|
for i := 0; i < int(maxTransactionsLists); i++ {
|
||||||
res, err := commitTxs()
|
if lastTx, res, err = commitTxs(lastTx); err != nil {
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
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.
|
// commitL2Transactions tries to commit the transactions into the given state.
|
||||||
func (w *worker) commitL2Transactions(
|
func (w *worker) commitL2Transactions(
|
||||||
env *environment,
|
env *environment,
|
||||||
|
firstTransaction *types.Transaction,
|
||||||
txsLocal *transactionsByPriceAndNonce,
|
txsLocal *transactionsByPriceAndNonce,
|
||||||
txsRemote *transactionsByPriceAndNonce,
|
txsRemote *transactionsByPriceAndNonce,
|
||||||
maxBytesPerTxList uint64,
|
maxBytesPerTxList uint64,
|
||||||
) {
|
) *types.Transaction {
|
||||||
var (
|
var (
|
||||||
txs = txsLocal
|
txs = txsLocal
|
||||||
isLocal = true
|
isLocal = true
|
||||||
|
lastTransaction *types.Transaction
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if firstTransaction != nil {
|
||||||
|
env.txs = append(env.txs, firstTransaction)
|
||||||
|
}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
// If we don't have enough gas for any further transactions then we're done.
|
// If we don't have enough gas for any further transactions then we're done.
|
||||||
if env.gasPool.Gas() < params.TxGas {
|
if env.gasPool.Gas() < params.TxGas {
|
||||||
|
|
@ -319,10 +329,13 @@ func (w *worker) commitL2Transactions(
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if len(b) > int(maxBytesPerTxList) {
|
if len(b) > int(maxBytesPerTxList) {
|
||||||
|
lastTransaction = env.txs[env.tcount-1]
|
||||||
env.txs = env.txs[0 : env.tcount-1]
|
env.txs = env.txs[0 : env.tcount-1]
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return lastTransaction
|
||||||
}
|
}
|
||||||
|
|
||||||
// encodeAndComporeessTxList encodes and compresses the given transactions list.
|
// encodeAndComporeessTxList encodes and compresses the given transactions list.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue