Skip to content

Commit 7a41587

Browse files
committed
fix: debugging static sharding
1 parent 85864a5 commit 7a41587

File tree

3 files changed

+67
-18
lines changed

3 files changed

+67
-18
lines changed

packages/browser-tests/scripts/docker-entrypoint.sh

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,26 @@
33
# Docker entrypoint script for waku-browser-tests
44
# Handles CLI arguments and converts them to environment variables
55
# Supports reading discovered addresses from /etc/addrs/addrs.env (10k sim pattern)
6+
echo "docker-entrypoint.sh"
7+
echo "Using address: $addrs1"
8+
export WAKU_LIGHTPUSH_NODE="$addrs1"
9+
echo "Num Args: $#"
10+
echo "Args: $@"
11+
612

713
# Check if address file exists and source it
8-
if [ -f "/etc/addrs/addrs.env" ]; then
9-
echo "Sourcing discovered addresses from /etc/addrs/addrs.env"
10-
source /etc/addrs/addrs.env
11-
if [ -n "$addrs1" ]; then
12-
export WAKU_LIGHTPUSH_NODE="$addrs1"
13-
echo "Using discovered lightpush node: $WAKU_LIGHTPUSH_NODE"
14-
fi
15-
fi
14+
# if [ -f "/etc/addrs/addrs.env" ]; then
15+
# echo "Sourcing discovered addresses from /etc/addrs/addrs.env"
16+
# source /etc/addrs/addrs.env
17+
# if [ -n "$addrs1" ]; then
18+
# export WAKU_LIGHTPUSH_NODE="$addrs1"
19+
# echo "Using discovered lightpush node: $WAKU_LIGHTPUSH_NODE"
20+
# else
21+
# echo "addrs1 already set. Using $addrs1"
22+
# fi
23+
# fi
24+
25+
echo "WAKU_LIGHTPUSH_NODE=$addrs1"
1626

1727
# Parse command line arguments
1828
while [[ $# -gt 0 ]]; do
@@ -38,7 +48,8 @@ while [[ $# -gt 0 ]]; do
3848
shift
3949
;;
4050
*)
41-
# Unknown argument, keep it for the main command
51+
# Unknown argument, notify user and keep it for the main command
52+
echo "Warning: Unknown argument '$1' will be passed to the main command"
4253
break
4354
;;
4455
esac

packages/browser-tests/src/server.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,14 @@ app.get("/app/index.html", (_req: Request, res: Response) => {
3131
}
3232
if (process.env.WAKU_SHARD) {
3333
networkConfig.shards = [parseInt(process.env.WAKU_SHARD, 10)];
34+
console.log("Using static shard:", networkConfig.shards);
3435
}
3536

3637
const lightpushNode = process.env.WAKU_LIGHTPUSH_NODE || null;
3738
const enrBootstrap = process.env.WAKU_ENR_BOOTSTRAP || null;
3839

40+
console.log("Network config on server start, pre headless:", networkConfig);
41+
3942
const configScript = ` <script>
4043
window.__WAKU_NETWORK_CONFIG = ${JSON.stringify(networkConfig)};
4144
window.__WAKU_LIGHTPUSH_NODE = ${JSON.stringify(lightpushNode)};

packages/browser-tests/web/index.ts

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,17 @@ import {
55
NetworkConfig,
66
CreateNodeOptions,
77
} from "@waku/sdk";
8-
import { DEFAULT_CLUSTER_ID, DEFAULT_NUM_SHARDS } from "@waku/interfaces";
8+
import {
9+
AutoSharding,
10+
DEFAULT_CLUSTER_ID,
11+
DEFAULT_NUM_SHARDS,
12+
ShardId,
13+
StaticSharding,
14+
} from "@waku/interfaces";
915
import { bootstrap } from "@libp2p/bootstrap";
1016
import { EnrDecoder, TransportProtocol } from "@waku/enr";
1117
import type { ITestBrowser } from "../types/global.js";
18+
import { StaticShardingRoutingInfo } from "@waku/utils";
1219

1320
export interface SerializableSDKProtocolResult {
1421
successes: string[];
@@ -119,18 +126,22 @@ export class WakuHeadless {
119126
Array.isArray(staticShards) &&
120127
staticShards.length > 0
121128
) {
129+
console.log("Using static sharding with shards:", staticShards);
122130
return {
123131
clusterId,
124-
shards: staticShards,
125-
} as NetworkConfig;
132+
} as StaticSharding;
126133
}
127134

128135
const numShardsInCluster =
129136
(providedConfig as any)?.numShardsInCluster ?? DEFAULT_NUM_SHARDS;
137+
console.log(
138+
"Using auto sharding with num shards in cluster:",
139+
numShardsInCluster,
140+
);
130141
return {
131142
clusterId,
132143
numShardsInCluster,
133-
} as NetworkConfig;
144+
} as AutoSharding;
134145
}
135146

136147
async pushMessageV3(
@@ -141,7 +152,12 @@ export class WakuHeadless {
141152
if (!this.waku) {
142153
throw new Error("Waku node not started");
143154
}
144-
console.log("Pushing message via v3 lightpush:", contentTopic, payload, pubsubTopic);
155+
console.log(
156+
"Pushing message via v3 lightpush:",
157+
contentTopic,
158+
payload,
159+
pubsubTopic,
160+
);
145161
console.log("Waku node:", this.waku);
146162
console.log("Network config:", this.networkConfig);
147163

@@ -163,7 +179,20 @@ export class WakuHeadless {
163179
throw new Error("Lightpush service not available");
164180
}
165181

166-
const encoder = this.waku.createEncoder({ contentTopic });
182+
let shardId: ShardId | undefined;
183+
if (pubsubTopic) {
184+
const staticShardingRoutingInfo =
185+
StaticShardingRoutingInfo.fromPubsubTopic(
186+
pubsubTopic,
187+
this.networkConfig as StaticSharding,
188+
);
189+
shardId = staticShardingRoutingInfo?.shardId;
190+
}
191+
192+
const encoder = this.waku.createEncoder({
193+
contentTopic,
194+
shardId,
195+
});
167196
console.log("Encoder:", encoder);
168197
console.log("Pubsub topic:", pubsubTopic);
169198
console.log("Encoder pubsub topic:", encoder.pubsubTopic);
@@ -192,7 +221,10 @@ export class WakuHeadless {
192221
);
193222
}
194223
} catch (error) {
195-
console.error("Couldn't send message via preferred lightpush node:", error);
224+
console.error(
225+
"Couldn't send message via preferred lightpush node:",
226+
error,
227+
);
196228
result = await lightPush.send(encoder, {
197229
payload: processedPayload,
198230
timestamp: new Date(),
@@ -264,7 +296,7 @@ export class WakuHeadless {
264296
filterMultiaddrs: false,
265297
};
266298

267-
if (this.enrBootstrap && this.shouldUseCustomBootstrap(options)) {
299+
if (this.enrBootstrap) {
268300
const multiaddrs = await this.getBootstrapMultiaddrs();
269301

270302
if (multiaddrs.length > 0) {
@@ -307,7 +339,10 @@ export class WakuHeadless {
307339
await this.waku.dial(this.lightpushNode);
308340
} catch {
309341
// Ignore dial errors
310-
console.warn("Failed to dial preferred lightpush node:", this.lightpushNode);
342+
console.warn(
343+
"Failed to dial preferred lightpush node:",
344+
this.lightpushNode,
345+
);
311346
}
312347
}
313348

0 commit comments

Comments
 (0)