mirror of
https://github.com/logos-messaging/js-waku.git
synced 2026-01-05 23:33:08 +00:00
chore: changing default pubsub topic to its static sharding version (#2083)
* changing default pubsub topic to its static sharding version * keeping RFC's Waku Message test vectors * reverting change in changelog * setting pubsub topic when creating nwaku node * adding shardInfo to runMultipleNodes call * adding shardInfo to runMultipleNodes call in lightpush tests * add pubsub topics to nwaku.start * get rid of it.only that remained * fixing compliance tests * setting clusterId to 0 * removing unnecessary fix * adding shardInfo when creating nodes * fixing wait for remote peer tests * fixing peer exchange test * refactor * removing unnecessary variable * feat: create default shard info, update tests (#2085) * feat: create default shard info, update tests * add link * fix tests * remoe only * up tests * up test --------- Co-authored-by: Sasha <118575614+weboko@users.noreply.github.com>
This commit is contained in:
parent
04bd518210
commit
08fc2d133a
@ -3,14 +3,11 @@ import type { NodeCapabilityCount } from "@waku/interfaces";
|
|||||||
/**
|
/**
|
||||||
* The ENR tree for the different fleets.
|
* The ENR tree for the different fleets.
|
||||||
* SANDBOX and TEST fleets are for The Waku Network.
|
* SANDBOX and TEST fleets are for The Waku Network.
|
||||||
* DEPRECATED_DEFAULT_PUBSUB is the fleet of nodes supporting the now deprecated DefaultPubsubTopic.
|
|
||||||
*/
|
*/
|
||||||
export const enrTree = {
|
export const enrTree = {
|
||||||
SANDBOX:
|
SANDBOX:
|
||||||
"enrtree://AIRVQ5DDA4FFWLRBCHJWUWOO6X6S4ZTZ5B667LQ6AJU6PEYDLRD5O@sandbox.waku.nodes.status.im",
|
"enrtree://AIRVQ5DDA4FFWLRBCHJWUWOO6X6S4ZTZ5B667LQ6AJU6PEYDLRD5O@sandbox.waku.nodes.status.im",
|
||||||
TEST: "enrtree://AOGYWMBYOUIMOENHXCHILPKY3ZRFEULMFI4DOM442QSZ73TT2A7VI@test.waku.nodes.status.im",
|
TEST: "enrtree://AOGYWMBYOUIMOENHXCHILPKY3ZRFEULMFI4DOM442QSZ73TT2A7VI@test.waku.nodes.status.im"
|
||||||
DEPRECATED_DEFAULT_PUBSUB:
|
|
||||||
"enrtree://ANEDLO25QVUGJOUTQFRYKWX6P4Z4GKVESBMHML7DZ6YK4LGS5FC5O@prod.wakuv2.nodes.status.im"
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const DEFAULT_BOOTSTRAP_TAG_NAME = "bootstrap";
|
export const DEFAULT_BOOTSTRAP_TAG_NAME = "bootstrap";
|
||||||
|
|||||||
@ -1,9 +1,14 @@
|
|||||||
/**
|
import { ShardInfo } from "./enr";
|
||||||
* DefaultPubsubTopic is the default gossipsub topic to use for Waku.
|
|
||||||
*/
|
|
||||||
export const DefaultPubsubTopic = "/waku/2/default-waku/proto";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The default cluster ID for The Waku Network
|
* The default cluster ID for The Waku Network
|
||||||
*/
|
*/
|
||||||
export const DEFAULT_CLUSTER_ID = 1;
|
export const DEFAULT_CLUSTER_ID = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DefaultShardInfo is default configuration for The Waku Network.
|
||||||
|
*/
|
||||||
|
export const DefaultShardInfo: ShardInfo = {
|
||||||
|
clusterId: DEFAULT_CLUSTER_ID,
|
||||||
|
shards: [0, 1, 2, 3, 4, 5, 6, 7, 8]
|
||||||
|
};
|
||||||
|
|||||||
@ -73,31 +73,35 @@ export type ProtocolUseOptions = {
|
|||||||
export type ProtocolCreateOptions = {
|
export type ProtocolCreateOptions = {
|
||||||
/**
|
/**
|
||||||
* @deprecated
|
* @deprecated
|
||||||
* Waku will stop supporting named sharding. Only static sharding and autosharding will be supported moving forward.
|
* Should be used ONLY if some other than The Waku Network is in use.
|
||||||
*/
|
*
|
||||||
pubsubTopics?: PubsubTopic[];
|
* See [Waku v2 Topic Usage Recommendations](https://github.com/vacp2p/rfc-index/blob/main/waku/informational/23/topics.md#pubsub-topics) for details.
|
||||||
/**
|
|
||||||
* Waku supports usage of multiple pubsub topics. This is achieved through static sharding for now, and auto-sharding in the future.
|
|
||||||
* The format to specify a shard is:
|
|
||||||
* clusterId: number, shards: number[]
|
|
||||||
* To learn more about the sharding specifications implemented, see [Relay Sharding](https://rfc.vac.dev/spec/51/).
|
|
||||||
* The Pubsub Topic to use. Defaults to {@link @waku/core!DefaultPubsubTopic }.
|
|
||||||
*
|
*
|
||||||
* If no pubsub topic is specified, the default pubsub topic is used.
|
|
||||||
* The set of pubsub topics that are used to initialize the Waku node, will need to be used by the protocols as well
|
|
||||||
* You cannot currently add or remove pubsub topics after initialization.
|
|
||||||
* This is used by:
|
* This is used by:
|
||||||
* - WakuRelay to receive, route and send messages,
|
* - WakuRelay to receive, route and send messages,
|
||||||
* - WakuLightPush to send messages,
|
* - WakuLightPush to send messages,
|
||||||
* - WakuStore to retrieve messages.
|
* - WakuStore to retrieve messages.
|
||||||
* See [Waku v2 Topic Usage Recommendations](https://github.com/vacp2p/rfc-index/blob/main/waku/informational/23/topics.md) for details.
|
|
||||||
*
|
*
|
||||||
|
* If no pubsub topic is specified, the default pubsub topic will be determined from DefaultShardInfo.
|
||||||
|
*
|
||||||
|
* You cannot add or remove pubsub topics after initialization of the node.
|
||||||
|
*/
|
||||||
|
pubsubTopics?: PubsubTopic[];
|
||||||
|
/**
|
||||||
|
* ShardInfo is used to determine which network is in use.
|
||||||
|
* Defaults to {@link @waku/interfaces!DefaultShardInfo}.
|
||||||
|
* Default value is configured for The Waku Network
|
||||||
|
*
|
||||||
|
* The format to specify a shard is:
|
||||||
|
* clusterId: number, shards: number[]
|
||||||
|
* To learn more about the sharding specification, see [Relay Sharding](https://rfc.vac.dev/spec/51/).
|
||||||
*/
|
*/
|
||||||
shardInfo?: Partial<ShardingParams>;
|
shardInfo?: Partial<ShardingParams>;
|
||||||
/**
|
/**
|
||||||
* Content topics are used to determine pubsubTopics
|
* Content topics are used to determine network in use.
|
||||||
* If not provided pubsubTopics will be determined based on shardInfo
|
* See [Waku v2 Topic Usage Recommendations](https://github.com/vacp2p/rfc-index/blob/main/waku/informational/23/topics.md#content-topics) for details.
|
||||||
* See [Waku v2 Topic Usage Recommendations](https://github.com/vacp2p/rfc-index/blob/main/waku/informational/23/topics.md) for details.
|
*
|
||||||
|
* You cannot add or remove content topics after initialization of the node.
|
||||||
*/
|
*/
|
||||||
contentTopics?: string[];
|
contentTopics?: string[];
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
import { Decoder as DecoderV0 } from "@waku/core/lib/message/version_0";
|
import { Decoder as DecoderV0 } from "@waku/core/lib/message/version_0";
|
||||||
import {
|
import {
|
||||||
type EncoderOptions as BaseEncoderOptions,
|
type EncoderOptions as BaseEncoderOptions,
|
||||||
DefaultPubsubTopic,
|
|
||||||
type IDecoder,
|
type IDecoder,
|
||||||
type IEncoder,
|
type IEncoder,
|
||||||
type IMessage,
|
type IMessage,
|
||||||
@ -101,7 +100,7 @@ export interface EncoderOptions extends BaseEncoderOptions {
|
|||||||
* in [26/WAKU2-PAYLOAD](https://rfc.vac.dev/spec/26/).
|
* in [26/WAKU2-PAYLOAD](https://rfc.vac.dev/spec/26/).
|
||||||
*/
|
*/
|
||||||
export function createEncoder({
|
export function createEncoder({
|
||||||
pubsubTopic = DefaultPubsubTopic,
|
pubsubTopic,
|
||||||
pubsubTopicShardInfo,
|
pubsubTopicShardInfo,
|
||||||
contentTopic,
|
contentTopic,
|
||||||
symKey,
|
symKey,
|
||||||
@ -198,7 +197,7 @@ class Decoder extends DecoderV0 implements IDecoder<DecodedMessage> {
|
|||||||
export function createDecoder(
|
export function createDecoder(
|
||||||
contentTopic: string,
|
contentTopic: string,
|
||||||
symKey: Uint8Array,
|
symKey: Uint8Array,
|
||||||
pubsubTopicShardInfo: SingleShardInfo | PubsubTopic = DefaultPubsubTopic
|
pubsubTopicShardInfo?: SingleShardInfo | PubsubTopic
|
||||||
): Decoder {
|
): Decoder {
|
||||||
return new Decoder(
|
return new Decoder(
|
||||||
determinePubsubTopic(contentTopic, pubsubTopicShardInfo),
|
determinePubsubTopic(contentTopic, pubsubTopicShardInfo),
|
||||||
|
|||||||
@ -11,7 +11,6 @@ import { sha256 } from "@noble/hashes/sha256";
|
|||||||
import {
|
import {
|
||||||
ActiveSubscriptions,
|
ActiveSubscriptions,
|
||||||
Callback,
|
Callback,
|
||||||
DefaultPubsubTopic,
|
|
||||||
IAsyncIterator,
|
IAsyncIterator,
|
||||||
IDecodedMessage,
|
IDecodedMessage,
|
||||||
IDecoder,
|
IDecoder,
|
||||||
@ -75,9 +74,8 @@ class Relay implements IRelay {
|
|||||||
|
|
||||||
this.observers = new Map();
|
this.observers = new Map();
|
||||||
|
|
||||||
// Default PubsubTopic decoder
|
|
||||||
// TODO: User might want to decide what decoder should be used (e.g. for RLN)
|
// TODO: User might want to decide what decoder should be used (e.g. for RLN)
|
||||||
this.defaultDecoder = new TopicOnlyDecoder();
|
this.defaultDecoder = new TopicOnlyDecoder(pubsubTopics[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -204,8 +202,9 @@ class Relay implements IRelay {
|
|||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
public getMeshPeers(topic: TopicStr = DefaultPubsubTopic): PeerIdStr[] {
|
public getMeshPeers(topic?: TopicStr): PeerIdStr[] {
|
||||||
return this.gossipSub.getMeshPeers(topic);
|
// if no TopicStr is provided - returns empty array
|
||||||
|
return this.gossipSub.getMeshPeers(topic || "");
|
||||||
}
|
}
|
||||||
|
|
||||||
private subscribeToAllTopics(): void {
|
private subscribeToAllTopics(): void {
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
import { DefaultPubsubTopic } from "@waku/interfaces";
|
|
||||||
import type {
|
import type {
|
||||||
IDecodedMessage,
|
IDecodedMessage,
|
||||||
IDecoder,
|
IDecoder,
|
||||||
IProtoMessage
|
IProtoMessage,
|
||||||
|
PubsubTopic
|
||||||
} from "@waku/interfaces";
|
} from "@waku/interfaces";
|
||||||
import { TopicOnlyMessage as ProtoTopicOnlyMessage } from "@waku/proto";
|
import { TopicOnlyMessage as ProtoTopicOnlyMessage } from "@waku/proto";
|
||||||
|
|
||||||
@ -23,10 +23,13 @@ export class TopicOnlyMessage implements IDecodedMessage {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This decoder is used only for reading `contentTopic` from the WakuMessage
|
||||||
export class TopicOnlyDecoder implements IDecoder<TopicOnlyMessage> {
|
export class TopicOnlyDecoder implements IDecoder<TopicOnlyMessage> {
|
||||||
public pubsubTopic = DefaultPubsubTopic;
|
|
||||||
public contentTopic = "";
|
public contentTopic = "";
|
||||||
|
|
||||||
|
// pubsubTopic is ignored
|
||||||
|
public constructor(public pubsubTopic: PubsubTopic) {}
|
||||||
|
|
||||||
public fromWireToProtoObj(
|
public fromWireToProtoObj(
|
||||||
bytes: Uint8Array
|
bytes: Uint8Array
|
||||||
): Promise<IProtoMessage | undefined> {
|
): Promise<IProtoMessage | undefined> {
|
||||||
|
|||||||
@ -5,11 +5,7 @@ import {
|
|||||||
wakuLocalPeerCacheDiscovery,
|
wakuLocalPeerCacheDiscovery,
|
||||||
wakuPeerExchangeDiscovery
|
wakuPeerExchangeDiscovery
|
||||||
} from "@waku/discovery";
|
} from "@waku/discovery";
|
||||||
import {
|
import { type Libp2pComponents, PubsubTopic } from "@waku/interfaces";
|
||||||
DefaultPubsubTopic,
|
|
||||||
type Libp2pComponents,
|
|
||||||
PubsubTopic
|
|
||||||
} from "@waku/interfaces";
|
|
||||||
|
|
||||||
const DEFAULT_NODE_REQUIREMENTS = {
|
const DEFAULT_NODE_REQUIREMENTS = {
|
||||||
lightPush: 1,
|
lightPush: 1,
|
||||||
@ -20,10 +16,7 @@ const DEFAULT_NODE_REQUIREMENTS = {
|
|||||||
export function defaultPeerDiscoveries(
|
export function defaultPeerDiscoveries(
|
||||||
pubsubTopics: PubsubTopic[]
|
pubsubTopics: PubsubTopic[]
|
||||||
): ((components: Libp2pComponents) => PeerDiscovery)[] {
|
): ((components: Libp2pComponents) => PeerDiscovery)[] {
|
||||||
const isDefaultPubsubTopic = pubsubTopics.includes(DefaultPubsubTopic);
|
const dnsEnrTrees = [enrTree["SANDBOX"], enrTree["TEST"]];
|
||||||
const dnsEnrTrees = isDefaultPubsubTopic
|
|
||||||
? [enrTree["DEPRECATED_DEFAULT_PUBSUB"]]
|
|
||||||
: [enrTree["SANDBOX"], enrTree["TEST"]];
|
|
||||||
|
|
||||||
const discoveries = [
|
const discoveries = [
|
||||||
wakuDnsDiscovery(dnsEnrTrees, DEFAULT_NODE_REQUIREMENTS),
|
wakuDnsDiscovery(dnsEnrTrees, DEFAULT_NODE_REQUIREMENTS),
|
||||||
|
|||||||
@ -9,7 +9,7 @@ import { all as filterAll, wss } from "@libp2p/websockets/filters";
|
|||||||
import { wakuMetadata } from "@waku/core";
|
import { wakuMetadata } from "@waku/core";
|
||||||
import {
|
import {
|
||||||
type CreateLibp2pOptions,
|
type CreateLibp2pOptions,
|
||||||
DefaultPubsubTopic,
|
DefaultShardInfo,
|
||||||
type IMetadata,
|
type IMetadata,
|
||||||
type Libp2p,
|
type Libp2p,
|
||||||
type Libp2pComponents,
|
type Libp2pComponents,
|
||||||
@ -138,12 +138,15 @@ function configureNetworkOptions(
|
|||||||
options.shardInfo = { contentTopics: options.contentTopics };
|
options.shardInfo = { contentTopics: options.contentTopics };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!options.shardInfo) {
|
||||||
|
options.shardInfo = DefaultShardInfo;
|
||||||
|
}
|
||||||
|
|
||||||
const shardInfo = options.shardInfo
|
const shardInfo = options.shardInfo
|
||||||
? ensureShardingConfigured(options.shardInfo)
|
? ensureShardingConfigured(options.shardInfo)
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
options.pubsubTopics = shardInfo?.pubsubTopics ??
|
options.pubsubTopics = options.pubsubTopics ?? shardInfo?.pubsubTopics;
|
||||||
options.pubsubTopics ?? [DefaultPubsubTopic];
|
|
||||||
|
|
||||||
return shardInfo?.shardInfo;
|
return shardInfo?.shardInfo;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,6 +5,8 @@
|
|||||||
* @module
|
* @module
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { PubsubTopic, ShardInfo, SingleShardInfo } from "@waku/interfaces";
|
||||||
|
|
||||||
export const NOISE_KEY_1 = new Uint8Array(
|
export const NOISE_KEY_1 = new Uint8Array(
|
||||||
((): number[] => {
|
((): number[] => {
|
||||||
const b = [];
|
const b = [];
|
||||||
@ -65,3 +67,13 @@ export const MOCHA_HOOK_MAX_TIMEOUT = 50_000;
|
|||||||
|
|
||||||
export const SEPOLIA_RPC_URL =
|
export const SEPOLIA_RPC_URL =
|
||||||
process.env.SEPOLIA_RPC_URL || "https://sepolia.gateway.tenderly.co";
|
process.env.SEPOLIA_RPC_URL || "https://sepolia.gateway.tenderly.co";
|
||||||
|
|
||||||
|
export const DefaultTestPubsubTopic: PubsubTopic = "/waku/2/rs/0/0";
|
||||||
|
export const DefaultTestShardInfo: ShardInfo = {
|
||||||
|
clusterId: 0,
|
||||||
|
shards: [0]
|
||||||
|
};
|
||||||
|
export const DefaultTestSingleShardInfo: SingleShardInfo = {
|
||||||
|
clusterId: 0,
|
||||||
|
shard: 0
|
||||||
|
};
|
||||||
|
|||||||
@ -1,12 +1,9 @@
|
|||||||
import { DecodedMessage } from "@waku/core";
|
import { DecodedMessage } from "@waku/core";
|
||||||
import {
|
import { PubsubTopic, ShardingParams } from "@waku/interfaces";
|
||||||
DefaultPubsubTopic,
|
|
||||||
PubsubTopic,
|
|
||||||
ShardingParams
|
|
||||||
} from "@waku/interfaces";
|
|
||||||
import { ensureShardingConfigured, Logger } from "@waku/utils";
|
import { ensureShardingConfigured, Logger } from "@waku/utils";
|
||||||
import { expect } from "chai";
|
import { expect } from "chai";
|
||||||
|
|
||||||
|
import { DefaultTestPubsubTopic } from "../constants";
|
||||||
import { Args, MessageRpcQuery, MessageRpcResponse } from "../types";
|
import { Args, MessageRpcQuery, MessageRpcResponse } from "../types";
|
||||||
import { delay, makeLogFileName } from "../utils/index.js";
|
import { delay, makeLogFileName } from "../utils/index.js";
|
||||||
|
|
||||||
@ -105,7 +102,7 @@ export class ServiceNodesFleet {
|
|||||||
|
|
||||||
public async sendRelayMessage(
|
public async sendRelayMessage(
|
||||||
message: MessageRpcQuery,
|
message: MessageRpcQuery,
|
||||||
pubsubTopic: string = DefaultPubsubTopic
|
pubsubTopic: string = DefaultTestPubsubTopic
|
||||||
): Promise<boolean> {
|
): Promise<boolean> {
|
||||||
const relayMessagePromises: Promise<boolean>[] = this.nodes.map((node) =>
|
const relayMessagePromises: Promise<boolean>[] = this.nodes.map((node) =>
|
||||||
node.sendMessage(message, pubsubTopic)
|
node.sendMessage(message, pubsubTopic)
|
||||||
@ -221,7 +218,7 @@ class MultipleNodesMessageCollector {
|
|||||||
}
|
}
|
||||||
): Promise<boolean> {
|
): Promise<boolean> {
|
||||||
const startTime = Date.now();
|
const startTime = Date.now();
|
||||||
const pubsubTopic = options?.pubsubTopic || DefaultPubsubTopic;
|
const pubsubTopic = options?.pubsubTopic || DefaultTestPubsubTopic;
|
||||||
const timeoutDuration = options?.timeoutDuration || 400;
|
const timeoutDuration = options?.timeoutDuration || 400;
|
||||||
const exact = options?.exact || false;
|
const exact = options?.exact || false;
|
||||||
|
|
||||||
|
|||||||
@ -1,10 +1,10 @@
|
|||||||
import { DecodedMessage } from "@waku/core";
|
import { DecodedMessage } from "@waku/core";
|
||||||
import { DefaultPubsubTopic } from "@waku/interfaces";
|
|
||||||
import { Logger } from "@waku/utils";
|
import { Logger } from "@waku/utils";
|
||||||
import { bytesToUtf8, utf8ToBytes } from "@waku/utils/bytes";
|
import { bytesToUtf8, utf8ToBytes } from "@waku/utils/bytes";
|
||||||
import { AssertionError, expect } from "chai";
|
import { AssertionError, expect } from "chai";
|
||||||
import { equals } from "uint8arrays/equals";
|
import { equals } from "uint8arrays/equals";
|
||||||
|
|
||||||
|
import { DefaultTestPubsubTopic } from "../constants.js";
|
||||||
import { MessageRpcResponse } from "../types.js";
|
import { MessageRpcResponse } from "../types.js";
|
||||||
import { base64ToUtf8 } from "../utils/base64_utf8.js";
|
import { base64ToUtf8 } from "../utils/base64_utf8.js";
|
||||||
import { delay } from "../utils/delay.js";
|
import { delay } from "../utils/delay.js";
|
||||||
@ -269,6 +269,8 @@ export class MessageCollector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private getPubsubTopicToUse(pubsubTopic: string | undefined): string {
|
private getPubsubTopicToUse(pubsubTopic: string | undefined): string {
|
||||||
return pubsubTopic || this.nwaku?.pubsubTopics?.[0] || DefaultPubsubTopic;
|
return (
|
||||||
|
pubsubTopic || this.nwaku?.pubsubTopics?.[0] || DefaultTestPubsubTopic
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,12 +1,12 @@
|
|||||||
import type { PeerId } from "@libp2p/interface";
|
import type { PeerId } from "@libp2p/interface";
|
||||||
import { peerIdFromString } from "@libp2p/peer-id";
|
import { peerIdFromString } from "@libp2p/peer-id";
|
||||||
import { Multiaddr, multiaddr } from "@multiformats/multiaddr";
|
import { Multiaddr, multiaddr } from "@multiformats/multiaddr";
|
||||||
import { DefaultPubsubTopic } from "@waku/interfaces";
|
|
||||||
import { isDefined } from "@waku/utils";
|
import { isDefined } from "@waku/utils";
|
||||||
import { Logger } from "@waku/utils";
|
import { Logger } from "@waku/utils";
|
||||||
import pRetry from "p-retry";
|
import pRetry from "p-retry";
|
||||||
import portfinder from "portfinder";
|
import portfinder from "portfinder";
|
||||||
|
|
||||||
|
import { DefaultTestPubsubTopic } from "../constants.js";
|
||||||
import {
|
import {
|
||||||
Args,
|
Args,
|
||||||
LogLevel,
|
LogLevel,
|
||||||
@ -245,7 +245,7 @@ export class ServiceNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async ensureSubscriptions(
|
public async ensureSubscriptions(
|
||||||
pubsubTopics: string[] = [DefaultPubsubTopic]
|
pubsubTopics: string[] = [DefaultTestPubsubTopic]
|
||||||
): Promise<boolean> {
|
): Promise<boolean> {
|
||||||
return this.restCall<boolean>(
|
return this.restCall<boolean>(
|
||||||
"/relay/v1/subscriptions",
|
"/relay/v1/subscriptions",
|
||||||
@ -257,7 +257,7 @@ export class ServiceNode {
|
|||||||
|
|
||||||
public async messages(pubsubTopic?: string): Promise<MessageRpcResponse[]> {
|
public async messages(pubsubTopic?: string): Promise<MessageRpcResponse[]> {
|
||||||
return this.restCall<MessageRpcResponse[]>(
|
return this.restCall<MessageRpcResponse[]>(
|
||||||
`/relay/v1/messages/${encodeURIComponent(pubsubTopic || this?.args?.pubsubTopic?.[0] || DefaultPubsubTopic)}`,
|
`/relay/v1/messages/${encodeURIComponent(pubsubTopic || this?.args?.pubsubTopic?.[0] || DefaultTestPubsubTopic)}`,
|
||||||
"GET",
|
"GET",
|
||||||
null,
|
null,
|
||||||
async (response) => {
|
async (response) => {
|
||||||
@ -291,7 +291,7 @@ export class ServiceNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return this.restCall<boolean>(
|
return this.restCall<boolean>(
|
||||||
`/relay/v1/messages/${encodeURIComponent(pubsubTopic || this.args?.pubsubTopic?.[0] || DefaultPubsubTopic)}`,
|
`/relay/v1/messages/${encodeURIComponent(pubsubTopic || this.args?.pubsubTopic?.[0] || DefaultTestPubsubTopic)}`,
|
||||||
"POST",
|
"POST",
|
||||||
message,
|
message,
|
||||||
async (response) => response.status === 200
|
async (response) => response.status === 200
|
||||||
@ -411,7 +411,8 @@ export function defaultArgs(): Args {
|
|||||||
rest: true,
|
rest: true,
|
||||||
restAdmin: true,
|
restAdmin: true,
|
||||||
websocketSupport: true,
|
websocketSupport: true,
|
||||||
logLevel: LogLevel.Trace
|
logLevel: LogLevel.Trace,
|
||||||
|
pubsubTopic: ["/waku/2/rs/0/0"]
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -7,6 +7,7 @@ import { expect } from "chai";
|
|||||||
import {
|
import {
|
||||||
afterEachCustom,
|
afterEachCustom,
|
||||||
beforeEachCustom,
|
beforeEachCustom,
|
||||||
|
DefaultTestShardInfo,
|
||||||
delay,
|
delay,
|
||||||
NOISE_KEY_1
|
NOISE_KEY_1
|
||||||
} from "../../src/index.js";
|
} from "../../src/index.js";
|
||||||
@ -28,7 +29,7 @@ describe("Connection state", function () {
|
|||||||
let nwaku2PeerId: Multiaddr;
|
let nwaku2PeerId: Multiaddr;
|
||||||
|
|
||||||
beforeEachCustom(this, async () => {
|
beforeEachCustom(this, async () => {
|
||||||
waku = await createLightNode({ shardInfo: { shards: [0] } });
|
waku = await createLightNode({ shardInfo: DefaultTestShardInfo });
|
||||||
nwaku1 = new ServiceNode(makeLogFileName(this.ctx) + "1");
|
nwaku1 = new ServiceNode(makeLogFileName(this.ctx) + "1");
|
||||||
nwaku2 = new ServiceNode(makeLogFileName(this.ctx) + "2");
|
nwaku2 = new ServiceNode(makeLogFileName(this.ctx) + "2");
|
||||||
await nwaku1.start({ filter: true });
|
await nwaku1.start({ filter: true });
|
||||||
@ -89,10 +90,12 @@ describe("Connection state", function () {
|
|||||||
|
|
||||||
it("`waku:online` between 2 js-waku relay nodes", async function () {
|
it("`waku:online` between 2 js-waku relay nodes", async function () {
|
||||||
const waku1 = await createRelayNode({
|
const waku1 = await createRelayNode({
|
||||||
staticNoiseKey: NOISE_KEY_1
|
staticNoiseKey: NOISE_KEY_1,
|
||||||
|
shardInfo: DefaultTestShardInfo
|
||||||
});
|
});
|
||||||
const waku2 = await createRelayNode({
|
const waku2 = await createRelayNode({
|
||||||
libp2p: { addresses: { listen: ["/ip4/0.0.0.0/tcp/0/ws"] } }
|
libp2p: { addresses: { listen: ["/ip4/0.0.0.0/tcp/0/ws"] } },
|
||||||
|
shardInfo: DefaultTestShardInfo
|
||||||
});
|
});
|
||||||
|
|
||||||
let eventCount1 = 0;
|
let eventCount1 = 0;
|
||||||
|
|||||||
@ -7,11 +7,13 @@ import { expect } from "chai";
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
afterEachCustom,
|
afterEachCustom,
|
||||||
|
DefaultTestPubsubTopic,
|
||||||
makeLogFileName,
|
makeLogFileName,
|
||||||
NOISE_KEY_1,
|
NOISE_KEY_1,
|
||||||
ServiceNode,
|
ServiceNode,
|
||||||
tearDownNodes
|
tearDownNodes
|
||||||
} from "../src/index.js";
|
} from "../src/index.js";
|
||||||
|
import { DefaultTestShardInfo } from "../src/index.js";
|
||||||
|
|
||||||
describe("ENR Interop: ServiceNode", function () {
|
describe("ENR Interop: ServiceNode", function () {
|
||||||
let waku: RelayNode;
|
let waku: RelayNode;
|
||||||
@ -28,12 +30,14 @@ describe("ENR Interop: ServiceNode", function () {
|
|||||||
relay: true,
|
relay: true,
|
||||||
store: false,
|
store: false,
|
||||||
filter: false,
|
filter: false,
|
||||||
lightpush: false
|
lightpush: false,
|
||||||
|
pubsubTopic: [DefaultTestPubsubTopic]
|
||||||
});
|
});
|
||||||
const multiAddrWithId = await nwaku.getMultiaddrWithId();
|
const multiAddrWithId = await nwaku.getMultiaddrWithId();
|
||||||
|
|
||||||
waku = await createRelayNode({
|
waku = await createRelayNode({
|
||||||
staticNoiseKey: NOISE_KEY_1
|
staticNoiseKey: NOISE_KEY_1,
|
||||||
|
shardInfo: DefaultTestShardInfo
|
||||||
});
|
});
|
||||||
await waku.start();
|
await waku.start();
|
||||||
await waku.dial(multiAddrWithId);
|
await waku.dial(multiAddrWithId);
|
||||||
@ -60,12 +64,14 @@ describe("ENR Interop: ServiceNode", function () {
|
|||||||
relay: true,
|
relay: true,
|
||||||
store: true,
|
store: true,
|
||||||
filter: false,
|
filter: false,
|
||||||
lightpush: false
|
lightpush: false,
|
||||||
|
pubsubTopic: [DefaultTestPubsubTopic]
|
||||||
});
|
});
|
||||||
const multiAddrWithId = await nwaku.getMultiaddrWithId();
|
const multiAddrWithId = await nwaku.getMultiaddrWithId();
|
||||||
|
|
||||||
waku = await createRelayNode({
|
waku = await createRelayNode({
|
||||||
staticNoiseKey: NOISE_KEY_1
|
staticNoiseKey: NOISE_KEY_1,
|
||||||
|
shardInfo: DefaultTestShardInfo
|
||||||
});
|
});
|
||||||
await waku.start();
|
await waku.start();
|
||||||
await waku.dial(multiAddrWithId);
|
await waku.dial(multiAddrWithId);
|
||||||
@ -93,12 +99,14 @@ describe("ENR Interop: ServiceNode", function () {
|
|||||||
store: true,
|
store: true,
|
||||||
filter: true,
|
filter: true,
|
||||||
lightpush: true,
|
lightpush: true,
|
||||||
legacyFilter: true
|
legacyFilter: true,
|
||||||
|
pubsubTopic: [DefaultTestPubsubTopic]
|
||||||
});
|
});
|
||||||
const multiAddrWithId = await nwaku.getMultiaddrWithId();
|
const multiAddrWithId = await nwaku.getMultiaddrWithId();
|
||||||
|
|
||||||
waku = await createRelayNode({
|
waku = await createRelayNode({
|
||||||
staticNoiseKey: NOISE_KEY_1
|
staticNoiseKey: NOISE_KEY_1,
|
||||||
|
shardInfo: DefaultTestShardInfo
|
||||||
});
|
});
|
||||||
await waku.start();
|
await waku.start();
|
||||||
await waku.dial(multiAddrWithId);
|
await waku.dial(multiAddrWithId);
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
import {
|
import {
|
||||||
DefaultPubsubTopic,
|
|
||||||
ISubscriptionSDK,
|
ISubscriptionSDK,
|
||||||
LightNode,
|
LightNode,
|
||||||
SDKProtocolResult
|
SDKProtocolResult
|
||||||
@ -17,6 +16,8 @@ import { describe } from "mocha";
|
|||||||
import {
|
import {
|
||||||
afterEachCustom,
|
afterEachCustom,
|
||||||
beforeEachCustom,
|
beforeEachCustom,
|
||||||
|
DefaultTestPubsubTopic,
|
||||||
|
DefaultTestShardInfo,
|
||||||
ServiceNode,
|
ServiceNode,
|
||||||
ServiceNodesFleet
|
ServiceNodesFleet
|
||||||
} from "../../src/index.js";
|
} from "../../src/index.js";
|
||||||
@ -31,25 +32,25 @@ describe("Waku Filter: Peer Management: E2E", function () {
|
|||||||
let serviceNodes: ServiceNodesFleet;
|
let serviceNodes: ServiceNodesFleet;
|
||||||
let subscription: ISubscriptionSDK;
|
let subscription: ISubscriptionSDK;
|
||||||
|
|
||||||
const pubsubTopic = DefaultPubsubTopic;
|
|
||||||
const contentTopic = "/test";
|
const contentTopic = "/test";
|
||||||
|
|
||||||
const encoder = createEncoder({
|
const encoder = createEncoder({
|
||||||
pubsubTopic,
|
pubsubTopic: DefaultTestPubsubTopic,
|
||||||
contentTopic
|
contentTopic
|
||||||
});
|
});
|
||||||
|
|
||||||
const decoder = createDecoder(contentTopic, pubsubTopic);
|
const decoder = createDecoder(contentTopic, DefaultTestPubsubTopic);
|
||||||
|
|
||||||
beforeEachCustom(this, async () => {
|
beforeEachCustom(this, async () => {
|
||||||
[serviceNodes, waku] = await runMultipleNodes(
|
[serviceNodes, waku] = await runMultipleNodes(
|
||||||
this.ctx,
|
this.ctx,
|
||||||
undefined,
|
DefaultTestShardInfo,
|
||||||
undefined,
|
undefined,
|
||||||
5
|
5
|
||||||
);
|
);
|
||||||
const { error, subscription: sub } =
|
const { error, subscription: sub } = await waku.filter.createSubscription(
|
||||||
await waku.filter.createSubscription(pubsubTopic);
|
DefaultTestPubsubTopic
|
||||||
|
);
|
||||||
if (!sub || error) {
|
if (!sub || error) {
|
||||||
throw new Error("Could not create subscription");
|
throw new Error("Could not create subscription");
|
||||||
}
|
}
|
||||||
@ -183,7 +184,7 @@ describe("Waku Filter: Peer Management: E2E", function () {
|
|||||||
it("Renews peer on consistent missed messages", async function () {
|
it("Renews peer on consistent missed messages", async function () {
|
||||||
const [serviceNodes, waku] = await runMultipleNodes(
|
const [serviceNodes, waku] = await runMultipleNodes(
|
||||||
this.ctx,
|
this.ctx,
|
||||||
undefined,
|
DefaultTestShardInfo,
|
||||||
undefined,
|
undefined,
|
||||||
2
|
2
|
||||||
);
|
);
|
||||||
@ -199,8 +200,9 @@ describe("Waku Filter: Peer Management: E2E", function () {
|
|||||||
).toString();
|
).toString();
|
||||||
await waku.dial(await nodeWithoutDiscovery.getMultiaddrWithId());
|
await waku.dial(await nodeWithoutDiscovery.getMultiaddrWithId());
|
||||||
|
|
||||||
const { error, subscription: sub } =
|
const { error, subscription: sub } = await waku.filter.createSubscription(
|
||||||
await waku.filter.createSubscription(pubsubTopic);
|
DefaultTestPubsubTopic
|
||||||
|
);
|
||||||
if (!sub || error) {
|
if (!sub || error) {
|
||||||
throw new Error("Could not create subscription");
|
throw new Error("Could not create subscription");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
import { createDecoder, createEncoder, waitForRemotePeer } from "@waku/core";
|
import { createDecoder, createEncoder, waitForRemotePeer } from "@waku/core";
|
||||||
import {
|
import {
|
||||||
DefaultPubsubTopic,
|
|
||||||
ISubscriptionSDK,
|
ISubscriptionSDK,
|
||||||
LightNode,
|
LightNode,
|
||||||
ProtocolCreateOptions,
|
ProtocolCreateOptions,
|
||||||
@ -19,6 +18,7 @@ import { Context } from "mocha";
|
|||||||
import pRetry from "p-retry";
|
import pRetry from "p-retry";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
DefaultTestPubsubTopic,
|
||||||
NOISE_KEY_1,
|
NOISE_KEY_1,
|
||||||
ServiceNodesFleet,
|
ServiceNodesFleet,
|
||||||
waitForConnections
|
waitForConnections
|
||||||
@ -76,7 +76,7 @@ export async function runMultipleNodes(
|
|||||||
): Promise<[ServiceNodesFleet, LightNode]> {
|
): Promise<[ServiceNodesFleet, LightNode]> {
|
||||||
const pubsubTopics = shardInfo
|
const pubsubTopics = shardInfo
|
||||||
? shardInfoToPubsubTopics(shardInfo)
|
? shardInfoToPubsubTopics(shardInfo)
|
||||||
: [DefaultPubsubTopic];
|
: [DefaultTestPubsubTopic];
|
||||||
// create numServiceNodes nodes
|
// create numServiceNodes nodes
|
||||||
const serviceNodes = await ServiceNodesFleet.createAndRun(
|
const serviceNodes = await ServiceNodesFleet.createAndRun(
|
||||||
context,
|
context,
|
||||||
|
|||||||
@ -11,7 +11,11 @@ import {
|
|||||||
Tags,
|
Tags,
|
||||||
utf8ToBytes
|
utf8ToBytes
|
||||||
} from "@waku/sdk";
|
} from "@waku/sdk";
|
||||||
import { ensureShardingConfigured, shardInfoToPubsubTopics } from "@waku/utils";
|
import {
|
||||||
|
encodeRelayShard,
|
||||||
|
ensureShardingConfigured,
|
||||||
|
shardInfoToPubsubTopics
|
||||||
|
} from "@waku/utils";
|
||||||
import { getConnectedPeersForProtocolAndShard } from "@waku/utils/libp2p";
|
import { getConnectedPeersForProtocolAndShard } from "@waku/utils/libp2p";
|
||||||
import { expect } from "chai";
|
import { expect } from "chai";
|
||||||
import fc from "fast-check";
|
import fc from "fast-check";
|
||||||
@ -20,6 +24,7 @@ import Sinon from "sinon";
|
|||||||
import {
|
import {
|
||||||
afterEachCustom,
|
afterEachCustom,
|
||||||
beforeEachCustom,
|
beforeEachCustom,
|
||||||
|
DefaultTestShardInfo,
|
||||||
delay,
|
delay,
|
||||||
makeLogFileName,
|
makeLogFileName,
|
||||||
ServiceNode,
|
ServiceNode,
|
||||||
@ -426,6 +431,7 @@ describe("getConnectedPeersForProtocolAndShard", function () {
|
|||||||
expect(peers.length).to.be.equal(1);
|
expect(peers.length).to.be.equal(1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("getPeers", function () {
|
describe("getPeers", function () {
|
||||||
let peerStore: PeerStore;
|
let peerStore: PeerStore;
|
||||||
let connectionManager: Libp2pComponents["connectionManager"];
|
let connectionManager: Libp2pComponents["connectionManager"];
|
||||||
@ -448,7 +454,7 @@ describe("getPeers", function () {
|
|||||||
let allPeers: Peer[];
|
let allPeers: Peer[];
|
||||||
|
|
||||||
beforeEachCustom(this, async () => {
|
beforeEachCustom(this, async () => {
|
||||||
waku = await createLightNode();
|
waku = await createLightNode({ shardInfo: DefaultTestShardInfo });
|
||||||
peerStore = waku.libp2p.peerStore;
|
peerStore = waku.libp2p.peerStore;
|
||||||
connectionManager = waku.libp2p.components.connectionManager;
|
connectionManager = waku.libp2p.components.connectionManager;
|
||||||
|
|
||||||
@ -540,6 +546,10 @@ describe("getPeers", function () {
|
|||||||
anotherDifferentCodecPeer
|
anotherDifferentCodecPeer
|
||||||
];
|
];
|
||||||
|
|
||||||
|
allPeers.forEach((peer) => {
|
||||||
|
peer.metadata.set("shardInfo", encodeRelayShard(DefaultTestShardInfo));
|
||||||
|
});
|
||||||
|
|
||||||
Sinon.stub(peerStore, "get").callsFake(async (peerId) => {
|
Sinon.stub(peerStore, "get").callsFake(async (peerId) => {
|
||||||
return allPeers.find((peer) => peer.id.equals(peerId))!;
|
return allPeers.find((peer) => peer.id.equals(peerId))!;
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { DefaultPubsubTopic, LightNode } from "@waku/interfaces";
|
import { LightNode } from "@waku/interfaces";
|
||||||
import { createEncoder, utf8ToBytes } from "@waku/sdk";
|
import { createEncoder, utf8ToBytes } from "@waku/sdk";
|
||||||
import { expect } from "chai";
|
import { expect } from "chai";
|
||||||
import { describe } from "mocha";
|
import { describe } from "mocha";
|
||||||
@ -6,11 +6,14 @@ import { describe } from "mocha";
|
|||||||
import {
|
import {
|
||||||
afterEachCustom,
|
afterEachCustom,
|
||||||
beforeEachCustom,
|
beforeEachCustom,
|
||||||
|
DefaultTestShardInfo,
|
||||||
|
DefaultTestSingleShardInfo,
|
||||||
ServiceNodesFleet
|
ServiceNodesFleet
|
||||||
} from "../../src/index.js";
|
} from "../../src/index.js";
|
||||||
import {
|
import {
|
||||||
runMultipleNodes,
|
runMultipleNodes,
|
||||||
teardownNodesWithRedundancy
|
teardownNodesWithRedundancy,
|
||||||
|
TestContentTopic
|
||||||
} from "../filter/utils.js";
|
} from "../filter/utils.js";
|
||||||
|
|
||||||
describe("Waku Light Push: Peer Management: E2E", function () {
|
describe("Waku Light Push: Peer Management: E2E", function () {
|
||||||
@ -21,7 +24,7 @@ describe("Waku Light Push: Peer Management: E2E", function () {
|
|||||||
beforeEachCustom(this, async () => {
|
beforeEachCustom(this, async () => {
|
||||||
[serviceNodes, waku] = await runMultipleNodes(
|
[serviceNodes, waku] = await runMultipleNodes(
|
||||||
this.ctx,
|
this.ctx,
|
||||||
undefined,
|
DefaultTestShardInfo,
|
||||||
undefined,
|
undefined,
|
||||||
5
|
5
|
||||||
);
|
);
|
||||||
@ -32,8 +35,8 @@ describe("Waku Light Push: Peer Management: E2E", function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const encoder = createEncoder({
|
const encoder = createEncoder({
|
||||||
pubsubTopic: DefaultPubsubTopic,
|
pubsubTopicShardInfo: DefaultTestSingleShardInfo,
|
||||||
contentTopic: "/test"
|
contentTopic: TestContentTopic
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Number of peers are maintained correctly", async function () {
|
it("Number of peers are maintained correctly", async function () {
|
||||||
|
|||||||
@ -17,6 +17,7 @@ describe("nwaku", () => {
|
|||||||
"--rest-admin=true",
|
"--rest-admin=true",
|
||||||
"--websocket-support=true",
|
"--websocket-support=true",
|
||||||
"--log-level=TRACE",
|
"--log-level=TRACE",
|
||||||
|
"--pubsub-topic=/waku/2/rs/0/0",
|
||||||
"--ports-shift=42"
|
"--ports-shift=42"
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@ -2,17 +2,16 @@ import tests from "@libp2p/interface-compliance-tests/peer-discovery";
|
|||||||
import { PeerExchangeCodec, PeerExchangeDiscovery } from "@waku/discovery";
|
import { PeerExchangeCodec, PeerExchangeDiscovery } from "@waku/discovery";
|
||||||
import type { LightNode } from "@waku/interfaces";
|
import type { LightNode } from "@waku/interfaces";
|
||||||
import { createLightNode } from "@waku/sdk";
|
import { createLightNode } from "@waku/sdk";
|
||||||
import { singleShardInfoToPubsubTopic } from "@waku/utils";
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
beforeEachCustom,
|
beforeEachCustom,
|
||||||
|
DefaultTestPubsubTopic,
|
||||||
|
DefaultTestShardInfo,
|
||||||
makeLogFileName,
|
makeLogFileName,
|
||||||
ServiceNode,
|
ServiceNode,
|
||||||
tearDownNodes
|
tearDownNodes
|
||||||
} from "../../src/index.js";
|
} from "../../src/index.js";
|
||||||
|
|
||||||
const pubsubTopic = [singleShardInfoToPubsubTopic({ clusterId: 0, shard: 2 })];
|
|
||||||
|
|
||||||
describe("Peer Exchange", function () {
|
describe("Peer Exchange", function () {
|
||||||
describe("Compliance Test", function () {
|
describe("Compliance Test", function () {
|
||||||
this.timeout(100_000);
|
this.timeout(100_000);
|
||||||
@ -42,15 +41,14 @@ describe("Peer Exchange", function () {
|
|||||||
|
|
||||||
tests({
|
tests({
|
||||||
async setup() {
|
async setup() {
|
||||||
waku = await createLightNode();
|
waku = await createLightNode({ shardInfo: DefaultTestShardInfo });
|
||||||
await waku.start();
|
await waku.start();
|
||||||
|
|
||||||
const nwaku2Ma = await nwaku2.getMultiaddrWithId();
|
const nwaku2Ma = await nwaku2.getMultiaddrWithId();
|
||||||
|
|
||||||
const peerExchange = new PeerExchangeDiscovery(
|
const peerExchange = new PeerExchangeDiscovery(waku.libp2p.components, [
|
||||||
waku.libp2p.components,
|
DefaultTestPubsubTopic
|
||||||
pubsubTopic
|
]);
|
||||||
);
|
|
||||||
|
|
||||||
peerExchange.addEventListener("waku:peer-exchange:started", (event) => {
|
peerExchange.addEventListener("waku:peer-exchange:started", (event) => {
|
||||||
if (event.detail === true) {
|
if (event.detail === true) {
|
||||||
|
|||||||
@ -3,20 +3,21 @@ import type { PeerId } from "@libp2p/interface";
|
|||||||
import { wakuPeerExchangeDiscovery } from "@waku/discovery";
|
import { wakuPeerExchangeDiscovery } from "@waku/discovery";
|
||||||
import type { LightNode, PeersByDiscoveryResult } from "@waku/interfaces";
|
import type { LightNode, PeersByDiscoveryResult } from "@waku/interfaces";
|
||||||
import { createLightNode, Tags } from "@waku/sdk";
|
import { createLightNode, Tags } from "@waku/sdk";
|
||||||
import { Logger, singleShardInfoToPubsubTopic } from "@waku/utils";
|
import { Logger } from "@waku/utils";
|
||||||
import { expect } from "chai";
|
import { expect } from "chai";
|
||||||
import Sinon, { SinonSpy } from "sinon";
|
import Sinon, { SinonSpy } from "sinon";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
afterEachCustom,
|
afterEachCustom,
|
||||||
beforeEachCustom,
|
beforeEachCustom,
|
||||||
|
DefaultTestPubsubTopic,
|
||||||
|
DefaultTestShardInfo,
|
||||||
makeLogFileName,
|
makeLogFileName,
|
||||||
ServiceNode,
|
ServiceNode,
|
||||||
tearDownNodes
|
tearDownNodes
|
||||||
} from "../../src/index.js";
|
} from "../../src/index.js";
|
||||||
|
|
||||||
export const log = new Logger("test:pe");
|
export const log = new Logger("test:pe");
|
||||||
const pubsubTopic = [singleShardInfoToPubsubTopic({ clusterId: 0, shard: 2 })];
|
|
||||||
|
|
||||||
describe("Peer Exchange", function () {
|
describe("Peer Exchange", function () {
|
||||||
this.timeout(150_000);
|
this.timeout(150_000);
|
||||||
@ -31,13 +32,13 @@ describe("Peer Exchange", function () {
|
|||||||
nwaku1 = new ServiceNode(makeLogFileName(this.ctx) + "1");
|
nwaku1 = new ServiceNode(makeLogFileName(this.ctx) + "1");
|
||||||
nwaku2 = new ServiceNode(makeLogFileName(this.ctx) + "2");
|
nwaku2 = new ServiceNode(makeLogFileName(this.ctx) + "2");
|
||||||
await nwaku1.start({
|
await nwaku1.start({
|
||||||
pubsubTopic: pubsubTopic,
|
pubsubTopic: [DefaultTestPubsubTopic],
|
||||||
discv5Discovery: true,
|
discv5Discovery: true,
|
||||||
peerExchange: true,
|
peerExchange: true,
|
||||||
relay: true
|
relay: true
|
||||||
});
|
});
|
||||||
await nwaku2.start({
|
await nwaku2.start({
|
||||||
pubsubTopic: pubsubTopic,
|
pubsubTopic: [DefaultTestPubsubTopic],
|
||||||
discv5Discovery: true,
|
discv5Discovery: true,
|
||||||
peerExchange: true,
|
peerExchange: true,
|
||||||
discv5BootstrapNode: (await nwaku1.info()).enrUri,
|
discv5BootstrapNode: (await nwaku1.info()).enrUri,
|
||||||
@ -52,10 +53,11 @@ describe("Peer Exchange", function () {
|
|||||||
|
|
||||||
it("getPeersByDiscovery", async function () {
|
it("getPeersByDiscovery", async function () {
|
||||||
waku = await createLightNode({
|
waku = await createLightNode({
|
||||||
|
shardInfo: DefaultTestShardInfo,
|
||||||
libp2p: {
|
libp2p: {
|
||||||
peerDiscovery: [
|
peerDiscovery: [
|
||||||
bootstrap({ list: [(await nwaku2.getMultiaddrWithId()).toString()] }),
|
bootstrap({ list: [(await nwaku2.getMultiaddrWithId()).toString()] }),
|
||||||
wakuPeerExchangeDiscovery(pubsubTopic)
|
wakuPeerExchangeDiscovery([DefaultTestPubsubTopic])
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -102,7 +104,7 @@ describe("Peer Exchange", function () {
|
|||||||
libp2p: {
|
libp2p: {
|
||||||
peerDiscovery: [
|
peerDiscovery: [
|
||||||
bootstrap({ list: [(await nwaku2.getMultiaddrWithId()).toString()] }),
|
bootstrap({ list: [(await nwaku2.getMultiaddrWithId()).toString()] }),
|
||||||
wakuPeerExchangeDiscovery(pubsubTopic)
|
wakuPeerExchangeDiscovery([DefaultTestPubsubTopic])
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -128,7 +130,7 @@ describe("Peer Exchange", function () {
|
|||||||
|
|
||||||
nwaku3 = new ServiceNode(makeLogFileName(this) + "3");
|
nwaku3 = new ServiceNode(makeLogFileName(this) + "3");
|
||||||
await nwaku3.start({
|
await nwaku3.start({
|
||||||
pubsubTopic: pubsubTopic,
|
pubsubTopic: [DefaultTestPubsubTopic],
|
||||||
discv5Discovery: true,
|
discv5Discovery: true,
|
||||||
peerExchange: true,
|
peerExchange: true,
|
||||||
discv5BootstrapNode: (await nwaku1.info()).enrUri,
|
discv5BootstrapNode: (await nwaku1.info()).enrUri,
|
||||||
|
|||||||
@ -7,6 +7,8 @@ import { expect } from "chai";
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
afterEachCustom,
|
afterEachCustom,
|
||||||
|
DefaultTestPubsubTopic,
|
||||||
|
DefaultTestShardInfo,
|
||||||
delay,
|
delay,
|
||||||
makeLogFileName,
|
makeLogFileName,
|
||||||
NOISE_KEY_1,
|
NOISE_KEY_1,
|
||||||
@ -48,12 +50,14 @@ describe("Wait for remote peer", function () {
|
|||||||
relay: true,
|
relay: true,
|
||||||
store: false,
|
store: false,
|
||||||
filter: false,
|
filter: false,
|
||||||
lightpush: false
|
lightpush: false,
|
||||||
|
pubsubTopic: [DefaultTestPubsubTopic]
|
||||||
});
|
});
|
||||||
const multiAddrWithId = await nwaku.getMultiaddrWithId();
|
const multiAddrWithId = await nwaku.getMultiaddrWithId();
|
||||||
|
|
||||||
waku1 = await createRelayNode({
|
waku1 = await createRelayNode({
|
||||||
staticNoiseKey: NOISE_KEY_1
|
staticNoiseKey: NOISE_KEY_1,
|
||||||
|
shardInfo: DefaultTestShardInfo
|
||||||
});
|
});
|
||||||
await waku1.start();
|
await waku1.start();
|
||||||
|
|
||||||
@ -62,7 +66,7 @@ describe("Wait for remote peer", function () {
|
|||||||
await waku1.dial(multiAddrWithId);
|
await waku1.dial(multiAddrWithId);
|
||||||
await waitPromise;
|
await waitPromise;
|
||||||
|
|
||||||
const peers = waku1.relay.getMeshPeers();
|
const peers = waku1.relay.getMeshPeers(DefaultTestPubsubTopic);
|
||||||
const nimPeerId = multiAddrWithId.getPeerId();
|
const nimPeerId = multiAddrWithId.getPeerId();
|
||||||
|
|
||||||
expect(nimPeerId).to.not.be.undefined;
|
expect(nimPeerId).to.not.be.undefined;
|
||||||
@ -72,7 +76,8 @@ describe("Wait for remote peer", function () {
|
|||||||
it("Relay - times out", function (done) {
|
it("Relay - times out", function (done) {
|
||||||
this.timeout(5000);
|
this.timeout(5000);
|
||||||
createRelayNode({
|
createRelayNode({
|
||||||
staticNoiseKey: NOISE_KEY_1
|
staticNoiseKey: NOISE_KEY_1,
|
||||||
|
shardInfo: DefaultTestShardInfo
|
||||||
})
|
})
|
||||||
.then((waku1) => waku1.start().then(() => waku1))
|
.then((waku1) => waku1.start().then(() => waku1))
|
||||||
.then((waku1) => {
|
.then((waku1) => {
|
||||||
@ -101,7 +106,8 @@ describe("Wait for remote peer", function () {
|
|||||||
const multiAddrWithId = await nwaku.getMultiaddrWithId();
|
const multiAddrWithId = await nwaku.getMultiaddrWithId();
|
||||||
|
|
||||||
waku2 = await createLightNode({
|
waku2 = await createLightNode({
|
||||||
staticNoiseKey: NOISE_KEY_1
|
staticNoiseKey: NOISE_KEY_1,
|
||||||
|
shardInfo: DefaultTestShardInfo
|
||||||
});
|
});
|
||||||
await waku2.start();
|
await waku2.start();
|
||||||
await waku2.dial(multiAddrWithId);
|
await waku2.dial(multiAddrWithId);
|
||||||
@ -129,7 +135,8 @@ describe("Wait for remote peer", function () {
|
|||||||
const multiAddrWithId = await nwaku.getMultiaddrWithId();
|
const multiAddrWithId = await nwaku.getMultiaddrWithId();
|
||||||
|
|
||||||
waku2 = await createLightNode({
|
waku2 = await createLightNode({
|
||||||
staticNoiseKey: NOISE_KEY_1
|
staticNoiseKey: NOISE_KEY_1,
|
||||||
|
shardInfo: DefaultTestShardInfo
|
||||||
});
|
});
|
||||||
await waku2.start();
|
await waku2.start();
|
||||||
const waitPromise = waitForRemotePeer(waku2, [Protocols.Store], 2000);
|
const waitPromise = waitForRemotePeer(waku2, [Protocols.Store], 2000);
|
||||||
@ -159,7 +166,8 @@ describe("Wait for remote peer", function () {
|
|||||||
const multiAddrWithId = await nwaku.getMultiaddrWithId();
|
const multiAddrWithId = await nwaku.getMultiaddrWithId();
|
||||||
|
|
||||||
waku2 = await createLightNode({
|
waku2 = await createLightNode({
|
||||||
staticNoiseKey: NOISE_KEY_1
|
staticNoiseKey: NOISE_KEY_1,
|
||||||
|
shardInfo: DefaultTestShardInfo
|
||||||
});
|
});
|
||||||
await waku2.start();
|
await waku2.start();
|
||||||
await waku2.dial(multiAddrWithId);
|
await waku2.dial(multiAddrWithId);
|
||||||
@ -187,7 +195,8 @@ describe("Wait for remote peer", function () {
|
|||||||
const multiAddrWithId = await nwaku.getMultiaddrWithId();
|
const multiAddrWithId = await nwaku.getMultiaddrWithId();
|
||||||
|
|
||||||
waku2 = await createLightNode({
|
waku2 = await createLightNode({
|
||||||
staticNoiseKey: NOISE_KEY_1
|
staticNoiseKey: NOISE_KEY_1,
|
||||||
|
shardInfo: DefaultTestShardInfo
|
||||||
});
|
});
|
||||||
await waku2.start();
|
await waku2.start();
|
||||||
await waku2.dial(multiAddrWithId);
|
await waku2.dial(multiAddrWithId);
|
||||||
@ -215,7 +224,8 @@ describe("Wait for remote peer", function () {
|
|||||||
const multiAddrWithId = await nwaku.getMultiaddrWithId();
|
const multiAddrWithId = await nwaku.getMultiaddrWithId();
|
||||||
|
|
||||||
waku2 = await createLightNode({
|
waku2 = await createLightNode({
|
||||||
staticNoiseKey: NOISE_KEY_1
|
staticNoiseKey: NOISE_KEY_1,
|
||||||
|
shardInfo: DefaultTestShardInfo
|
||||||
});
|
});
|
||||||
await waku2.start();
|
await waku2.start();
|
||||||
await waku2.dial(multiAddrWithId);
|
await waku2.dial(multiAddrWithId);
|
||||||
|
|||||||
@ -20,6 +20,8 @@ import { expect } from "chai";
|
|||||||
import {
|
import {
|
||||||
afterEachCustom,
|
afterEachCustom,
|
||||||
beforeEachCustom,
|
beforeEachCustom,
|
||||||
|
DefaultTestShardInfo,
|
||||||
|
DefaultTestSingleShardInfo,
|
||||||
makeLogFileName,
|
makeLogFileName,
|
||||||
NOISE_KEY_1,
|
NOISE_KEY_1,
|
||||||
NOISE_KEY_2,
|
NOISE_KEY_2,
|
||||||
@ -51,7 +53,8 @@ describe("Waku Dial [node only]", function () {
|
|||||||
const multiAddrWithId = await nwaku.getMultiaddrWithId();
|
const multiAddrWithId = await nwaku.getMultiaddrWithId();
|
||||||
|
|
||||||
waku = await createLightNode({
|
waku = await createLightNode({
|
||||||
staticNoiseKey: NOISE_KEY_1
|
staticNoiseKey: NOISE_KEY_1,
|
||||||
|
shardInfo: DefaultTestShardInfo
|
||||||
});
|
});
|
||||||
await waku.start();
|
await waku.start();
|
||||||
await waku.dial(multiAddrWithId);
|
await waku.dial(multiAddrWithId);
|
||||||
@ -84,7 +87,8 @@ describe("Waku Dial [node only]", function () {
|
|||||||
const multiAddrWithId = await nwaku.getMultiaddrWithId();
|
const multiAddrWithId = await nwaku.getMultiaddrWithId();
|
||||||
|
|
||||||
waku = await createLightNode({
|
waku = await createLightNode({
|
||||||
staticNoiseKey: NOISE_KEY_1
|
staticNoiseKey: NOISE_KEY_1,
|
||||||
|
shardInfo: DefaultTestShardInfo
|
||||||
});
|
});
|
||||||
await waku.start();
|
await waku.start();
|
||||||
await waku.dial(multiAddrWithId);
|
await waku.dial(multiAddrWithId);
|
||||||
@ -112,6 +116,7 @@ describe("Waku Dial [node only]", function () {
|
|||||||
const multiAddrWithId = await nwaku.getMultiaddrWithId();
|
const multiAddrWithId = await nwaku.getMultiaddrWithId();
|
||||||
waku = await createLightNode({
|
waku = await createLightNode({
|
||||||
staticNoiseKey: NOISE_KEY_1,
|
staticNoiseKey: NOISE_KEY_1,
|
||||||
|
shardInfo: DefaultTestShardInfo,
|
||||||
libp2p: {
|
libp2p: {
|
||||||
peerDiscovery: [bootstrap({ list: [multiAddrWithId.toString()] })]
|
peerDiscovery: [bootstrap({ list: [multiAddrWithId.toString()] })]
|
||||||
}
|
}
|
||||||
@ -137,6 +142,7 @@ describe("Waku Dial [node only]", function () {
|
|||||||
|
|
||||||
waku = await createLightNode({
|
waku = await createLightNode({
|
||||||
staticNoiseKey: NOISE_KEY_1,
|
staticNoiseKey: NOISE_KEY_1,
|
||||||
|
shardInfo: DefaultTestShardInfo,
|
||||||
libp2p: {
|
libp2p: {
|
||||||
peerDiscovery: [bootstrap({ list: [nwakuMa.toString()] })]
|
peerDiscovery: [bootstrap({ list: [nwakuMa.toString()] })]
|
||||||
}
|
}
|
||||||
@ -166,11 +172,13 @@ describe("Decryption Keys", function () {
|
|||||||
let waku2: RelayNode;
|
let waku2: RelayNode;
|
||||||
beforeEachCustom(this, async () => {
|
beforeEachCustom(this, async () => {
|
||||||
[waku1, waku2] = await Promise.all([
|
[waku1, waku2] = await Promise.all([
|
||||||
createRelayNode({ staticNoiseKey: NOISE_KEY_1 }).then((waku) =>
|
createRelayNode({
|
||||||
waku.start().then(() => waku)
|
staticNoiseKey: NOISE_KEY_1,
|
||||||
),
|
shardInfo: DefaultTestShardInfo
|
||||||
|
}).then((waku) => waku.start().then(() => waku)),
|
||||||
createRelayNode({
|
createRelayNode({
|
||||||
staticNoiseKey: NOISE_KEY_2,
|
staticNoiseKey: NOISE_KEY_2,
|
||||||
|
shardInfo: DefaultTestShardInfo,
|
||||||
libp2p: { addresses: { listen: ["/ip4/0.0.0.0/tcp/0/ws"] } }
|
libp2p: { addresses: { listen: ["/ip4/0.0.0.0/tcp/0/ws"] } }
|
||||||
}).then((waku) => waku.start().then(() => waku))
|
}).then((waku) => waku.start().then(() => waku))
|
||||||
]);
|
]);
|
||||||
@ -194,12 +202,18 @@ describe("Decryption Keys", function () {
|
|||||||
this.timeout(10000);
|
this.timeout(10000);
|
||||||
|
|
||||||
const symKey = generateSymmetricKey();
|
const symKey = generateSymmetricKey();
|
||||||
const decoder = createDecoder(TestContentTopic, symKey);
|
const decoder = createDecoder(
|
||||||
|
TestContentTopic,
|
||||||
|
symKey,
|
||||||
|
DefaultTestSingleShardInfo
|
||||||
|
);
|
||||||
|
|
||||||
const encoder = createEncoder({
|
const encoder = createEncoder({
|
||||||
contentTopic: TestContentTopic,
|
contentTopic: TestContentTopic,
|
||||||
|
pubsubTopicShardInfo: DefaultTestSingleShardInfo,
|
||||||
symKey
|
symKey
|
||||||
});
|
});
|
||||||
|
|
||||||
const messageText = "Message is encrypted";
|
const messageText = "Message is encrypted";
|
||||||
const messageTimestamp = new Date("1995-12-17T03:24:00");
|
const messageTimestamp = new Date("1995-12-17T03:24:00");
|
||||||
const message = {
|
const message = {
|
||||||
@ -239,10 +253,12 @@ describe("User Agent", function () {
|
|||||||
[waku1, waku2] = await Promise.all([
|
[waku1, waku2] = await Promise.all([
|
||||||
createRelayNode({
|
createRelayNode({
|
||||||
staticNoiseKey: NOISE_KEY_1,
|
staticNoiseKey: NOISE_KEY_1,
|
||||||
userAgent: waku1UserAgent
|
userAgent: waku1UserAgent,
|
||||||
|
shardInfo: DefaultTestShardInfo
|
||||||
}).then((waku) => waku.start().then(() => waku)),
|
}).then((waku) => waku.start().then(() => waku)),
|
||||||
createRelayNode({
|
createRelayNode({
|
||||||
staticNoiseKey: NOISE_KEY_2,
|
staticNoiseKey: NOISE_KEY_2,
|
||||||
|
shardInfo: DefaultTestShardInfo,
|
||||||
libp2p: { addresses: { listen: ["/ip4/0.0.0.0/tcp/0/ws"] } }
|
libp2p: { addresses: { listen: ["/ip4/0.0.0.0/tcp/0/ws"] } }
|
||||||
}).then((waku) => waku.start().then(() => waku))
|
}).then((waku) => waku.start().then(() => waku))
|
||||||
]);
|
]);
|
||||||
|
|||||||
@ -228,6 +228,7 @@ export function contentTopicsByPubsubTopic(
|
|||||||
*/
|
*/
|
||||||
export function determinePubsubTopic(
|
export function determinePubsubTopic(
|
||||||
contentTopic: string,
|
contentTopic: string,
|
||||||
|
// TODO: make it accept ShardInfo https://github.com/waku-org/js-waku/issues/2086
|
||||||
pubsubTopicShardInfo?: SingleShardInfo | PubsubTopic
|
pubsubTopicShardInfo?: SingleShardInfo | PubsubTopic
|
||||||
): string {
|
): string {
|
||||||
if (typeof pubsubTopicShardInfo == "string") {
|
if (typeof pubsubTopicShardInfo == "string") {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user