display current fork (+ next fork if applicable) in slot start / status (#5731)

Extend slot start message and default status bar with information about
current head fork and the next fork transition (corresponding to head).
This is useful to know whether a synced client is aware of a future fork
and can also be useful when syncing from old forks to follow progress
across the various forks.

```
 peers: 8 ❯ finalized: 741c2ce2:230474 ❯ head: b330f58b:230477:20 ❯ fork: Capella (next: Deneb:231680) ❯ time: 230599:24 (7379192) ❯ sync: 00h24m (99.63%) 2.6492slots/s (QwQUwQPQDQ:7375263)/opt
```

```
INF 2024-01-12 12:18:00.001+01:00 Slot start                                 topics="beacnde" slot=7379190 epoch=230599 fork="Capella (next: Deneb:231680)" sync="--h--m (99.62%) 0.0000slots/s (wwwwwwwwww:7375167)/opt" peers=0 head=741c2ce2:7375168 finalized=230472:723abe7e delay=1ms861us
```
This commit is contained in:
Etan Kissling 2024-01-12 21:40:34 +01:00 committed by GitHub
parent b54bbdecae
commit 16256a5230
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 1 deletions

View File

@ -440,6 +440,7 @@ type
defaultValue: "peers: $connected_peers;" &
"finalized: $finalized_root:$finalized_epoch;" &
"head: $head_root:$head_epoch:$head_epoch_slot;" &
"fork: $consensus_fork;" &
"time: $epoch:$epoch_slot ($slot);" &
"sync: $sync_status|" &
"ETH: $attached_validators_balance"

View File

@ -884,7 +884,7 @@ func forkDigests(node: BeaconNode): auto =
# https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.5/specs/phase0/p2p-interface.md#attestation-subnet-subscription
proc updateAttestationSubnetHandlers(node: BeaconNode, slot: Slot) =
if node.gossipState.card == 0:
# When disconnected, updateGossipState is responsible for all things
# When disconnected, updateBlocksGossipStatus is responsible for all things
# subnets - in particular, it will remove subscriptions on the edge where
# we enter the disconnected state.
return
@ -1507,6 +1507,18 @@ proc onSlotEnd(node: BeaconNode, slot: Slot) {.async.} =
await node.updateGossipStatus(slot + 1)
func formatForkSchedule(node: BeaconNode): string =
let consensusFork =
node.dag.cfg.consensusForkAtEpoch(node.dag.head.slot.epoch)
var res = $consensusFork
if consensusFork != ConsensusFork.high:
let
nextConsensusFork = consensusFork.succ()
nextForkEpoch = node.dag.cfg.consensusForkEpoch(nextConsensusFork)
if nextForkEpoch != FAR_FUTURE_EPOCH:
res.add " (next: " & $nextConsensusFork & ":" & $nextForkEpoch & ")"
res
func syncStatus(node: BeaconNode, wallSlot: Slot): string =
let optimistic_head = not node.dag.head.executionValid
if node.syncManager.inProgress:
@ -1550,6 +1562,7 @@ proc onSlotStart(node: BeaconNode, wallTime: BeaconTime,
info "Slot start",
slot = shortLog(wallSlot),
epoch = shortLog(wallSlot.epoch),
fork = node.formatForkSchedule(),
sync = node.syncStatus(wallSlot),
peers = len(node.network.peerPool),
head = shortLog(node.dag.head),
@ -1982,6 +1995,9 @@ when not defined(windows):
of "attached_validators_balance":
formatGwei(node.attachedValidatorBalanceTotal)
of "consensus_fork":
node.formatForkSchedule()
of "sync_status":
node.syncStatus(node.currentSlot)
else:

View File

@ -816,6 +816,20 @@ func setStateRoot*(x: var ForkedHashedBeaconState, root: Eth2Digest) =
withState(x): forkyState.root = root
{.pop.}
func consensusForkEpoch*(
cfg: RuntimeConfig, consensusFork: ConsensusFork): Epoch =
case consensusFork
of ConsensusFork.Deneb:
cfg.DENEB_FORK_EPOCH
of ConsensusFork.Capella:
cfg.CAPELLA_FORK_EPOCH
of ConsensusFork.Bellatrix:
cfg.BELLATRIX_FORK_EPOCH
of ConsensusFork.Altair:
cfg.ALTAIR_FORK_EPOCH
of ConsensusFork.Phase0:
GENESIS_EPOCH
func consensusForkAtEpoch*(cfg: RuntimeConfig, epoch: Epoch): ConsensusFork =
## Return the current fork for the given epoch.
static: