From fb5f0e9422cc9f3280ea4ae6dea90caf9018d2ce Mon Sep 17 00:00:00 2001 From: Gabriel mermelstein Date: Fri, 12 Jul 2024 17:54:07 +0300 Subject: [PATCH 01/15] only mounting rlnRelay if relay is configured --- examples/wakustealthcommitments/node_spec.nim | 5 ++++- waku/factory/waku.nim | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/examples/wakustealthcommitments/node_spec.nim b/examples/wakustealthcommitments/node_spec.nim index 4416f565fb..dabaa0f753 100644 --- a/examples/wakustealthcommitments/node_spec.nim +++ b/examples/wakustealthcommitments/node_spec.nim @@ -34,7 +34,6 @@ proc setup*(): Waku = # Override configuration conf.maxMessageSize = twnClusterConf.maxMessageSize conf.clusterId = twnClusterConf.clusterId - conf.rlnRelay = twnClusterConf.rlnRelay conf.rlnRelayEthContractAddress = twnClusterConf.rlnRelayEthContractAddress conf.rlnRelayDynamic = twnClusterConf.rlnRelayDynamic conf.rlnRelayBandwidthThreshold = twnClusterConf.rlnRelayBandwidthThreshold @@ -44,6 +43,10 @@ proc setup*(): Waku = conf.rlnEpochSizeSec = twnClusterConf.rlnEpochSizeSec conf.rlnRelayUserMessageLimit = twnClusterConf.rlnRelayUserMessageLimit + # Only set rlnRelay to true if relay is configured + if conf.relay: + conf.rlnRelay = twnClusterConf.rlnRelay + debug "Starting node" var waku = Waku.init(conf).valueOr: error "Waku initialization failed", error = error diff --git a/waku/factory/waku.nim b/waku/factory/waku.nim index c6c651cc18..a45eedbd16 100644 --- a/waku/factory/waku.nim +++ b/waku/factory/waku.nim @@ -115,6 +115,10 @@ proc init*(T: type Waku, conf: WakuNodeConf): Result[Waku, string] = confCopy.discv5BootstrapNodes & twnClusterConf.discv5BootstrapNodes confCopy.rlnEpochSizeSec = twnClusterConf.rlnEpochSizeSec confCopy.rlnRelayUserMessageLimit = twnClusterConf.rlnRelayUserMessageLimit + + # Only set rlnRelay to true if relay is configured + if confCopy.relay: + confCopy.rlnRelay = twnClusterConf.rlnRelay else: discard From 7cf27697a1f88d0d0badd48babb7d94e1e27f96b Mon Sep 17 00:00:00 2001 From: Gabriel mermelstein Date: Fri, 12 Jul 2024 18:13:50 +0300 Subject: [PATCH 02/15] fix bug --- waku/factory/waku.nim | 1 - 1 file changed, 1 deletion(-) diff --git a/waku/factory/waku.nim b/waku/factory/waku.nim index a45eedbd16..1ee4cb8622 100644 --- a/waku/factory/waku.nim +++ b/waku/factory/waku.nim @@ -105,7 +105,6 @@ proc init*(T: type Waku, conf: WakuNodeConf): Result[Waku, string] = # Override configuration confCopy.maxMessageSize = twnClusterConf.maxMessageSize confCopy.clusterId = twnClusterConf.clusterId - confCopy.rlnRelay = twnClusterConf.rlnRelay confCopy.rlnRelayEthContractAddress = twnClusterConf.rlnRelayEthContractAddress confCopy.rlnRelayChainId = twnClusterConf.rlnRelayChainId confCopy.rlnRelayDynamic = twnClusterConf.rlnRelayDynamic From 8766ad61e7ebe369fff5633c876a99d660ca6135 Mon Sep 17 00:00:00 2001 From: Gabriel mermelstein Date: Fri, 12 Jul 2024 18:54:18 +0300 Subject: [PATCH 03/15] not starting switch if relay and store are not mounted --- waku/node/waku_node.nim | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/waku/node/waku_node.nim b/waku/node/waku_node.nim index bf1ae74e20..cae5d9fff4 100644 --- a/waku/node/waku_node.nim +++ b/waku/node/waku_node.nim @@ -1288,8 +1288,11 @@ proc start*(node: WakuNode) {.async.} = return node.announcedAddresses node.switch.peerInfo.addressMappers.add(addressMapper) - ## The switch will update addresses after start using the addressMapper - await node.switch.start() + # Start the switch only if there's libp2p protocols mounted + # TO DO: verify rest of protocols. Maybe write a proc isBootstrapOnly() that checks it + if not node.wakuRelay.isNil() or not node.wakuStore.isNil(): + ## The switch will update addresses after start using the addressMapper + await node.switch.start() node.started = true From c29a263bcae4841636e37c053c60120018ccca91 Mon Sep 17 00:00:00 2001 From: Gabriel mermelstein Date: Wed, 17 Jul 2024 13:00:03 +0300 Subject: [PATCH 04/15] checking for protocols --- waku/node/waku_node.nim | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/waku/node/waku_node.nim b/waku/node/waku_node.nim index cae5d9fff4..3c820ee947 100644 --- a/waku/node/waku_node.nim +++ b/waku/node/waku_node.nim @@ -1261,6 +1261,16 @@ proc printNodeNetworkInfo*(node: WakuNode): void = info "Announcing addresses", full = announcedStr info "DNS: discoverable ENR ", enr = node.enr.toUri() +proc isBootstrapOnly(node: WakuNode) = + # Check if no protocols are mounted + if node.wakuRelay.isNil() and node.wakuStore.isNil() and node.wakuArchive.isNil() and + node.wakuLegacyStore.isNil() and node.wakuFilter.isNil() and + node.wakuRlnRelay.isNil() and node.wakuLightPush.isNil() and + node.wakuMetadata.isNil(): + return true + else: + return false + proc start*(node: WakuNode) {.async.} = ## Starts a created Waku Node and ## all its mounted protocols. @@ -1290,7 +1300,7 @@ proc start*(node: WakuNode) {.async.} = # Start the switch only if there's libp2p protocols mounted # TO DO: verify rest of protocols. Maybe write a proc isBootstrapOnly() that checks it - if not node.wakuRelay.isNil() or not node.wakuStore.isNil(): + if not node.isBootstrapOnly(): ## The switch will update addresses after start using the addressMapper await node.switch.start() From 402399fb70e1e4a8d4da4a1752b90cdba11e70da Mon Sep 17 00:00:00 2001 From: Gabriel mermelstein Date: Wed, 17 Jul 2024 13:05:40 +0300 Subject: [PATCH 05/15] fix compilation error --- waku/node/waku_node.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/waku/node/waku_node.nim b/waku/node/waku_node.nim index 3c820ee947..76b406539c 100644 --- a/waku/node/waku_node.nim +++ b/waku/node/waku_node.nim @@ -1261,7 +1261,7 @@ proc printNodeNetworkInfo*(node: WakuNode): void = info "Announcing addresses", full = announcedStr info "DNS: discoverable ENR ", enr = node.enr.toUri() -proc isBootstrapOnly(node: WakuNode) = +proc isBootstrapOnly(node: WakuNode): bool = # Check if no protocols are mounted if node.wakuRelay.isNil() and node.wakuStore.isNil() and node.wakuArchive.isNil() and node.wakuLegacyStore.isNil() and node.wakuFilter.isNil() and From 16896ec1d2e5d605864e7714e049c1e79679d04b Mon Sep 17 00:00:00 2001 From: Gabriel mermelstein Date: Wed, 17 Jul 2024 13:20:02 +0300 Subject: [PATCH 06/15] taking into account clients --- waku/node/waku_node.nim | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/waku/node/waku_node.nim b/waku/node/waku_node.nim index 76b406539c..5ce126e3ad 100644 --- a/waku/node/waku_node.nim +++ b/waku/node/waku_node.nim @@ -1266,7 +1266,9 @@ proc isBootstrapOnly(node: WakuNode): bool = if node.wakuRelay.isNil() and node.wakuStore.isNil() and node.wakuArchive.isNil() and node.wakuLegacyStore.isNil() and node.wakuFilter.isNil() and node.wakuRlnRelay.isNil() and node.wakuLightPush.isNil() and - node.wakuMetadata.isNil(): + node.wakuMetadata.isNil() and node.wakuStoreClient.isNil() and + node.wakuLegacyStoreClient.isNil() and node.wakuFilterClient.isNil() and + node.wakuLightpushClient.isNil(): return true else: return false From 3f04544cd619cbf741082d9687788d62e5d99d4b Mon Sep 17 00:00:00 2001 From: Gabriel mermelstein Date: Wed, 17 Jul 2024 15:20:52 +0300 Subject: [PATCH 07/15] mounting protocols before starting nodes in tests --- tests/waku_store/test_wakunode_store.nim | 12 +++++------ .../waku_store_legacy/test_wakunode_store.nim | 20 +++++++++---------- waku/node/waku_node.nim | 2 ++ 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/tests/waku_store/test_wakunode_store.nim b/tests/waku_store/test_wakunode_store.nim index 1f48d18f27..94b3d4e36f 100644 --- a/tests/waku_store/test_wakunode_store.nim +++ b/tests/waku_store/test_wakunode_store.nim @@ -74,8 +74,6 @@ procSuite "WakuNode - Store": clientKey = generateSecp256k1Key() client = newTestWakuNode(clientKey, parseIpAddress("0.0.0.0"), Port(0)) - waitFor allFutures(client.start(), server.start()) - let mountArchiveRes = server.mountArchive(archiveA) assert mountArchiveRes.isOk(), mountArchiveRes.error @@ -83,6 +81,8 @@ procSuite "WakuNode - Store": client.mountStoreClient() + waitFor allFutures(client.start(), server.start()) + ## Given let req = StoreQueryRequest(includeData: true, contentTopics: @[DefaultContentTopic]) @@ -109,8 +109,6 @@ procSuite "WakuNode - Store": clientKey = generateSecp256k1Key() client = newTestWakuNode(clientKey, parseIpAddress("0.0.0.0"), Port(0)) - waitFor allFutures(client.start(), server.start()) - let mountArchiveRes = server.mountArchive(archiveA) assert mountArchiveRes.isOk(), mountArchiveRes.error @@ -118,6 +116,8 @@ procSuite "WakuNode - Store": client.mountStoreClient() + waitFor allFutures(client.start(), server.start()) + ## Given let req = StoreQueryRequest( includeData: true, @@ -165,8 +165,6 @@ procSuite "WakuNode - Store": clientKey = generateSecp256k1Key() client = newTestWakuNode(clientKey, parseIpAddress("0.0.0.0"), Port(0)) - waitFor allFutures(client.start(), server.start()) - let mountArchiveRes = server.mountArchive(archiveA) assert mountArchiveRes.isOk(), mountArchiveRes.error @@ -174,6 +172,8 @@ procSuite "WakuNode - Store": client.mountStoreClient() + waitFor allFutures(client.start(), server.start()) + ## Given let req = StoreQueryRequest( includeData: true, diff --git a/tests/waku_store_legacy/test_wakunode_store.nim b/tests/waku_store_legacy/test_wakunode_store.nim index 496ab753e5..ed3b08f717 100644 --- a/tests/waku_store_legacy/test_wakunode_store.nim +++ b/tests/waku_store_legacy/test_wakunode_store.nim @@ -65,8 +65,6 @@ procSuite "WakuNode - Store Legacy": clientKey = generateSecp256k1Key() client = newTestWakuNode(clientKey, parseIpAddress("0.0.0.0"), Port(0)) - waitFor allFutures(client.start(), server.start()) - let mountArchiveRes = server.mountLegacyArchive(archiveA) assert mountArchiveRes.isOk(), mountArchiveRes.error @@ -74,6 +72,8 @@ procSuite "WakuNode - Store Legacy": client.mountLegacyStoreClient() + waitFor allFutures(client.start(), server.start()) + ## Given let req = HistoryQuery(contentTopics: @[DefaultContentTopic]) let serverPeer = server.peerInfo.toRemotePeerInfo() @@ -99,8 +99,6 @@ procSuite "WakuNode - Store Legacy": clientKey = generateSecp256k1Key() client = newTestWakuNode(clientKey, parseIpAddress("0.0.0.0"), Port(0)) - waitFor allFutures(client.start(), server.start()) - let mountArchiveRes = server.mountLegacyArchive(archiveA) assert mountArchiveRes.isOk(), mountArchiveRes.error @@ -108,6 +106,8 @@ procSuite "WakuNode - Store Legacy": client.mountLegacyStoreClient() + waitFor allFutures(client.start(), server.start()) + ## Given let req = HistoryQuery( contentTopics: @[DefaultContentTopic], @@ -154,8 +154,6 @@ procSuite "WakuNode - Store Legacy": clientKey = generateSecp256k1Key() client = newTestWakuNode(clientKey, parseIpAddress("0.0.0.0"), Port(0)) - waitFor allFutures(client.start(), server.start()) - let mountArchiveRes = server.mountLegacyArchive(archiveA) assert mountArchiveRes.isOk(), mountArchiveRes.error @@ -163,6 +161,8 @@ procSuite "WakuNode - Store Legacy": client.mountLegacyStoreClient() + waitFor allFutures(client.start(), server.start()) + ## Given let req = HistoryQuery( contentTopics: @[DefaultContentTopic], @@ -213,8 +213,6 @@ procSuite "WakuNode - Store Legacy": clientKey = generateSecp256k1Key() client = newTestWakuNode(clientKey, parseIpAddress("0.0.0.0"), Port(0)) - waitFor allFutures(client.start(), server.start(), filterSource.start()) - waitFor filterSource.mountFilter() let driver = newSqliteArchiveDriver() @@ -225,6 +223,8 @@ procSuite "WakuNode - Store Legacy": waitFor server.mountFilterClient() client.mountLegacyStoreClient() + waitFor allFutures(client.start(), server.start(), filterSource.start()) + ## Given let message = fakeWakuMessage() let @@ -279,8 +279,6 @@ procSuite "WakuNode - Store Legacy": clientKey = generateSecp256k1Key() client = newTestWakuNode(clientKey, parseIpAddress("0.0.0.0"), Port(0)) - waitFor allFutures(client.start(), server.start()) - let mountArchiveRes = server.mountLegacyArchive(archiveA) assert mountArchiveRes.isOk(), mountArchiveRes.error @@ -288,6 +286,8 @@ procSuite "WakuNode - Store Legacy": client.mountLegacyStoreClient() + waitFor allFutures(client.start(), server.start()) + ## Forcing a bad cursor with empty digest data var data: array[32, byte] = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, diff --git a/waku/node/waku_node.nim b/waku/node/waku_node.nim index 5ce126e3ad..5ec9433678 100644 --- a/waku/node/waku_node.nim +++ b/waku/node/waku_node.nim @@ -1305,6 +1305,8 @@ proc start*(node: WakuNode) {.async.} = if not node.isBootstrapOnly(): ## The switch will update addresses after start using the addressMapper await node.switch.start() + else: + warn "Did not start libp2p switch as no protocols are mounted" node.started = true From 4edb0d8e4dc84b2e6ef48d19fab0a0094bcbf7a5 Mon Sep 17 00:00:00 2001 From: Gabriel mermelstein Date: Wed, 17 Jul 2024 15:25:25 +0300 Subject: [PATCH 08/15] removing unnecessary else --- waku/node/waku_node.nim | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/waku/node/waku_node.nim b/waku/node/waku_node.nim index 5ec9433678..0461e6d1f4 100644 --- a/waku/node/waku_node.nim +++ b/waku/node/waku_node.nim @@ -1270,8 +1270,7 @@ proc isBootstrapOnly(node: WakuNode): bool = node.wakuLegacyStoreClient.isNil() and node.wakuFilterClient.isNil() and node.wakuLightpushClient.isNil(): return true - else: - return false + return false proc start*(node: WakuNode) {.async.} = ## Starts a created Waku Node and From 8f7191e97649da0efdc36ad7e080afed7e2cd387 Mon Sep 17 00:00:00 2001 From: Gabriel mermelstein Date: Wed, 17 Jul 2024 15:42:13 +0300 Subject: [PATCH 09/15] more mounting before starting --- tests/waku_store/test_wakunode_store.nim | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/waku_store/test_wakunode_store.nim b/tests/waku_store/test_wakunode_store.nim index 94b3d4e36f..961f660c20 100644 --- a/tests/waku_store/test_wakunode_store.nim +++ b/tests/waku_store/test_wakunode_store.nim @@ -225,8 +225,6 @@ procSuite "WakuNode - Store": clientKey = generateSecp256k1Key() client = newTestWakuNode(clientKey, parseIpAddress("0.0.0.0"), Port(0)) - waitFor allFutures(client.start(), server.start(), filterSource.start()) - waitFor filterSource.mountFilter() let driver = newSqliteArchiveDriver() @@ -237,6 +235,8 @@ procSuite "WakuNode - Store": waitFor server.mountFilterClient() client.mountStoreClient() + waitFor allFutures(client.start(), server.start(), filterSource.start()) + ## Given let message = fakeWakuMessage() let hash = computeMessageHash(DefaultPubSubTopic, message) @@ -297,8 +297,6 @@ procSuite "WakuNode - Store": clientKey = generateSecp256k1Key() client = newTestWakuNode(clientKey, parseIpAddress("0.0.0.0"), Port(0)) - waitFor allFutures(client.start(), server.start()) - let mountArchiveRes = server.mountArchive(archiveA) assert mountArchiveRes.isOk(), mountArchiveRes.error @@ -306,6 +304,8 @@ procSuite "WakuNode - Store": client.mountStoreClient() + waitFor allFutures(client.start(), server.start()) + ## Forcing a bad cursor with empty digest data var cursor: WakuMessageHash = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -340,8 +340,6 @@ procSuite "WakuNode - Store": clientKey = generateSecp256k1Key() client = newTestWakuNode(clientKey, parseIpAddress("0.0.0.0"), Port(0)) - waitFor allFutures(client.start(), server.start()) - let mountArchiveRes = server.mountArchive(archiveA) assert mountArchiveRes.isOk(), mountArchiveRes.error @@ -349,6 +347,8 @@ procSuite "WakuNode - Store": client.mountStoreClient() + waitFor allFutures(client.start(), server.start()) + ## Given let req = StoreQueryRequest(includeData: true, contentTopics: @[DefaultContentTopic]) @@ -384,8 +384,6 @@ procSuite "WakuNode - Store": clientKey = generateSecp256k1Key() client = newTestWakuNode(clientKey, parseIpAddress("0.0.0.0"), Port(0)) - waitFor allFutures(client.start(), server.start()) - let mountArchiveRes = server.mountArchive(archiveA) assert mountArchiveRes.isOk(), mountArchiveRes.error @@ -393,6 +391,8 @@ procSuite "WakuNode - Store": client.mountStoreClient() + waitFor allFutures(client.start(), server.start()) + ## Given let req = StoreQueryRequest(includeData: true, contentTopics: @[DefaultContentTopic]) From dd89b58a4b3cab6aae6d277f7d4342257934855c Mon Sep 17 00:00:00 2001 From: Gabriel mermelstein Date: Wed, 17 Jul 2024 16:49:17 +0300 Subject: [PATCH 10/15] mounting libp2p protocols only if configured --- waku/factory/node_factory.nim | 23 ++++++++++++----------- waku/node/waku_node.nim | 13 ++++++++++--- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/waku/factory/node_factory.nim b/waku/factory/node_factory.nim index c13c1dd124..4d6481312b 100644 --- a/waku/factory/node_factory.nim +++ b/waku/factory/node_factory.nim @@ -122,9 +122,6 @@ proc setupProtocols( ## Optionally include persistent message storage. ## No protocols are started yet. - node.mountMetadata(conf.clusterId).isOkOr: - return err("failed to mount waku metadata protocol: " & error) - node.mountSharding(conf.clusterId, uint32(conf.pubsubTopics.len)).isOkOr: return err("failed to mount waku sharding: " & error) @@ -191,12 +188,6 @@ proc setupProtocols( return err("failed to mount waku rendezvous protocol: " & getCurrentExceptionMsg()) - # Keepalive mounted on all nodes - try: - await mountLibp2pPing(node) - except CatchableError: - return err("failed to mount libp2p ping protocol: " & getCurrentExceptionMsg()) - var onFatalErrorAction = proc(msg: string) {.gcsafe, closure.} = ## Action to be taken when an internal error occurs during the node run. ## e.g. the connection with the database is lost and not recovered. @@ -278,18 +269,18 @@ proc setupProtocols( except CatchableError: return err("failed to mount waku store protocol: " & getCurrentExceptionMsg()) - mountStoreClient(node) if conf.storenode != "": let storeNode = parsePeerInfo(conf.storenode) if storeNode.isOk(): + mountStoreClient(node) node.peerManager.addServicePeer(storeNode.value, store_common.WakuStoreCodec) else: return err("failed to set node waku store peer: " & storeNode.error) - mountLegacyStoreClient(node) if conf.storenode != "": let storeNode = parsePeerInfo(conf.storenode) if storeNode.isOk(): + mountLegacyStoreClient(node) node.peerManager.addServicePeer( storeNode.value, legacy_common.WakuLegacyStoreCodec ) @@ -354,6 +345,16 @@ proc setupProtocols( return err("failed to set node waku peer-exchange peer: " & peerExchangeNode.error) + if not isBootstrapOnly(node): + node.mountMetadata(conf.clusterId).isOkOr: + return err("failed to mount waku metadata protocol: " & error) + + # Keepalive mounted on all nodes + try: + await mountLibp2pPing(node) + except CatchableError: + return err("failed to mount libp2p ping protocol: " & getCurrentExceptionMsg()) + return ok() ## Start node diff --git a/waku/node/waku_node.nim b/waku/node/waku_node.nim index 0461e6d1f4..e977b500df 100644 --- a/waku/node/waku_node.nim +++ b/waku/node/waku_node.nim @@ -1261,15 +1261,22 @@ proc printNodeNetworkInfo*(node: WakuNode): void = info "Announcing addresses", full = announcedStr info "DNS: discoverable ENR ", enr = node.enr.toUri() -proc isBootstrapOnly(node: WakuNode): bool = +proc isBootstrapOnly*(node: WakuNode): bool = # Check if no protocols are mounted - if node.wakuRelay.isNil() and node.wakuStore.isNil() and node.wakuArchive.isNil() and + #[ if node.wakuRelay.isNil() and node.wakuStore.isNil() and node.wakuArchive.isNil() and node.wakuLegacyStore.isNil() and node.wakuFilter.isNil() and node.wakuRlnRelay.isNil() and node.wakuLightPush.isNil() and node.wakuMetadata.isNil() and node.wakuStoreClient.isNil() and node.wakuLegacyStoreClient.isNil() and node.wakuFilterClient.isNil() and node.wakuLightpushClient.isNil(): - return true + return true ]# + #[ for nodeField, fieldValue in fieldPairs(node[]): + # echo "nodeField ", nodeField + if fieldValue is LPProtocol: + echo "nodeField ", nodeField, " is of LPProtocol" ]# + + echo "node.switch.peerInfo.protocols: ", node.switch.peerInfo.protocols + return false proc start*(node: WakuNode) {.async.} = From 7ae36966d35f4dd7d6bd5672f77e66237d07f9c3 Mon Sep 17 00:00:00 2001 From: Gabriel mermelstein Date: Wed, 17 Jul 2024 17:23:44 +0300 Subject: [PATCH 11/15] setting default switch protocols --- tests/node/test_wakunode_peer_manager.nim | 29 ++++++++++------------- waku/node/waku_node.nim | 12 ++++++---- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/tests/node/test_wakunode_peer_manager.nim b/tests/node/test_wakunode_peer_manager.nim index 4e10556f73..3437707a17 100644 --- a/tests/node/test_wakunode_peer_manager.nim +++ b/tests/node/test_wakunode_peer_manager.nim @@ -30,9 +30,6 @@ import ./peer_manager/peer_store/utils, ./utils -const DEFAULT_PROTOCOLS: seq[string] = - @["/ipfs/id/1.0.0", "/libp2p/autonat/1.0.0", "/libp2p/circuit/relay/0.2.0/hop"] - let listenIp = ValidIpAddress.init("0.0.0.0") listenPort = Port(0) @@ -302,7 +299,7 @@ suite "Peer Manager": # Then the stored protocols should be the default (libp2p) ones check: clientPeerStore.peerExists(serverPeerId) - clientPeerStore.get(serverPeerId).protocols == DEFAULT_PROTOCOLS + clientPeerStore.get(serverPeerId).protocols == DefaultSwitchProtocols asyncTest "Peer Protocol Support Verification (Before Connection)": # Given the server has mounted some Waku protocols @@ -316,7 +313,7 @@ suite "Peer Manager": check: clientPeerStore.peerExists(serverPeerId) clientPeerStore.get(serverPeerId).protocols == - DEFAULT_PROTOCOLS & @[WakuRelayCodec, WakuFilterSubscribeCodec] + DefaultSwitchProtocols & @[WakuRelayCodec, WakuFilterSubscribeCodec] asyncTest "Service-Specific Peer Addition": # Given a server mounts some Waku protocols @@ -342,10 +339,10 @@ suite "Peer Manager": check: clientPeerStore.peerExists(serverPeerId) clientPeerStore.get(serverPeerId).protocols == - DEFAULT_PROTOCOLS & @[WakuFilterSubscribeCodec] + DefaultSwitchProtocols & @[WakuFilterSubscribeCodec] clientPeerStore.peerExists(server2PeerId) clientPeerStore.get(server2PeerId).protocols == - DEFAULT_PROTOCOLS & @[WakuRelayCodec] + DefaultSwitchProtocols & @[WakuRelayCodec] # Cleanup await server2.stop() @@ -367,7 +364,7 @@ suite "Peer Manager": chainedComparison( clientPeerStore[ProtoBook][serverPeerId], serverRemotePeerInfo.protocols, - DEFAULT_PROTOCOLS, + DefaultSwitchProtocols, ) chainedComparison( clientPeerStore[AgentBook][serverPeerId], # FIXME: Not assigned @@ -433,7 +430,7 @@ suite "Peer Manager": chainedComparison( clientPeerStore[ProtoBook][serverPeerId], serverRemotePeerInfo.protocols, - DEFAULT_PROTOCOLS, + DefaultSwitchProtocols, ) chainedComparison( clientPeerStore[AgentBook][serverPeerId], # FIXME: Not assigned @@ -484,7 +481,7 @@ suite "Peer Manager": chainedComparison( clientPeerStore[ProtoBook][server2PeerId], server2RemotePeerInfo.protocols, - DEFAULT_PROTOCOLS, + DefaultSwitchProtocols, ) chainedComparison( clientPeerStore[AgentBook][server2PeerId], # FIXME: Not assigned @@ -833,7 +830,7 @@ suite "Mount Order": check: clientPeerStore.peerExists(serverPeerId) clientPeerStore.get(serverPeerId).protocols == - DEFAULT_PROTOCOLS & @[WakuRelayCodec] + DefaultSwitchProtocols & @[WakuRelayCodec] # Cleanup await server.stop() @@ -857,7 +854,7 @@ suite "Mount Order": check: clientPeerStore.peerExists(serverPeerId) clientPeerStore.get(serverPeerId).protocols == - DEFAULT_PROTOCOLS & @[WakuRelayCodec] + DefaultSwitchProtocols & @[WakuRelayCodec] # Cleanup await server.stop() @@ -881,7 +878,7 @@ suite "Mount Order": check: clientPeerStore.peerExists(serverPeerId) clientPeerStore.get(serverPeerId).protocols == - DEFAULT_PROTOCOLS & @[WakuRelayCodec] + DefaultSwitchProtocols & @[WakuRelayCodec] # Cleanup await server.stop() @@ -905,7 +902,7 @@ suite "Mount Order": check: clientPeerStore.peerExists(serverPeerId) clientPeerStore.get(serverPeerId).protocols == - DEFAULT_PROTOCOLS & @[WakuRelayCodec] + DefaultSwitchProtocols & @[WakuRelayCodec] # Cleanup await server.stop() @@ -928,7 +925,7 @@ suite "Mount Order": # Then the peer store should contain the peer but not the mounted protocol check: clientPeerStore.peerExists(serverPeerId) - clientPeerStore.get(serverPeerId).protocols == DEFAULT_PROTOCOLS + clientPeerStore.get(serverPeerId).protocols == DefaultSwitchProtocols # Cleanup await server.stop() @@ -951,7 +948,7 @@ suite "Mount Order": # Then the peer store should contain the peer but not the mounted protocol check: clientPeerStore.peerExists(serverPeerId) - clientPeerStore.get(serverPeerId).protocols == DEFAULT_PROTOCOLS + clientPeerStore.get(serverPeerId).protocols == DefaultSwitchProtocols # Cleanup await server.stop() diff --git a/waku/node/waku_node.nim b/waku/node/waku_node.nim index e977b500df..ec43cb38ce 100644 --- a/waku/node/waku_node.nim +++ b/waku/node/waku_node.nim @@ -15,8 +15,8 @@ import libp2p/protocols/ping, libp2p/protocols/pubsub/gossipsub, libp2p/protocols/pubsub/rpc/messages, - libp2p/protocols/connectivity/autonat/client, - libp2p/protocols/connectivity/autonat/service, + libp2p/protocols/connectivity/autonat/[client, service, server], + libp2p/protocols/connectivity/relay/utils, libp2p/protocols/rendezvous, libp2p/builders, libp2p/transports/transport, @@ -76,6 +76,10 @@ const clientId* = "Nimbus Waku v2 node" const WakuNodeVersionString* = "version / git commit hash: " & git_version +# Default protocols mounted into a Waku Switch +const DefaultSwitchProtocols*: seq[string] = + @[IdentifyCodec, AutonatCodec, RelayV2HopCodec] + # key and crypto modules different type # TODO: Move to application instance (e.g., `WakuNode2`) @@ -1275,8 +1279,8 @@ proc isBootstrapOnly*(node: WakuNode): bool = if fieldValue is LPProtocol: echo "nodeField ", nodeField, " is of LPProtocol" ]# - echo "node.switch.peerInfo.protocols: ", node.switch.peerInfo.protocols - + if toHashSet(node.switch.peerInfo.protocols) == toHashSet(DefaultSwitchProtocols): + return true return false proc start*(node: WakuNode) {.async.} = From f8d79ff6aea5c41083911af6fb5079013ffb1661 Mon Sep 17 00:00:00 2001 From: Gabriel mermelstein Date: Wed, 17 Jul 2024 18:01:49 +0300 Subject: [PATCH 12/15] not configuring store client as default --- tests/factory/test_node_factory.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/factory/test_node_factory.nim b/tests/factory/test_node_factory.nim index 0b68338e23..7bf820eba4 100644 --- a/tests/factory/test_node_factory.nim +++ b/tests/factory/test_node_factory.nim @@ -16,7 +16,7 @@ suite "Node Factory": node.wakuArchive.isNil() node.wakuStore.isNil() node.wakuFilter.isNil() - not node.wakuStoreClient.isNil() + node.wakuStoreClient.isNil() not node.rendezvous.isNil() test "Set up a node with Store enabled": From 12528a741e4f17a166f4127becc0476a5a0de7de Mon Sep 17 00:00:00 2001 From: Gabriel mermelstein Date: Wed, 17 Jul 2024 18:03:28 +0300 Subject: [PATCH 13/15] adding temporary debug logs for control-c stopper --- apps/wakunode2/wakunode2.nim | 3 +++ waku/factory/waku.nim | 8 ++++++++ waku/node/waku_node.nim | 8 +++++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/apps/wakunode2/wakunode2.nim b/apps/wakunode2/wakunode2.nim index afa84f6537..85521e89b8 100644 --- a/apps/wakunode2/wakunode2.nim +++ b/apps/wakunode2/wakunode2.nim @@ -93,8 +93,11 @@ when isMainModule: ## Stop node gracefully on shutdown. proc asyncStopper(node: Waku) {.async: (raises: [Exception]).} = + echo "----------- asyncStopper 1 ------------" nodeHealthMonitor.setOverallHealth(HealthStatus.SHUTTING_DOWN) + echo "----------- asyncStopper 2 ------------" await node.stop() + echo "----------- asyncStopper 3 ------------" quit(QuitSuccess) # Handle Ctrl-C SIGINT diff --git a/waku/factory/waku.nim b/waku/factory/waku.nim index 1ee4cb8622..d57fe6a839 100644 --- a/waku/factory/waku.nim +++ b/waku/factory/waku.nim @@ -241,14 +241,22 @@ proc startWaku*(waku: ptr Waku): Future[Result[void, string]] {.async: (raises: # Waku shutdown proc stop*(waku: Waku): Future[void] {.async: (raises: [Exception]).} = + echo "---------- Waku stop 1 --------" + if not waku.restServer.isNil(): + echo "---------- Waku stop 2 --------" await waku.restServer.stop() + echo "---------- Waku stop 3 --------" if not waku.metricsServer.isNil(): + echo "---------- Waku stop 4 --------" await waku.metricsServer.stop() + echo "---------- Waku stop 5 --------" if not waku.wakuDiscv5.isNil(): + echo "---------- Waku stop 6 --------" await waku.wakuDiscv5.stop() + echo "---------- Waku stop 7 --------" if not waku.node.isNil(): await waku.node.stop() diff --git a/waku/node/waku_node.nim b/waku/node/waku_node.nim index ec43cb38ce..5730616190 100644 --- a/waku/node/waku_node.nim +++ b/waku/node/waku_node.nim @@ -1328,20 +1328,26 @@ proc start*(node: WakuNode) {.async.} = info "Node started successfully" proc stop*(node: WakuNode) {.async.} = + echo "--------------- STOP 1 -------------" ## By stopping the switch we are stopping all the underlying mounted protocols - await node.switch.stop() + if not node.isBootstrapOnly(): + await node.switch.stop() + echo "--------------- STOP 2 -------------" node.peerManager.stop() + echo "--------------- STOP 3 -------------" if not node.wakuRlnRelay.isNil(): try: await node.wakuRlnRelay.stop() ## this can raise an exception except Exception: error "exception stopping the node", error = getCurrentExceptionMsg() + echo "--------------- STOP 4 -------------" if not node.wakuArchive.isNil(): await node.wakuArchive.stopWait() + echo "--------------- STOP 5 -------------" node.started = false proc isReady*(node: WakuNode): Future[bool] {.async: (raises: [Exception]).} = From 8d453318d2f5aacdee7e198c1732e2fababbe277 Mon Sep 17 00:00:00 2001 From: Gabriel mermelstein Date: Wed, 17 Jul 2024 18:38:56 +0300 Subject: [PATCH 14/15] mounting protocols before starting in filter test --- tests/node/test_wakunode_filter.nim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/node/test_wakunode_filter.nim b/tests/node/test_wakunode_filter.nim index 8580538fa2..375dbeee91 100644 --- a/tests/node/test_wakunode_filter.nim +++ b/tests/node/test_wakunode_filter.nim @@ -52,11 +52,11 @@ suite "Waku Filter - End to End": clientClone = newTestWakuNode(clientKey, parseIpAddress("0.0.0.0"), Port(23451)) # Used for testing client restarts - await allFutures(server.start(), client.start()) - await server.mountFilter() await client.mountFilterClient() + await allFutures(server.start(), client.start()) + client.wakuFilterClient.registerPushHandler(messagePushHandler) serverRemotePeerInfo = server.peerInfo.toRemotePeerInfo() clientPeerId = client.peerInfo.toRemotePeerInfo().peerId From 09a4e8111fb223476cab983fdc85a60e5c1968bb Mon Sep 17 00:00:00 2001 From: Gabriel mermelstein Date: Tue, 30 Jul 2024 12:02:37 +0300 Subject: [PATCH 15/15] fixing tests --- tests/node/test_wakunode_lightpush.nim | 5 ++--- tests/node/test_wakunode_peer_exchange.nim | 24 +++++++++++++--------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/tests/node/test_wakunode_lightpush.nim b/tests/node/test_wakunode_lightpush.nim index 0527c034e2..6f3e07bd1f 100644 --- a/tests/node/test_wakunode_lightpush.nim +++ b/tests/node/test_wakunode_lightpush.nim @@ -56,13 +56,12 @@ suite "Waku Lightpush - End To End": server = newTestWakuNode(serverKey, ValidIpAddress.init("0.0.0.0"), Port(0)) client = newTestWakuNode(clientKey, ValidIpAddress.init("0.0.0.0"), Port(0)) - await allFutures(server.start(), client.start()) - await server.start() - await server.mountRelay() await server.mountLightpush() # without rln-relay client.mountLightpushClient() + await allFutures(server.start(), client.start()) + serverRemotePeerInfo = server.peerInfo.toRemotePeerInfo() pubsubTopic = DefaultPubsubTopic contentTopic = DefaultContentTopic diff --git a/tests/node/test_wakunode_peer_exchange.nim b/tests/node/test_wakunode_peer_exchange.nim index c2a235045e..15adc8a094 100644 --- a/tests/node/test_wakunode_peer_exchange.nim +++ b/tests/node/test_wakunode_peer_exchange.nim @@ -67,29 +67,31 @@ suite "Waku Peer Exchange": suite "fetchPeerExchangePeers": var node2 {.threadvar.}: WakuNode + var node3 {.threadvar.}: WakuNode asyncSetup: + # node and node2 have Peer Exchange mounted, node3 doesn't node = newTestWakuNode(generateSecp256k1Key(), bindIp, bindPort) node2 = newTestWakuNode(generateSecp256k1Key(), bindIp, bindPort) + node3 = newTestWakuNode(generateSecp256k1Key(), bindIp, bindPort) - await allFutures(node.start(), node2.start()) + await allFutures([node.mountPeerExchange(), node2.mountPeerExchange()]) + await allFutures(node.start(), node2.start(), node3.start()) asyncTeardown: await allFutures(node.stop(), node2.stop()) asyncTest "Node fetches without mounting peer exchange": # When a node, without peer exchange mounted, fetches peers - let res = await node.fetchPeerExchangePeers(1) + let res = await node3.fetchPeerExchangePeers(1) # Then no peers are fetched check: - node.peerManager.peerStore.peers.len == 0 + node3.peerManager.peerStore.peers.len == 0 res.error == "PeerExchange is not mounted" asyncTest "Node fetches with mounted peer exchange, but no peers": # Given a node with peer exchange mounted - await node.mountPeerExchange() - # When a node fetches peers let res = await node.fetchPeerExchangePeers(1) check res.error == "Peer exchange failure: peer_not_found_failure" @@ -99,7 +101,6 @@ suite "Waku Peer Exchange": asyncTest "Node succesfully exchanges px peers with faked discv5": # Given both nodes mount peer exchange - await allFutures([node.mountPeerExchange(), node2.mountPeerExchange()]) check node.peerManager.peerStore.peers.len == 0 # Mock that we discovered a node (to avoid running discv5) @@ -254,6 +255,13 @@ suite "Waku Peer Exchange with discv5": let disc2 = WakuDiscoveryV5.new(node2.rng, conf2, some(node2.enr), some(node2.peerManager)) + # Mount peer exchange + await node1.mountPeerExchange() + await node3.mountPeerExchange() + + # Mount relay in order to accept connections + await node2.mountRelay() + await allFutures(node1.start(), node2.start(), node3.start()) let resultDisc1StartRes = await disc1.start() assert resultDisc1StartRes.isOk(), resultDisc1StartRes.error @@ -272,10 +280,6 @@ suite "Waku Peer Exchange with discv5": await node1.peerManager.connectRelay(node2.switch.peerInfo.toRemotePeerInfo()) ) - # Mount peer exchange - await node1.mountPeerExchange() - await node3.mountPeerExchange() - let dialResponse = await node3.dialForPeerExchange(node1.switch.peerInfo.toRemotePeerInfo())