From 338c8ac825c33a2a02517c5973a3e3d6ad4a5186 Mon Sep 17 00:00:00 2001 From: Freddy Caceres Date: Fri, 3 Jun 2022 01:50:26 +0200 Subject: [PATCH 1/4] return MinGasPrice as minium on GetGasPrice api --- rpc/backend/backend.go | 1 + rpc/backend/evm_backend.go | 8 ++++++++ rpc/namespaces/ethereum/eth/api.go | 9 +++++++++ 3 files changed, 18 insertions(+) diff --git a/rpc/backend/backend.go b/rpc/backend/backend.go index e9692c8dbf..49b456f731 100644 --- a/rpc/backend/backend.go +++ b/rpc/backend/backend.go @@ -69,6 +69,7 @@ type EVMBackend interface { GetTxByTxIndex(height int64, txIndex uint) (*tmrpctypes.ResultTx, error) EstimateGas(args evmtypes.TransactionArgs, blockNrOptional *types.BlockNumber) (hexutil.Uint64, error) BaseFee(height int64) (*big.Int, error) + GlobalMinGasPrice() (sdk.Dec, error) // Fee API FeeHistory(blockCount rpc.DecimalOrHex, lastBlock rpc.BlockNumber, rewardPercentiles []float64) (*types.FeeHistoryResult, error) diff --git a/rpc/backend/evm_backend.go b/rpc/backend/evm_backend.go index 81887bd6ce..bc5bad0b4e 100644 --- a/rpc/backend/evm_backend.go +++ b/rpc/backend/evm_backend.go @@ -818,6 +818,14 @@ func (b *Backend) BaseFee(height int64) (*big.Int, error) { return res.BaseFee.BigInt(), nil } +func (b *Backend) GlobalMinGasPrice() (sdk.Dec, error) { + res, err := b.queryClient.FeeMarket.Params(b.ctx, &feemarkettypes.QueryParamsRequest{}) + if err != nil { + return sdk.ZeroDec(), err + } + return res.Params.MinGasPrice, nil +} + // FeeHistory returns data relevant for fee estimation based on the specified range of blocks. func (b *Backend) FeeHistory( userBlockCount rpc.DecimalOrHex, // number blocks to fetch, maximum is 100 diff --git a/rpc/namespaces/ethereum/eth/api.go b/rpc/namespaces/ethereum/eth/api.go index 2086e37a42..e7adf75072 100644 --- a/rpc/namespaces/ethereum/eth/api.go +++ b/rpc/namespaces/ethereum/eth/api.go @@ -211,6 +211,15 @@ func (e *PublicAPI) GasPrice() (*hexutil.Big, error) { result = big.NewInt(e.backend.RPCMinGasPrice()) } + // return at least GlobalMinGasPrice from FeeMarket module + minGasPrice, err := e.backend.GlobalMinGasPrice() + if err != nil { + return nil, err + } + if result.Cmp(minGasPrice.BigInt()) == -1 { + result = minGasPrice.BigInt() + } + return (*hexutil.Big)(result), nil } From 71131dd2fe913fd0aaa80a3efd0e728d1da039e1 Mon Sep 17 00:00:00 2001 From: Freddy Caceres Date: Fri, 3 Jun 2022 01:54:45 +0200 Subject: [PATCH 2/4] update logic --- rpc/namespaces/ethereum/eth/api.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/rpc/namespaces/ethereum/eth/api.go b/rpc/namespaces/ethereum/eth/api.go index e7adf75072..07add625ac 100644 --- a/rpc/namespaces/ethereum/eth/api.go +++ b/rpc/namespaces/ethereum/eth/api.go @@ -216,8 +216,9 @@ func (e *PublicAPI) GasPrice() (*hexutil.Big, error) { if err != nil { return nil, err } - if result.Cmp(minGasPrice.BigInt()) == -1 { - result = minGasPrice.BigInt() + minGasPriceInt := minGasPrice.BigInt() + if result.Cmp(minGasPriceInt) < 0 { + result = minGasPriceInt } return (*hexutil.Big)(result), nil From 3ec1609525f0591d0f9663187c338a3ea9fd9f92 Mon Sep 17 00:00:00 2001 From: Freddy Caceres Date: Fri, 3 Jun 2022 13:14:41 +0200 Subject: [PATCH 3/4] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ecfee6d5ab..b8ac147222 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,6 +44,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ - (rpc) [tharsis#1081](https://github.com/tharsis/ethermint/pull/1081) Deduplicate some json-rpc logic codes, cleanup several dead functions. - (ante) [tharsis#1062](https://github.com/tharsis/ethermint/pull/1062) Emit event of eth tx hash in ante handler to support query failed transactions. - (analytics) [tharsis#1106](https://github.com/tharsis/ethermint/pull/1106) Update telemetry to Ethermint modules. +- (rpc)[tharsis#1108](https://github.com/tharsis/ethermint/pull/1108) Update GetGasPrice RPC endpoint with global `MinGasPrice` ### Improvements From 7040a5ae940febc5dfe8e0829613e294c7ec0cb1 Mon Sep 17 00:00:00 2001 From: Freddy Caceres Date: Fri, 3 Jun 2022 13:27:52 +0200 Subject: [PATCH 4/4] globalmingsprice comment --- CHANGELOG.md | 2 +- rpc/backend/evm_backend.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b8ac147222..4860072df8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,7 +44,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ - (rpc) [tharsis#1081](https://github.com/tharsis/ethermint/pull/1081) Deduplicate some json-rpc logic codes, cleanup several dead functions. - (ante) [tharsis#1062](https://github.com/tharsis/ethermint/pull/1062) Emit event of eth tx hash in ante handler to support query failed transactions. - (analytics) [tharsis#1106](https://github.com/tharsis/ethermint/pull/1106) Update telemetry to Ethermint modules. -- (rpc)[tharsis#1108](https://github.com/tharsis/ethermint/pull/1108) Update GetGasPrice RPC endpoint with global `MinGasPrice` +- (rpc) [tharsis#1108](https://github.com/tharsis/ethermint/pull/1108) Update GetGasPrice RPC endpoint with global `MinGasPrice` ### Improvements diff --git a/rpc/backend/evm_backend.go b/rpc/backend/evm_backend.go index bc5bad0b4e..d5d8a84a86 100644 --- a/rpc/backend/evm_backend.go +++ b/rpc/backend/evm_backend.go @@ -818,6 +818,7 @@ func (b *Backend) BaseFee(height int64) (*big.Int, error) { return res.BaseFee.BigInt(), nil } +// GlobalMinGasPrice returns MinGasPrice param from FeeMarket func (b *Backend) GlobalMinGasPrice() (sdk.Dec, error) { res, err := b.queryClient.FeeMarket.Params(b.ctx, &feemarkettypes.QueryParamsRequest{}) if err != nil {