Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Commit

Permalink
evm: fail early on StateDB functions (#566)
Browse files Browse the repository at this point in the history
* ADD stateErr on keeper

* UPDATE init stateErr

* UPDATE test case

* Update x/evm/keeper/statedb.go

Co-authored-by: Federico Kunze Küllmer <[email protected]>

* ADD comment

* UPDATE clear evm state error

* REMOVE unnecessary clear

* ADD comment

* UPDATE false value

Co-authored-by: Federico Kunze Küllmer <[email protected]>
  • Loading branch information
davcrypto and fedekunze authored Sep 17, 2021
1 parent d4db62a commit 742b6d1
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Improvements

* (evm) [tharsis#461](https://github.com/tharsis/ethermint/pull/461) Increase performance of `StateDB` transaction log storage (r/w).
* (evm) [tharsis#566](https://github.com/tharsis/ethermint/pull/566) Introduce `stateErr` store in `StateDB` to avoid meaningless operations if any error happened before

## [v0.5.0] - 2021-08-20

Expand Down
4 changes: 4 additions & 0 deletions x/evm/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ type Keeper struct {

// EVM Hooks for tx post-processing
hooks types.EvmHooks

// error from previous state operation
stateErr error
}

// NewKeeper generates new evm module keeper
Expand Down Expand Up @@ -87,6 +90,7 @@ func NewKeeper(
transientKey: transientKey,
tracer: tracer,
debug: debug,
stateErr: nil,
}
}

Expand Down
6 changes: 6 additions & 0 deletions x/evm/keeper/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ func (k *Keeper) ApplyTransaction(tx *ethtypes.Transaction) (*types.MsgEthereumT
ctx := k.Ctx()
params := k.GetParams(ctx)

// ensure keeper state error is cleared
defer k.ClearStateError()

// return error if contract creation or call are disabled through governance
if !params.EnableCreate && tx.To() == nil {
return nil, stacktrace.Propagate(types.ErrCreateDisabled, "failed to create new contract")
Expand Down Expand Up @@ -248,6 +251,9 @@ func (k *Keeper) ApplyMessage(evm *vm.EVM, msg core.Message, cfg *params.ChainCo
vmErr error // vm errors do not effect consensus and are therefore not assigned to err
)

// ensure keeper state error is cleared
defer k.ClearStateError()

sender := vm.AccountRef(msg.From())
contractCreation := msg.To() == nil

Expand Down
Loading

0 comments on commit 742b6d1

Please sign in to comment.