rpc: Update GetGasPrice RPC endpoint with global MinGasPrice (#1108)

* return MinGasPrice as minium on GetGasPrice api

* update logic

* update changelog

* globalmingsprice comment

Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com>
This commit is contained in:
crypto-facs 2022-06-03 15:31:57 +02:00 committed by GitHub
parent 72444a676c
commit da99f11be3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 0 deletions

View File

@ -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. - (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. - (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. - (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 ### Improvements

View File

@ -69,6 +69,7 @@ type EVMBackend interface {
GetTxByTxIndex(height int64, txIndex uint) (*tmrpctypes.ResultTx, error) GetTxByTxIndex(height int64, txIndex uint) (*tmrpctypes.ResultTx, error)
EstimateGas(args evmtypes.TransactionArgs, blockNrOptional *types.BlockNumber) (hexutil.Uint64, error) EstimateGas(args evmtypes.TransactionArgs, blockNrOptional *types.BlockNumber) (hexutil.Uint64, error)
BaseFee(height int64) (*big.Int, error) BaseFee(height int64) (*big.Int, error)
GlobalMinGasPrice() (sdk.Dec, error)
// Fee API // Fee API
FeeHistory(blockCount rpc.DecimalOrHex, lastBlock rpc.BlockNumber, rewardPercentiles []float64) (*types.FeeHistoryResult, error) FeeHistory(blockCount rpc.DecimalOrHex, lastBlock rpc.BlockNumber, rewardPercentiles []float64) (*types.FeeHistoryResult, error)

View File

@ -818,6 +818,15 @@ func (b *Backend) BaseFee(height int64) (*big.Int, error) {
return res.BaseFee.BigInt(), nil 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 {
return sdk.ZeroDec(), err
}
return res.Params.MinGasPrice, nil
}
// FeeHistory returns data relevant for fee estimation based on the specified range of blocks. // FeeHistory returns data relevant for fee estimation based on the specified range of blocks.
func (b *Backend) FeeHistory( func (b *Backend) FeeHistory(
userBlockCount rpc.DecimalOrHex, // number blocks to fetch, maximum is 100 userBlockCount rpc.DecimalOrHex, // number blocks to fetch, maximum is 100

View File

@ -211,6 +211,16 @@ func (e *PublicAPI) GasPrice() (*hexutil.Big, error) {
result = big.NewInt(e.backend.RPCMinGasPrice()) result = big.NewInt(e.backend.RPCMinGasPrice())
} }
// return at least GlobalMinGasPrice from FeeMarket module
minGasPrice, err := e.backend.GlobalMinGasPrice()
if err != nil {
return nil, err
}
minGasPriceInt := minGasPrice.BigInt()
if result.Cmp(minGasPriceInt) < 0 {
result = minGasPriceInt
}
return (*hexutil.Big)(result), nil return (*hexutil.Big)(result), nil
} }