From 4b28f3289943f4b45c32963f57df8b0865cd18e3 Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Fri, 24 Sep 2021 04:50:39 +0000 Subject: [PATCH] BlockState.AddTransactions: fix revert in the case where tx is the first in the sequence --- miner/collator.go | 7 ++++++- miner/worker.go | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/miner/collator.go b/miner/collator.go index 5514b5086448b..6d9b3283d0b4b 100644 --- a/miner/collator.go +++ b/miner/collator.go @@ -320,7 +320,12 @@ func (bs *collatorBlockState) AddTransactions(txs types.Transactions) (error, ty if retErr != nil { bs.logs = bs.logs[:len(bs.logs)-tcount] - bs.state.RevertToSnapshot(bs.snapshots[len(bs.snapshots)-(tcount+1)]) + if tcount != 0 { + // first transaction in the sequence failed so the state will already be reverted + // to what it was before the sequence was applied + bs.state.RevertToSnapshot(bs.snapshots[len(bs.snapshots)-(tcount+1)]) + } + bs.snapshots = bs.snapshots[:len(bs.snapshots)-(tcount+1)] return retErr, nil diff --git a/miner/worker.go b/miner/worker.go index d3151b3ea9b7f..337bc731f6712 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -609,7 +609,7 @@ func (w *worker) makeEnv(parent *types.Block, header *types.Header, coinbase com state: state, gasPool: new(core.GasPool).AddGas(header.GasLimit), tcount: 0, - snapshots: []int{state.Snapshot()}, + snapshots: []int{}, } ctx, cancel := context.WithCancel(context.Background())