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

Fix gas price in rpc endpoints #568

Merged
merged 3 commits into from
Sep 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions ethereum/rpc/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -77,18 +78,15 @@ 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(),
clientCtx: clientCtx,
queryClient: types.NewQueryClient(clientCtx),
logger: logger.With("module", "evm-backend"),
chainID: chainID,
cfg: *appConf,
cfg: appConf,
}
}

Expand Down Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion ethereum/rpc/backend/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion ethereum/rpc/namespaces/eth/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
8 changes: 8 additions & 0 deletions testutil/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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).
Expand Down
3 changes: 3 additions & 0 deletions types/coin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down