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

Fail early on StateDB functions #566

Merged
merged 11 commits into from
Sep 17, 2021
Merged
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