Skip to content

Commit

Permalink
feat(miner): count last oversized transaction (#273)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaikocha authored Jun 12, 2024
1 parent 89b3fdd commit 451a668
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions miner/taiko_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -90,28 +90,32 @@ func (w *worker) BuildTransactionsLists(
remotes[address] = txs
}

w.commitL2Transactions(
lastTransaction := w.commitL2Transactions(
env,
firstTransaction,
newTransactionsByPriceAndNonce(signer, locals, baseFee),
newTransactionsByPriceAndNonce(signer, remotes, baseFee),
maxBytesPerTxList,
)

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
}

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

0 comments on commit 451a668

Please sign in to comment.