Skip to content

Commit

Permalink
display current fork (+ next fork if applicable) in slot start / status
Browse files Browse the repository at this point in the history
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
```
  • Loading branch information
etan-status committed Jan 12, 2024
1 parent b54bbde commit 670da0f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions beacon_chain/conf.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
18 changes: 17 additions & 1 deletion beacon_chain/nimbus_beacon_node.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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:
Expand Down
14 changes: 14 additions & 0 deletions beacon_chain/spec/forks.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 670da0f

Please sign in to comment.