Danish Arora 124a29ebba
feat(static-sharding): filter peer connections per shards (#1626)
* add interface for `ShardInfo`

* enr: add deserialization logic & setup getters

* add sharding related utils

* utils: add shard<-> bytes conversion helpers

* pass `pubSubTopics` to `Waku`

* add `rs`/`rsv` details during discovery

* connection-manager: discard irrelevant peers

* add tests for static sharding - peer exchange

* update `ConnectionManager` tests to account for topic validity

* add js suffix to import

* address some comments

* move shardInfo encoding to ENR

* test: update for new API

* enr: add tests for serialisation & deserialisation

* address comment

* update test

* move getPeershardInfo to ConnectionManager and return ShardInfo instead of bytes

* update encoding and decoding relay shards to also factor for shards>64

* relay shard encoding decoding: use DataView and verbose spec tests

* improve tests for relay shard encoding decoding

* rm: only

* improve log message for unconfigured pubsub topic

* minor improvement

* fix: buffer <> Uint8array problems with shard decoding

* fix: test

* rm: only
2023-10-10 20:18:02 +05:30

21 lines
665 B
TypeScript

import type { PubSubTopic, ShardInfo } from "@waku/interfaces";
export const shardInfoToPubSubTopics = (
shardInfo: ShardInfo
): PubSubTopic[] => {
return shardInfo.indexList.map(
(index) => `/waku/2/rs/${shardInfo.cluster}/${index}`
);
};
export function ensurePubsubTopicIsConfigured(
pubsubTopic: PubSubTopic,
configuredTopics: PubSubTopic[]
): void {
if (!configuredTopics.includes(pubsubTopic)) {
throw new Error(
`PubSub topic ${pubsubTopic} has not been configured on this instance. Configured topics are: ${configuredTopics}. Please update your configuration by passing in the topic during Waku node instantiation.`
);
}
}