Skip to content

Commit

Permalink
remove autosharding from ShardInfo, add to EncoderOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
adklempner committed Dec 4, 2023
1 parent 362a910 commit 5a4774a
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 40 deletions.
1 change: 0 additions & 1 deletion packages/interfaces/src/enr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export interface Waku2 {
export interface ShardInfo {
clusterId: number;
shards: number[];
autosharding?: boolean;
contentTopics?: string[];
}

Expand Down
22 changes: 11 additions & 11 deletions packages/message-encryption/src/ecies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ class Encoder implements IEncoder {
}

export interface EncoderOptions extends BaseEncoderOptions {
/** Indicates if autosharding is enabled */
autosharding?: boolean;
/** The public key to encrypt the payload for. */
publicKey: Uint8Array;
/** An optional private key to be used to sign the payload before encryption. */
Expand All @@ -102,17 +104,15 @@ export interface EncoderOptions extends BaseEncoderOptions {
* The payload can optionally be signed with the given private key as defined
* in [26/WAKU2-PAYLOAD](https://rfc.vac.dev/spec/26/).
*/
export function createEncoder(
{
pubsubTopicShardInfo,
contentTopic,
publicKey,
sigPrivKey,
ephemeral = false,
metaSetter
}: EncoderOptions,
autosharding = false
): Encoder {
export function createEncoder({
autosharding = false,
pubsubTopicShardInfo,
contentTopic,
publicKey,
sigPrivKey,
ephemeral = false,
metaSetter
}: EncoderOptions): Encoder {
return new Encoder(
autosharding
? contentTopicToPubsubTopic(contentTopic)
Expand Down
22 changes: 11 additions & 11 deletions packages/message-encryption/src/symmetric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ class Encoder implements IEncoder {
}

export interface EncoderOptions extends BaseEncoderOptions {
/** Indicates if autosharding is enabled */
autosharding?: boolean;
/** The symmetric key to encrypt the payload with. */
symKey: Uint8Array;
/** An optional private key to be used to sign the payload before encryption. */
Expand All @@ -102,17 +104,15 @@ export interface EncoderOptions extends BaseEncoderOptions {
* The payload can optionally be signed with the given private key as defined
* in [26/WAKU2-PAYLOAD](https://rfc.vac.dev/spec/26/).
*/
export function createEncoder(
{
pubsubTopicShardInfo,
contentTopic,
symKey,
sigPrivKey,
ephemeral = false,
metaSetter
}: EncoderOptions,
autosharding = false
): Encoder {
export function createEncoder({
autosharding = false,
pubsubTopicShardInfo,
contentTopic,
symKey,
sigPrivKey,
ephemeral = false,
metaSetter
}: EncoderOptions): Encoder {
return new Encoder(
autosharding
? contentTopicToPubsubTopic(contentTopic)
Expand Down
1 change: 0 additions & 1 deletion packages/tests/tests/filter/multiple_pubsub.node.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ describe("Waku Filter V2 (Autosharding): Multiple PubsubTopics", function () {
const shardInfo: ShardInfo = {
clusterId: 3,
shards: [0, 1, 2],
autosharding: true,
contentTopics: [customContentTopic1, customContentTopic2]
};
const customEncoder1 = createEncoder(
Expand Down
2 changes: 0 additions & 2 deletions packages/tests/tests/light-push/multiple_pubsub.node.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ describe("Waku Light Push (Autosharding): Multiple PubsubTopics", function () {
const shardInfo: ShardInfo = {
clusterId: 3,
shards: [0, 1, 2],
autosharding: true,
contentTopics: [customContentTopic1, customContentTopic2]
};
const customEncoder1 = createEncoder(
Expand Down Expand Up @@ -356,7 +355,6 @@ describe("Waku Light Push (Autosharding): Multiple PubsubTopics", function () {
const shardInfo: ShardInfo = {
clusterId,
shards: [0, 1, 2],
autosharding: true,
contentTopics: [customContentTopic1, customContentTopic2]
};
const customEncoder1 = createEncoder(
Expand Down
2 changes: 1 addition & 1 deletion packages/tests/tests/light-push/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export async function runNodes(
if (waku) {
await waku.dial(await nwaku.getMultiaddrWithId());
await waitForRemotePeer(waku, [Protocols.LightPush]);
if (shardInfo?.autosharding) {
if (shardInfo?.contentTopics && shardInfo.contentTopics.length > 0) {
await nwaku.ensureSubscriptionsAutosharding(shardInfo!.contentTopics!);
}
await nwaku.ensureSubscriptions(pubsubTopics);
Expand Down
3 changes: 0 additions & 3 deletions packages/tests/tests/relay/multiple_pubsub.node.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,13 +328,11 @@ describe("Waku Relay (Autosharding), multiple pubsub topics", function () {
const shardInfo1: ShardInfo = {
clusterId: 3,
shards: [1],
autosharding: true,
contentTopics: [customContentTopic1]
};
const shardInfo2: ShardInfo = {
clusterId: 3,
shards: [2],
autosharding: true,
contentTopics: [customContentTopic2]
};
const customEncoder1 = createEncoder(
Expand All @@ -356,7 +354,6 @@ describe("Waku Relay (Autosharding), multiple pubsub topics", function () {
const shardInfoBothShards: ShardInfo = {
clusterId: 3,
shards: [1, 2],
autosharding: true,
contentTopics: [customContentTopic1, customContentTopic2]
};

Expand Down
4 changes: 1 addition & 3 deletions packages/tests/tests/sharding/peer_management.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,6 @@ describe("Autoharding: Peer Management", function () {
waku = await createLightNode({
shardInfo: {
...shardInfo,
autosharding: true,
contentTopics: [ContentTopic]
},
libp2p: {
Expand Down Expand Up @@ -324,8 +323,7 @@ describe("Autoharding: Peer Management", function () {
waku = await createLightNode({
shardInfo: {
...shardInfoToDial,
contentTopics: [ContentTopic],
autosharding: true
contentTopics: [ContentTopic]
},
libp2p: {
peerDiscovery: [
Expand Down
1 change: 0 additions & 1 deletion packages/tests/tests/sharding/running_nodes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ describe("Autosharding: Running Nodes", () => {
waku = await createLightNode({
shardInfo: {
...shardInfoBothShards,
autosharding: true,
// For autosharding, we configure multiple pubsub topics by using two content topics that hash to different shards
contentTopics: [ContentTopic, ContentTopic2]
}
Expand Down
2 changes: 0 additions & 2 deletions packages/tests/tests/store/multiple_pubsub.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ describe("Waku Store (Autosharding), custom pubsub topic", function () {
const shardInfo1: ShardInfo = {
clusterId,
shards: [1],
autosharding: true,
contentTopics: [customContentTopic1]
};
const customDecoder1 = createDecoder(
Expand All @@ -210,7 +209,6 @@ describe("Waku Store (Autosharding), custom pubsub topic", function () {
const shardInfoBothShards: ShardInfo = {
clusterId,
shards: [0, 1],
autosharding: true,
contentTopics: [customContentTopic1, customContentTopic2]
};

Expand Down
5 changes: 1 addition & 4 deletions packages/utils/src/common/sharding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ export const shardInfoToPubsubTopics = (
): PubsubTopic[] => {
if (shardInfo.clusterId === undefined || shardInfo.shards === undefined)
throw new Error("Invalid shard");
if (shardInfo.autosharding) {
if (!shardInfo.contentTopics) {
throw new Error("Content topics must be set if autosharding is enabled");
}
if (shardInfo.contentTopics && shardInfo.contentTopics.length > 0) {
return shardInfo.contentTopics.map((contentTopic) =>
contentTopicToPubsubTopic(contentTopic, shardInfo.clusterId)
);
Expand Down

0 comments on commit 5a4774a

Please sign in to comment.