From 52a4a5d6c90645f1334b571148551263c5d9d502 Mon Sep 17 00:00:00 2001 From: Arseniy Klempner Date: Thu, 9 Oct 2025 21:11:43 -0700 Subject: [PATCH] feat: set nodekey and staticnode flags for each nwaku node --- packages/run/docker-compose.yml | 17 ++++++++-- packages/run/scripts/info.ts | 24 ++++++-------- packages/run/scripts/start.ts | 24 ++++++-------- packages/run/tests/basic.spec.ts | 54 +++++++++++++++++--------------- 4 files changed, 63 insertions(+), 56 deletions(-) diff --git a/packages/run/docker-compose.yml b/packages/run/docker-compose.yml index 7e5a0c5a7d..807654bf14 100644 --- a/packages/run/docker-compose.yml +++ b/packages/run/docker-compose.yml @@ -37,6 +37,9 @@ services: nwaku-1: <<: *nwaku-base container_name: waku-local-node-1 + networks: + default: + ipv4_address: 172.20.0.10 ports: - "${NODE1_TCP_PORT:-30303}:30303/tcp" - "${NODE1_WS_PORT:-60000}:60000/tcp" @@ -47,6 +50,8 @@ services: postgres: condition: service_healthy command: + - --nodekey=e419c3cf4f09ac3babdf61856e6faa0e0c6a7d97674d5401a0114616549c7632 + - --staticnode=/ip4/172.20.0.11/tcp/60001/ws/p2p/16Uiu2HAm5aZU47YkiUoARqivbCXwuFPzFFXXiURAorySqAQbL6EQ - --relay=true - --filter=true - --lightpush=true @@ -66,8 +71,8 @@ services: - --tcp-port=30303 - --websocket-support=true - --websocket-port=60000 + - --ext-multiaddr=/dns4/nwaku-1/tcp/60000/ws - --ext-multiaddr=/ip4/127.0.0.1/tcp/60000/ws - - --ext-multiaddr-only=true - --rest=true - --rest-address=0.0.0.0 - --rest-port=8646 @@ -79,6 +84,9 @@ services: nwaku-2: <<: *nwaku-base container_name: waku-local-node-2 + networks: + default: + ipv4_address: 172.20.0.11 ports: - "${NODE2_TCP_PORT:-30304}:30304/tcp" - "${NODE2_WS_PORT:-60001}:60001/tcp" @@ -91,6 +99,8 @@ services: nwaku-1: condition: service_started command: + - --nodekey=50632ab0efd313bfb4aa842de716f03dacd181c863770abd145e3409290fdaa7 + - --staticnode=/ip4/172.20.0.10/tcp/60000/ws/p2p/16Uiu2HAmF6oAsd23RMAnZb3NJgxXrExxBTPMdEoih232iAZkviU2 - --relay=true - --filter=true - --lightpush=true @@ -110,8 +120,8 @@ services: - --tcp-port=30304 - --websocket-support=true - --websocket-port=60001 + - --ext-multiaddr=/dns4/nwaku-2/tcp/60001/ws - --ext-multiaddr=/ip4/127.0.0.1/tcp/60001/ws - - --ext-multiaddr-only=true - --rest=true - --rest-address=0.0.0.0 - --rest-port=8647 @@ -126,3 +136,6 @@ volumes: networks: default: name: waku-local-network + ipam: + config: + - subnet: 172.20.0.0/16 diff --git a/packages/run/scripts/info.ts b/packages/run/scripts/info.ts index 9be1daca6d..b06ed14079 100755 --- a/packages/run/scripts/info.ts +++ b/packages/run/scripts/info.ts @@ -10,10 +10,6 @@ interface Colors { yellow: string; } -interface NodeInfo { - listenAddresses: string[]; -} - // ANSI color codes const colors: Colors = { reset: "\x1b[0m", @@ -41,16 +37,10 @@ try { const node1Port: string = process.env.NODE1_WS_PORT || "60000"; const node2Port: string = process.env.NODE2_WS_PORT || "60001"; - // Fetch node info - const node1Info: NodeInfo = await fetch( - "http://127.0.0.1:8646/debug/v1/info" - ).then((r) => r.json()); - const node2Info: NodeInfo = await fetch( - "http://127.0.0.1:8647/debug/v1/info" - ).then((r) => r.json()); - - const peer1: string = node1Info.listenAddresses[0].split("/p2p/")[1]; - const peer2: string = node2Info.listenAddresses[0].split("/p2p/")[1]; + // Static peer IDs from --nodekey configuration + // cspell:ignore nodekey + const peer1: string = "16Uiu2HAmF6oAsd23RMAnZb3NJgxXrExxBTPMdEoih232iAZkviU2"; + const peer2: string = "16Uiu2HAm5aZU47YkiUoARqivbCXwuFPzFFXXiURAorySqAQbL6EQ"; // Print TypeScript-style config process.stdout.write( @@ -71,6 +61,12 @@ try { ` ${colors.yellow}"/ip4/127.0.0.1/tcp/${node2Port}/ws/p2p/${peer2}"${colors.reset}\n` ); process.stdout.write(` ],\n`); + process.stdout.write(` numPeersToUse: ${colors.cyan}2${colors.reset},\n`); + process.stdout.write(` libp2p: {\n`); + process.stdout.write( + ` filterMultiaddrs: ${colors.cyan}false${colors.reset}\n` + ); + process.stdout.write(` },\n`); process.stdout.write(` networkConfig: {\n`); process.stdout.write( ` clusterId: ${colors.cyan}${clusterId}${colors.reset},\n` diff --git a/packages/run/scripts/start.ts b/packages/run/scripts/start.ts index aefa613d15..3e161a9c87 100755 --- a/packages/run/scripts/start.ts +++ b/packages/run/scripts/start.ts @@ -11,10 +11,6 @@ interface Colors { yellow: string; } -interface NodeInfo { - listenAddresses: string[]; -} - // ANSI color codes const colors: Colors = { reset: "\x1b[0m", @@ -105,16 +101,10 @@ try { const node1Port: string = process.env.NODE1_WS_PORT || "60000"; const node2Port: string = process.env.NODE2_WS_PORT || "60001"; - // Fetch node info - const node1Info: NodeInfo = await fetch( - "http://127.0.0.1:8646/debug/v1/info" - ).then((r) => r.json()); - const node2Info: NodeInfo = await fetch( - "http://127.0.0.1:8647/debug/v1/info" - ).then((r) => r.json()); - - const peer1: string = node1Info.listenAddresses[0].split("/p2p/")[1]; - const peer2: string = node2Info.listenAddresses[0].split("/p2p/")[1]; + // Static peer IDs from --nodekey configuration + // cspell:ignore nodekey + const peer1: string = "16Uiu2HAmF6oAsd23RMAnZb3NJgxXrExxBTPMdEoih232iAZkviU2"; + const peer2: string = "16Uiu2HAm5aZU47YkiUoARqivbCXwuFPzFFXXiURAorySqAQbL6EQ"; // Print TypeScript-style config process.stdout.write( @@ -142,6 +132,12 @@ try { ` ${colors.yellow}"/ip4/127.0.0.1/tcp/${node2Port}/ws/p2p/${peer2}"${colors.reset}\n` ); process.stdout.write(` ],\n`); + process.stdout.write(` numPeersToUse: ${colors.cyan}2${colors.reset},\n`); + process.stdout.write(` libp2p: {\n`); + process.stdout.write( + ` filterMultiaddrs: ${colors.cyan}false${colors.reset}\n` + ); + process.stdout.write(` },\n`); process.stdout.write(` networkConfig: {\n`); process.stdout.write( ` clusterId: ${colors.cyan}${clusterId}${colors.reset},\n` diff --git a/packages/run/tests/basic.spec.ts b/packages/run/tests/basic.spec.ts index 995ed83a93..2d00c40793 100644 --- a/packages/run/tests/basic.spec.ts +++ b/packages/run/tests/basic.spec.ts @@ -37,18 +37,8 @@ describe("Waku Run - Basic Test", function () { throw new Error("Nodes failed to start within expected time"); } - // Connect the two nwaku nodes together - const node1Info = await fetch("http://127.0.0.1:8646/debug/v1/info").then( - (r) => r.json() - ); - const peer1Multiaddr = node1Info.listenAddresses[0]; - - await fetch("http://127.0.0.1:8647/admin/v1/peers", { - method: "POST", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify([peer1Multiaddr]) - }); - + // Nodes automatically connect via --staticnode configuration + // cspell:ignore staticnode // Wait a bit for the connection to establish await new Promise((resolve) => setTimeout(resolve, 2000)); }); @@ -63,21 +53,15 @@ describe("Waku Run - Basic Test", function () { }); }); - it("should connect to nodes and send lightpush message", async function () { + it("should connect to both nodes and send lightpush message to both peers", async function () { // Step 2: Connect to nodes via js-waku const node1Port = process.env.NODE1_WS_PORT || "60000"; const node2Port = process.env.NODE2_WS_PORT || "60001"; - // Fetch node info to get peer IDs - const node1Info = await fetch("http://127.0.0.1:8646/debug/v1/info").then( - (r) => r.json() - ); - const node2Info = await fetch("http://127.0.0.1:8647/debug/v1/info").then( - (r) => r.json() - ); - - const peer1 = node1Info.listenAddresses[0].split("/p2p/")[1]; - const peer2 = node2Info.listenAddresses[0].split("/p2p/")[1]; + // Static peer IDs from --nodekey configuration + // cspell:ignore nodekey + const peer1 = "16Uiu2HAmF6oAsd23RMAnZb3NJgxXrExxBTPMdEoih232iAZkviU2"; + const peer2 = "16Uiu2HAm5aZU47YkiUoARqivbCXwuFPzFFXXiURAorySqAQbL6EQ"; const networkConfig = { clusterId: 0, @@ -90,13 +74,26 @@ describe("Waku Run - Basic Test", function () { `/ip4/127.0.0.1/tcp/${node1Port}/ws/p2p/${peer1}`, `/ip4/127.0.0.1/tcp/${node2Port}/ws/p2p/${peer2}` ], - networkConfig + networkConfig, + numPeersToUse: 2, // Use both peers for sending + libp2p: { + filterMultiaddrs: false + } }); await waku.start(); + + // Wait for both peers to be connected await waku.waitForPeers([Protocols.LightPush]); - // Step 3: Send a lightpush message + // Verify we're connected to both peers + const connectedPeers = waku.libp2p.getPeers(); + expect(connectedPeers.length).to.equal( + 2, + "Should be connected to both nwaku nodes" + ); + + // Step 3: Send lightpush message - it should be sent to both peers const contentTopic = "/test/1/basic/proto"; const routingInfo = createRoutingInfo(networkConfig, { contentTopic }); const encoder = createEncoder({ contentTopic, routingInfo }); @@ -105,6 +102,11 @@ describe("Waku Run - Basic Test", function () { payload: new TextEncoder().encode("Hello Waku!") }); - expect(result.successes.length).to.be.greaterThan(0); + // With numPeersToUse=2, the message should be sent to both peers + expect(result.successes.length).to.equal( + 2, + "Message should be sent to both peers" + ); + expect(result.failures?.length || 0).to.equal(0, "Should have no failures"); }); });