Skip to content

Commit

Permalink
Enusre pending state is ready for tx execution
Browse files Browse the repository at this point in the history
This commit ensures that StateDB.Prepare is called on the pending state
before it is returned from the miner/worker. This prevents access logs
from previous transaction executions from interfering with the gas cost
calculations of the subsequently executed transaction.

The problem this solves was introdued by this upstream PR
ethereum/go-ethereum#21509 which added an
access list to the state which was used to reduce gas costs for repeated
access of the same state locations, this resulted in the pending block
having the access list of the last executed transaction, which could
cause gas estimates to be wrong when the estimated transaction accessed
some of the same state as the prior transaction.
  • Loading branch information
piersy committed Feb 28, 2022
1 parent 503f156 commit ebb3e7c
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,12 @@ func (w *worker) pending() (*types.Block, *state.StateDB) {
if w.snapshotState == nil {
return nil, nil
}
return w.snapshotBlock, w.snapshotState.Copy()
stateCopy := w.snapshotState.Copy()
// Call Prepare to ensure that any access logs from the last executed
// transaction have been erased.
// See https://github.com/celo-org/celo-blockchain/pull/1858#issuecomment-1054159493
stateCopy.Prepare(common.Hash{}, 0)
return w.snapshotBlock, stateCopy
}

// pendingBlock returns pending block.
Expand Down

0 comments on commit ebb3e7c

Please sign in to comment.