fix: debugging static sharding

This commit is contained in:
Arseniy Klempner 2025-09-10 13:45:27 -07:00
parent 1612b766cd
commit 797311a405
No known key found for this signature in database
GPG Key ID: 51653F18863BD24B
3 changed files with 81 additions and 30 deletions

View File

@ -3,16 +3,26 @@
# Docker entrypoint script for waku-browser-tests
# Handles CLI arguments and converts them to environment variables
# Supports reading discovered addresses from /etc/addrs/addrs.env (10k sim pattern)
echo "docker-entrypoint.sh"
echo "Using address: $addrs1"
export WAKU_LIGHTPUSH_NODE="$addrs1"
echo "Num Args: $#"
echo "Args: $@"
# Check if address file exists and source it
if [ -f "/etc/addrs/addrs.env" ]; then
echo "Sourcing discovered addresses from /etc/addrs/addrs.env"
source /etc/addrs/addrs.env
if [ -n "$addrs1" ]; then
export WAKU_LIGHTPUSH_NODE="$addrs1"
echo "Using discovered lightpush node: $WAKU_LIGHTPUSH_NODE"
fi
fi
# if [ -f "/etc/addrs/addrs.env" ]; then
# echo "Sourcing discovered addresses from /etc/addrs/addrs.env"
# source /etc/addrs/addrs.env
# if [ -n "$addrs1" ]; then
# export WAKU_LIGHTPUSH_NODE="$addrs1"
# echo "Using discovered lightpush node: $WAKU_LIGHTPUSH_NODE"
# else
# echo "addrs1 already set. Using $addrs1"
# fi
# fi
echo "WAKU_LIGHTPUSH_NODE=$addrs1"
# Parse command line arguments
while [[ $# -gt 0 ]]; do
@ -38,7 +48,8 @@ while [[ $# -gt 0 ]]; do
shift
;;
*)
# Unknown argument, keep it for the main command
# Unknown argument, notify user and keep it for the main command
echo "Warning: Unknown argument '$1' will be passed to the main command"
break
;;
esac

View File

@ -31,11 +31,14 @@ app.get("/app/index.html", (_req: Request, res: Response) => {
}
if (process.env.WAKU_SHARD) {
networkConfig.shards = [parseInt(process.env.WAKU_SHARD, 10)];
console.log("Using static shard:", networkConfig.shards);
}
const lightpushNode = process.env.WAKU_LIGHTPUSH_NODE || null;
const enrBootstrap = process.env.WAKU_ENR_BOOTSTRAP || null;
console.log("Network config on server start, pre headless:", networkConfig);
const configScript = ` <script>
window.__WAKU_NETWORK_CONFIG = ${JSON.stringify(networkConfig)};
window.__WAKU_LIGHTPUSH_NODE = ${JSON.stringify(lightpushNode)};

View File

@ -5,10 +5,17 @@ import {
NetworkConfig,
CreateNodeOptions,
} from "@waku/sdk";
import { DEFAULT_CLUSTER_ID, DEFAULT_NUM_SHARDS } from "@waku/interfaces";
import {
AutoSharding,
DEFAULT_CLUSTER_ID,
DEFAULT_NUM_SHARDS,
ShardId,
StaticSharding,
} from "@waku/interfaces";
import { bootstrap } from "@libp2p/bootstrap";
import { EnrDecoder, TransportProtocol } from "@waku/enr";
import type { ITestBrowser } from "../types/global.js";
import { StaticShardingRoutingInfo } from "@waku/utils";
export interface SerializableSDKProtocolResult {
successes: string[];
@ -119,18 +126,33 @@ export class WakuHeadless {
Array.isArray(staticShards) &&
staticShards.length > 0
) {
console.log("Using static sharding with shards:", staticShards);
return {
clusterId,
shards: staticShards,
} as NetworkConfig;
} as StaticSharding;
}
const numShardsInCluster =
(providedConfig as any)?.numShardsInCluster ?? DEFAULT_NUM_SHARDS;
console.log(
"Using auto sharding with num shards in cluster:",
numShardsInCluster,
);
return {
clusterId,
numShardsInCluster,
} as NetworkConfig;
} as AutoSharding;
}
private async send(
lightPush: any,
encoder: any,
payload: Uint8Array,
) {
return lightPush.send(encoder, {
payload,
timestamp: new Date(),
});
}
async pushMessageV3(
@ -141,7 +163,12 @@ export class WakuHeadless {
if (!this.waku) {
throw new Error("Waku node not started");
}
console.log("Pushing message via v3 lightpush:", contentTopic, payload, pubsubTopic);
console.log(
"Pushing message via v3 lightpush:",
contentTopic,
payload,
pubsubTopic,
);
console.log("Waku node:", this.waku);
console.log("Network config:", this.networkConfig);
@ -163,7 +190,20 @@ export class WakuHeadless {
throw new Error("Lightpush service not available");
}
const encoder = this.waku.createEncoder({ contentTopic });
let shardId: ShardId | undefined;
if (pubsubTopic) {
const staticShardingRoutingInfo =
StaticShardingRoutingInfo.fromPubsubTopic(
pubsubTopic,
this.networkConfig as StaticSharding,
);
shardId = staticShardingRoutingInfo?.shardId;
}
const encoder = this.waku.createEncoder({
contentTopic,
shardId,
});
console.log("Encoder:", encoder);
console.log("Pubsub topic:", pubsubTopic);
console.log("Encoder pubsub topic:", encoder.pubsubTopic);
@ -181,10 +221,7 @@ export class WakuHeadless {
this.lightpushNode,
);
if (preferredPeerId) {
result = await lightPush.send(encoder, {
payload: processedPayload,
timestamp: new Date(),
});
result = await this.send(lightPush, encoder, processedPayload);
console.log("✅ Message sent via preferred lightpush node");
} else {
throw new Error(
@ -192,17 +229,14 @@ export class WakuHeadless {
);
}
} catch (error) {
console.error("Couldn't send message via preferred lightpush node:", error);
result = await lightPush.send(encoder, {
payload: processedPayload,
timestamp: new Date(),
});
console.error(
"Couldn't send message via preferred lightpush node:",
error,
);
result = await this.send(lightPush, encoder, processedPayload);
}
} else {
result = await lightPush.send(encoder, {
payload: processedPayload,
timestamp: new Date(),
});
result = await this.send(lightPush, encoder, processedPayload);
}
const serializableResult = makeSerializable(result);
@ -264,7 +298,7 @@ export class WakuHeadless {
filterMultiaddrs: false,
};
if (this.enrBootstrap && this.shouldUseCustomBootstrap(options)) {
if (this.enrBootstrap) {
const multiaddrs = await this.getBootstrapMultiaddrs();
if (multiaddrs.length > 0) {
@ -307,7 +341,10 @@ export class WakuHeadless {
await this.waku.dial(this.lightpushNode);
} catch {
// Ignore dial errors
console.warn("Failed to dial preferred lightpush node:", this.lightpushNode);
console.warn(
"Failed to dial preferred lightpush node:",
this.lightpushNode,
);
}
}