From 356071e03ef0007077022c0446cb0941f1d4311b Mon Sep 17 00:00:00 2001 From: LordGhostX Date: Mon, 13 May 2024 14:43:25 +0100 Subject: [PATCH 1/8] intro --- docs/guides/js-waku/light-send-receive.md | 37 +++++++++++------------ 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/docs/guides/js-waku/light-send-receive.md b/docs/guides/js-waku/light-send-receive.md index c14585db..2e44dfe9 100644 --- a/docs/guides/js-waku/light-send-receive.md +++ b/docs/guides/js-waku/light-send-receive.md @@ -24,6 +24,8 @@ await node.start(); When the `defaultBootstrap` parameter is set to `true`, your node will be bootstrapped using the [default bootstrap method](/guides/js-waku/configure-discovery#default-bootstrap-method). Have a look at the [Bootstrap Nodes and Discover Peers](/guides/js-waku/configure-discovery) guide to learn more methods to bootstrap nodes. ::: +Your node will route messages to the default pubsub topic (`/waku/2/default-waku/proto`). If your project uses a different shared pubsub topic, you can change this using the `ShardInfo` parameter: + ## Connect to remote peers Use the `waitForRemotePeer()` function to wait for the node to connect with peers on the Waku Network: @@ -41,10 +43,7 @@ The `protocols` parameter allows you to specify the [protocols](/learn/concepts/ import { waitForRemotePeer, Protocols } from "@waku/sdk"; // Wait for peer connections with specific protocols -await waitForRemotePeer(node, [ - Protocols.LightPush, - Protocols.Filter, -]); +await waitForRemotePeer(node, [Protocols.LightPush, Protocols.Filter]); ``` ## Choose a content topic @@ -66,8 +65,8 @@ The `ephemeral` parameter allows you to specify whether messages should **NOT** ```js const encoder = createEncoder({ - contentTopic: contentTopic, // message content topic - ephemeral: true, // allows messages NOT be stored on the network + contentTopic: contentTopic, // message content topic + ephemeral: true, // allows messages NOT be stored on the network }); ``` @@ -84,9 +83,9 @@ import protobuf from "protobufjs"; // Create a message structure using Protobuf const ChatMessage = new protobuf.Type("ChatMessage") - .add(new protobuf.Field("timestamp", 1, "uint64")) - .add(new protobuf.Field("sender", 2, "string")) - .add(new protobuf.Field("message", 3, "string")); + .add(new protobuf.Field("timestamp", 1, "uint64")) + .add(new protobuf.Field("sender", 2, "string")) + .add(new protobuf.Field("message", 3, "string")); ``` :::info @@ -100,9 +99,9 @@ To send messages over the Waku Network using the `Light Push` protocol, create a ```js // Create a new message object const protoMessage = ChatMessage.create({ - timestamp: Date.now(), - sender: "Alice", - message: "Hello, World!", + timestamp: Date.now(), + sender: "Alice", + message: "Hello, World!", }); // Serialise the message using Protobuf @@ -110,7 +109,7 @@ const serialisedMessage = ChatMessage.encode(protoMessage).finish(); // Send the message using Light Push await node.lightPush.send(encoder, { - payload: serialisedMessage, + payload: serialisedMessage, }); ``` @@ -121,11 +120,11 @@ To receive messages using the `Filter` protocol, create a callback function for ```js // Create the callback function const callback = (wakuMessage) => { - // Check if there is a payload on the message - if (!wakuMessage.payload) return; - // Render the messageObj as desired in your application - const messageObj = ChatMessage.decode(wakuMessage.payload); - console.log(messageObj); + // Check if there is a payload on the message + if (!wakuMessage.payload) return; + // Render the messageObj as desired in your application + const messageObj = ChatMessage.decode(wakuMessage.payload); + console.log(messageObj); }; // Create a Filter subscription @@ -148,4 +147,4 @@ await subscription.unsubscribe([contentTopic]); :::tip Congratulations! You have successfully sent and received messages over the Waku Network using the `Light Push` and `Filter` protocols. Have a look at the [light-js](https://github.com/waku-org/js-waku-examples/tree/master/examples/light-js) and [light-chat](https://github.com/waku-org/js-waku-examples/tree/master/examples/light-chat) examples for working demos. -::: \ No newline at end of file +::: From b48f0ce7640a35bcfa28b97615749beb9c95ac31 Mon Sep 17 00:00:00 2001 From: LordGhostX Date: Tue, 14 May 2024 00:15:07 +0100 Subject: [PATCH 2/8] update js-waku docs --- docs/guides/js-waku/light-send-receive.md | 37 ++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/docs/guides/js-waku/light-send-receive.md b/docs/guides/js-waku/light-send-receive.md index 2e44dfe9..109788a1 100644 --- a/docs/guides/js-waku/light-send-receive.md +++ b/docs/guides/js-waku/light-send-receive.md @@ -24,7 +24,18 @@ await node.start(); When the `defaultBootstrap` parameter is set to `true`, your node will be bootstrapped using the [default bootstrap method](/guides/js-waku/configure-discovery#default-bootstrap-method). Have a look at the [Bootstrap Nodes and Discover Peers](/guides/js-waku/configure-discovery) guide to learn more methods to bootstrap nodes. ::: -Your node will route messages to the default pubsub topic (`/waku/2/default-waku/proto`). If your project uses a different shared pubsub topic, you can change this using the `ShardInfo` parameter: +By default, your node will route messages to the standard pubsub topic (`/waku/2/default-waku/proto`). If your project uses a different shared pubsub topic, you can configure this using the `ShardInfo` parameter: + +```js +// Create the shard info +const shardInfo = { clusterId: 3, shards: [1, 2] }; + +// Create node with custom shard info +const node = await createLightNode({ + defaultBootstrap: true, + shardInfo: shardInfo, +}); +``` ## Connect to remote peers @@ -70,6 +81,20 @@ const encoder = createEncoder({ }); ``` +The `pubsubTopicShardInfo` parameter allows you to configure a different shared pubsub topic for your `encoder` and `decoder`: + +```js +// Create the shard info +const shardInfo = { clusterId: 3, shard: 1 }; + +// Create encoder and decoder with custom shard info +const encoder = createEncoder({ + contentTopic: contentTopic, + pubsubTopicShardInfo: shardInfo, +}); +const decoder = createDecoder(contentTopic, shardInfo); +``` + :::info In this example, users send and receive messages on a shared content topic. However, real applications may have users broadcasting messages while others listen or only have 1:1 exchanges. Waku supports all these use cases. ::: @@ -139,6 +164,16 @@ if (error) { await subscription.subscribe([decoder], callback); ``` +The `pubsubTopicShardInfo` parameter allows you to configure a different shared pubsub topic for your `Filter` subscription: + +```js +// Create the shard info +const shardInfo = { clusterId: 3, shard: 1 }; + +// Create Filter subscription with custom shard info +const subscription = await node.filter.createSubscription(shardInfo); +``` + You can use the `subscription.unsubscribe()` function to stop receiving messages from a content topic: ```js From 2f964177a08088d72f750f1731b63f6d8dd70010 Mon Sep 17 00:00:00 2001 From: LordGhostX <47832826+LordGhostX@users.noreply.github.com> Date: Wed, 5 Jun 2024 16:41:40 +0100 Subject: [PATCH 3/8] update shard instructions Co-authored-by: Sasha <118575614+weboko@users.noreply.github.com> --- docs/guides/js-waku/light-send-receive.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/guides/js-waku/light-send-receive.md b/docs/guides/js-waku/light-send-receive.md index 109788a1..c695cc1c 100644 --- a/docs/guides/js-waku/light-send-receive.md +++ b/docs/guides/js-waku/light-send-receive.md @@ -24,7 +24,7 @@ await node.start(); When the `defaultBootstrap` parameter is set to `true`, your node will be bootstrapped using the [default bootstrap method](/guides/js-waku/configure-discovery#default-bootstrap-method). Have a look at the [Bootstrap Nodes and Discover Peers](/guides/js-waku/configure-discovery) guide to learn more methods to bootstrap nodes. ::: -By default, your node will route messages to the standard pubsub topic (`/waku/2/default-waku/proto`). If your project uses a different shared pubsub topic, you can configure this using the `ShardInfo` parameter: +A node needs to know how to route messages. In order to do that you can use standard pubsub topic (`/waku/2/default-waku/proto`). If your project uses a different shared pubsub topic, you can configure this using the `ShardInfo` parameter or by using a set of `contentTopics` that your node will be using: ```js // Create the shard info From 50e58fa4bb0c80b83af8e7906e900625555b1ef8 Mon Sep 17 00:00:00 2001 From: LordGhostX Date: Tue, 11 Jun 2024 17:12:52 +0100 Subject: [PATCH 4/8] remove chat references in message structure --- docs/guides/js-waku/light-send-receive.md | 8 ++++---- docs/guides/js-waku/use-waku-react.md | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/guides/js-waku/light-send-receive.md b/docs/guides/js-waku/light-send-receive.md index c695cc1c..2a89d2dc 100644 --- a/docs/guides/js-waku/light-send-receive.md +++ b/docs/guides/js-waku/light-send-receive.md @@ -107,7 +107,7 @@ Create your application's message structure using [Protobuf's valid message](htt import protobuf from "protobufjs"; // Create a message structure using Protobuf -const ChatMessage = new protobuf.Type("ChatMessage") +const DataPacket = new protobuf.Type("DataPacket") .add(new protobuf.Field("timestamp", 1, "uint64")) .add(new protobuf.Field("sender", 2, "string")) .add(new protobuf.Field("message", 3, "string")); @@ -123,14 +123,14 @@ To send messages over the Waku Network using the `Light Push` protocol, create a ```js // Create a new message object -const protoMessage = ChatMessage.create({ +const protoMessage = DataPacket.create({ timestamp: Date.now(), sender: "Alice", message: "Hello, World!", }); // Serialise the message using Protobuf -const serialisedMessage = ChatMessage.encode(protoMessage).finish(); +const serialisedMessage = DataPacket.encode(protoMessage).finish(); // Send the message using Light Push await node.lightPush.send(encoder, { @@ -148,7 +148,7 @@ const callback = (wakuMessage) => { // Check if there is a payload on the message if (!wakuMessage.payload) return; // Render the messageObj as desired in your application - const messageObj = ChatMessage.decode(wakuMessage.payload); + const messageObj = DataPacket.decode(wakuMessage.payload); console.log(messageObj); }; diff --git a/docs/guides/js-waku/use-waku-react.md b/docs/guides/js-waku/use-waku-react.md index 163e14e3..974af9ac 100644 --- a/docs/guides/js-waku/use-waku-react.md +++ b/docs/guides/js-waku/use-waku-react.md @@ -118,7 +118,7 @@ function App() { const decoder = createDecoder(contentTopic); // Create a message structure using Protobuf - const ChatMessage = new protobuf.Type("ChatMessage") + const DataPacket = new protobuf.Type("DataPacket") .add(new protobuf.Field("timestamp", 1, "uint64")) .add(new protobuf.Field("message", 2, "string")); @@ -223,13 +223,13 @@ function App() { // Create a new message object const timestamp = Date.now(); - const protoMessage = ChatMessage.create({ + const protoMessage = DataPacket.create({ timestamp: timestamp, message: inputMessage }); // Serialise the message and push to the network - const payload = ChatMessage.encode(protoMessage).finish(); + const payload = DataPacket.encode(protoMessage).finish(); const { recipients, errors } = await push({ payload, timestamp }); // Check for errors @@ -258,7 +258,7 @@ function App() { useEffect(() => { setMessages(filterMessages.map((wakuMessage) => { if (!wakuMessage.payload) return; - return ChatMessage.decode(wakuMessage.payload); + return DataPacket.decode(wakuMessage.payload); })); }, [filterMessages]); } @@ -283,7 +283,7 @@ function App() { const allMessages = storeMessages.concat(filterMessages); setMessages(allMessages.map((wakuMessage) => { if (!wakuMessage.payload) return; - return ChatMessage.decode(wakuMessage.payload); + return DataPacket.decode(wakuMessage.payload); })); }, [filterMessages, storeMessages]); } @@ -295,4 +295,4 @@ To explore the available Store query options, have a look at the [Retrieve Messa :::tip You have successfully integrated `@waku/sdk` into a React application using the `@waku/react` package. Have a look at the [web-chat](https://github.com/waku-org/js-waku-examples/tree/master/examples/web-chat) example for a working demo and the [Building a Tic-Tac-Toe Game with Waku](https://blog.waku.org/tictactoe-tutorial) tutorial to learn more. -::: \ No newline at end of file +::: From de1b757f2da70dd9810e5936e4ad3037fcca2fc5 Mon Sep 17 00:00:00 2001 From: LordGhostX Date: Sun, 16 Jun 2024 16:22:26 +0100 Subject: [PATCH 5/8] add info on contentTopics parameter --- docs/guides/js-waku/light-send-receive.md | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/docs/guides/js-waku/light-send-receive.md b/docs/guides/js-waku/light-send-receive.md index 2a89d2dc..8012b3ff 100644 --- a/docs/guides/js-waku/light-send-receive.md +++ b/docs/guides/js-waku/light-send-receive.md @@ -24,13 +24,17 @@ await node.start(); When the `defaultBootstrap` parameter is set to `true`, your node will be bootstrapped using the [default bootstrap method](/guides/js-waku/configure-discovery#default-bootstrap-method). Have a look at the [Bootstrap Nodes and Discover Peers](/guides/js-waku/configure-discovery) guide to learn more methods to bootstrap nodes. ::: -A node needs to know how to route messages. In order to do that you can use standard pubsub topic (`/waku/2/default-waku/proto`). If your project uses a different shared pubsub topic, you can configure this using the `ShardInfo` parameter or by using a set of `contentTopics` that your node will be using: +A node needs to know how to route messages. In order to do that you can use standard pubsub topic (`/waku/2/default-waku/proto`). If your project uses a different pubsub topic, you can configure this by providing a set of [content topics](/learn/concepts/content-topics) for the node to use with the `contentTopics` parameter or by using the `ShardInfo` parameter: ```js -// Create the shard info -const shardInfo = { clusterId: 3, shards: [1, 2] }; +// Create node with content topics +const node = await createLightNode({ + defaultBootstrap: true, + contentTopics: [/*set of content topics*/], +}); // Create node with custom shard info +const shardInfo = { clusterId: 3, shards: [1, 2] }; const node = await createLightNode({ defaultBootstrap: true, shardInfo: shardInfo, @@ -59,7 +63,7 @@ await waitForRemotePeer(node, [Protocols.LightPush, Protocols.Filter]); ## Choose a content topic -[Choose a content topic](/learn/concepts/content-topics) for your application and create a message `encoder` and `decoder`: +Choose a [content topic](/learn/concepts/content-topics) for your application and create a message `encoder` and `decoder`: ```js import { createEncoder, createDecoder } from "@waku/sdk"; From 83f8290d065be1ecfa2901885109d9d6b85270cf Mon Sep 17 00:00:00 2001 From: Danish Arora Date: Mon, 30 Sep 2024 23:26:47 +0530 Subject: [PATCH 6/8] chore: update guide for v0.027 --- docs/guides/js-waku/light-send-receive.md | 41 +++++++++++++---------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/docs/guides/js-waku/light-send-receive.md b/docs/guides/js-waku/light-send-receive.md index 8012b3ff..307e8c55 100644 --- a/docs/guides/js-waku/light-send-receive.md +++ b/docs/guides/js-waku/light-send-receive.md @@ -24,20 +24,25 @@ await node.start(); When the `defaultBootstrap` parameter is set to `true`, your node will be bootstrapped using the [default bootstrap method](/guides/js-waku/configure-discovery#default-bootstrap-method). Have a look at the [Bootstrap Nodes and Discover Peers](/guides/js-waku/configure-discovery) guide to learn more methods to bootstrap nodes. ::: -A node needs to know how to route messages. In order to do that you can use standard pubsub topic (`/waku/2/default-waku/proto`). If your project uses a different pubsub topic, you can configure this by providing a set of [content topics](/learn/concepts/content-topics) for the node to use with the `contentTopics` parameter or by using the `ShardInfo` parameter: +A node needs to know how to route messages. By default, it will use The Waku Network configuration (`{ clusterId: 1, shards: [0,1,2,3,4,5,6,7] }`). If your project uses a different network configuration, you can configure this using the `networkConfig` parameter: ```js -// Create node with content topics +// Create node with static sharding const node = await createLightNode({ defaultBootstrap: true, - contentTopics: [/*set of content topics*/], + networkConfig: { + clusterId: 1, + shards: [0, 1, 2, 3], + }, }); -// Create node with custom shard info -const shardInfo = { clusterId: 3, shards: [1, 2] }; +// Create node with auto sharding const node = await createLightNode({ defaultBootstrap: true, - shardInfo: shardInfo, + networkConfig: { + clusterId: 1, + contentTopics: ["/my-app/1/notifications/proto"], + }, }); ``` @@ -85,18 +90,18 @@ const encoder = createEncoder({ }); ``` -The `pubsubTopicShardInfo` parameter allows you to configure a different shared pubsub topic for your `encoder` and `decoder`: +The `pubsubTopicShardInfo` parameter allows you to configure a different network configuration for your `encoder` and `decoder`: ```js -// Create the shard info -const shardInfo = { clusterId: 3, shard: 1 }; +// Create the network config +const networkConfig = { clusterId: 3, shards: [1, 2] }; -// Create encoder and decoder with custom shard info +// Create encoder and decoder with custom network config const encoder = createEncoder({ contentTopic: contentTopic, - pubsubTopicShardInfo: shardInfo, + pubsubTopicShardInfo: networkConfig, }); -const decoder = createDecoder(contentTopic, shardInfo); +const decoder = createDecoder(contentTopic, networkConfig); ``` :::info @@ -168,14 +173,14 @@ if (error) { await subscription.subscribe([decoder], callback); ``` -The `pubsubTopicShardInfo` parameter allows you to configure a different shared pubsub topic for your `Filter` subscription: +The `pubsubTopicShardInfo` parameter allows you to configure a different network configuration for your `Filter` subscription: ```js -// Create the shard info -const shardInfo = { clusterId: 3, shard: 1 }; +// Create the network config +const networkConfig = { clusterId: 3, shards: [1, 2] }; -// Create Filter subscription with custom shard info -const subscription = await node.filter.createSubscription(shardInfo); +// Create Filter subscription with custom network config +const subscription = await node.filter.createSubscription(networkConfig); ``` You can use the `subscription.unsubscribe()` function to stop receiving messages from a content topic: @@ -186,4 +191,4 @@ await subscription.unsubscribe([contentTopic]); :::tip Congratulations! You have successfully sent and received messages over the Waku Network using the `Light Push` and `Filter` protocols. Have a look at the [light-js](https://github.com/waku-org/js-waku-examples/tree/master/examples/light-js) and [light-chat](https://github.com/waku-org/js-waku-examples/tree/master/examples/light-chat) examples for working demos. -::: +::: \ No newline at end of file From e34e764b7f19be38d3c913b0f59c2534351812a9 Mon Sep 17 00:00:00 2001 From: Danish Arora Date: Tue, 1 Oct 2024 12:00:30 +0530 Subject: [PATCH 7/8] chore: prioritize autosharding over static sharding --- docs/guides/js-waku/light-send-receive.md | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/docs/guides/js-waku/light-send-receive.md b/docs/guides/js-waku/light-send-receive.md index 307e8c55..809a767d 100644 --- a/docs/guides/js-waku/light-send-receive.md +++ b/docs/guides/js-waku/light-send-receive.md @@ -24,24 +24,30 @@ await node.start(); When the `defaultBootstrap` parameter is set to `true`, your node will be bootstrapped using the [default bootstrap method](/guides/js-waku/configure-discovery#default-bootstrap-method). Have a look at the [Bootstrap Nodes and Discover Peers](/guides/js-waku/configure-discovery) guide to learn more methods to bootstrap nodes. ::: -A node needs to know how to route messages. By default, it will use The Waku Network configuration (`{ clusterId: 1, shards: [0,1,2,3,4,5,6,7] }`). If your project uses a different network configuration, you can configure this using the `networkConfig` parameter: +A node needs to know how to route messages. By default, it will use The Waku Network configuration (`{ clusterId: 1, shards: [0,1,2,3,4,5,6,7] }`). For most applications, it's recommended to use autosharding: ```js -// Create node with static sharding +// Create node with auto sharding (recommended) const node = await createLightNode({ defaultBootstrap: true, networkConfig: { clusterId: 1, - shards: [0, 1, 2, 3], + contentTopics: ["/my-app/1/notifications/proto"], }, }); +``` + +### Alternative network configuration -// Create node with auto sharding +If your project requires a specific network configuration, you can use static sharding: + +```js +// Create node with static sharding const node = await createLightNode({ defaultBootstrap: true, networkConfig: { clusterId: 1, - contentTopics: ["/my-app/1/notifications/proto"], + shards: [0, 1, 2, 3], }, }); ``` From 350dacc7477a791bab234041e0a233d4aa29fe0a Mon Sep 17 00:00:00 2001 From: Danish Arora Date: Tue, 1 Oct 2024 12:20:47 +0530 Subject: [PATCH 8/8] chore: update cspell for autosharding --- .cspell.json | 1 + 1 file changed, 1 insertion(+) diff --git a/.cspell.json b/.cspell.json index 038c3ad2..10e618d3 100644 --- a/.cspell.json +++ b/.cspell.json @@ -17,6 +17,7 @@ "enrtree", "Discv5", "gossipsub", + "autosharding", "lightpush", "pubtopic1", "proto",