bor: check nil-blocks in other places (#8788)

This commit is contained in:
Alex Sharov 2023-11-20 12:46:32 +07:00 committed by GitHub
parent d557679a0b
commit f476fe690f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 12 deletions

View File

@ -1451,22 +1451,13 @@ func (c *Bor) GetRootHash(ctx context.Context, tx kv.Tx, start, end uint64) (str
}
func (c *Bor) getHeaderByNumber(ctx context.Context, tx kv.Tx, number uint64) (*types.Header, error) {
_, err := c.blockReader.BlockByNumber(ctx, tx, number)
if err != nil {
return nil, err
}
header, err := c.blockReader.HeaderByNumber(ctx, tx, number)
if err != nil {
return nil, err
}
if header == nil {
return nil, fmt.Errorf("block header not found: %d", number)
return nil, fmt.Errorf("[bor] header not found: %d", number)
}
return header, nil
}

View File

@ -84,11 +84,16 @@ func borVerify(ctx context.Context, config *config, start uint64, end uint64, ha
}
} else {
// in case of milestone(isCheckpoint==false) get the hash of endBlock
block, err := config.blockReader.BlockByNumber(context.Background(), roTx, end)
block, err := config.blockReader.BlockByNumber(ctx, roTx, end)
if err != nil {
log.Debug("[bor] Failed to get end block hash while whitelisting milestone", "number", end, "err", err)
return hash, errEndBlock
}
if block == nil {
err := fmt.Errorf("[bor] block not found: %d", end)
log.Debug("[bor] Failed to get end block hash while whitelisting milestone", "number", end, "err", err)
return hash, err
}
localHash = fmt.Sprintf("%v", block.Hash())[2:]
}
@ -135,7 +140,7 @@ func borVerify(ctx context.Context, config *config, start uint64, end uint64, ha
}
// fetch the end block hash
block, err := config.blockReader.BlockByNumber(context.Background(), roTx, end)
block, err := config.blockReader.BlockByNumber(ctx, roTx, end)
if err != nil {
log.Debug("[bor] Failed to get end block hash while whitelisting", "err", err)
return hash, errEndBlock