diff --git a/rpc/backend/backend.go b/rpc/backend/backend.go index 340524cd..e8444ee6 100644 --- a/rpc/backend/backend.go +++ b/rpc/backend/backend.go @@ -49,6 +49,7 @@ type EVMBackend interface { Accounts() ([]common.Address, error) Syncing() (interface{}, error) SetEtherbase(etherbase common.Address) bool + SetGasPrice(gasPrice hexutil.Big) bool ImportRawKey(privkey, password string) (common.Address, error) ListAccounts() ([]common.Address, error) NewMnemonic(uid string, language keyring.Language, hdPath, bip39Passphrase string, algo keyring.SignatureAlgo) (*keyring.Record, error) diff --git a/rpc/backend/node_info.go b/rpc/backend/node_info.go index 0cc42d85..abc2cb1b 100644 --- a/rpc/backend/node_info.go +++ b/rpc/backend/node_info.go @@ -10,6 +10,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/tx" sdkcrypto "github.com/cosmos/cosmos-sdk/crypto" "github.com/cosmos/cosmos-sdk/crypto/keyring" + sdkconfig "github.com/cosmos/cosmos-sdk/server/config" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" authtx "github.com/cosmos/cosmos-sdk/x/auth/tx" @@ -19,6 +20,7 @@ import ( "github.com/ethereum/go-ethereum/crypto" "github.com/evmos/ethermint/crypto/ethsecp256k1" rpctypes "github.com/evmos/ethermint/rpc/types" + "github.com/evmos/ethermint/server/config" ethermint "github.com/evmos/ethermint/types" evmtypes "github.com/evmos/ethermint/x/evm/types" tmtypes "github.com/tendermint/tendermint/types" @@ -239,6 +241,35 @@ func (b *Backend) NewMnemonic(uid string, language keyring.Language, hdPath, bip return info, err } +// SetGasPrice sets the minimum accepted gas price for the miner. +// NOTE: this function accepts only integers to have the same interface than go-eth +// to use float values, the gas prices must be configured using the configuration file +func (b *Backend) SetGasPrice(gasPrice hexutil.Big) bool { + appConf := config.GetConfig(b.clientCtx.Viper) + + var unit string + minGasPrices := appConf.GetMinGasPrices() + + // fetch the base denom from the sdk Config in case it's not currently defined on the node config + if len(minGasPrices) == 0 || minGasPrices.Empty() { + var err error + unit, err = sdk.GetBaseDenom() + if err != nil { + b.logger.Debug("could not get the denom of smallest unit registered", "error", err.Error()) + return false + } + } else { + unit = minGasPrices[0].Denom + } + + c := sdk.NewDecCoin(unit, sdk.NewIntFromBigInt(gasPrice.ToInt())) + + appConf.SetMinGasPrices(sdk.DecCoins{c}) + sdkconfig.WriteConfigFile(b.clientCtx.Viper.ConfigFileUsed(), appConf) + b.logger.Info("Your configuration file was modified. Please RESTART your node.", "gas-price", c.String()) + return true +} + // UnprotectedAllowed returns the node configuration value for allowing // unprotected transactions (i.e not replay-protected) func (b Backend) UnprotectedAllowed() bool { diff --git a/rpc/namespaces/ethereum/miner/api.go b/rpc/namespaces/ethereum/miner/api.go index 98313b3b..23f68860 100644 --- a/rpc/namespaces/ethereum/miner/api.go +++ b/rpc/namespaces/ethereum/miner/api.go @@ -4,6 +4,7 @@ import ( "github.com/cosmos/cosmos-sdk/server" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common/hexutil" "github.com/tendermint/tendermint/libs/log" @@ -34,3 +35,9 @@ func (api *API) SetEtherbase(etherbase common.Address) bool { api.logger.Debug("miner_setEtherbase") return api.backend.SetEtherbase(etherbase) } + +// SetGasPrice sets the minimum accepted gas price for the miner. +func (api *API) SetGasPrice(gasPrice hexutil.Big) bool { + api.logger.Info(api.ctx.Viper.ConfigFileUsed()) + return api.backend.SetGasPrice(gasPrice) +}