Skip to content

Commit d13e8fd

Browse files
committed
fix: gasPrice api to use PendingBlockAndReceipts
1 parent 7ea1d52 commit d13e8fd

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

internal/ethapi/api.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,9 @@ func (s *PublicEthereumAPI) GasPrice(ctx context.Context) (*hexutil.Big, error)
6868
if err != nil {
6969
return nil, err
7070
}
71-
bNrOrHash := rpc.BlockNumberOrHashWithNumber(rpc.PendingBlockNumber)
72-
block, err := s.b.BlockByNumberOrHash(ctx, bNrOrHash)
73-
if err != nil {
74-
return nil, err
75-
}
76-
if block.BaseFee() != nil {
77-
tipcap.Add(tipcap, block.BaseFee())
71+
pendingBlock, _ := s.b.PendingBlockAndReceipts()
72+
if pendingBlock != nil && pendingBlock.BaseFee() != nil {
73+
tipcap.Add(tipcap, pendingBlock.BaseFee())
7874
}
7975
return (*hexutil.Big)(tipcap), err
8076
}

internal/ethapi/backend.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ type Backend interface {
6363
BlockByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Block, error)
6464
BlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error)
6565
BlockByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*types.Block, error)
66+
PendingBlockAndReceipts() (*types.Block, types.Receipts)
6667
StateAndHeaderByNumber(ctx context.Context, number rpc.BlockNumber) (*state.StateDB, *types.Header, error)
6768
StateAndHeaderByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*state.StateDB, *types.Header, error)
6869
StateAt(root common.Hash) (*state.StateDB, error)

0 commit comments

Comments
 (0)