feat: setup node to use autosharding in rln-js

This commit is contained in:
Arseniy Klempner 2024-01-11 19:13:03 -08:00
parent 504bcd4431
commit d99a7da194
No known key found for this signature in database
GPG Key ID: 59967D458EFBF01B
3 changed files with 959 additions and 689 deletions

File diff suppressed because it is too large Load Diff

View File

@ -10,8 +10,8 @@
},
"dependencies": {
"@waku/rln": "0.1.1-0fbf6be",
"@waku/sdk": "^0.0.20",
"@waku/utils": "^0.0.12",
"@waku/sdk": "0.0.22",
"@waku/utils": "0.0.14",
"ethers": "^5.7.2",
"multiaddr": "^10.0.1",
"next": "13.5.6",
@ -22,6 +22,7 @@
},
"devDependencies": {
"@metamask/types": "^1.1.0",
"@multiformats/multiaddr-matcher": "^1.1.2",
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",

View File

@ -19,6 +19,7 @@ import {
RLNContract,
} from "@waku/rln";
import { RLN } from "@/services/rln";
import { contentTopicToShardIndex } from "@waku/utils";
type InitOptions = {
membershipID: number;
@ -84,12 +85,15 @@ export class Waku implements IWaku {
this.initEncoder(options);
this.decoder = new RLNDecoder(
options.rln.rlnInstance,
createDecoder(this.contentTopic)
createDecoder(this.contentTopic, { clusterId: 1 })
);
if (!this.node) {
this.emitStatusEvent(WakuStatusEventPayload.INITIALIZING);
this.node = await createLightNode({ defaultBootstrap: true });
this.node = await createLightNode({
defaultBootstrap: true,
shardInfo: { clusterId: 1, contentTopics: [CONTENT_TOPIC] },
});
this.emitStatusEvent(WakuStatusEventPayload.STARTING);
await this.node.start();
this.emitStatusEvent(WakuStatusEventPayload.WAITING_FOR_PEERS);
@ -119,6 +123,7 @@ export class Waku implements IWaku {
createEncoder({
ephemeral: false,
contentTopic: this.contentTopic,
pubsubTopicShardInfo: { clusterId: 1 },
}),
rln.rlnInstance,
membershipID,
@ -145,7 +150,11 @@ export class Waku implements IWaku {
}
private async subscribeToMessages(options: SubscribeOptions) {
await options.node.filter.subscribe(options.decoder, (message) => {
const subscription = await options.node.filter.createSubscription({
clusterId: 1,
shard: contentTopicToShardIndex(CONTENT_TOPIC),
});
await subscription.subscribe(options.decoder, (message) => {
try {
const { timestamp, nick, text } = ProtoChatMessage.decode(
message.payload