From 16256a523035a6d2cbdf018c0ad2372f032e2b7c Mon Sep 17 00:00:00 2001 From: Etan Kissling Date: Fri, 12 Jan 2024 21:40:34 +0100 Subject: [PATCH] display current fork (+ next fork if applicable) in slot start / status (#5731) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 ``` --- beacon_chain/conf.nim | 1 + beacon_chain/nimbus_beacon_node.nim | 18 +++++++++++++++++- beacon_chain/spec/forks.nim | 14 ++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/beacon_chain/conf.nim b/beacon_chain/conf.nim index c655e4cd2..ed0229b1c 100644 --- a/beacon_chain/conf.nim +++ b/beacon_chain/conf.nim @@ -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" diff --git a/beacon_chain/nimbus_beacon_node.nim b/beacon_chain/nimbus_beacon_node.nim index 8be8cb117..8f95a4885 100644 --- a/beacon_chain/nimbus_beacon_node.nim +++ b/beacon_chain/nimbus_beacon_node.nim @@ -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: diff --git a/beacon_chain/spec/forks.nim b/beacon_chain/spec/forks.nim index e7a26c589..c0ddaa6be 100644 --- a/beacon_chain/spec/forks.nim +++ b/beacon_chain/spec/forks.nim @@ -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: