Skip to content

Commit e335fbe

Browse files
change shardinfo terminology with RFC
1 parent 6e4b9c5 commit e335fbe

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

packages/core/src/lib/stream_manager.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ export class StreamManager {
5555
}
5656

5757
private prepareNewStream(peer: Peer): void {
58-
const streamPromise = this.newStream(peer).catch(() => {
58+
const streamPromise = this.newStream(peer).catch((error) => {
5959
// No error thrown as this call is not triggered by the user
6060
this.log.error(
61-
`Failed to prepare a new stream for ${peer.id.toString()}`
61+
`Failed to prepare a new stream for ${peer.id.toString()}: ${error}`
6262
);
6363
});
6464
this.streamPool.set(peer.id.toString(), streamPromise);

packages/interfaces/src/enr.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@ export interface Waku2 {
1818
lightPush: boolean;
1919
}
2020

21-
//TODO: adhere to terminology from the metadata protocol
2221
export interface ShardInfo {
23-
cluster: number;
24-
indexList: number[];
22+
clusterId: number;
23+
shards: number[];
2524
}
2625

2726
export interface IEnr extends Map<ENRKey, ENRValue> {

packages/utils/src/common/sharding.ts

+25-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,34 @@ import type { PubSubTopic, ShardInfo } from "@waku/interfaces";
33
export const shardInfoToPubSubTopics = (
44
shardInfo: ShardInfo
55
): PubSubTopic[] => {
6-
return shardInfo.indexList.map(
7-
(index) => `/waku/2/rs/${shardInfo.cluster}/${index}`
6+
return shardInfo.shards.map(
7+
(index) => `/waku/2/rs/${shardInfo.clusterId}/${index}`
88
);
99
};
1010

11+
export const pubSubTopicToShardInfo = (topic: PubSubTopic): ShardInfo => {
12+
const parts = topic.split("/"); // Split the topic string into parts
13+
14+
if (
15+
parts.length === 6 &&
16+
parts[1] === "waku" &&
17+
parts[2] === "2" &&
18+
parts[3] === "rs"
19+
) {
20+
const cluster = parts[4];
21+
const index = parts[5];
22+
23+
return {
24+
clusterId: parseInt(cluster),
25+
shards: [parseInt(index)]
26+
};
27+
} else {
28+
throw new Error(
29+
`Invalid topic ${topic}. Expected format: /waku/2/rs/<cluster>/<index>`
30+
);
31+
}
32+
};
33+
1134
export function ensurePubsubTopicIsConfigured(
1235
pubsubTopic: PubSubTopic,
1336
configuredTopics: PubSubTopic[]

0 commit comments

Comments
 (0)