forked from cerc-io/plugeth
ethstats: fix bug in block reporting (#28398)
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.
This commit is contained in:
parent
6c6982163b
commit
54f35c68be
@ -76,12 +76,18 @@ type backend interface {
|
|||||||
// reporting to ethstats
|
// reporting to ethstats
|
||||||
type fullNodeBackend interface {
|
type fullNodeBackend interface {
|
||||||
backend
|
backend
|
||||||
Miner() *miner.Miner
|
|
||||||
BlockByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Block, error)
|
BlockByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Block, error)
|
||||||
CurrentBlock() *types.Block
|
CurrentBlock() *types.Header
|
||||||
SuggestGasTipCap(ctx context.Context) (*big.Int, error)
|
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
|
// Service implements an Ethereum netstats reporting daemon that pushes local
|
||||||
// chain statistics up to a monitoring server.
|
// chain statistics up to a monitoring server.
|
||||||
type Service struct {
|
type Service struct {
|
||||||
@ -634,7 +640,8 @@ func (s *Service) assembleBlockStats(block *types.Block) *blockStats {
|
|||||||
fullBackend, ok := s.backend.(fullNodeBackend)
|
fullBackend, ok := s.backend.(fullNodeBackend)
|
||||||
if ok {
|
if ok {
|
||||||
if block == nil {
|
if block == nil {
|
||||||
block = fullBackend.CurrentBlock()
|
head := fullBackend.CurrentBlock()
|
||||||
|
block, _ = fullBackend.BlockByNumber(context.Background(), rpc.BlockNumber(head.Number.Uint64()))
|
||||||
}
|
}
|
||||||
header = block.Header()
|
header = block.Header()
|
||||||
td = fullBackend.GetTd(context.Background(), header.Hash())
|
td = fullBackend.GetTd(context.Background(), header.Hash())
|
||||||
@ -779,10 +786,11 @@ func (s *Service) reportStats(conn *connWrapper) error {
|
|||||||
gasprice int
|
gasprice int
|
||||||
)
|
)
|
||||||
// check if backend is a full node
|
// check if backend is a full node
|
||||||
fullBackend, ok := s.backend.(fullNodeBackend)
|
if fullBackend, ok := s.backend.(fullNodeBackend); ok {
|
||||||
if ok {
|
if miningBackend, ok := s.backend.(miningNodeBackend); ok {
|
||||||
mining = fullBackend.Miner().Mining()
|
mining = miningBackend.Miner().Mining()
|
||||||
hashrate = int(fullBackend.Miner().Hashrate())
|
hashrate = int(miningBackend.Miner().Hashrate())
|
||||||
|
}
|
||||||
|
|
||||||
sync := fullBackend.SyncProgress()
|
sync := fullBackend.SyncProgress()
|
||||||
syncing = fullBackend.CurrentHeader().Number.Uint64() >= sync.HighestBlock
|
syncing = fullBackend.CurrentHeader().Number.Uint64() >= sync.HighestBlock
|
||||||
|
Loading…
Reference in New Issue
Block a user