Skip to content

Commit e2cbfe8

Browse files
authored
Beacon sync update sched lru and maint update (#3811)
* Don't startle log file observers with an `error` message on legit shutdown detail Use `debug` message instead * Code cosmetics, readability updates * Providing ETA calculator * Code cosmetics, logging & metrics updates details + Log block numbers without a leading hash `#` + Avoid "(from queue)" info in log statements + Rename `lastState` -> `syncState` + Log ETA with regular block & header `info` log gravity + Grafana example update * Replace `keyed_queue` by `minilru` * Bump minilru * Re-implement handling of LRU evicted sync peers details Using `miniurl.putWithEvicted()` for post-processing evicted peers
1 parent 6135980 commit e2cbfe8

24 files changed

+926
-258
lines changed

execution_chain/core/chain/header_chain_cache.nim

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ declareGauge nec_sync_dangling, "" &
7777
declareGauge nec_sync_consensus_head, "" &
7878
"Block number of latest consensus head"
7979

80+
declareGauge nec_sync_distance_to_sync, "" &
81+
"Distance from execution head to consensus head"
82+
8083
type
8184
HccDbInfo = object
8285
## For database table storage and clean up
@@ -138,7 +141,7 @@ const
138141
# ------------------------------------------------------------------------------
139142

140143
func bnStr(w: BlockNumber): string =
141-
"#" & $w
144+
$w
142145

143146
func bnStr(h: Header): string =
144147
h.number.bnStr
@@ -310,10 +313,10 @@ proc headUpdateFromCL(hc: HeaderChainRef; h: Header; f: Hash32) =
310313
## This function prepares a new session and notifies some registered
311314
## client app.
312315
##
313-
if f != zeroHash32 and # finalised hash is set
314-
hc.chain.baseNumber() + 1 < h.number: # otherwise useless
316+
if f != zeroHash32: # finalised hash is set
315317

316-
if hc.session.mode == closed:
318+
if hc.chain.baseNumber() + 1 < h.number and # otherwise useless
319+
hc.session.mode == closed:
317320
# Set new session environment
318321
hc.session = HccSession( # start new session
319322
mode: collecting,
@@ -335,6 +338,9 @@ proc headUpdateFromCL(hc: HeaderChainRef; h: Header; f: Hash32) =
335338
# For logging and metrics
336339
hc.session.consHeadNum = h.number
337340
metrics.set(nec_sync_consensus_head, h.number.int64)
341+
if hc.chain.latestNumber <= h.number:
342+
metrics.set(nec_sync_distance_to_sync,
343+
(h.number - hc.chain.latestNumber).int64)
338344

339345
# ------------------------------------------------------------------------------
340346
# Public constructor/destructor et al.
@@ -361,7 +367,6 @@ proc clear*(hc: HeaderChainRef) =
361367
##
362368
hc.session.reset # clear session state object
363369
hc.persistClear() # clear database
364-
metrics.set(nec_sync_consensus_head, 0) # clear metrics register
365370
metrics.set(nec_sync_dangling, 0) # ditto
366371

367372
proc stop*(hc: HeaderChainRef) =
@@ -642,6 +647,12 @@ func latestConsHeadNumber*(hc: HeaderChainRef): BlockNumber =
642647
##
643648
hc.session.consHeadNum
644649

650+
proc updateMetrics*(hc: HeaderChainRef) =
651+
## Update/adjust some metrics, i.p. `nec_sync_distance_to_sync`
652+
if hc.chain.latestNumber <= hc.session.consHeadNum:
653+
metrics.set(nec_sync_distance_to_sync,
654+
(hc.session.consHeadNum - hc.chain.latestNumber).int64)
655+
645656
# ------------------------------------------------------------------------------
646657
# Public debugging helpers
647658
# ------------------------------------------------------------------------------

0 commit comments

Comments
 (0)