mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 18:32:23 +00:00
ethstats: did some error handling in ethstats.go
This commit is contained in:
parent
b6474e9f90
commit
69b496bb5f
1 changed files with 9 additions and 7 deletions
|
|
@ -632,6 +632,7 @@ func (s *Service) assembleBlockStats(block *types.Block) *blockStats {
|
||||||
td *big.Int
|
td *big.Int
|
||||||
txs []txStats
|
txs []txStats
|
||||||
uncles []*types.Header
|
uncles []*types.Header
|
||||||
|
err error
|
||||||
)
|
)
|
||||||
|
|
||||||
// check if backend is a full node
|
// check if backend is a full node
|
||||||
|
|
@ -640,12 +641,13 @@ func (s *Service) assembleBlockStats(block *types.Block) *blockStats {
|
||||||
// Retrieve current chain head if no block is given.
|
// Retrieve current chain head if no block is given.
|
||||||
if block == nil {
|
if block == nil {
|
||||||
head := fullBackend.CurrentBlock()
|
head := fullBackend.CurrentBlock()
|
||||||
block, _ = fullBackend.BlockByNumber(context.Background(), rpc.BlockNumber(head.Number.Uint64()))
|
block, err = fullBackend.BlockByNumber(context.Background(), rpc.BlockNumber(head.Number.Uint64()))
|
||||||
}
|
// Short circuit if no block is available. It might happen when
|
||||||
// Short circuit if no block is available. It might happen when
|
// the blockchain is reorging.
|
||||||
// the blockchain is reorging.
|
if err != nil {
|
||||||
if block == nil {
|
log.Error("Failed to retrieve block by number", "err", err)
|
||||||
return nil
|
return nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
header = block.Header()
|
header = block.Header()
|
||||||
td = fullBackend.GetTd(context.Background(), header.Hash())
|
td = fullBackend.GetTd(context.Background(), header.Hash())
|
||||||
|
|
@ -712,7 +714,7 @@ func (s *Service) reportHistory(conn *connWrapper, list []uint64) error {
|
||||||
// Retrieve the next block if it's known to us
|
// Retrieve the next block if it's known to us
|
||||||
var block *types.Block
|
var block *types.Block
|
||||||
if ok {
|
if ok {
|
||||||
block, _ = fullBackend.BlockByNumber(context.Background(), rpc.BlockNumber(number)) // TODO ignore error here ?
|
block, _ = fullBackend.BlockByNumber(context.Background(), rpc.BlockNumber(number))
|
||||||
} else {
|
} else {
|
||||||
if header, _ := s.backend.HeaderByNumber(context.Background(), rpc.BlockNumber(number)); header != nil {
|
if header, _ := s.backend.HeaderByNumber(context.Background(), rpc.BlockNumber(number)); header != nil {
|
||||||
block = types.NewBlockWithHeader(header)
|
block = types.NewBlockWithHeader(header)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue