diff --git a/waku/node/waku_node.nim b/waku/node/waku_node.nim index 5df6200a19..c7724c6c86 100644 --- a/waku/node/waku_node.nim +++ b/waku/node/waku_node.nim @@ -732,8 +732,8 @@ proc lightpushPublish*(node: WakuNode, pubsubTopic: Option[PubsubTopic], message when defined(rln): proc mountRlnRelay*(node: WakuNode, rlnConf: WakuRlnConfig, - spamHandler: Option[SpamHandler] = none(SpamHandler), - registrationHandler: Option[RegistrationHandler] = none(RegistrationHandler)) {.async.} = + spamHandler = none(SpamHandler), + registrationHandler = none(RegistrationHandler)) {.async.} = info "mounting rln relay" if node.wakuRelay.isNil(): @@ -903,3 +903,11 @@ proc stop*(node: WakuNode) {.async.} = await node.wakuRlnRelay.stop() node.started = false + +proc isReady*(node: WakuNode): bool = + when defined(rln): + if node.wakuRlnRelay == nil: + return false + return node.wakuRlnRelay.isReady() + ## TODO: add other protocol `isReady` checks + return true diff --git a/waku/waku_rln_relay/group_manager/group_manager_base.nim b/waku/waku_rln_relay/group_manager/group_manager_base.nim index 0dc1ceb307..79bf2835bb 100644 --- a/waku/waku_rln_relay/group_manager/group_manager_base.nim +++ b/waku/waku_rln_relay/group_manager/group_manager_base.nim @@ -41,6 +41,7 @@ type initialized*: bool latestIndex*: MembershipIndex validRoots*: Deque[MerkleNode] + isReady*: bool # This proc is used to initialize the group manager # Any initialization logic should be implemented here diff --git a/waku/waku_rln_relay/group_manager/on_chain/group_manager.nim b/waku/waku_rln_relay/group_manager/on_chain/group_manager.nim index 56c82cb27b..1427b45aef 100644 --- a/waku/waku_rln_relay/group_manager/on_chain/group_manager.nim +++ b/waku/waku_rln_relay/group_manager/on_chain/group_manager.nim @@ -388,6 +388,8 @@ proc startOnchainSync(g: OnchainGroupManager): Future[void] {.async.} = # listen to blockheaders and contract events try: await g.startListeningToEvents() + # rln is ready now + g.isReady = true except CatchableError: raise newException(ValueError, "failed to start listening to events: " & getCurrentExceptionMsg()) diff --git a/waku/waku_rln_relay/group_manager/static/group_manager.nim b/waku/waku_rln_relay/group_manager/static/group_manager.nim index c2ccae8c21..0b0af9cec3 100644 --- a/waku/waku_rln_relay/group_manager/static/group_manager.nim +++ b/waku/waku_rln_relay/group_manager/static/group_manager.nim @@ -36,6 +36,7 @@ method init*(g: StaticGroupManager): Future[void] {.async,gcsafe.} = g.latestIndex += MembershipIndex(idCommitments.len() - 1) g.initialized = true + g.isReady = true return diff --git a/waku/waku_rln_relay/rln_relay.nim b/waku/waku_rln_relay/rln_relay.nim index 887e28d00f..6f20ce36f7 100644 --- a/waku/waku_rln_relay/rln_relay.nim +++ b/waku/waku_rln_relay/rln_relay.nim @@ -400,6 +400,14 @@ proc mount(conf: WakuRlnConfig, return WakuRLNRelay(groupManager: groupManager, messageBucket: messageBucket) +proc isReady*(rlnPeer: WakuRLNRelay): bool = + ## returns true if the rln-relay protocol is ready to relay messages + ## returns false otherwise + + # could be nil during startup + if rlnPeer.groupManager == nil: + return false + return rlnPeer.groupManager.isReady proc new*(T: type WakuRlnRelay, conf: WakuRlnConfig,