Skip to content

Commit 9cab60e

Browse files
committed
feat: set nodekey and staticnode flags for each nwaku node
1 parent 97e90f1 commit 9cab60e

File tree

4 files changed

+63
-56
lines changed

4 files changed

+63
-56
lines changed

packages/run/docker-compose.yml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ services:
3737
nwaku-1:
3838
<<: *nwaku-base
3939
container_name: waku-local-node-1
40+
networks:
41+
default:
42+
ipv4_address: 172.20.0.10
4043
ports:
4144
- "${NODE1_TCP_PORT:-30303}:30303/tcp"
4245
- "${NODE1_WS_PORT:-60000}:60000/tcp"
@@ -47,6 +50,8 @@ services:
4750
postgres:
4851
condition: service_healthy
4952
command:
53+
- --nodekey=e419c3cf4f09ac3babdf61856e6faa0e0c6a7d97674d5401a0114616549c7632
54+
- --staticnode=/ip4/172.20.0.11/tcp/60001/ws/p2p/16Uiu2HAm5aZU47YkiUoARqivbCXwuFPzFFXXiURAorySqAQbL6EQ
5055
- --relay=true
5156
- --filter=true
5257
- --lightpush=true
@@ -66,8 +71,8 @@ services:
6671
- --tcp-port=30303
6772
- --websocket-support=true
6873
- --websocket-port=60000
74+
- --ext-multiaddr=/dns4/nwaku-1/tcp/60000/ws
6975
- --ext-multiaddr=/ip4/127.0.0.1/tcp/60000/ws
70-
- --ext-multiaddr-only=true
7176
- --rest=true
7277
- --rest-address=0.0.0.0
7378
- --rest-port=8646
@@ -79,6 +84,9 @@ services:
7984
nwaku-2:
8085
<<: *nwaku-base
8186
container_name: waku-local-node-2
87+
networks:
88+
default:
89+
ipv4_address: 172.20.0.11
8290
ports:
8391
- "${NODE2_TCP_PORT:-30304}:30304/tcp"
8492
- "${NODE2_WS_PORT:-60001}:60001/tcp"
@@ -91,6 +99,8 @@ services:
9199
nwaku-1:
92100
condition: service_started
93101
command:
102+
- --nodekey=50632ab0efd313bfb4aa842de716f03dacd181c863770abd145e3409290fdaa7
103+
- --staticnode=/ip4/172.20.0.10/tcp/60000/ws/p2p/16Uiu2HAmF6oAsd23RMAnZb3NJgxXrExxBTPMdEoih232iAZkviU2
94104
- --relay=true
95105
- --filter=true
96106
- --lightpush=true
@@ -110,8 +120,8 @@ services:
110120
- --tcp-port=30304
111121
- --websocket-support=true
112122
- --websocket-port=60001
123+
- --ext-multiaddr=/dns4/nwaku-2/tcp/60001/ws
113124
- --ext-multiaddr=/ip4/127.0.0.1/tcp/60001/ws
114-
- --ext-multiaddr-only=true
115125
- --rest=true
116126
- --rest-address=0.0.0.0
117127
- --rest-port=8647
@@ -126,3 +136,6 @@ volumes:
126136
networks:
127137
default:
128138
name: waku-local-network
139+
ipam:
140+
config:
141+
- subnet: 172.20.0.0/16

packages/run/scripts/info.ts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ interface Colors {
1010
yellow: string;
1111
}
1212

