rpc: fix gas price (#568)
Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com>
This commit is contained in:
parent
b59d9a23ea
commit
b8ae5984c5
@ -56,6 +56,7 @@ type Backend interface {
|
||||
GetTxByEthHash(txHash common.Hash) (*tmrpctypes.ResultTx, error)
|
||||
EstimateGas(args evmtypes.CallArgs, blockNrOptional *types.BlockNumber) (hexutil.Uint64, error)
|
||||
RPCGasCap() uint64
|
||||
RPCMinGasPrice() int64
|
||||
}
|
||||
|
||||
var _ Backend = (*EVMBackend)(nil)
|
||||
@ -77,10 +78,7 @@ func NewEVMBackend(ctx *server.Context, logger log.Logger, clientCtx client.Cont
|
||||
panic(err)
|
||||
}
|
||||
|
||||
appConf, err := config.ParseConfig(ctx.Viper)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
appConf := config.GetConfig(ctx.Viper)
|
||||
|
||||
return &EVMBackend{
|
||||
ctx: context.Background(),
|
||||
@ -88,7 +86,7 @@ func NewEVMBackend(ctx *server.Context, logger log.Logger, clientCtx client.Cont
|
||||
queryClient: types.NewQueryClient(clientCtx),
|
||||
logger: logger.With("module", "evm-backend"),
|
||||
chainID: chainID,
|
||||
cfg: *appConf,
|
||||
cfg: appConf,
|
||||
}
|
||||
}
|
||||
|
||||
@ -700,3 +698,18 @@ func (e *EVMBackend) GetTransactionCount(address common.Address, blockNum types.
|
||||
func (e *EVMBackend) RPCGasCap() uint64 {
|
||||
return e.cfg.JSONRPC.GasCap
|
||||
}
|
||||
|
||||
// RPCMinGasPrice return the minimum gas price for a transaction.
|
||||
func (e *EVMBackend) RPCMinGasPrice() int64 {
|
||||
evmParams, err := e.queryClient.Params(context.Background(), &evmtypes.QueryParamsRequest{})
|
||||
if err == nil {
|
||||
minGasPrice := e.cfg.GetMinGasPrices()
|
||||
for _, coin := range minGasPrice {
|
||||
if coin.Denom == evmParams.Params.EvmDenom {
|
||||
return coin.Amount.TruncateInt64()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ethermint.DefaultGasPrice
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ import (
|
||||
func (e *EVMBackend) setTxDefaults(args types.SendTxArgs) (types.SendTxArgs, error) {
|
||||
if args.GasPrice == nil {
|
||||
// TODO: Suggest a gas price based on the previous included txs
|
||||
args.GasPrice = (*hexutil.Big)(new(big.Int).SetUint64(e.RPCGasCap()))
|
||||
args.GasPrice = (*hexutil.Big)(new(big.Int).SetInt64(e.RPCMinGasPrice()))
|
||||
}
|
||||
|
||||
if args.Nonce == nil {
|
||||
|
@ -164,7 +164,7 @@ func (e *PublicAPI) Hashrate() hexutil.Uint64 {
|
||||
// GasPrice returns the current gas price based on Ethermint's gas price oracle.
|
||||
func (e *PublicAPI) GasPrice() *hexutil.Big {
|
||||
e.logger.Debug("eth_gasPrice")
|
||||
out := new(big.Int).SetUint64(e.backend.RPCGasCap())
|
||||
out := new(big.Int).SetInt64(e.backend.RPCMinGasPrice())
|
||||
return (*hexutil.Big)(out)
|
||||
}
|
||||
|
||||
|
@ -221,6 +221,7 @@ func New(t *testing.T, cfg Config) *Network {
|
||||
appCfg.Telemetry.Enabled = false
|
||||
|
||||
ctx := server.NewDefaultContext()
|
||||
|
||||
tmCfg := ctx.Config
|
||||
tmCfg.Consensus.TimeoutCommit = cfg.TimeoutCommit
|
||||
|
||||
@ -359,6 +360,13 @@ func New(t *testing.T, cfg Config) *Network {
|
||||
require.NoError(t, writeFile(fmt.Sprintf("%v.json", nodeDirName), gentxsDir, txBz))
|
||||
|
||||
config.WriteConfigFile(filepath.Join(nodeDir, "config/app.toml"), appCfg)
|
||||
ctx.Viper.AddConfigPath(fmt.Sprintf("%s/config", nodeDir))
|
||||
ctx.Viper.SetConfigName("app")
|
||||
ctx.Viper.SetConfigType("toml")
|
||||
err = ctx.Viper.ReadInConfig()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
clientCtx := client.Context{}.
|
||||
WithKeyringDir(nodeDir).
|
||||
|
@ -19,6 +19,9 @@ const (
|
||||
// BaseDenomUnit defines the base denomination unit for Photons.
|
||||
// 1 photon = 1x10^{BaseDenomUnit} aphoton
|
||||
BaseDenomUnit = 18
|
||||
|
||||
// DefaultGasPrice is default gas price for evm transactions
|
||||
DefaultGasPrice = 20
|
||||
)
|
||||
|
||||
// PowerReduction defines the default power reduction value for staking
|
||||
|
Loading…
Reference in New Issue
Block a user