From fd6e8f527fa1ec5db601674feb1dfb090ca3f48e Mon Sep 17 00:00:00 2001 From: irrun Date: Thu, 19 Dec 2024 22:55:32 +0800 Subject: [PATCH 1/3] fix: refetch same idx tx after bundle tx dropped --- miner/worker_builder.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/miner/worker_builder.go b/miner/worker_builder.go index 8a152f8d2c..f054bdaa86 100644 --- a/miner/worker_builder.go +++ b/miner/worker_builder.go @@ -413,13 +413,14 @@ func (w *worker) simulateBundle( ethSentToSystem = new(big.Int) ) - currentState := state.Copy() + txsLen := len(bundle.Txs) + for i := 0; i < txsLen; i++ { + tx := bundle.Txs[i] - for i, tx := range bundle.Txs { state.SetTxContext(tx.Hash(), i+currentTxCount) sysBalanceBefore := state.GetBalance(consensus.SystemAddress) - prevState := currentState.Copy() + prevState := state.Copy() prevGasPool := new(core.GasPool).AddGas(gasPool.Gas()) receipt, err := core.ApplyTransaction(w.chainConfig, w.chain, &w.coinbase, gasPool, state, env.header, tx, @@ -432,6 +433,8 @@ func (w *worker) simulateBundle( state = prevState gasPool = prevGasPool bundle.Txs = bundle.Txs.Remove(i) + txsLen = len(bundle.Txs) + i-- continue } @@ -454,6 +457,8 @@ func (w *worker) simulateBundle( state = prevState gasPool = prevGasPool bundle.Txs = bundle.Txs.Remove(i) + txsLen = len(bundle.Txs) + i-- continue } From 8dbd4d4a4cc4d1363e9b831bc8ae71cfe403d89a Mon Sep 17 00:00:00 2001 From: irrun Date: Fri, 20 Dec 2024 10:49:33 +0800 Subject: [PATCH 2/3] fix: using snapshot instead of state copy --- miner/worker_builder.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/miner/worker_builder.go b/miner/worker_builder.go index f054bdaa86..5dd8030ffd 100644 --- a/miner/worker_builder.go +++ b/miner/worker_builder.go @@ -420,8 +420,8 @@ func (w *worker) simulateBundle( state.SetTxContext(tx.Hash(), i+currentTxCount) sysBalanceBefore := state.GetBalance(consensus.SystemAddress) - prevState := state.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()) @@ -430,8 +430,8 @@ func (w *worker) simulateBundle( 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-- @@ -454,8 +454,8 @@ 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-- From bf073f079207c93896c800172b23bbcb915b8b3e Mon Sep 17 00:00:00 2001 From: irrun Date: Tue, 24 Dec 2024 16:50:38 +0800 Subject: [PATCH 3/3] fix: panic issue --- miner/worker_builder.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/miner/worker_builder.go b/miner/worker_builder.go index 5dd8030ffd..23bd255808 100644 --- a/miner/worker_builder.go +++ b/miner/worker_builder.go @@ -454,8 +454,7 @@ 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.RevertToSnapshot(snap) - gasPool.SetGas(gp) + // do not need to revert the state and gas pool for they are already reverted in ApplyTransaction bundle.Txs = bundle.Txs.Remove(i) txsLen = len(bundle.Txs) i--