mirror of
https://github.com/status-im/nimbus-eth2.git
synced 2025-02-19 17:58:23 +00:00
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"
|
desc: "Node agent string which is used as identifier in network"
|
||||||
name: "agent-string" }: string
|
name: "agent-string" }: string
|
||||||
|
|
||||||
|
subscribeAllSubnets* {.
|
||||||
|
defaultValue: false,
|
||||||
|
desc: "Subscribe to all attestation subnet topics when gossiping"
|
||||||
|
name: "subscribe-all-subnets" }: bool
|
||||||
|
|
||||||
case cmd* {.
|
case cmd* {.
|
||||||
command
|
command
|
||||||
defaultValue: noCommand }: BNStartUpCmd
|
defaultValue: noCommand }: BNStartUpCmd
|
||||||
|
@ -377,6 +377,7 @@ func getStabilitySubnets(stabilitySubnets: auto): set[uint8] =
|
|||||||
|
|
||||||
proc cycleAttestationSubnets(node: BeaconNode, wallSlot: Slot) =
|
proc cycleAttestationSubnets(node: BeaconNode, wallSlot: Slot) =
|
||||||
static: doAssert RANDOM_SUBNETS_PER_VALIDATOR == 1
|
static: doAssert RANDOM_SUBNETS_PER_VALIDATOR == 1
|
||||||
|
doAssert not node.config.subscribeAllSubnets
|
||||||
|
|
||||||
# Only know RANDAO mix, which determines shuffling seed, one epoch in
|
# Only know RANDAO mix, which determines shuffling seed, one epoch in
|
||||||
# advance. When node.chainDag.headState.data.data.slot.epoch is ahead
|
# advance. When node.chainDag.headState.data.data.slot.epoch is ahead
|
||||||
@ -434,6 +435,10 @@ proc cycleAttestationSubnets(node: BeaconNode, wallSlot: Slot) =
|
|||||||
|
|
||||||
node.installAttestationSubnetHandlers(newSubnets)
|
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 =
|
let stabilitySubnets =
|
||||||
getStabilitySubnets(node.attestationSubnets.stabilitySubnets)
|
getStabilitySubnets(node.attestationSubnets.stabilitySubnets)
|
||||||
if stabilitySubnets != prevStabilitySubnets:
|
if stabilitySubnets != prevStabilitySubnets:
|
||||||
@ -441,6 +446,9 @@ proc cycleAttestationSubnets(node: BeaconNode, wallSlot: Slot) =
|
|||||||
|
|
||||||
proc getAttestationSubnetHandlers(node: BeaconNode) =
|
proc getAttestationSubnetHandlers(node: BeaconNode) =
|
||||||
var initialSubnets: set[uint8]
|
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:
|
for i in 0'u8 ..< ATTESTATION_SUBNET_COUNT:
|
||||||
initialSubnets.incl i
|
initialSubnets.incl i
|
||||||
|
|
||||||
@ -458,6 +466,9 @@ proc getAttestationSubnetHandlers(node: BeaconNode) =
|
|||||||
expiration: wallEpoch + getStabilitySubnetLength())
|
expiration: wallEpoch + getStabilitySubnetLength())
|
||||||
|
|
||||||
node.updateStabilitySubnetMetadata(
|
node.updateStabilitySubnetMetadata(
|
||||||
|
if node.config.subscribeAllSubnets:
|
||||||
|
initialSubnets
|
||||||
|
else:
|
||||||
node.attestationSubnets.stabilitySubnets.getStabilitySubnets)
|
node.attestationSubnets.stabilitySubnets.getStabilitySubnets)
|
||||||
|
|
||||||
# Sets the "current" and "future" attestation subnets. One of these gets
|
# Sets the "current" and "future" attestation subnets. One of these gets
|
||||||
@ -474,7 +485,6 @@ proc getAttestationSubnetHandlers(node: BeaconNode) =
|
|||||||
node.installAttestationSubnetHandlers(initialSubnets)
|
node.installAttestationSubnetHandlers(initialSubnets)
|
||||||
|
|
||||||
proc addMessageHandlers(node: BeaconNode) =
|
proc addMessageHandlers(node: BeaconNode) =
|
||||||
# As a side-effect, this gets the attestation subnets too.
|
|
||||||
node.network.subscribe(node.topicBeaconBlocks, enableTopicMetrics = true)
|
node.network.subscribe(node.topicBeaconBlocks, enableTopicMetrics = true)
|
||||||
node.network.subscribe(getAttesterSlashingsTopic(node.forkDigest))
|
node.network.subscribe(getAttesterSlashingsTopic(node.forkDigest))
|
||||||
node.network.subscribe(getProposerSlashingsTopic(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.network.subscribe(getAggregateAndProofsTopic(node.forkDigest), enableTopicMetrics = true)
|
||||||
node.getAttestationSubnetHandlers()
|
node.getAttestationSubnetHandlers()
|
||||||
|
|
||||||
|
|
||||||
func getTopicSubscriptionEnabled(node: BeaconNode): bool =
|
func getTopicSubscriptionEnabled(node: BeaconNode): bool =
|
||||||
node.attestationSubnets.enabled
|
node.attestationSubnets.enabled
|
||||||
|
|
||||||
@ -548,8 +557,10 @@ proc updateGossipStatus(node: BeaconNode, slot: Slot) =
|
|||||||
syncQueueLen
|
syncQueueLen
|
||||||
node.removeMessageHandlers()
|
node.removeMessageHandlers()
|
||||||
|
|
||||||
# Subscription or unsubscription might have occurred; recheck.
|
# Subscription or unsubscription might have occurred; recheck. Since Nimbus
|
||||||
if node.getTopicSubscriptionEnabled:
|
# 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.
|
# This exits early all but one call each epoch.
|
||||||
node.cycleAttestationSubnets(slot)
|
node.cycleAttestationSubnets(slot)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user