ethstats: fix bug in block reporting #28398 (#1452)

Fixes a bug where the ethstats omits to report full block contents. This bug was a side-effect of https://github.com/ethereum/go-ethereum/pull/26777,  where `CurrentBlock` was changed to return a header instead of a block, leading to a failed type assertion.

Co-authored-by: kaliubuntu0206 <139627505+kaliubuntu0206@users.noreply.github.com>
This commit is contained in:
Daniel Liu 2025-09-13 10:03:18 +08:00 committed by GitHub
parent ccaa69e8e9
commit 00970f929e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -84,12 +84,18 @@ type backend interface {
// reporting to ethstats
type fullNodeBackend interface {
backend
Miner() *miner.Miner
BlockByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Block, error)
CurrentBlock() *types.Block
CurrentBlock() *types.Header
SuggestGasTipCap(ctx context.Context) (*big.Int, error)
}
// miningNodeBackend encompasses the functionality necessary for a mining node
// reporting to ethstats
type miningNodeBackend interface {
fullNodeBackend
Miner() *miner.Miner
}
// Service implements an Ethereum netstats reporting daemon that pushes local
// chain statistics up to a monitoring server.
type Service struct {
@ -688,7 +694,8 @@ func (s *Service) assembleBlockStats(block *types.Block) *blockStats {
fullBackend, ok := s.backend.(fullNodeBackend)
if ok {
if block == nil {
block = fullBackend.CurrentBlock()
head := fullBackend.CurrentBlock()
block, _ = fullBackend.BlockByNumber(context.Background(), rpc.BlockNumber(head.Number.Uint64()))
}
header = block.Header()
td = fullBackend.GetTd(context.Background(), header.Hash())
@ -835,10 +842,11 @@ func (s *Service) reportStats(conn *connWrapper) error {
gasprice int
)
// check if backend is a full node
fullBackend, ok := s.backend.(fullNodeBackend)
if ok {
mining = fullBackend.Miner().Mining()
hashrate = int(fullBackend.Miner().HashRate())
if fullBackend, ok := s.backend.(fullNodeBackend); ok {
if miningBackend, ok := s.backend.(miningNodeBackend); ok {
mining = miningBackend.Miner().Mining()
hashrate = int(miningBackend.Miner().HashRate())
}
sync := fullBackend.Downloader().Progress()
syncing = fullBackend.CurrentHeader().Number.Uint64() >= sync.HighestBlock