From bc82f3f8eb4118081128c88db824044c175e26b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Federico=20Kunze=20K=C3=BCllmer?= <31522760+fedekunze@users.noreply.github.com> Date: Tue, 28 Sep 2021 10:42:18 +0200 Subject: [PATCH] rpc: fix gas price (#596) --- ethereum/rpc/backend/backend.go | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/ethereum/rpc/backend/backend.go b/ethereum/rpc/backend/backend.go index 6c1ffea1..e53e5eac 100644 --- a/ethereum/rpc/backend/backend.go +++ b/ethereum/rpc/backend/backend.go @@ -720,19 +720,22 @@ func (e *EVMBackend) RPCGasCap() uint64 { return e.cfg.JSONRPC.GasCap } -// RPCMinGasPrice return the minimum gas price for a transaction. +// RPCMinGasPrice returns the minimum gas price for a transaction obtained from +// the node config. If set value is 0, it will default to 20. + 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() - } - } + if err != nil { + return ethermint.DefaultGasPrice } - return ethermint.DefaultGasPrice + minGasPrice := e.cfg.GetMinGasPrices() + amt := minGasPrice.AmountOf(evmParams.Params.EvmDenom).TruncateInt64() + if amt == 0 { + return ethermint.DefaultGasPrice + } + + return amt } // ChainConfig return the ethereum chain configuration