check if block is nil (#4528)

* check if block is nil

* added to rpcdaemon22
This commit is contained in:
Enrique Jose Avila Asapche 2022-06-24 16:48:40 +03:00 committed by GitHub
parent 5e2f6bb2db
commit 389af4fc06
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 0 deletions

View File

@ -203,6 +203,9 @@ func (b *GasPriceOracleBackend) HeaderByNumber(ctx context.Context, number rpc.B
if err != nil { if err != nil {
return nil, err return nil, err
} }
if block == nil {
return nil, nil
}
return block.Header(), nil return block.Header(), nil
} }
func (b *GasPriceOracleBackend) BlockByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Block, error) { func (b *GasPriceOracleBackend) BlockByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Block, error) {

View File

@ -202,6 +202,9 @@ func (b *GasPriceOracleBackend) HeaderByNumber(ctx context.Context, number rpc.B
if err != nil { if err != nil {
return nil, err return nil, err
} }
if block == nil {
return nil, nil
}
return block.Header(), nil return block.Header(), nil
} }
func (b *GasPriceOracleBackend) BlockByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Block, error) { func (b *GasPriceOracleBackend) BlockByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Block, error) {

View File

@ -118,6 +118,9 @@ func NewOracle(backend OracleBackend, params Config) *Oracle {
// baseFee to the returned bigInt // baseFee to the returned bigInt
func (gpo *Oracle) SuggestTipCap(ctx context.Context) (*big.Int, error) { func (gpo *Oracle) SuggestTipCap(ctx context.Context) (*big.Int, error) {
head, _ := gpo.backend.HeaderByNumber(ctx, rpc.LatestBlockNumber) head, _ := gpo.backend.HeaderByNumber(ctx, rpc.LatestBlockNumber)
if head == nil {
return gpo.lastPrice, nil
}
headHash := head.Hash() headHash := head.Hash()
// If the latest gasprice is still available, return it. // If the latest gasprice is still available, return it.