13-
interface NodeInfo {
14-
listenAddresses: string[];
15-
}
16-
1713
// ANSI color codes
1814
const colors: Colors = {
1915
reset: "\x1b[0m",
@@ -41,16 +37,10 @@ try {
4137
const node1Port: string = process.env.NODE1_WS_PORT || "60000";
4238
const node2Port: string = process.env.NODE2_WS_PORT || "60001";
4339

44-
// Fetch node info
45-
const node1Info: NodeInfo = await fetch(
46-
"http://127.0.0.1:8646/debug/v1/info"
47-
).then((r) => r.json());
48-
const node2Info: NodeInfo = await fetch(
49-
"http://127.0.0.1:8647/debug/v1/info"
50-
).then((r) => r.json());
51-
52-
const peer1: string = node1Info.listenAddresses[0].split("/p2p/")[1];
53-
const peer2: string = node2Info.listenAddresses[0].split("/p2p/")[1];
40+
// Static peer IDs from --nodekey configuration
41+
// cspell:ignore nodekey
42+
const peer1: string = "16Uiu2HAmF6oAsd23RMAnZb3NJgxXrExxBTPMdEoih232iAZkviU2";
43+
const peer2: string = "16Uiu2HAm5aZU47YkiUoARqivbCXwuFPzFFXXiURAorySqAQbL6EQ";
5444

5545
// Print TypeScript-style config
5646
process.stdout.write(
@@ -71,6 +61,12 @@ try {
7161
` ${colors.yellow}"/ip4/127.0.0.1/tcp/${node2Port}/ws/p2p/${peer2}"${colors.reset}\n`
7262
);
7363
process.stdout.write(` ],\n`);
64+
process.stdout.write(` numPeersToUse: ${colors.cyan}2${colors.reset},\n`);
65+
process.stdout.write(` libp2p: {\n`);
66+
process.stdout.write(
67+
` filterMultiaddrs: ${colors.cyan}false${colors.reset}\n`
68+
);
69+
process.stdout.write(` },\n`);
7470
process.stdout.write(` networkConfig: {\n`);
7571
process.stdout.write(
7672
` clusterId: ${colors.cyan}${clusterId}${colors.reset},\n`

packages/run/scripts/start.ts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ interface Colors {
1111
yellow: string;
1212
}
1313

14-
interface NodeInfo {
15-
listenAddresses: string[];
16-
}
17-
1814
// ANSI color codes
1915
const colors: Colors = {
2016
reset: "\x1b[0m",
@@ -105,16 +101,10 @@ try {
105101
const node1Port: string = process.env.NODE1_WS_PORT || "60000";
106102
const node2Port: string = process.env.NODE2_WS_PORT || "60001";
107103

108-
// Fetch node info
109-
const node1Info: NodeInfo = await fetch(
110-
"http://127.0.0.1:8646/debug/v1/info"
111-
).then((r) => r.json());
112-
const node2Info: NodeInfo = await fetch(
113-
"http://127.0.0.1:8647/debug/v1/info"
114-
).then((r) => r.json());
115-
116-
const peer1: string = node1Info.listenAddresses[0].split("/p2p/")[1];
117-
const peer2: string = node2Info.listenAddresses[0].split("/p2p/")[1];
104+
// Static peer IDs from --nodekey configuration
105+
// cspell:ignore nodekey
106+
const peer1: string = "16Uiu2HAmF6oAsd23RMAnZb3NJgxXrExxBTPMdEoih232iAZkviU2";
107+
const peer2: string = "16Uiu2HAm5aZU47YkiUoARqivbCXwuFPzFFXXiURAorySqAQbL6EQ";
118108

119109
// Print TypeScript-style config
120110
process.stdout.write(
@@ -142,6 +132,12 @@ try {
142132
` ${colors.yellow}"/ip4/127.0.0.1/tcp/${node2Port}/ws/p2p/${peer2}"${colors.reset}\n`
143133
);
144134
process.stdout.write(` ],\n`);
135+
process.stdout.write(` numPeersToUse: ${colors.cyan}2${colors.reset},\n`);
136+
process.stdout.write(` libp2p: {\n`);
137+
process.stdout.write(
138+
` filterMultiaddrs: ${colors.cyan}false${colors.reset}\n`
139+
);
140+
process.stdout.write(` },\n`);
145141
process.stdout.write(` networkConfig: {\n`);
146142
process.stdout.write(
147143
` clusterId: ${colors.cyan}${clusterId}${colors.reset},\n`

packages/run/tests/basic.spec.ts

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,8 @@ describe("Waku Run - Basic Test", function () {
3737
throw new Error("Nodes failed to start within expected time");
3838
}
3939

40-
// Connect the two nwaku nodes together
41-
const node1Info = await fetch("http://127.0.0.1:8646/debug/v1/info").then(
42-
(r) => r.json()
43-
);
44-
const peer1Multiaddr = node1Info.listenAddresses[0];
45-
46-
await fetch("http://127.0.0.1:8647/admin/v1/peers", {
47-
method: "POST",
48-
headers: { "Content-Type": "application/json" },
49-
body: JSON.stringify([peer1Multiaddr])
50-
});
51-
40+
// Nodes automatically connect via --staticnode configuration
41+
// cspell:ignore staticnode
5242
// Wait a bit for the connection to establish
5343
await new Promise((resolve) => setTimeout(resolve, 2000));
5444
});
@@ -63,21 +53,15 @@ describe("Waku Run - Basic Test", function () {
6353
});
6454
});
6555

66-
it("should connect to nodes and send lightpush message", async function () {
56+
it("should connect to both nodes and send lightpush message to both peers", async function () {
6757
// Step 2: Connect to nodes via js-waku
6858
const node1Port = process.env.NODE1_WS_PORT || "60000";
6959
const node2Port = process.env.NODE2_WS_PORT || "60001";
7060

71-
// Fetch node info to get peer IDs
72-
const node1Info = await fetch("http://127.0.0.1:8646/debug/v1/info").then(
73-
(r) => r.json()
74-
);
75-
const node2Info = await fetch("http://127.0.0.1:8647/debug/v1/info").then(
76-
(r) => r.json()
77-
);
78-
79-
const peer1 = node1Info.listenAddresses[0].split("/p2p/")[1];
80-
const peer2 = node2Info.listenAddresses[0].split("/p2p/")[1];
61+
// Static peer IDs from --nodekey configuration
62+
// cspell:ignore nodekey
63+
const peer1 = "16Uiu2HAmF6oAsd23RMAnZb3NJgxXrExxBTPMdEoih232iAZkviU2";
64+
const peer2 = "16Uiu2HAm5aZU47YkiUoARqivbCXwuFPzFFXXiURAorySqAQbL6EQ";
8165

8266
const networkConfig = {
8367
clusterId: 0,
@@ -90,13 +74,26 @@ describe("Waku Run - Basic Test", function () {
9074
`/ip4/127.0.0.1/tcp/${node1Port}/ws/p2p/${peer1}`,
9175
`/ip4/127.0.0.1/tcp/${node2Port}/ws/p2p/${peer2}`
9276
],
93-
networkConfig
77+
networkConfig,
78+
numPeersToUse: 2, // Use both peers for sending
79+
libp2p: {
80+
filterMultiaddrs: false
81+
}
9482
});
9583

9684
await waku.start();
85+
86+
// Wait for both peers to be connected
9787
await waku.waitForPeers([Protocols.LightPush]);
9888

99-
// Step 3: Send a lightpush message
89+
// Verify we're connected to both peers
90+
const connectedPeers = waku.libp2p.getPeers();
91+
expect(connectedPeers.length).to.equal(
92+
2,
93+
"Should be connected to both nwaku nodes"
94+
);
95+
96+
// Step 3: Send lightpush message - it should be sent to both peers
10097
const contentTopic = "/test/1/basic/proto";
10198
const routingInfo = createRoutingInfo(networkConfig, { contentTopic });
10299
const encoder = createEncoder({ contentTopic, routingInfo });
@@ -105,6 +102,11 @@ describe("Waku Run - Basic Test", function () {
105102
payload: new TextEncoder().encode("Hello Waku!")
106103
});
107104

108-
expect(result.successes.length).to.be.greaterThan(0);
105+
// With numPeersToUse=2, the message should be sent to both peers
106+
expect(result.successes.length).to.equal(
107+
2,
108+
"Message should be sent to both peers"
109+
);
110+
expect(result.failures?.length || 0).to.equal(0, "Should have no failures");
109111
});
110112
});

0 commit comments

Comments
 (0)