Skip to content

Commit

Permalink
show vanity logs on compounding activation of known validators (#6882)
Browse files Browse the repository at this point in the history
  • Loading branch information
tersec authored Jan 30, 2025
1 parent 67ac6fc commit 7a6cc69
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 27 deletions.
32 changes: 29 additions & 3 deletions beacon_chain/consensus_object_pools/blockchain_dag.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2322,7 +2322,7 @@ proc loadExecutionBlockHash*(

from std/packedsets import PackedSet, incl, items

func getValidatorChangeStatuses(
func getBlsToExecutionChangeStatuses(
state: ForkedHashedBeaconState, vis: openArray[ValidatorIndex]):
PackedSet[ValidatorIndex] =
var res: PackedSet[ValidatorIndex]
Expand All @@ -2338,6 +2338,7 @@ func checkBlsToExecutionChanges(
# Within each fork, BLS_WITHDRAWAL_PREFIX to ETH1_ADDRESS_WITHDRAWAL_PREFIX
# and never ETH1_ADDRESS_WITHDRAWAL_PREFIX to BLS_WITHDRAWAL_PREFIX. Latter
# can still happen via reorgs.
#
# Cases:
# 1) unchanged (BLS_WITHDRAWAL_PREFIX or ETH1_ADDRESS_WITHDRAWAL_PREFIX) from
# old to new head.
Expand All @@ -2352,7 +2353,25 @@ func checkBlsToExecutionChanges(
# Since it tracks head, it's possible reorgs trigger reporting the same
# validator indices multiple times; this is fine.
withState(state):
anyIt( vis, forkyState.data.validators[it].has_eth1_withdrawal_credential)
anyIt(vis, forkyState.data.validators[it].has_eth1_withdrawal_credential)

func getCompoundingStatuses(
state: ForkedHashedBeaconState, vis: openArray[ValidatorIndex]):
PackedSet[ValidatorIndex] =
var res: PackedSet[ValidatorIndex]
withState(state):
for vi in vis:
if forkyState.data.validators[vi].withdrawal_credentials.data[0] !=
COMPOUNDING_WITHDRAWAL_PREFIX:
res.incl vi
res

func checkCompoundingChanges(
state: ForkedHashedBeaconState, vis: PackedSet[ValidatorIndex]): bool =
# Since it tracks head, it's possible reorgs trigger reporting the same
# validator indices multiple times; this is fine.
withState(state):
anyIt(vis, forkyState.data.validators[it].has_compounding_withdrawal_credential)

proc updateHead*(
dag: ChainDAGRef, newHead: BlockRef, quarantine: var Quarantine,
Expand Down Expand Up @@ -2393,7 +2412,9 @@ proc updateHead*(
lastHeadStateRoot = getStateRoot(dag.headState)
lastHeadMergeComplete = dag.headState.is_merge_transition_complete()
lastHeadKind = dag.headState.kind
lastKnownValidatorsChangeStatuses = getValidatorChangeStatuses(
lastKnownValidatorsChangeStatuses = getBlsToExecutionChangeStatuses(
dag.headState, knownValidators)
lastKnownCompoundingChangeStatuses = getCompoundingStatuses(
dag.headState, knownValidators)

# Start off by making sure we have the right state - updateState will try
Expand Down Expand Up @@ -2437,6 +2458,11 @@ proc updateHead*(
dag.headState, lastKnownValidatorsChangeStatuses):
dag.vanityLogs.onKnownBlsToExecutionChange()

if dag.vanityLogs.onKnownCompoundingChange != nil and
checkCompoundingChanges(
dag.headState, lastKnownCompoundingChangeStatuses):
dag.vanityLogs.onKnownCompoundingChange()

dag.db.putHeadBlock(newHead.root)

updateBeaconMetrics(dag.headState, dag.head.bid, cache)
Expand Down
28 changes: 11 additions & 17 deletions beacon_chain/consensus_object_pools/consensus_manager.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# beacon_chain
# Copyright (c) 2018-2024 Status Research & Development GmbH
# Copyright (c) 2018-2025 Status Research & Development GmbH
# Licensed and distributed under either of
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
Expand Down Expand Up @@ -221,23 +221,17 @@ proc updateExecutionClientHead*(

func getKnownValidatorsForBlsChangeTracking(
self: ConsensusManager, newHead: BlockRef): seq[ValidatorIndex] =
# Ensure that large nodes won't be overloaded by a nice-to-have, but
# Ensure that large nodes won't be overwhelmed by a nice-to-have, but
# inessential cosmetic feature.
const MAX_CHECKED_INDICES = 64

if newHead.bid.slot.epoch >= self.dag.cfg.CAPELLA_FORK_EPOCH:
var res = newSeqOfCap[ValidatorIndex](min(
len(self.actionTracker.knownValidators), MAX_CHECKED_INDICES))
for vi in self.actionTracker.knownValidators.keys():
res.add vi
if res.len >= MAX_CHECKED_INDICES:
break
res
else:
# It is not possible for any BLS to execution changes, for any validator,
# to have been yet processed.
# https://github.com/nim-lang/Nim/issues/19802
(static(@[]))
const MAX_CHECKED_INDICES = 32

var res = newSeqOfCap[ValidatorIndex](min(
len(self.actionTracker.knownValidators), MAX_CHECKED_INDICES))
for vi in self.actionTracker.knownValidators.keys():
res.add vi
if res.len >= MAX_CHECKED_INDICES:
break
res

proc updateHead*(self: var ConsensusManager, newHead: BlockRef) =
## Trigger fork choice and update the DAG with the new head block
Expand Down
12 changes: 8 additions & 4 deletions beacon_chain/consensus_object_pools/vanity_logs/vanity_logs.nim
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# beacon_chain
# Copyright (c) 2022-2024 Status Research & Development GmbH
# Copyright (c) 2022-2025 Status Research & Development GmbH
# Licensed and distributed under either of
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
# at your option. This file may not be copied, modified, or distributed except according to those terms.

{.push raises: [].}

import
std/os,
chronicles
import chronicles

from std/os import `/`

type
LogProc = proc() {.gcsafe, raises: [].}
Expand Down Expand Up @@ -38,6 +38,10 @@ type
# in case of chain reorgs around the upgrade.
onUpgradeToElectra*: LogProc

# Gets displayed on a change to compounding for a validator known to the
# known in a head block.
onKnownCompoundingChange*: LogProc

# Created by https://beatscribe.com (beatscribe#1008 on Discord)
# These need to be the main body of the log not to be reformatted or escaped.

Expand Down
10 changes: 7 additions & 3 deletions beacon_chain/nimbus_beacon_node.nim
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,17 @@ func getVanityLogs(stdoutKind: StdoutLogKind): VanityLogs =
onUpgradeToCapella: capellaColor,
onKnownBlsToExecutionChange: capellaBlink,
onUpgradeToDeneb: denebColor,
onUpgradeToElectra: electraColor)
onUpgradeToElectra: electraColor,
onKnownCompoundingChange: electraBlink)
of StdoutLogKind.NoColors:
VanityLogs(
onMergeTransitionBlock: bellatrixMono,
onFinalizedMergeTransitionBlock: bellatrixMono,
onUpgradeToCapella: capellaMono,
onKnownBlsToExecutionChange: capellaMono,
onUpgradeToDeneb: denebMono,
onUpgradeToElectra: electraMono)
onUpgradeToElectra: electraMono,
onKnownCompoundingChange: electraMono)
of StdoutLogKind.Json, StdoutLogKind.None:
VanityLogs(
onMergeTransitionBlock:
Expand All @@ -173,7 +175,9 @@ func getVanityLogs(stdoutKind: StdoutLogKind): VanityLogs =
onUpgradeToDeneb:
(proc() = notice "🐟 Proto-Danksharding is ON 🐟"),
onUpgradeToElectra:
(proc() = notice "πŸ¦’ Compounding is ON πŸ¦’"))
(proc() = notice "πŸ¦’ Compounding is available πŸ¦’"),
onKnownCompoundingChange:
(proc() = notice "πŸ¦’ Compounding is activated πŸ¦’"))

func getVanityMascot(consensusFork: ConsensusFork): string =
case consensusFork
Expand Down

0 comments on commit 7a6cc69

Please sign in to comment.