Skip to content

Commit

Permalink
fix: nil map in bundlepool and refine code
Browse files Browse the repository at this point in the history
  • Loading branch information
Lredhdx committed Dec 20, 2024
1 parent 5bd2b5a commit 6bbc128
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions miner/worker_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,23 +366,25 @@ func (w *worker) simulateBundle(
bundleGasFees = new(big.Int)
)

currentState := state.Copy()

for i, tx := range bundle.Txs {
txsLen := len(bundle.Txs)
for i := 0; i < txsLen; i++ {
tx := bundle.Txs[i]
state.SetTxContext(tx.Hash(), i+currentTxCount)

prevState := currentState.Copy()
prevGasPool := new(core.GasPool).AddGas(gasPool.Gas())
snap := state.Snapshot()
gp := gasPool.Gas()

receipt, err := core.ApplyTransaction(w.chainConfig, w.chain, &w.coinbase, gasPool, state, env.header, tx,
&tempGasUsed, *w.chain.GetVMConfig())
if err != nil {
log.Warn("fail to simulate bundle", "hash", bundle.Hash().String(), "err", err)
if containsHash(bundle.DroppingTxHashes, tx.Hash()) {
log.Warn("drop tx in bundle", "hash", tx.Hash().String())
state = prevState
gasPool = prevGasPool
state.RevertToSnapshot(snap)
gasPool.SetGas(gp)
bundle.Txs = bundle.Txs.Remove(i)
txsLen = len(bundle.Txs)
i--
continue
}

Expand All @@ -402,9 +404,11 @@ func (w *worker) simulateBundle(
// for unRevertible tx but itself can be dropped, we drop it and revert the state and gas pool
if containsHash(bundle.DroppingTxHashes, receipt.TxHash) {
log.Warn("drop tx in bundle", "hash", receipt.TxHash.String())
state = prevState
gasPool = prevGasPool
state.RevertToSnapshot(snap)
gasPool.SetGas(gp)
bundle.Txs = bundle.Txs.Remove(i)
txsLen = len(bundle.Txs)
i--
continue
}
err = errNonRevertingTxInBundleFailed
Expand Down

0 comments on commit 6bbc128

Please sign in to comment.