2025-06-05 11:19:00 +03:00
|
|
|
import { LightNode, Protocols } from "@waku/interfaces";
|
feat!: Introduce routing info concept
Concepts are being mixed up between the global network config (static vs auto sharding), that needs to be the same of all nodes in the network, individual node configuration (eg relay node subscribing to a given shard), and the routing characteristic of a specific message (eg pubsub topic, shard).
This stops proper configuration of nwaku post 0.36.0 because we know need to be deliberate on whether nwaku nodes are running with auto or static sharding.
It also included various back and forth conversions between shards, pubsub topics, etc.
With this change, we tidy up the network configuration, and make it explicit whether it is static or auto sharded.
We also introduce the concept of routing info, which is specific to a message, and tied to the overall network configuration.
Routing info abstract pubsub topic, shard, and autosharding needs. Which should lead to easier tidy up of the pubsub concept at a later stage.
# Conflicts:
# packages/core/src/lib/connection_manager/connection_manager.ts
# packages/core/src/lib/metadata/metadata.ts
# packages/interfaces/src/metadata.ts
# packages/interfaces/src/sharding.ts
# packages/relay/src/create.ts
# packages/sdk/src/filter/filter.ts
# packages/sdk/src/filter/types.ts
# packages/sdk/src/light_push/light_push.spec.ts
# packages/tests/tests/sharding/auto_sharding.spec.ts
# packages/tests/tests/sharding/static_sharding.spec.ts
# Conflicts:
# packages/sdk/src/store/store.ts
2025-07-11 13:33:45 +10:00
|
|
|
import { createDecoder, createLightNode, utf8ToBytes } from "@waku/sdk";
|
2025-07-19 14:24:30 +10:00
|
|
|
import {
|
|
|
|
|
contentTopicToPubsubTopic,
|
|
|
|
|
createRoutingInfo,
|
|
|
|
|
delay
|
|
|
|
|
} from "@waku/utils";
|
2025-06-05 11:19:00 +03:00
|
|
|
import { expect } from "chai";
|
|
|
|
|
|
|
|
|
|
import {
|
|
|
|
|
afterEachCustom,
|
|
|
|
|
beforeEachCustom,
|
|
|
|
|
makeLogFileName,
|
|
|
|
|
MessageCollector,
|
|
|
|
|
ServiceNode,
|
|
|
|
|
tearDownNodes
|
|
|
|
|
} from "../../tests/src/index.js";
|
|
|
|
|
|
|
|
|
|
const ContentTopic = "/waku/2/content/test.js";
|
|
|
|
|
|
|
|
|
|
describe("Longevity", function () {
|
|
|
|
|
const testDurationMs = 2 * 60 * 60 * 1000; // 2 hours
|
2025-07-14 11:38:42 +03:00
|
|
|
this.timeout(testDurationMs * 1.1);
|
2025-06-05 11:19:00 +03:00
|
|
|
let waku: LightNode;
|
|
|
|
|
let nwaku: ServiceNode;
|
|
|
|
|
let messageCollector: MessageCollector;
|
|
|
|
|
|
|
|
|
|
beforeEachCustom(this, async () => {
|
|
|
|
|
nwaku = new ServiceNode(makeLogFileName(this.ctx));
|
|
|
|
|
messageCollector = new MessageCollector(nwaku);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
afterEachCustom(this, async () => {
|
|
|
|
|
await tearDownNodes(nwaku, waku);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("Filter - 2 hours", async function () {
|
feat!: Introduce routing info concept
Concepts are being mixed up between the global network config (static vs auto sharding), that needs to be the same of all nodes in the network, individual node configuration (eg relay node subscribing to a given shard), and the routing characteristic of a specific message (eg pubsub topic, shard).
This stops proper configuration of nwaku post 0.36.0 because we know need to be deliberate on whether nwaku nodes are running with auto or static sharding.
It also included various back and forth conversions between shards, pubsub topics, etc.
With this change, we tidy up the network configuration, and make it explicit whether it is static or auto sharded.
We also introduce the concept of routing info, which is specific to a message, and tied to the overall network configuration.
Routing info abstract pubsub topic, shard, and autosharding needs. Which should lead to easier tidy up of the pubsub concept at a later stage.
# Conflicts:
# packages/core/src/lib/connection_manager/connection_manager.ts
# packages/core/src/lib/metadata/metadata.ts
# packages/interfaces/src/metadata.ts
# packages/interfaces/src/sharding.ts
# packages/relay/src/create.ts
# packages/sdk/src/filter/filter.ts
# packages/sdk/src/filter/types.ts
# packages/sdk/src/light_push/light_push.spec.ts
# packages/tests/tests/sharding/auto_sharding.spec.ts
# packages/tests/tests/sharding/static_sharding.spec.ts
# Conflicts:
# packages/sdk/src/store/store.ts
2025-07-11 13:33:45 +10:00
|
|
|
const networkConfig = { clusterId: 0, numShardsInCluster: 8 };
|
2025-06-05 11:19:00 +03:00
|
|
|
|
|
|
|
|
const testStart = new Date();
|
|
|
|
|
|
|
|
|
|
const testEnd = Date.now() + testDurationMs;
|
|
|
|
|
|
|
|
|
|
const report: {
|
|
|
|
|
messageId: number;
|
|
|
|
|
timestamp: string;
|
|
|
|
|
sent: boolean;
|
|
|
|
|
received: boolean;
|
|
|
|
|
error?: string;
|
|
|
|
|
}[] = [];
|
|
|
|
|
|
|
|
|
|
await nwaku.start(
|
|
|
|
|
{
|
|
|
|
|
store: true,
|
|
|
|
|
filter: true,
|
|
|
|
|
relay: true,
|
|
|
|
|
clusterId: 0,
|
|
|
|
|
shard: [0],
|
|
|
|
|
contentTopic: [ContentTopic]
|
|
|
|
|
},
|
|
|
|
|
{ retries: 3 }
|
|
|
|
|
);
|
|
|
|
|
|
2025-07-19 14:24:30 +10:00
|
|
|
await nwaku.ensureSubscriptions([
|
|
|
|
|
contentTopicToPubsubTopic(
|
|
|
|
|
ContentTopic,
|
|
|
|
|
networkConfig.clusterId,
|
|
|
|
|
networkConfig.numShardsInCluster
|
|
|
|
|
)
|
|
|
|
|
]);
|
2025-06-05 11:19:00 +03:00
|
|
|
|
feat!: Introduce routing info concept
Concepts are being mixed up between the global network config (static vs auto sharding), that needs to be the same of all nodes in the network, individual node configuration (eg relay node subscribing to a given shard), and the routing characteristic of a specific message (eg pubsub topic, shard).
This stops proper configuration of nwaku post 0.36.0 because we know need to be deliberate on whether nwaku nodes are running with auto or static sharding.
It also included various back and forth conversions between shards, pubsub topics, etc.
With this change, we tidy up the network configuration, and make it explicit whether it is static or auto sharded.
We also introduce the concept of routing info, which is specific to a message, and tied to the overall network configuration.
Routing info abstract pubsub topic, shard, and autosharding needs. Which should lead to easier tidy up of the pubsub concept at a later stage.
# Conflicts:
# packages/core/src/lib/connection_manager/connection_manager.ts
# packages/core/src/lib/metadata/metadata.ts
# packages/interfaces/src/metadata.ts
# packages/interfaces/src/sharding.ts
# packages/relay/src/create.ts
# packages/sdk/src/filter/filter.ts
# packages/sdk/src/filter/types.ts
# packages/sdk/src/light_push/light_push.spec.ts
# packages/tests/tests/sharding/auto_sharding.spec.ts
# packages/tests/tests/sharding/static_sharding.spec.ts
# Conflicts:
# packages/sdk/src/store/store.ts
2025-07-11 13:33:45 +10:00
|
|
|
waku = await createLightNode({ networkConfig });
|
2025-06-05 11:19:00 +03:00
|
|
|
await waku.start();
|
|
|
|
|
await waku.dial(await nwaku.getMultiaddrWithId());
|
|
|
|
|
await waku.waitForPeers([Protocols.Filter]);
|
|
|
|
|
|
feat!: Introduce routing info concept
Concepts are being mixed up between the global network config (static vs auto sharding), that needs to be the same of all nodes in the network, individual node configuration (eg relay node subscribing to a given shard), and the routing characteristic of a specific message (eg pubsub topic, shard).
This stops proper configuration of nwaku post 0.36.0 because we know need to be deliberate on whether nwaku nodes are running with auto or static sharding.
It also included various back and forth conversions between shards, pubsub topics, etc.
With this change, we tidy up the network configuration, and make it explicit whether it is static or auto sharded.
We also introduce the concept of routing info, which is specific to a message, and tied to the overall network configuration.
Routing info abstract pubsub topic, shard, and autosharding needs. Which should lead to easier tidy up of the pubsub concept at a later stage.
# Conflicts:
# packages/core/src/lib/connection_manager/connection_manager.ts
# packages/core/src/lib/metadata/metadata.ts
# packages/interfaces/src/metadata.ts
# packages/interfaces/src/sharding.ts
# packages/relay/src/create.ts
# packages/sdk/src/filter/filter.ts
# packages/sdk/src/filter/types.ts
# packages/sdk/src/light_push/light_push.spec.ts
# packages/tests/tests/sharding/auto_sharding.spec.ts
# packages/tests/tests/sharding/static_sharding.spec.ts
# Conflicts:
# packages/sdk/src/store/store.ts
2025-07-11 13:33:45 +10:00
|
|
|
const routingInfo = createRoutingInfo(networkConfig, {
|
|
|
|
|
contentTopic: ContentTopic
|
|
|
|
|
});
|
|
|
|
|
const decoder = createDecoder(ContentTopic, routingInfo);
|
2025-07-02 12:37:54 +02:00
|
|
|
const hasSubscribed = await waku.filter.subscribe(
|
2025-06-05 11:19:00 +03:00
|
|
|
[decoder],
|
|
|
|
|
messageCollector.callback
|
|
|
|
|
);
|
2025-07-02 12:37:54 +02:00
|
|
|
if (!hasSubscribed) throw new Error("Failed to subscribe from the start.");
|
2025-06-05 11:19:00 +03:00
|
|
|
|
|
|
|
|
let messageId = 0;
|
|
|
|
|
|
|
|
|
|
while (Date.now() < testEnd) {
|
|
|
|
|
const now = new Date();
|
|
|
|
|
const message = `ping-${messageId}`;
|
|
|
|
|
let sent = false;
|
|
|
|
|
let received = false;
|
|
|
|
|
let err: string | undefined;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
await nwaku.sendMessage(
|
|
|
|
|
ServiceNode.toMessageRpcQuery({
|
|
|
|
|
contentTopic: ContentTopic,
|
|
|
|
|
payload: utf8ToBytes(message)
|
feat!: Introduce routing info concept
Concepts are being mixed up between the global network config (static vs auto sharding), that needs to be the same of all nodes in the network, individual node configuration (eg relay node subscribing to a given shard), and the routing characteristic of a specific message (eg pubsub topic, shard).
This stops proper configuration of nwaku post 0.36.0 because we know need to be deliberate on whether nwaku nodes are running with auto or static sharding.
It also included various back and forth conversions between shards, pubsub topics, etc.
With this change, we tidy up the network configuration, and make it explicit whether it is static or auto sharded.
We also introduce the concept of routing info, which is specific to a message, and tied to the overall network configuration.
Routing info abstract pubsub topic, shard, and autosharding needs. Which should lead to easier tidy up of the pubsub concept at a later stage.
# Conflicts:
# packages/core/src/lib/connection_manager/connection_manager.ts
# packages/core/src/lib/metadata/metadata.ts
# packages/interfaces/src/metadata.ts
# packages/interfaces/src/sharding.ts
# packages/relay/src/create.ts
# packages/sdk/src/filter/filter.ts
# packages/sdk/src/filter/types.ts
# packages/sdk/src/light_push/light_push.spec.ts
# packages/tests/tests/sharding/auto_sharding.spec.ts
# packages/tests/tests/sharding/static_sharding.spec.ts
# Conflicts:
# packages/sdk/src/store/store.ts
2025-07-11 13:33:45 +10:00
|
|
|
}),
|
|
|
|
|
routingInfo
|
2025-06-05 11:19:00 +03:00
|
|
|
);
|
|
|
|
|
sent = true;
|
|
|
|
|
|
|
|
|
|
received = await messageCollector.waitForMessages(1, {
|
|
|
|
|
timeoutDuration: 5000
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (received) {
|
|
|
|
|
messageCollector.verifyReceivedMessage(0, {
|
|
|
|
|
expectedMessageText: message,
|
|
|
|
|
expectedContentTopic: ContentTopic,
|
feat!: Introduce routing info concept
Concepts are being mixed up between the global network config (static vs auto sharding), that needs to be the same of all nodes in the network, individual node configuration (eg relay node subscribing to a given shard), and the routing characteristic of a specific message (eg pubsub topic, shard).
This stops proper configuration of nwaku post 0.36.0 because we know need to be deliberate on whether nwaku nodes are running with auto or static sharding.
It also included various back and forth conversions between shards, pubsub topics, etc.
With this change, we tidy up the network configuration, and make it explicit whether it is static or auto sharded.
We also introduce the concept of routing info, which is specific to a message, and tied to the overall network configuration.
Routing info abstract pubsub topic, shard, and autosharding needs. Which should lead to easier tidy up of the pubsub concept at a later stage.
# Conflicts:
# packages/core/src/lib/connection_manager/connection_manager.ts
# packages/core/src/lib/metadata/metadata.ts
# packages/interfaces/src/metadata.ts
# packages/interfaces/src/sharding.ts
# packages/relay/src/create.ts
# packages/sdk/src/filter/filter.ts
# packages/sdk/src/filter/types.ts
# packages/sdk/src/light_push/light_push.spec.ts
# packages/tests/tests/sharding/auto_sharding.spec.ts
# packages/tests/tests/sharding/static_sharding.spec.ts
# Conflicts:
# packages/sdk/src/store/store.ts
2025-07-11 13:33:45 +10:00
|
|
|
expectedPubsubTopic: routingInfo.pubsubTopic
|
2025-06-05 11:19:00 +03:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
} catch (e: any) {
|
|
|
|
|
err = e.message || String(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
report.push({
|
|
|
|
|
messageId,
|
|
|
|
|
timestamp: now.toISOString(),
|
|
|
|
|
sent,
|
|
|
|
|
received,
|
|
|
|
|
error: err
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
messageId++;
|
|
|
|
|
messageCollector.list = []; // clearing the message collector
|
|
|
|
|
await delay(400);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const failedMessages = report.filter(
|
|
|
|
|
(m) => !m.sent || !m.received || m.error
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
console.log("\n=== Longevity Test Summary ===");
|
|
|
|
|
console.log("Start time:", testStart.toISOString());
|
|
|
|
|
console.log("End time:", new Date().toISOString());
|
|
|
|
|
console.log("Total messages:", report.length);
|
|
|
|
|
console.log("Failures:", failedMessages.length);
|
|
|
|
|
|
|
|
|
|
if (failedMessages.length > 0) {
|
|
|
|
|
console.log("\n--- Failed Messages ---");
|
|
|
|
|
for (const fail of failedMessages) {
|
|
|
|
|
console.log(
|
|
|
|
|
`#${fail.messageId} @ ${fail.timestamp} | sent: ${fail.sent} | received: ${fail.received} | error: ${fail.error || "N/A"}`
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
expect(
|
|
|
|
|
failedMessages.length,
|
|
|
|
|
`Some messages failed: ${failedMessages.length}`
|
|
|
|
|
).to.eq(0);
|
|
|
|
|
});
|
|
|
|
|
});
|