Skip to content

Commit 44c0c5f

Browse files
committed
chore: add metrics for preconf timings
1 parent 99e62fa commit 44c0c5f

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

eth/catalyst/api.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import (
3838
"github.com/ethereum/go-ethereum/eth/ethconfig"
3939
"github.com/ethereum/go-ethereum/internal/version"
4040
"github.com/ethereum/go-ethereum/log"
41+
"github.com/ethereum/go-ethereum/metrics"
4142
"github.com/ethereum/go-ethereum/miner"
4243
"github.com/ethereum/go-ethereum/node"
4344
"github.com/ethereum/go-ethereum/params/forks"
@@ -160,6 +161,10 @@ type ConsensusAPI struct {
160161
forkchoiceLock sync.Mutex // Lock for the forkChoiceUpdated method
161162
newPayloadLock sync.Mutex // Lock for the NewPayload method
162163

164+
// Metrics
165+
newFragV0Time *metrics.Timer
166+
sealFragV0Time *metrics.Timer
167+
envV0Time *metrics.Timer
163168
}
164169

165170
// NewConsensusAPI creates a new consensus api for the given backend.
@@ -181,6 +186,11 @@ func newConsensusAPIWithoutHeartbeat(eth *eth.Ethereum) *ConsensusAPI {
181186
localBlocks: newPayloadQueue(),
182187
invalidBlocksHits: make(map[common.Hash]int),
183188
invalidTipsets: make(map[common.Hash]*types.Header),
189+
190+
// Metrics
191+
newFragV0Time: metrics.GetOrRegisterTimer("engine/frag/new", nil),
192+
sealFragV0Time: metrics.GetOrRegisterTimer("engine/frag/seal", nil),
193+
envV0Time: metrics.GetOrRegisterTimer("engine/frag/env", nil),
184194
}
185195
eth.Downloader().SetBadBlockCallback(api.setInvalidAncestor)
186196
return api
@@ -1356,6 +1366,7 @@ func validateRequests(requests [][]byte) error {
13561366
func (api *ConsensusAPI) NewFragV0(frag engine.SignedNewFrag) (string, error) {
13571367
log.Info("new frag received", "forBlock", frag.Frag.BlockNumber, "current", api.eth.BlockChain().CurrentBlock().Number)
13581368

1369+
start := time.Now()
13591370
api.eth.BlockChain().UnsealedBlockLock().Lock()
13601371
res, err := api.newFragV0(frag)
13611372
if err != nil {
@@ -1364,7 +1375,8 @@ func (api *ConsensusAPI) NewFragV0(frag engine.SignedNewFrag) (string, error) {
13641375
}
13651376
api.eth.BlockChain().UnsealedBlockLock().Unlock()
13661377

1367-
log.Info("new frag handled successfully")
1378+
api.newFragV0Time.Update(time.Since(start))
1379+
log.Info("new frag handled successfully", "time", time.Since(start))
13681380

13691381
return res, err
13701382
}
@@ -1444,6 +1456,7 @@ func (api *ConsensusAPI) SealFragV0(seal engine.SignedSeal) (string, error) {
14441456
return engine.VALID, nil
14451457
}
14461458

1459+
start := time.Now()
14471460
api.eth.BlockChain().UnsealedBlockLock().Lock()
14481461
res, err := api.sealFragV0(seal)
14491462
if err != nil {
@@ -1452,6 +1465,9 @@ func (api *ConsensusAPI) SealFragV0(seal engine.SignedSeal) (string, error) {
14521465
}
14531466
api.eth.BlockChain().UnsealedBlockLock().Unlock()
14541467

1468+
api.sealFragV0Time.Update(time.Since(start))
1469+
log.Info("seal handled successfully", "time", time.Since(start))
1470+
14551471
return res, err
14561472
}
14571473

@@ -1520,6 +1536,7 @@ func (api *ConsensusAPI) ValidateSealFragV0(preSealedBlock *types.Block, seal en
15201536
func (api *ConsensusAPI) EnvV0(env engine.SignedEnv) (string, error) {
15211537
log.Info("env received", "forBlock", env.Env.Number, "current", api.eth.BlockChain().CurrentBlock().Number, "env", env.Env)
15221538

1539+
start := time.Now()
15231540
api.eth.BlockChain().UnsealedBlockLock().Lock()
15241541
res, err := api.envV0(env)
15251542
if err != nil {
@@ -1529,7 +1546,8 @@ func (api *ConsensusAPI) EnvV0(env engine.SignedEnv) (string, error) {
15291546
}
15301547
api.eth.BlockChain().UnsealedBlockLock().Unlock()
15311548

1532-
log.Info("env handled successfully")
1549+
api.envV0Time.Update(time.Since(start))
1550+
log.Info("env handled successfully", "time", time.Since(start))
15331551

15341552
return res, err
15351553
}

0 commit comments

Comments
 (0)