Skip to content

Conversation

@dguenther
Copy link
Contributor

@dguenther dguenther commented Mar 31, 2025

Motivation

@hughy and I have a basic implementation of validator custody for peerDAS.

We're planning to do more testing on this, but would appreciate a review on the architecture since we're still pretty new!

This relates to #7632 - If it merges, we'll update our PR to account for it.

Description

  • Centralizes custody values like sampledGroups and custodyGroups into CustodyConfig. CustodyConfig is now treated as a singleton.
  • Creates a new advertisedGroupCount in CustodyConfig, used for the custody group count in the node's metadata/ENR.
  • Adds setSamplingGroupCount and setAdvertisedGroupCount to NetworkCore API. Updated by an EventEmitter on CustodyConfig.
  • Adds LocalValidatorRegistry to track connected validators.
  • Updates custody requirement in chain.onForkChoiceFinalized.

Not Included

I'll open separate issues for these if we're okay merging this PR without them.

  • Backfilling groups when the target custody group count increases
  • Handling changes in other peers' custody group counts
  • Race conditions around group count changing during syncing

Closes #7619

dguenther and others added 19 commits March 25, 2025 12:36
- VALIDATOR_CUSTODY_REQUIREMENT
- BALANCE_PER_ADDITIONAL_CUSTODY_GROUP
- define getCustodyColumnsMeta as private method
Add targetCustodyGroupCount and advertisedCustodyGroupCount
use validator effective balances instead of raw balances assuming spec changes

for now do not use cached state to access effective balances. update if cached
state available when triggering updates to CustodyConfig

return CUSTODY_REQUIREMENT if validatorIndices is empty
- set target CGC based on latest finalized state
- convert getValidatorsCustodyRequirement to use CachedBeaconStateAllForks

- TODO: the chain does not currently have a means of identifying validator indices for the node
define LocalValidatorRegistry to track indices of validators that have
registered with the node.

read indices of local validators from LocalValidatorRegistry when updating
validator custody requirements.

borrow logic from ValidatorMonitor for registering and pruning validators from
the map in LocalValidatorRegistry.

register validators and prune validators in tandem from LocalValidatorRegistry and ValidatorMonitor.
TODO: re-use validator registry in ValidatorMonitor.

we need to be able to determine the indices of connected validators even if
metrics are disabled.
@CLAassistant
Copy link

CLAassistant commented Mar 31, 2025

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
0 out of 2 committers have signed the CLA.

❌ dguenther
❌ hughy
You have signed the CLA already but the status is still pending? Let us recheck it.

dguenther and others added 7 commits March 31, 2025 15:36
use existing BeaconProposerCache to access the list of indices of connected
validators

add method to BeaconProposerCache to access validator indices

connected validator clients call 'prepareBeaconProposer' every epoch which adds
or updates an entry in the BeaconProposerCache. we can use this cache instead
of introducing a duplicative data structure
Copy link
Member

@matthewkeil matthewkeil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great start !!!!

Copy link
Member

@matthewkeil matthewkeil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I spent some time thinking about what you have here and the architecture of Lodestar. There are a couple things that I think will help long-term. I also spent some time speaking with @twoeths to make sure we go down the right path.

Here are some design considerations that we may want to incorporate

  • Always using the custodyConfig directly to pull values.
  • Keeping a custodyConfig on the main thread and one on the network thread
  • Maintain update of attached validators and balances happening on the chain in onFinalizedEpoch
  • Pass update of custody to the network (on main thread) via the ChainEventEmitter
  • Pass update of custody to the network (on network thread) via worker api

Using the method that Tuyen employed we can use the custodyConfig from the chain object directly on the main thread network object which will keep those two in sync.

this.custodyConfig = modules.chain.custodyConfig;

I'm also thinking about breaking updateCustodyRequirement into two parts. First will be calculating the custody requirement and the second will be updating the custodyConfig(s). This way we can calculate the update in onFinalizedEpoch and then event the custodyRequirement value to the network object on both main and network threads easily.

const custodyRequirement = calculateCustodyRequirement(state, validatorIndices, config);
this.custodyConfig.updateTargetCustody(custodyRequirement);
this.events.emit(ChainEvent.UpdateTargetCustody, custodyRequirement);

In the network object there would be an onUpdateTargetCustody that would be the handler for that event (kind of what you have now but will listen to the chain event bus instead of the custodyConfig object). The handler would call this.getApi().updateTargetCustody(custodyRequirement) to send the value to the network thread so that object could be updated for the PeerManager and other consumers on the network thread.

hughy and others added 11 commits April 3, 2025 10:42
reverts changes leftover from an earlier approach to tracking local validators
alongside the ValidatorMonitor

- removes 'getLocalValidatorIndices' method from ValidatorMonitor
- sleeps during onClockSlot only if metrics enabled
- define CustodyConfigOpts type to encapsulate options for CustodyConfig
- by default, enable validator custody
- add separate method for calculating target custody group count to prevent
  calculation if validator custody disabled
- add CLI flag, 'chain.noValidatorCustody', to disable validator custody
- remove CustodyConfigOpts
- remove calculateTargetCustodyGroupCount
- condition all custody update logic in onForkChoiceFinalized on
  noValidatorCustody flag
@dguenther dguenther marked this pull request as ready for review April 8, 2025 04:15
@dguenther dguenther requested a review from a team as a code owner April 8, 2025 04:16
Copy link
Member

@matthewkeil matthewkeil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just the small nit about using the getter so it consistent with how its done for the chain config. Looks great otherwise!!

Copy link
Member

@matthewkeil matthewkeil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!! 🚀

@matthewkeil matthewkeil merged commit 08ddb0b into ChainSafe:peerDAS Apr 14, 2025
2 checks passed
@dguenther dguenther deleted the peerDAS-validator-custody branch April 17, 2025 15:09
@wemeetagain
Copy link
Member

🎉 This PR is included in v1.34.0 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants