Skip to content

Commit

Permalink
fix(discv5): Fixing issue that prevented the wakunode2 from starting (#…
Browse files Browse the repository at this point in the history
…1829)

* Fixing issue that prevented the wakunode2 from starting

The issue was introduced in PR#1818.

Before this commit, the `wakunode2` app crashed with the next error:

ERR 2023-06-27 15:57:27.268+00:00 5/7 Starting node and protocols failed
topics="wakunode main" tid=1 file=wakunode2.nim:92 error="failed to
start waku discovery v5: "

* fix tests accordingly

* publisher.nim, subscriber.nim: fix
  • Loading branch information
Ivansete-status authored Jun 27, 2023
1 parent ae05f0a commit 3aefade
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 7 deletions.
2 changes: 1 addition & 1 deletion apps/wakunode2/app.nim
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ proc startNode(node: WakuNode, conf: WakuNodeConf,

proc startApp*(app: App): Future[AppResult[void]] {.async.} =
if app.wakuDiscv5.isSome():
let res = await app.wakuDiscv5.get().start()
let res = app.wakuDiscv5.get().start()

if res.isErr():
return err("failed to start waku discovery v5: " & res.error)
Expand Down
2 changes: 1 addition & 1 deletion examples/v2/publisher.nim
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ proc setupAndPublish(rng: ref HmacDrbgContext) {.async.} =
await node.mountRelay()
node.peerManager.start()

let discv5Res = await wakuDiscv5.start()
let discv5Res = wakuDiscv5.start()
if discv5Res.isErr():
error "failed to start discv5", error= discv5Res.error
quit(1)
Expand Down
2 changes: 1 addition & 1 deletion examples/v2/subscriber.nim
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ proc setupAndSubscribe(rng: ref HmacDrbgContext) {.async.} =
await node.mountRelay()
node.peerManager.start()

let discv5Res = await wakuDiscv5.start()
let discv5Res = wakuDiscv5.start()
if discv5Res.isErr():
error "failed to start discv5", error = discv5Res.error
quit(1)
Expand Down
21 changes: 19 additions & 2 deletions tests/v2/test_waku_discv5.nim
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,14 @@ procSuite "Waku Discovery v5":
bootstrapRecords = @[record1, record2]
)

await allFutures(node1.start(), node2.start(), node3.start())
let res1 = node1.start()
assert res1.isOk(), res1.error

let res2 = node2.start()
assert res2.isOk(), res2.error

let res3 = node3.start()
assert res3.isOk(), res3.error

## When
let res = await node3.findRandomPeers()
Expand Down Expand Up @@ -231,7 +238,17 @@ procSuite "Waku Discovery v5":
)

# Start nodes' discoveryV5 protocols
await allFutures(node1.start(), node2.start(), node3.start(), node4.start())
let res1 = node1.start()
assert res1.isOk(), res1.error

let res2 = node2.start()
assert res2.isOk(), res2.error

let res3 = node3.start()
assert res3.isOk(), res3.error

let res4 = node4.start()
assert res4.isOk(), res4.error

## Given
let recordPredicate: WakuDiscv5Predicate = proc(record: waku_enr.Record): bool =
Expand Down
5 changes: 4 additions & 1 deletion tests/v2/test_waku_peer_exchange.nim
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,10 @@ procSuite "Waku Peer Exchange":


await allFutures(node1.start(), node2.start(), node3.start())
await allFutures(disc1.start(), disc2.start())
let resultDisc1StartRes = disc1.start()
assert resultDisc1StartRes.isOk(), resultDisc1StartRes.error
let resultDisc2StartRes = disc2.start()
assert resultDisc2StartRes.isOk(), resultDisc2StartRes.error
asyncSpawn disc1.searchLoop(node1.peerManager, none(enr.Record))
asyncSpawn disc2.searchLoop(node2.peerManager, none(enr.Record))

Expand Down
4 changes: 3 additions & 1 deletion waku/v2/waku_discv5.nim
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ proc searchLoop*(wd: WakuDiscoveryV5, peerManager: PeerManager, record: Option[e
# Also, give some time to dial the discovered nodes and update stats, etc.
await sleepAsync(5.seconds)

proc start*(wd: WakuDiscoveryV5): Future[Result[void, string]] {.async.} =
proc start*(wd: WakuDiscoveryV5): Result[void, string] =
if wd.listening:
return err("already listening")

Expand All @@ -205,6 +205,8 @@ proc start*(wd: WakuDiscoveryV5): Future[Result[void, string]] {.async.} =
debug "Successfully started discovery v5 service"
info "Discv5: discoverable ENR ", enr = wd.protocol.localNode.record.toUri()

ok()

proc stop*(wd: WakuDiscoveryV5): Future[void] {.async.} =
if not wd.listening:
return
Expand Down

0 comments on commit 3aefade

Please sign in to comment.