Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -1778,7 +1778,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool, makeWitness
// Fire a single chain head event if we've progressed the chain
defer func() {
if lastCanon != nil && bc.CurrentBlock().Hash() == lastCanon.Hash() {
bc.chainHeadFeed.Send(ChainHeadEvent{Header: lastCanon.Header()})
bc.chainHeadFeed.Send(ChainHeadEvent{Header: lastCanon.Header(), ProcessingTime: mclock.Now().Sub(stats.startTime)})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested locally the other day and actually needed to add it to this one SetCanonical (which already has a start time too)

I'm wondering if we actually make a new ethstats event focused around engine_newPayloadVX calls and do the timing there?

The issue with existing block ethstats event is chainHeadFeed can be fired from 5+ different locations which would all require timing (which i think won't make sense in some cases) and the ethstats report also sends current head block which doesn't have timing value.

This new event block_new_payload (?) would only fire when valid block comes over the engine api. thoughts?

Copy link
Member

@Savid Savid Dec 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i guess it's also fine if we accept block event sometimes returns no processingTime and just handle that on the ethstats server side

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PoC #33395

}
}()
// Start the parallel header verifier
Expand Down
5 changes: 4 additions & 1 deletion core/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package core

import (
"time"

"github.com/ethereum/go-ethereum/core/types"
)

Expand All @@ -33,5 +35,6 @@ type ChainEvent struct {
}

type ChainHeadEvent struct {
Header *types.Header
Header *types.Header
ProcessingTime time.Duration
}
68 changes: 35 additions & 33 deletions ethstats/ethstats.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func (s *Service) loop(chainHeadCh chan core.ChainHeadEvent, txEventCh chan core
// Start a goroutine that exhausts the subscriptions to avoid events piling up
var (
quitCh = make(chan struct{})
headCh = make(chan *types.Header, 1)
headCh = make(chan core.ChainHeadEvent, 1)
txCh = make(chan struct{}, 1)
)
go func() {
Expand All @@ -230,7 +230,7 @@ func (s *Service) loop(chainHeadCh chan core.ChainHeadEvent, txEventCh chan core
// Notify of chain head events, but drop if too frequent
case head := <-chainHeadCh:
select {
case headCh <- head.Header:
case headCh <- head:
default:
}

Expand Down Expand Up @@ -330,7 +330,7 @@ func (s *Service) loop(chainHeadCh chan core.ChainHeadEvent, txEventCh chan core
log.Warn("Requested history report failed", "err", err)
}
case head := <-headCh:
if err = s.reportBlock(conn, head); err != nil {
if err = s.reportBlock(conn, &head); err != nil {
log.Warn("Block stats report failed", "err", err)
}
if err = s.reportPending(conn); err != nil {
Expand Down Expand Up @@ -569,19 +569,20 @@ func (s *Service) reportLatency(conn *connWrapper) error {

// blockStats is the information to report about individual blocks.
type blockStats struct {
Number *big.Int `json:"number"`
Hash common.Hash `json:"hash"`
ParentHash common.Hash `json:"parentHash"`
Timestamp *big.Int `json:"timestamp"`
Miner common.Address `json:"miner"`
GasUsed uint64 `json:"gasUsed"`
GasLimit uint64 `json:"gasLimit"`
Diff string `json:"difficulty"`
TotalDiff string `json:"totalDifficulty"`
Txs []txStats `json:"transactions"`
TxHash common.Hash `json:"transactionsRoot"`
Root common.Hash `json:"stateRoot"`
Uncles uncleStats `json:"uncles"`
Number *big.Int `json:"number"`
Hash common.Hash `json:"hash"`
ParentHash common.Hash `json:"parentHash"`
Timestamp *big.Int `json:"timestamp"`
Miner common.Address `json:"miner"`
GasUsed uint64 `json:"gasUsed"`
GasLimit uint64 `json:"gasLimit"`
Diff string `json:"difficulty"`
TotalDiff string `json:"totalDifficulty"`
Txs []txStats `json:"transactions"`
TxHash common.Hash `json:"transactionsRoot"`
Root common.Hash `json:"stateRoot"`
Uncles uncleStats `json:"uncles"`
ProcessingTime uint64 `json:"processingTime"`
}

// txStats is the information to report about individual transactions.
Expand All @@ -601,9 +602,9 @@ func (s uncleStats) MarshalJSON() ([]byte, error) {
}

// reportBlock retrieves the current chain head and reports it to the stats server.
func (s *Service) reportBlock(conn *connWrapper, header *types.Header) error {
func (s *Service) reportBlock(conn *connWrapper, header *core.ChainHeadEvent) error {
// Gather the block details from the header or block chain
details := s.assembleBlockStats(header)
details := s.assembleBlockStats(header.Header, header.ProcessingTime)

// Short circuit if the block detail is not available.
if details == nil {
Expand All @@ -624,7 +625,7 @@ func (s *Service) reportBlock(conn *connWrapper, header *types.Header) error {

// assembleBlockStats retrieves any required metadata to report a single block
// and assembles the block stats. If block is nil, the current head is processed.
func (s *Service) assembleBlockStats(header *types.Header) *blockStats {
func (s *Service) assembleBlockStats(header *types.Header, processingTime time.Duration) *blockStats {
// Gather the block infos from the local blockchain
var (
txs []txStats
Expand Down Expand Up @@ -658,19 +659,20 @@ func (s *Service) assembleBlockStats(header *types.Header) *blockStats {
author, _ := s.engine.Author(header)

return &blockStats{
Number: header.Number,
Hash: header.Hash(),
ParentHash: header.ParentHash,
Timestamp: new(big.Int).SetUint64(header.Time),
Miner: author,
GasUsed: header.GasUsed,
GasLimit: header.GasLimit,
Diff: header.Difficulty.String(),
TotalDiff: "0", // unknown post-merge with pruned chain tail
Txs: txs,
TxHash: header.TxHash,
Root: header.Root,
Uncles: uncles,
Number: header.Number,
Hash: header.Hash(),
ParentHash: header.ParentHash,
Timestamp: new(big.Int).SetUint64(header.Time),
Miner: author,
GasUsed: header.GasUsed,
GasLimit: header.GasLimit,
Diff: header.Difficulty.String(),
TotalDiff: "0", // unknown post-merge with pruned chain tail
Txs: txs,
TxHash: header.TxHash,
Root: header.Root,
Uncles: uncles,
ProcessingTime: uint64(processingTime),
}
}

Expand Down Expand Up @@ -699,7 +701,7 @@ func (s *Service) reportHistory(conn *connWrapper, list []uint64) error {
// Retrieve the next block if it's known to us
header, _ := s.backend.HeaderByNumber(context.Background(), rpc.BlockNumber(number))
if header != nil {
history[len(history)-1-i] = s.assembleBlockStats(header)
history[len(history)-1-i] = s.assembleBlockStats(header, 0)
continue
}
// Ran out of blocks, cut the report short and send
Expand Down
Loading