allow always-on subscription to all attestation subnets when gossiping (#2225)
* allow always-on subscription to all attestation subnets when gossiping * in subscribe-all-subnets mode, consider all subnets to be stability subnets for ENR purposes
This commit is contained in:
parent
f5efcc8669
commit
dde973e2d4
|
@ -115,6 +115,11 @@ type
|
|||
desc: "Node agent string which is used as identifier in network"
|
||||
name: "agent-string" }: string
|
||||
|
||||
subscribeAllSubnets* {.
|
||||
defaultValue: false,
|
||||
desc: "Subscribe to all attestation subnet topics when gossiping"
|
||||
name: "subscribe-all-subnets" }: bool
|
||||
|
||||
case cmd* {.
|
||||
command
|
||||
defaultValue: noCommand }: BNStartUpCmd
|
||||
|
|
|
@ -377,6 +377,7 @@ func getStabilitySubnets(stabilitySubnets: auto): set[uint8] =
|
|||
|
||||
proc cycleAttestationSubnets(node: BeaconNode, wallSlot: Slot) =
|
||||
static: doAssert RANDOM_SUBNETS_PER_VALIDATOR == 1
|
||||
doAssert not node.config.subscribeAllSubnets
|
||||
|
||||
# Only know RANDAO mix, which determines shuffling seed, one epoch in
|
||||
# advance. When node.chainDag.headState.data.data.slot.epoch is ahead
|
||||
|
@ -434,6 +435,10 @@ proc cycleAttestationSubnets(node: BeaconNode, wallSlot: Slot) =
|
|||
|
||||
node.installAttestationSubnetHandlers(newSubnets)
|
||||
|
||||
if not node.config.subscribeAllSubnets:
|
||||
# In subscribeAllSubnets mode, this only gets set once, at initial subnet
|
||||
# attestation handler creation, since they're all considered as stability
|
||||
# subnets in that case.
|
||||
let stabilitySubnets =
|
||||
getStabilitySubnets(node.attestationSubnets.stabilitySubnets)
|
||||
if stabilitySubnets != prevStabilitySubnets:
|
||||
|
@ -441,6 +446,9 @@ proc cycleAttestationSubnets(node: BeaconNode, wallSlot: Slot) =
|
|||
|
||||
proc getAttestationSubnetHandlers(node: BeaconNode) =
|
||||
var initialSubnets: set[uint8]
|
||||
# If/when this stops subscribing to all attestation subnet handlers, the
|
||||
# subscribeAllSubnets implementation needs modification from its current
|
||||
# no-op/exploit-defaults version.
|
||||
for i in 0'u8 ..< ATTESTATION_SUBNET_COUNT:
|
||||
initialSubnets.incl i
|
||||
|
||||
|
@ -458,6 +466,9 @@ proc getAttestationSubnetHandlers(node: BeaconNode) =
|
|||
expiration: wallEpoch + getStabilitySubnetLength())
|
||||
|
||||
node.updateStabilitySubnetMetadata(
|
||||
if node.config.subscribeAllSubnets:
|
||||
initialSubnets
|
||||
else:
|
||||
node.attestationSubnets.stabilitySubnets.getStabilitySubnets)
|
||||
|
||||
# Sets the "current" and "future" attestation subnets. One of these gets
|
||||
|
@ -474,7 +485,6 @@ proc getAttestationSubnetHandlers(node: BeaconNode) =
|
|||
node.installAttestationSubnetHandlers(initialSubnets)
|
||||
|
||||
proc addMessageHandlers(node: BeaconNode) =
|
||||
# As a side-effect, this gets the attestation subnets too.
|
||||
node.network.subscribe(node.topicBeaconBlocks, enableTopicMetrics = true)
|
||||
node.network.subscribe(getAttesterSlashingsTopic(node.forkDigest))
|
||||
node.network.subscribe(getProposerSlashingsTopic(node.forkDigest))
|
||||
|
@ -482,7 +492,6 @@ proc addMessageHandlers(node: BeaconNode) =
|
|||
node.network.subscribe(getAggregateAndProofsTopic(node.forkDigest), enableTopicMetrics = true)
|
||||
node.getAttestationSubnetHandlers()
|
||||
|
||||
|
||||
func getTopicSubscriptionEnabled(node: BeaconNode): bool =
|
||||
node.attestationSubnets.enabled
|
||||
|
||||
|
@ -548,8 +557,10 @@ proc updateGossipStatus(node: BeaconNode, slot: Slot) =
|
|||
syncQueueLen
|
||||
node.removeMessageHandlers()
|
||||
|
||||
# Subscription or unsubscription might have occurred; recheck.
|
||||
if node.getTopicSubscriptionEnabled:
|
||||
# Subscription or unsubscription might have occurred; recheck. Since Nimbus
|
||||
# initially subscribes to all subnets, simply do not ever cycle attestation
|
||||
# subnets and they'll all remain subscribed.
|
||||
if node.getTopicSubscriptionEnabled and not node.config.subscribeAllSubnets:
|
||||
# This exits early all but one call each epoch.
|
||||
node.cycleAttestationSubnets(slot)
|
||||
|
||||
|
|
Loading…
Reference in New Issue