Skip to content

Commit 9ead3eb

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

File tree

4 files changed

+50
-18
lines changed

4 files changed

+50
-18
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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ try {
7171
` ${colors.yellow}"/ip4/127.0.0.1/tcp/${node2Port}/ws/p2p/${peer2}"${colors.reset}\n`
7272
);
7373
process.stdout.write(` ],\n`);
74+
process.stdout.write(` numPeersToUse: ${colors.cyan}2${colors.reset},\n`);
75+
process.stdout.write(` libp2p: {\n`);
76+
process.stdout.write(
77+
` filterMultiaddrs: ${colors.cyan}false${colors.reset}\n`
78+
);
79+
process.stdout.write(` },\n`);
7480
process.stdout.write(` networkConfig: {\n`);
7581
process.stdout.write(
7682
` clusterId: ${colors.cyan}${clusterId}${colors.reset},\n`

packages/run/scripts/start.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,12 @@ try {
142142
` ${colors.yellow}"/ip4/127.0.0.1/tcp/${node2Port}/ws/p2p/${peer2}"${colors.reset}\n`
143143
);
144144
process.stdout.write(` ],\n`);
145+
process.stdout.write(` numPeersToUse: ${colors.cyan}2${colors.reset},\n`);
146+
process.stdout.write(` libp2p: {\n`);
147+
process.stdout.write(
148+
` filterMultiaddrs: ${colors.cyan}false${colors.reset}\n`
149+
);
150+
process.stdout.write(` },\n`);
145151
process.stdout.write(` networkConfig: {\n`);
146152
process.stdout.write(
147153
` clusterId: ${colors.cyan}${clusterId}${colors.reset},\n`

packages/run/tests/basic.spec.ts

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,7 @@ 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
5241
// Wait a bit for the connection to establish
5342
await new Promise((resolve) => setTimeout(resolve, 2000));
5443
});
@@ -63,7 +52,7 @@ describe("Waku Run - Basic Test", function () {
6352
});
6453
});
6554

66-
it("should connect to nodes and send lightpush message", async function () {
55+
it("should connect to both nodes and send lightpush message to both peers", async function () {
6756
// Step 2: Connect to nodes via js-waku
6857
const node1Port = process.env.NODE1_WS_PORT || "60000";
6958
const node2Port = process.env.NODE2_WS_PORT || "60001";
@@ -90,13 +79,26 @@ describe("Waku Run - Basic Test", function () {
9079
`/ip4/127.0.0.1/tcp/${node1Port}/ws/p2p/${peer1}`,
9180
`/ip4/127.0.0.1/tcp/${node2Port}/ws/p2p/${peer2}`
9281
],
93-
networkConfig
82+
networkConfig,
83+
numPeersToUse: 2, // Use both peers for sending
84+
libp2p: {
85+
filterMultiaddrs: false
86+
}
9487
});
9588

9689
await waku.start();
90+
91+
// Wait for both peers to be connected
9792
await waku.waitForPeers([Protocols.LightPush]);
9893

99-
// Step 3: Send a lightpush message
94+
// Verify we're connected to both peers
95+
const connectedPeers = waku.libp2p.getPeers();
96+
expect(connectedPeers.length).to.equal(
97+
2,
98+
"Should be connected to both nwaku nodes"
99+
);
100+
101+
// Step 3: Send lightpush message - it should be sent to both peers
100102
const contentTopic = "/test/1/basic/proto";
101103
const routingInfo = createRoutingInfo(networkConfig, { contentTopic });
102104
const encoder = createEncoder({ contentTopic, routingInfo });
@@ -105,6 +107,11 @@ describe("Waku Run - Basic Test", function () {
105107
payload: new TextEncoder().encode("Hello Waku!")
106108
});
107109

108-
expect(result.successes.length).to.be.greaterThan(0);
110+
// With numPeersToUse=2, the message should be sent to both peers
111+
expect(result.successes.length).to.equal(
112+
2,
113+
"Message should be sent to both peers"
114+
);
115+
expect(result.failures?.length || 0).to.equal(0, "Should have no failures");
109116
});
110117
});

0 commit comments

Comments
 (0)