Skip to content

Commit db0de08

Browse files
authored
Merge branch 'master' into feat/continuous-discovery
2 parents 1e6d4f0 + 08fc2d1 commit db0de08

File tree

24 files changed

+189
-120
lines changed

24 files changed

+189
-120
lines changed

packages/discovery/src/dns/constants.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,11 @@ import type { NodeCapabilityCount } from "@waku/interfaces";
33
/**
44
* The ENR tree for the different fleets.
55
* SANDBOX and TEST fleets are for The Waku Network.
6-
* DEPRECATED_DEFAULT_PUBSUB is the fleet of nodes supporting the now deprecated DefaultPubsubTopic.
76
*/
87
export const enrTree = {
98
SANDBOX:
109
"enrtree://AIRVQ5DDA4FFWLRBCHJWUWOO6X6S4ZTZ5B667LQ6AJU6PEYDLRD5O@sandbox.waku.nodes.status.im",
11-
TEST: "enrtree://AOGYWMBYOUIMOENHXCHILPKY3ZRFEULMFI4DOM442QSZ73TT2A7VI@test.waku.nodes.status.im",
12-
DEPRECATED_DEFAULT_PUBSUB:
13-
"enrtree://ANEDLO25QVUGJOUTQFRYKWX6P4Z4GKVESBMHML7DZ6YK4LGS5FC5O@prod.wakuv2.nodes.status.im"
10+
TEST: "enrtree://AOGYWMBYOUIMOENHXCHILPKY3ZRFEULMFI4DOM442QSZ73TT2A7VI@test.waku.nodes.status.im"
1411
};
1512

1613
export const DEFAULT_BOOTSTRAP_TAG_NAME = "bootstrap";

packages/interfaces/src/constants.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1-
/**
2-
* DefaultPubsubTopic is the default gossipsub topic to use for Waku.
3-
*/
4-
export const DefaultPubsubTopic = "/waku/2/default-waku/proto";
1+
import { ShardInfo } from "./enr";
52

63
/**
74
* The default cluster ID for The Waku Network
85
*/
96
export const DEFAULT_CLUSTER_ID = 1;
7+
8+
/**
9+
* DefaultShardInfo is default configuration for The Waku Network.
10+
*/
11+
export const DefaultShardInfo: ShardInfo = {
12+
clusterId: DEFAULT_CLUSTER_ID,
13+
shards: [0, 1, 2, 3, 4, 5, 6, 7, 8]
14+
};

