From 389af4fc067478f4e2731a4cd055104ec3e2793d Mon Sep 17 00:00:00 2001 From: Enrique Jose Avila Asapche Date: Fri, 24 Jun 2022 16:48:40 +0300 Subject: [PATCH] check if block is nil (#4528) * check if block is nil * added to rpcdaemon22 --- cmd/rpcdaemon/commands/eth_system.go | 3 +++ cmd/rpcdaemon22/commands/eth_system.go | 3 +++ eth/gasprice/gasprice.go | 3 +++ 3 files changed, 9 insertions(+) diff --git a/cmd/rpcdaemon/commands/eth_system.go b/cmd/rpcdaemon/commands/eth_system.go index 654c4fc28..3a4bea0e5 100644 --- a/cmd/rpcdaemon/commands/eth_system.go +++ b/cmd/rpcdaemon/commands/eth_system.go @@ -203,6 +203,9 @@ func (b *GasPriceOracleBackend) HeaderByNumber(ctx context.Context, number rpc.B if err != nil { return nil, err } + if block == nil { + return nil, nil + } return block.Header(), nil } func (b *GasPriceOracleBackend) BlockByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Block, error) { diff --git a/cmd/rpcdaemon22/commands/eth_system.go b/cmd/rpcdaemon22/commands/eth_system.go index 1095cdd82..32cc015c8 100644 --- a/cmd/rpcdaemon22/commands/eth_system.go +++ b/cmd/rpcdaemon22/commands/eth_system.go @@ -202,6 +202,9 @@ func (b *GasPriceOracleBackend) HeaderByNumber(ctx context.Context, number rpc.B if err != nil { return nil, err } + if block == nil { + return nil, nil + } return block.Header(), nil } func (b *GasPriceOracleBackend) BlockByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Block, error) { diff --git a/eth/gasprice/gasprice.go b/eth/gasprice/gasprice.go index 168a48466..63a57aa1d 100644 --- a/eth/gasprice/gasprice.go +++ b/eth/gasprice/gasprice.go @@ -118,6 +118,9 @@ func NewOracle(backend OracleBackend, params Config) *Oracle { // baseFee to the returned bigInt func (gpo *Oracle) SuggestTipCap(ctx context.Context) (*big.Int, error) { head, _ := gpo.backend.HeaderByNumber(ctx, rpc.LatestBlockNumber) + if head == nil { + return gpo.lastPrice, nil + } headHash := head.Hash() // If the latest gasprice is still available, return it.