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

Update GetGasPrice RPC endpoint with global MinGasPrice #1108

Merged
merged 5 commits into from
Jun 3, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions rpc/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions rpc/backend/evm_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
crypto-facs marked this conversation as resolved.
Show resolved Hide resolved
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
Expand Down
10 changes: 10 additions & 0 deletions rpc/namespaces/ethereum/eth/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,16 @@ 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
}
minGasPriceInt := minGasPrice.BigInt()
if result.Cmp(minGasPriceInt) < 0 {
result = minGasPriceInt
}
crypto-facs marked this conversation as resolved.
Show resolved Hide resolved

return (*hexutil.Big)(result), nil
}

Expand Down