From 9fff27e4f34fb5097100ed76ee725ce056267f4b Mon Sep 17 00:00:00 2001 From: Morty <70688412+yiweichi@users.noreply.github.com> Date: Tue, 29 Oct 2024 16:07:33 +0800 Subject: [PATCH] fix(api): change gas_price to use pending block (#1082) * fix(api): change gas_price to use pending block --- internal/ethapi/api.go | 5 +++-- internal/ethapi/backend.go | 1 + params/version.go | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index b57bc67195f7..61f51c712648 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -68,8 +68,9 @@ func (s *PublicEthereumAPI) GasPrice(ctx context.Context) (*hexutil.Big, error) if err != nil { return nil, err } - if head := s.b.CurrentHeader(); head.BaseFee != nil { - tipcap.Add(tipcap, head.BaseFee) + pendingBlock, _ := s.b.PendingBlockAndReceipts() + if pendingBlock != nil && pendingBlock.BaseFee() != nil { + tipcap.Add(tipcap, pendingBlock.BaseFee()) } return (*hexutil.Big)(tipcap), err } diff --git a/internal/ethapi/backend.go b/internal/ethapi/backend.go index 45d595edd51c..581c370f23d4 100644 --- a/internal/ethapi/backend.go +++ b/internal/ethapi/backend.go @@ -63,6 +63,7 @@ type Backend interface { BlockByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Block, error) BlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error) BlockByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*types.Block, error) + PendingBlockAndReceipts() (*types.Block, types.Receipts) StateAndHeaderByNumber(ctx context.Context, number rpc.BlockNumber) (*state.StateDB, *types.Header, error) StateAndHeaderByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*state.StateDB, *types.Header, error) StateAt(root common.Hash) (*state.StateDB, error) diff --git a/params/version.go b/params/version.go index c523758cbe05..881b51ebecce 100644 --- a/params/version.go +++ b/params/version.go @@ -24,7 +24,7 @@ import ( const ( VersionMajor = 5 // Major version component of the current release VersionMinor = 7 // Minor version component of the current release - VersionPatch = 24 // Patch version component of the current release + VersionPatch = 25 // Patch version component of the current release VersionMeta = "mainnet" // Version metadata to append to the version string )