Skip to content

Commit

Permalink
BlockState.AddTransactions: fix revert in the case where tx is the fi…
Browse files Browse the repository at this point in the history
…rst in the sequence
  • Loading branch information
jwasinger committed Sep 24, 2021
1 parent 59c3bb9 commit 4b28f32
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion miner/collator.go
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion miner/worker.go
Expand Up @@ -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())
Expand Down

0 comments on commit 4b28f32

Please sign in to comment.