Skip to content

Commit

Permalink
chore(rln-relay): add isReady check
Browse files Browse the repository at this point in the history
  • Loading branch information
rymnc committed Sep 4, 2023
1 parent 4ed4145 commit bcd473d
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 2 deletions.
12 changes: 10 additions & 2 deletions waku/node/waku_node.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -903,3 +903,11 @@ proc stop*(node: WakuNode) {.async.} =
await node.wakuRlnRelay.stop()

node.started = false

proc isReady*(node: WakuNode) =
when defined(rln):
if node.wakuRlnRelay == nil:
return false
return node.wakuRlnRelay.isReady()
## TODO: add other protocol `isReady` checks
return true
1 change: 1 addition & 0 deletions waku/waku_rln_relay/group_manager/group_manager_base.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions waku/waku_rln_relay/group_manager/on_chain/group_manager.nim
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,9 @@ proc startOnchainSync(g: OnchainGroupManager): Future[void] {.async.} =
except CatchableError:
raise newException(ValueError, "failed to get the history/reconcile missed blocks: " & getCurrentExceptionMsg())

# rln is ready now
g.isReady = true

# listen to blockheaders and contract events
try:
await g.startListeningToEvents()
Expand Down
1 change: 1 addition & 0 deletions waku/waku_rln_relay/group_manager/static/group_manager.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 8 additions & 0 deletions waku/waku_rln_relay/rln_relay.nim
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,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,
Expand Down

0 comments on commit bcd473d

Please sign in to comment.