Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: migration docs #213

Merged
merged 3 commits into from
Sep 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
201 changes: 201 additions & 0 deletions docs/migrations/js-waku/migration_v0.026_0.027.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
# Migrating to Waku v0.027
danisharora099 marked this conversation as resolved.
Show resolved Hide resolved

A migration guide for refactoring your application code from Waku v0.026 to v0.027.
danisharora099 marked this conversation as resolved.
Show resolved Hide resolved

## Table of Contents

- [Migrating to Waku v0.027](#migrating-to-waku-v0027)
- [Table of Contents](#table-of-contents)
- [Network Configuration](#network-configuration)
- [Default Network Configuration](#default-network-configuration)
- [Static Sharding](#static-sharding)
- [Auto Sharding](#auto-sharding)
- [Pubsub Topic Configuration](#pubsub-topic-configuration)
- [Removed APIs](#removed-apis)
- [Type Changes](#type-changes)
- [Internal/Private Utility Function Changes](#internalprivate-utility-function-changes)

## Network Configuration

The way to configure network settings for a Waku node has been simplified. The new NetworkConfig type only allows for Static Sharding or Auto Sharding.

### Default Network Configuration

If no network configuration is provided when creating a Light Node, The Waku Network configuration will be used by default.

**Before**
```typescript
import { createLightNode } from "@waku/sdk";

const waku = await createLightNode();
// This would use the default pubsub topic, that was, `/waku/2/default-waku/proto`
```

**After**
```typescript
import { createLightNode } from "@waku/sdk";

const waku = await createLightNode();
// This will now use The Waku Network configuration by default:
// { clusterId: 1, shards: [0,1,2,3,4,5,6,7] }
```

### Static Sharding

**Before**
```typescript
import { createLightNode } from "@waku/sdk";

const waku = await createLightNode({
shardInfo: {
clusterId: 1,
shards: [0, 1, 2, 3]
}
});
```

**After**
```typescript
import { createLightNode } from "@waku/sdk";

const waku = await createLightNode({
networkConfig: {
clusterId: 1,
shards: [0, 1, 2, 3]
}
});
```


### Auto Sharding

**Before**
```typescript
import { createLightNode } from "@waku/sdk";

const waku = await createLightNode({
shardInfo: {
clusterId: 1,
contentTopics: ["/my-app/1/notifications/proto"]
}
});
```

**After**
```typescript
import { createLightNode } from "@waku/sdk";

const waku = await createLightNode({
networkConfig: {
clusterId: 1,
contentTopics: ["/my-app/1/notifications/proto"]
}
});
```

## Pubsub Topic Configuration

Named pubsub topics are no longer supported. You must use either Static Sharding or Auto Sharding to configure pubsub topics.

**Before**
```typescript
import { createLightNode } from "@waku/sdk";

const waku = await createLightNode({
pubsubTopics: ["/waku/2/default-waku/proto"]
});
```

**After**

Use Static Sharding:
```typescript
import { createLightNode } from "@waku/sdk";

const waku = await createLightNode({
networkConfig: {
clusterId: 1,
shards: [0, 1, 2, 3, 4, 5, 6, 7]
}
});
```

Or use Auto Sharding:
```typescript
import { createLightNode } from "@waku/sdk";

const waku = await createLightNode({
networkConfig: {
clusterId: 1,
contentTopics: ["/your-app/1/default/proto"]
}
});
```

## Removed APIs

The following APIs have been removed:

- ApplicationInfo type: Use `string` for application and version in `NetworkConfig` instead.
- `shardInfo` option in `createLightNode`: Use `networkConfig` instead.
- `pubsubTopics` option in `createLightNode`: Use `networkConfig` with Static Sharding or Auto Sharding instead.

If you were using `ApplicationInfo` before, you should now use `ContentTopicInfo` (Auto Sharding) and specify your application and version in the content topic `string`.

**Before**
```typescript
import { createLightNode } from "@waku/sdk";

const waku = await createLightNode({
shardInfo: {
clusterId: 1,
application: "my-app",
version: "1"
}
});
```

**After**
```typescript
import { createLightNode } from "@waku/sdk";

const waku = await createLightNode({
networkConfig: {
clusterId: 1,
contentTopics: ["/my-app/1/default/proto"]
}
});
```

## Type Changes

- `ShardingParams` has been removed. Use `NetworkConfig` instead.
- `NetworkConfig` is now defined as `StaticSharding` | `AutoSharding`.
- `StaticSharding` is equivalent to the previous `ShardInfo`.
- `AutoSharding` is equivalent to the previous `ContentTopicInfo`.

## Internal/Private Utility Function Changes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure we need to document them as they are internal and shouldn't be in the utils in the first place because we don't want anyone using them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm.. Not sure either.
Fine to have it if we aren't sure I guess, and we can remove it in the future if there's a reason


Several utility functions have been updated or added:

- `ensureShardingConfigured` has been removed. Use `derivePubsubTopicsFromNetworkConfig` instead.
- New function `derivePubsubTopicsFromNetworkConfig` has been added to derive pubsub topics from the network configuration.
- `shardInfoToPubsubTopics` now accepts `Partial<NetworkConfig>` instead of `Partial<ShardingParams>`.
- New function `pubsubTopicsToShardInfo` has been added to convert pubsub topics to a ShardInfo object.

If you were using any of these utility functions directly, you'll need to update your code accordingly.

**Before**
```typescript
import { ensureShardingConfigured } from "@waku/utils";

const result = ensureShardingConfigured(shardInfo);
```

**After**
```typescript
import { derivePubsubTopicsFromNetworkConfig } from "@waku/utils";

const pubsubTopics = derivePubsubTopicsFromNetworkConfig(networkConfig);
```
Note: The default `NetworkConfig` for The Waku Network is now `{ clusterId: 1, shards: [0,1,2,3,4,5,6,7] }.`
Loading