diff --git a/beacon_chain/nimbus_beacon_node.nim b/beacon_chain/nimbus_beacon_node.nim index 1a9101a90..e6778b966 100644 --- a/beacon_chain/nimbus_beacon_node.nim +++ b/beacon_chain/nimbus_beacon_node.nim @@ -793,9 +793,30 @@ proc removePhase0MessageHandlers(node: BeaconNode) = proc addAltairMessageHandlers(node: BeaconNode, slot: Slot) = node.addPhase0MessageHandlers(node.dag.forkDigests.altair) + var syncnets: BitArray[SYNC_COMMITTEE_SUBNET_COUNT] + + # TODO: What are the best topic params for this? + for committeeIdx in allSyncCommittees(): + closureScope: + let idx = committeeIdx + # TODO This should be done in dynamic way in trackSyncCommitteeTopics + node.network.subscribe(getSyncCommitteeTopic(node.dag.forkDigests.altair, idx), basicParams) + syncnets.setBit(idx.asInt) + + node.network.subscribe(getSyncCommitteeContributionAndProofTopic(node.dag.forkDigests.altair), basicParams) + node.network.updateSyncnetsMetadata(syncnets) + proc removeAltairMessageHandlers(node: BeaconNode) = node.removePhase0MessageHandlers(node.dag.forkDigests.altair) + for committeeIdx in allSyncCommittees(): + closureScope: + let idx = committeeIdx + # TODO This should be done in dynamic way in trackSyncCommitteeTopics + node.network.unsubscribe(getSyncCommitteeTopic(node.dag.forkDigests.altair, idx)) + + node.network.unsubscribe(getSyncCommitteeContributionAndProofTopic(node.dag.forkDigests.altair)) + func getTopicSubscriptionEnabled(node: BeaconNode): bool = node.attestationSubnets.enabled @@ -820,7 +841,11 @@ proc setupDoppelgangerDetection(node: BeaconNode, slot: Slot) = broadcastStartEpoch = node.processor.doppelgangerDetection.broadcastStartEpoch -proc updateGossipStatus(node: BeaconNode, slot: Slot) = +proc trackSyncCommitteeTopics*(node: BeaconNode) = + # TODO + discard + +proc updateGossipStatus(node: BeaconNode, slot: Slot) {.raises: [Defect, CatchableError].} = # Syncing tends to be ~1 block/s, and allow for an epoch of time for libp2p # subscribing to spin up. The faster the sync, the more wallSlot - headSlot # lead time is required @@ -1256,6 +1281,20 @@ proc installMessageValidators(node: BeaconNode) = proc (signedVoluntaryExit: SignedVoluntaryExit): ValidationResult = node.processor[].voluntaryExitValidator(signedVoluntaryExit)) + for committeeIdx in allSyncCommittees(): + closureScope: + let idx = committeeIdx + node.network.addValidator( + getSyncCommitteeTopic(node.dag.forkDigests.altair, idx), + # This proc needs to be within closureScope; don't lift out of loop. + proc(msg: SyncCommitteeMessage): ValidationResult = + node.processor.syncCommitteeMsgValidator(msg, idx)) + + node.network.addValidator( + getSyncCommitteeContributionAndProofTopic(node.dag.forkDigests.altair), + proc(msg: SignedContributionAndProof): ValidationResult = + node.processor.syncCommitteeContributionValidator(msg)) + proc stop*(node: BeaconNode) = bnStatus = BeaconNodeStatus.Stopping notice "Graceful shutdown"