Skip to content

Commit

Permalink
Remove ReadOnlyStateDB, use snapshot+revert
Browse files Browse the repository at this point in the history
I has been stated that StaticCall can do modifications to the state in
multiple places in the geth code base. Therefore, we first did a copy of
the state to avoid changes and later switched to used the
ReadOnlyStateDB to achieve the same result with better performance.

Upon closer examination, the only state change that StaticCall actually
does is "touching" the called address, which only makes a difference on
legacy Ethereum chains, and tracking the access list. This can be
avoided by doing a snapshot+revert. The performance impact should be
low, since the revert only has to undo the access list change.

With the removal of ReadOnlyStateDB, further testing of it is pointless:
Closes celo-org/celo-blockchain-planning#355
  • Loading branch information
karlb committed Aug 12, 2024
1 parent 57b63f8 commit 15f3961
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 133 deletions.
8 changes: 6 additions & 2 deletions contracts/celo_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,13 @@ func (b *CeloBackend) CallContract(ctx context.Context, call ethereum.CallMsg, b
txCtx := vm.TxContext{}
vmConfig := vm.Config{}

readOnlyStateDB := ReadOnlyStateDB{StateDB: b.State}
evm := vm.NewEVM(blockCtx, txCtx, &readOnlyStateDB, b.ChainConfig, vmConfig)
// While StaticCall does not actually change state, it changes the
// access lists. We don't want this to add any access list changes, so
// we do a snapshot+revert.
snapshot := b.State.Snapshot()
evm := vm.NewEVM(blockCtx, txCtx, b.State, b.ChainConfig, vmConfig)
ret, _, err := evm.StaticCall(vm.AccountRef(evm.Origin), *call.To, call.Data, call.Gas)
b.State.RevertToSnapshot(snapshot)

return ret, err
}
Expand Down
131 changes: 0 additions & 131 deletions contracts/read_only_statedb.go

This file was deleted.

0 comments on commit 15f3961

Please sign in to comment.