Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ethstats: fix bug in block reporting #28398

Merged
merged 2 commits into from Oct 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions ethstats/ethstats.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,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 {
Expand Down Expand Up @@ -634,7 +640,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())
Expand Down Expand Up @@ -779,10 +786,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.SyncProgress()
syncing = fullBackend.CurrentHeader().Number.Uint64() >= sync.HighestBlock
Expand Down