forked from cerc-io/laconicd-deprecated
evm: state transitions enabled params (#603)
* changelog * evm: state transitions enabled params * changelog entry * changelog
This commit is contained in:
parent
6f7634138a
commit
ca476d0871
@ -35,6 +35,15 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
|||||||
|
|
||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## Unreleased
|
||||||
|
|
||||||
|
### Improvements
|
||||||
|
|
||||||
|
* (deps) [\#610](https://github.com/cosmos/ethermint/pull/610) Update Go dependency to 1.15+.
|
||||||
|
* (deps) [\#608](https://github.com/cosmos/ethermint/pull/608) Bump Cosmos SDK version to [v0.39.2](https://github.com/cosmos/cosmos-sdk/tag/v0.39.2)
|
||||||
|
* (evm) [#603](https://github.com/cosmos/ethermint/pull/603) Add state transition params that enable or disable the EVM `Call` and `Create` operations.
|
||||||
|
* (deps) [\#602](https://github.com/cosmos/ethermint/pull/602) Bump tendermint version to [v0.33.9](https://github.com/tendermint/tendermint/releases/tag/v0.33.9)
|
||||||
|
|
||||||
## [v0.3.0] - 2020-11-16
|
## [v0.3.0] - 2020-11-16
|
||||||
|
|
||||||
### API Breaking
|
### API Breaking
|
||||||
|
@ -15,4 +15,10 @@ var (
|
|||||||
|
|
||||||
// ErrInvalidChainConfig returns an error resulting from an invalid ChainConfig.
|
// ErrInvalidChainConfig returns an error resulting from an invalid ChainConfig.
|
||||||
ErrInvalidChainConfig = sdkerrors.Register(ModuleName, 4, "invalid chain configuration")
|
ErrInvalidChainConfig = sdkerrors.Register(ModuleName, 4, "invalid chain configuration")
|
||||||
|
|
||||||
|
// ErrCreateDisabled returns an error if the EnableCreate parameter is false.
|
||||||
|
ErrCreateDisabled = sdkerrors.Register(ModuleName, 5, "EVM Create operation is disabled")
|
||||||
|
|
||||||
|
// ErrCallDisabled returns an error if the EnableCall parameter is false.
|
||||||
|
ErrCallDisabled = sdkerrors.Register(ModuleName, 6, "EVM Call operation is disabled")
|
||||||
)
|
)
|
||||||
|
@ -19,6 +19,8 @@ const (
|
|||||||
// Parameter keys
|
// Parameter keys
|
||||||
var (
|
var (
|
||||||
ParamStoreKeyEVMDenom = []byte("EVMDenom")
|
ParamStoreKeyEVMDenom = []byte("EVMDenom")
|
||||||
|
ParamStoreKeyEnableCreate = []byte("EnableCreate")
|
||||||
|
ParamStoreKeyEnableCall = []byte("EnableCall")
|
||||||
)
|
)
|
||||||
|
|
||||||
// ParamKeyTable returns the parameter key table.
|
// ParamKeyTable returns the parameter key table.
|
||||||
@ -28,13 +30,21 @@ func ParamKeyTable() params.KeyTable {
|
|||||||
|
|
||||||
// Params defines the EVM module parameters
|
// Params defines the EVM module parameters
|
||||||
type Params struct {
|
type Params struct {
|
||||||
|
// EVMDenom defines the token denomination used for state transitions on the
|
||||||
|
// EVM module.
|
||||||
EvmDenom string `json:"evm_denom" yaml:"evm_denom"`
|
EvmDenom string `json:"evm_denom" yaml:"evm_denom"`
|
||||||
|
// EnableCreate toggles state transitions that use the vm.Create function
|
||||||
|
EnableCreate bool `json:"enable_create" yaml:"enable_create"`
|
||||||
|
// EnableCall toggles state transitions that use the vm.Call function
|
||||||
|
EnableCall bool `json:"enable_call" yaml:"enable_call"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewParams creates a new Params instance
|
// NewParams creates a new Params instance
|
||||||
func NewParams(evmDenom string) Params {
|
func NewParams(evmDenom string, enableCreate, enableCall bool) Params {
|
||||||
return Params{
|
return Params{
|
||||||
EvmDenom: evmDenom,
|
EvmDenom: evmDenom,
|
||||||
|
EnableCreate: enableCreate,
|
||||||
|
EnableCall: enableCall,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,6 +52,8 @@ func NewParams(evmDenom string) Params {
|
|||||||
func DefaultParams() Params {
|
func DefaultParams() Params {
|
||||||
return Params{
|
return Params{
|
||||||
EvmDenom: ethermint.AttoPhoton,
|
EvmDenom: ethermint.AttoPhoton,
|
||||||
|
EnableCreate: true,
|
||||||
|
EnableCall: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,6 +67,8 @@ func (p Params) String() string {
|
|||||||
func (p *Params) ParamSetPairs() params.ParamSetPairs {
|
func (p *Params) ParamSetPairs() params.ParamSetPairs {
|
||||||
return params.ParamSetPairs{
|
return params.ParamSetPairs{
|
||||||
params.NewParamSetPair(ParamStoreKeyEVMDenom, &p.EvmDenom, validateEVMDenom),
|
params.NewParamSetPair(ParamStoreKeyEVMDenom, &p.EvmDenom, validateEVMDenom),
|
||||||
|
params.NewParamSetPair(ParamStoreKeyEnableCreate, &p.EnableCreate, validateBool),
|
||||||
|
params.NewParamSetPair(ParamStoreKeyEnableCall, &p.EnableCall, validateBool),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,8 +80,16 @@ func (p Params) Validate() error {
|
|||||||
func validateEVMDenom(i interface{}) error {
|
func validateEVMDenom(i interface{}) error {
|
||||||
denom, ok := i.(string)
|
denom, ok := i.(string)
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("invalid parameter type: %T", i)
|
return fmt.Errorf("invalid parameter EVM denom type: %T", i)
|
||||||
}
|
}
|
||||||
|
|
||||||
return sdk.ValidateDenom(denom)
|
return sdk.ValidateDenom(denom)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func validateBool(i interface{}) error {
|
||||||
|
_, ok := i.(bool)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("invalid parameter type: %T", i)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@ -15,7 +15,7 @@ func TestParamsValidate(t *testing.T) {
|
|||||||
{"default", DefaultParams(), false},
|
{"default", DefaultParams(), false},
|
||||||
{
|
{
|
||||||
"valid",
|
"valid",
|
||||||
NewParams("ara"),
|
NewParams("ara", true, true),
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -45,8 +45,11 @@ func TestParamsValidate(t *testing.T) {
|
|||||||
|
|
||||||
func TestParamsValidatePriv(t *testing.T) {
|
func TestParamsValidatePriv(t *testing.T) {
|
||||||
require.Error(t, validateEVMDenom(false))
|
require.Error(t, validateEVMDenom(false))
|
||||||
|
require.NoError(t, validateEVMDenom("aphoton"))
|
||||||
|
require.Error(t, validateBool(""))
|
||||||
|
require.NoError(t, validateBool(true))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParams_String(t *testing.T) {
|
func TestParams_String(t *testing.T) {
|
||||||
require.Equal(t, "evm_denom: aphoton\n", DefaultParams().String())
|
require.Equal(t, "evm_denom: aphoton\nenable_create: true\nenable_call: true\n", DefaultParams().String())
|
||||||
}
|
}
|
||||||
|
@ -101,8 +101,9 @@ func (st StateTransition) TransitionDb(ctx sdk.Context, config ChainConfig) (*Ex
|
|||||||
// Clear cache of accounts to handle changes outside of the EVM
|
// Clear cache of accounts to handle changes outside of the EVM
|
||||||
csdb.UpdateAccounts()
|
csdb.UpdateAccounts()
|
||||||
|
|
||||||
evmDenom := csdb.GetParams().EvmDenom
|
params := csdb.GetParams()
|
||||||
gasPrice := ctx.MinGasPrices().AmountOf(evmDenom)
|
|
||||||
|
gasPrice := ctx.MinGasPrices().AmountOf(params.EvmDenom)
|
||||||
if gasPrice.IsNil() {
|
if gasPrice.IsNil() {
|
||||||
return nil, errors.New("gas price cannot be nil")
|
return nil, errors.New("gas price cannot be nil")
|
||||||
}
|
}
|
||||||
@ -125,9 +126,17 @@ func (st StateTransition) TransitionDb(ctx sdk.Context, config ChainConfig) (*Ex
|
|||||||
// create contract or execute call
|
// create contract or execute call
|
||||||
switch contractCreation {
|
switch contractCreation {
|
||||||
case true:
|
case true:
|
||||||
|
if !params.EnableCreate {
|
||||||
|
return nil, ErrCreateDisabled
|
||||||
|
}
|
||||||
|
|
||||||
ret, contractAddress, leftOverGas, err = evm.Create(senderRef, st.Payload, gasLimit, st.Amount)
|
ret, contractAddress, leftOverGas, err = evm.Create(senderRef, st.Payload, gasLimit, st.Amount)
|
||||||
recipientLog = fmt.Sprintf("contract address %s", contractAddress.String())
|
recipientLog = fmt.Sprintf("contract address %s", contractAddress.String())
|
||||||
default:
|
default:
|
||||||
|
if !params.EnableCall {
|
||||||
|
return nil, ErrCreateDisabled
|
||||||
|
}
|
||||||
|
|
||||||
// Increment the nonce for the next transaction (just for evm state transition)
|
// Increment the nonce for the next transaction (just for evm state transition)
|
||||||
csdb.SetNonce(st.Sender, csdb.GetNonce(st.Sender)+1)
|
csdb.SetNonce(st.Sender, csdb.GetNonce(st.Sender)+1)
|
||||||
ret, leftOverGas, err = evm.Call(senderRef, *st.Recipient, st.Payload, gasLimit, st.Amount)
|
ret, leftOverGas, err = evm.Call(senderRef, *st.Recipient, st.Payload, gasLimit, st.Amount)
|
||||||
|
Loading…
Reference in New Issue
Block a user