Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: using snapshot instead of state copy #61

Merged
merged 3 commits into from
Dec 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions miner/worker_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,14 +413,15 @@ 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()
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())
Expand All @@ -429,9 +430,11 @@ 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--
continue
}

Expand All @@ -451,9 +454,10 @@ 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
// do not need to revert the state and gas pool for they are already reverted in ApplyTransaction

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"// do not need to revert the state and gas pool for they are already reverted in ApplyTransaction" I did not find that

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bundle.Txs = bundle.Txs.Remove(i)
txsLen = len(bundle.Txs)
i--
continue
}

Expand Down
Loading