packages/interfaces/src/protocols.ts

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -73,31 +73,35 @@ export type ProtocolUseOptions = {
7373
export type ProtocolCreateOptions = {
7474
/**
7575
* @deprecated
76-
* Waku will stop supporting named sharding. Only static sharding and autosharding will be supported moving forward.
77-
*/
78-
pubsubTopics?: PubsubTopic[];
79-
/**
80-
* Waku supports usage of multiple pubsub topics. This is achieved through static sharding for now, and auto-sharding in the future.
81-
* The format to specify a shard is:
82-
* clusterId: number, shards: number[]
83-
* To learn more about the sharding specifications implemented, see [Relay Sharding](https://rfc.vac.dev/spec/51/).
84-
* The Pubsub Topic to use. Defaults to {@link @waku/core!DefaultPubsubTopic }.
76+
* Should be used ONLY if some other than The Waku Network is in use.
77+
*
78+
* See [Waku v2 Topic Usage Recommendations](https://github.com/vacp2p/rfc-index/blob/main/waku/informational/23/topics.md#pubsub-topics) for details.
8579
*
86-
* If no pubsub topic is specified, the default pubsub topic is used.
87-
* The set of pubsub topics that are used to initialize the Waku node, will need to be used by the protocols as well
88-
* You cannot currently add or remove pubsub topics after initialization.
8980
* This is used by:
9081
* - WakuRelay to receive, route and send messages,
9182
* - WakuLightPush to send messages,
9283
* - WakuStore to retrieve messages.
93-
* See [Waku v2 Topic Usage Recommendations](https://github.com/vacp2p/rfc-index/blob/main/waku/informational/23/topics.md) for details.
9484
*
85+
* If no pubsub topic is specified, the default pubsub topic will be determined from DefaultShardInfo.
86+
*
87+
* You cannot add or remove pubsub topics after initialization of the node.
88+
*/
89+
pubsubTopics?: PubsubTopic[];
90+
/**
91+
* ShardInfo is used to determine which network is in use.
92+
* Defaults to {@link @waku/interfaces!DefaultShardInfo}.
93+
* Default value is configured for The Waku Network
94+
*
95+
* The format to specify a shard is:
96+
* clusterId: number, shards: number[]
97+
* To learn more about the sharding specification, see [Relay Sharding](https://rfc.vac.dev/spec/51/).
9598
*/
9699
shardInfo?: Partial<ShardingParams>;
97100
/**
98-
* Content topics are used to determine pubsubTopics
99-
* If not provided pubsubTopics will be determined based on shardInfo
100-
* See [Waku v2 Topic Usage Recommendations](https://github.com/vacp2p/rfc-index/blob/main/waku/informational/23/topics.md) for details.
101+
* Content topics are used to determine network in use.
102+
* See [Waku v2 Topic Usage Recommendations](https://github.com/vacp2p/rfc-index/blob/main/waku/informational/23/topics.md#content-topics) for details.
103+
*
104+
* You cannot add or remove content topics after initialization of the node.
101105
*/
102106
contentTopics?: string[];
103107
/**

packages/message-encryption/src/symmetric.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Decoder as DecoderV0 } from "@waku/core/lib/message/version_0";
22
import {
33
type EncoderOptions as BaseEncoderOptions,
4-
DefaultPubsubTopic,
54
type IDecoder,
65
type IEncoder,
76
type IMessage,
@@ -101,7 +100,7 @@ export interface EncoderOptions extends BaseEncoderOptions {
101100
* in [26/WAKU2-PAYLOAD](https://rfc.vac.dev/spec/26/).
102101
*/
103102
export function createEncoder({
104-
pubsubTopic = DefaultPubsubTopic,
103+
pubsubTopic,
105104
pubsubTopicShardInfo,
106105
contentTopic,
107106
symKey,
@@ -198,7 +197,7 @@ class Decoder extends DecoderV0 implements IDecoder<DecodedMessage> {
198197
export function createDecoder(
199198
contentTopic: string,
200199
symKey: Uint8Array,
201-
pubsubTopicShardInfo: SingleShardInfo | PubsubTopic = DefaultPubsubTopic
200+
pubsubTopicShardInfo?: SingleShardInfo | PubsubTopic
202201
): Decoder {
203202
return new Decoder(
204203
determinePubsubTopic(contentTopic, pubsubTopicShardInfo),

packages/relay/src/index.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { sha256 } from "@noble/hashes/sha256";
1111
import {
1212
ActiveSubscriptions,
1313
Callback,
14-
DefaultPubsubTopic,
1514
IAsyncIterator,
1615
IDecodedMessage,
1716
IDecoder,
@@ -75,9 +74,8 @@ class Relay implements IRelay {
7574

7675
this.observers = new Map();
7776

78-
// Default PubsubTopic decoder
7977
// TODO: User might want to decide what decoder should be used (e.g. for RLN)
80-
this.defaultDecoder = new TopicOnlyDecoder();
78+
this.defaultDecoder = new TopicOnlyDecoder(pubsubTopics[0]);
8179
}
8280

8381
/**
@@ -204,8 +202,9 @@ class Relay implements IRelay {
204202
return map;
205203
}
206204

207-
public getMeshPeers(topic: TopicStr = DefaultPubsubTopic): PeerIdStr[] {
208-
return this.gossipSub.getMeshPeers(topic);
205+
public getMeshPeers(topic?: TopicStr): PeerIdStr[] {
206+
// if no TopicStr is provided - returns empty array
207+
return this.gossipSub.getMeshPeers(topic || "");
209208
}
210209

211210
private subscribeToAllTopics(): void {

packages/relay/src/topic_only_message.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { DefaultPubsubTopic } from "@waku/interfaces";
21
import type {
32
IDecodedMessage,
43
IDecoder,
5-
IProtoMessage
4+
IProtoMessage,
5+
PubsubTopic
66
} from "@waku/interfaces";
77
import { TopicOnlyMessage as ProtoTopicOnlyMessage } from "@waku/proto";
88

@@ -23,10 +23,13 @@ export class TopicOnlyMessage implements IDecodedMessage {
2323
}
2424
}
2525

26+
// This decoder is used only for reading `contentTopic` from the WakuMessage
2627
export class TopicOnlyDecoder implements IDecoder<TopicOnlyMessage> {
27-
public pubsubTopic = DefaultPubsubTopic;
2828
public contentTopic = "";
2929

30+
// pubsubTopic is ignored
31+
public constructor(public pubsubTopic: PubsubTopic) {}
32+
3033
public fromWireToProtoObj(
3134
bytes: Uint8Array
3235
): Promise<IProtoMessage | undefined> {

packages/sdk/src/create/discovery.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@ import {
55
wakuLocalPeerCacheDiscovery,
66
wakuPeerExchangeDiscovery
77
} from "@waku/discovery";
8-
import {
9-
DefaultPubsubTopic,
10-
type Libp2pComponents,
11-
PubsubTopic
12-
} from "@waku/interfaces";
8+
import { type Libp2pComponents, PubsubTopic } from "@waku/interfaces";
139

1410
const DEFAULT_NODE_REQUIREMENTS = {
1511
lightPush: 1,
@@ -20,10 +16,7 @@ const DEFAULT_NODE_REQUIREMENTS = {
2016
export function defaultPeerDiscoveries(
2117
pubsubTopics: PubsubTopic[]
2218
): ((components: Libp2pComponents) => PeerDiscovery)[] {
23-
const isDefaultPubsubTopic = pubsubTopics.includes(DefaultPubsubTopic);
24-
const dnsEnrTrees = isDefaultPubsubTopic
25-
? [enrTree["DEPRECATED_DEFAULT_PUBSUB"]]
26-
: [enrTree["SANDBOX"], enrTree["TEST"]];
19+
const dnsEnrTrees = [enrTree["SANDBOX"], enrTree["TEST"]];
2720

2821
const discoveries = [
2922
wakuDnsDiscovery(dnsEnrTrees, DEFAULT_NODE_REQUIREMENTS),

packages/sdk/src/create/libp2p.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { all as filterAll, wss } from "@libp2p/websockets/filters";
99
import { wakuMetadata } from "@waku/core";
1010
import {
1111
type CreateLibp2pOptions,
12-
DefaultPubsubTopic,
12+
DefaultShardInfo,
1313
type IMetadata,
1414
type Libp2p,
1515
type Libp2pComponents,
@@ -138,12 +138,15 @@ function configureNetworkOptions(
138138
options.shardInfo = { contentTopics: options.contentTopics };
139139
}
140140

141+
if (!options.shardInfo) {
142+
options.shardInfo = DefaultShardInfo;
143+
}
144+
141145
const shardInfo = options.shardInfo
142146
? ensureShardingConfigured(options.shardInfo)
143147
: undefined;
144148

145-
options.pubsubTopics = shardInfo?.pubsubTopics ??
146-
options.pubsubTopics ?? [DefaultPubsubTopic];
149+
options.pubsubTopics = options.pubsubTopics ?? shardInfo?.pubsubTopics;
147150

148151
return shardInfo?.shardInfo;
149152
}

packages/tests/src/constants.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* @module
66
*/
77

8+
import { PubsubTopic, ShardInfo, SingleShardInfo } from "@waku/interfaces";
9+
810
export const NOISE_KEY_1 = new Uint8Array(
911
((): number[] => {
1012
const b = [];
@@ -65,3 +67,13 @@ export const MOCHA_HOOK_MAX_TIMEOUT = 50_000;
6567

6668
export const SEPOLIA_RPC_URL =
6769
process.env.SEPOLIA_RPC_URL || "https://sepolia.gateway.tenderly.co";
70+
71+
export const DefaultTestPubsubTopic: PubsubTopic = "/waku/2/rs/0/0";
72+
export const DefaultTestShardInfo: ShardInfo = {
73+
clusterId: 0,
74+
shards: [0]
75+
};
76+
export const DefaultTestSingleShardInfo: SingleShardInfo = {
77+
clusterId: 0,
78+
shard: 0
79+
};

packages/tests/src/lib/index.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
import { DecodedMessage } from "@waku/core";
2-
import {
3-
DefaultPubsubTopic,
4-
PubsubTopic,
5-
ShardingParams
6-
} from "@waku/interfaces";
2+
import { PubsubTopic, ShardingParams } from "@waku/interfaces";
73
import { ensureShardingConfigured, Logger } from "@waku/utils";
84
import { expect } from "chai";
95

6+
import { DefaultTestPubsubTopic } from "../constants";
107
import { Args, MessageRpcQuery, MessageRpcResponse } from "../types";
118
import { delay, makeLogFileName } from "../utils/index.js";
129

@@ -105,7 +102,7 @@ export class ServiceNodesFleet {
105102

106103
public async sendRelayMessage(
107104
message: MessageRpcQuery,
108-
pubsubTopic: string = DefaultPubsubTopic
105+
pubsubTopic: string = DefaultTestPubsubTopic
109106
): Promise<boolean> {
110107
const relayMessagePromises: Promise<boolean>[] = this.nodes.map((node) =>
111108
node.sendMessage(message, pubsubTopic)
@@ -221,7 +218,7 @@ class MultipleNodesMessageCollector {
221218
}
222219
): Promise<boolean> {
223220
const startTime = Date.now();
224-
const pubsubTopic = options?.pubsubTopic || DefaultPubsubTopic;
221+
const pubsubTopic = options?.pubsubTopic || DefaultTestPubsubTopic;
225222
const timeoutDuration = options?.timeoutDuration || 400;
226223
const exact = options?.exact || false;
227224

packages/tests/src/lib/message_collector.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { DecodedMessage } from "@waku/core";
2-
import { DefaultPubsubTopic } from "@waku/interfaces";
32
import { Logger } from "@waku/utils";
43
import { bytesToUtf8, utf8ToBytes } from "@waku/utils/bytes";
54
import { AssertionError, expect } from "chai";
65
import { equals } from "uint8arrays/equals";
76

7+
import { DefaultTestPubsubTopic } from "../constants.js";
88
import { MessageRpcResponse } from "../types.js";
99
import { base64ToUtf8 } from "../utils/base64_utf8.js";
1010
import { delay } from "../utils/delay.js";
@@ -269,6 +269,8 @@ export class MessageCollector {
269269
}
270270

271271
private getPubsubTopicToUse(pubsubTopic: string | undefined): string {
272-
return pubsubTopic || this.nwaku?.pubsubTopics?.[0] || DefaultPubsubTopic;
272+
return (
273+
pubsubTopic || this.nwaku?.pubsubTopics?.[0] || DefaultTestPubsubTopic
274+
);
273275
}
274276
}

packages/tests/src/lib/service_node.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import type { PeerId } from "@libp2p/interface";
22
import { peerIdFromString } from "@libp2p/peer-id";
33
import { Multiaddr, multiaddr } from "@multiformats/multiaddr";
4-
import { DefaultPubsubTopic } from "@waku/interfaces";
54
import { isDefined } from "@waku/utils";
65
import { Logger } from "@waku/utils";
76
import pRetry from "p-retry";
87
import portfinder from "portfinder";
98

9+
import { DefaultTestPubsubTopic } from "../constants.js";
1010
import {
1111
Args,
1212
LogLevel,
@@ -245,7 +245,7 @@ export class ServiceNode {
245245
}
246246

247247
public async ensureSubscriptions(
248-
pubsubTopics: string[] = [DefaultPubsubTopic]
248+
pubsubTopics: string[] = [DefaultTestPubsubTopic]
249249
): Promise<boolean> {
250250
return this.restCall<boolean>(
251251
"/relay/v1/subscriptions",
@@ -257,7 +257,7 @@ export class ServiceNode {
257257

258258
public async messages(pubsubTopic?: string): Promise<MessageRpcResponse[]> {
259259
return this.restCall<MessageRpcResponse[]>(
260-
`/relay/v1/messages/${encodeURIComponent(pubsubTopic || this?.args?.pubsubTopic?.[0] || DefaultPubsubTopic)}`,
260+
`/relay/v1/messages/${encodeURIComponent(pubsubTopic || this?.args?.pubsubTopic?.[0] || DefaultTestPubsubTopic)}`,
261261
"GET",
262262
null,
263263
async (response) => {
@@ -291,7 +291,7 @@ export class ServiceNode {
291291
}
292292

293293
return this.restCall<boolean>(
294-
`/relay/v1/messages/${encodeURIComponent(pubsubTopic || this.args?.pubsubTopic?.[0] || DefaultPubsubTopic)}`,
294+
`/relay/v1/messages/${encodeURIComponent(pubsubTopic || this.args?.pubsubTopic?.[0] || DefaultTestPubsubTopic)}`,
295295
"POST",
296296
message,
297297
async (response) => response.status === 200
@@ -411,7 +411,8 @@ export function defaultArgs(): Args {
411411
rest: true,
412412
restAdmin: true,
413413
websocketSupport: true,
414-
logLevel: LogLevel.Trace
414+
logLevel: LogLevel.Trace,
415+
pubsubTopic: ["/waku/2/rs/0/0"]
415416
};
416417
}
417418

packages/tests/tests/connection-mananger/connection_state.spec.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { expect } from "chai";
77
import {
88
afterEachCustom,
99
beforeEachCustom,
10+
DefaultTestShardInfo,
1011
delay,
1112
NOISE_KEY_1
1213
} from "../../src/index.js";
@@ -28,7 +29,7 @@ describe("Connection state", function () {
2829
let nwaku2PeerId: Multiaddr;
2930

3031
beforeEachCustom(this, async () => {
31-
waku = await createLightNode({ shardInfo: { shards: [0] } });
32+
waku = await createLightNode({ shardInfo: DefaultTestShardInfo });
3233
nwaku1 = new ServiceNode(makeLogFileName(this.ctx) + "1");
3334
nwaku2 = new ServiceNode(makeLogFileName(this.ctx) + "2");
3435
await nwaku1.start({ filter: true });
@@ -89,10 +90,12 @@ describe("Connection state", function () {
8990

9091
it("`waku:online` between 2 js-waku relay nodes", async function () {
9192
const waku1 = await createRelayNode({
92-
staticNoiseKey: NOISE_KEY_1
93+
staticNoiseKey: NOISE_KEY_1,
94+
shardInfo: DefaultTestShardInfo
9395
});
9496
const waku2 = await createRelayNode({
95-
libp2p: { addresses: { listen: ["/ip4/0.0.0.0/tcp/0/ws"] } }
97+
libp2p: { addresses: { listen: ["/ip4/0.0.0.0/tcp/0/ws"] } },
98+
shardInfo: DefaultTestShardInfo
9699
});
97100

98101
let eventCount1 = 0;

0 commit comments

Comments
 (0)