Skip to content

Commit

Permalink
add store nodes from shard.test fleet (#529)
Browse files Browse the repository at this point in the history
* u

* u

* t

* t

* u

* u

* t

* f

* r

* u

* d

* c
  • Loading branch information
felicio authored Mar 14, 2024
1 parent 3b1a686 commit 9adaeb6
Show file tree
Hide file tree
Showing 10 changed files with 378 additions and 188 deletions.
5 changes: 5 additions & 0 deletions .changeset/khaki-knives-cheat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@status-im/js': patch
---

use store nodes from `shard.test` fleet
5 changes: 3 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@
"smartStep": true,
"sourceMaps": true,
"env": {
"DEBUG": "*",
"DEBUG": "*,-vite*,-connect:*",
"DEBUG_HIDE_DATE": "0",
"DEBUG_COLORS": "1",
"VITE_NODE": "true"
},
"runtimeArgs": ["--preserve-symlinks"],
"outFiles": ["${workspaceFolder}/**/*.js"],
"resolveSourceMapLocations": ["**/*"]
"resolveSourceMapLocations": ["**/*"],
"outputCapture": "std"
},
{
"type": "node",
Expand Down
6 changes: 3 additions & 3 deletions packages/status-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,16 @@
"@bufbuild/protobuf": "1.4.2",
"@libp2p/bootstrap": "^9.0.10",
"@scure/base": "^1.1.1",
"@waku/message-encryption": "^0.0.23",
"@waku/sdk": "^0.0.21",
"@waku/message-encryption": "^0.0.24",
"@waku/sdk": "^0.0.22",
"ethereum-cryptography": "^1.0.3",
"ethers": "^6.2.1",
"multiformats": "^11.0.1"
},
"devDependencies": {
"@bufbuild/protoc-gen-es": "1.4.2",
"@status-im/eslint-config": "*",
"@waku/interfaces": "^0.0.20",
"@waku/interfaces": "^0.0.21",
"happy-dom": "^9.1.7"
},
"files": [
Expand Down
7 changes: 6 additions & 1 deletion packages/status-js/src/client/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,12 @@ export class Chat {
}

await this.client.waku.store.queryWithOrderedCallback(
[createDecoder(this.contentTopic, this.symmetricKey)],
[
createDecoder(this.contentTopic, this.symmetricKey, {
clusterId: 16,
shard: 32,
}),
],
wakuMessage => {
this.#fetchingMessages = true
this.client.handleWakuMessage(wakuMessage)
Expand Down
14 changes: 11 additions & 3 deletions packages/status-js/src/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import { handleWakuMessage } from './community/handle-waku-message'
import { LocalStorage } from './storage'

import type { ApplicationMetadataMessage_Type } from '../protos/application-metadata-message_pb'
import type { DecodedMessage } from './community/handle-waku-message'
import type { Storage } from './storage'
import type { LightNode } from '@waku/interfaces'
import type { DecodedMessage } from '@waku/message-encryption/symmetric'

const THROWAWAY_ACCOUNT_STORAGE_KEY = 'throwaway_account'

Expand All @@ -28,7 +28,7 @@ export interface ClientOptions {
* Public key of a community to join.
*/
publicKey: string
environment?: 'production' | 'test'
environment?: 'test' // 'production' | 'test'
/**
* Custom storage for data persistance
* @default window.localStorage
Expand Down Expand Up @@ -132,7 +132,7 @@ class Client {
}

static async start(options: ClientOptions): Promise<Client> {
const { environment = 'production' } = options
const { environment = 'test' } = options

let waku: LightNode | undefined
let client: Client | undefined
Expand Down Expand Up @@ -168,6 +168,10 @@ class Client {
}),
],
},
shardInfo: {
clusterId: 16,
shards: [32],
},
})
await waku.start()
await waitForRemotePeer(
Expand Down Expand Up @@ -269,6 +273,10 @@ class Client {
contentTopic,
symKey,
sigPrivKey: hexToBytes(this.#account.privateKey),
pubsubTopicShardInfo: {
clusterId: 16,
shard: 32,
},
}),
{ payload: message }
)
Expand Down
21 changes: 18 additions & 3 deletions packages/status-js/src/client/community/community.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,12 @@ export class Community {
public fetch = async () => {
// most recent page first
await this.client.waku.store.queryWithOrderedCallback(
[createDecoder(this.contentTopic, this.symmetricKey)],
[
createDecoder(this.contentTopic, this.symmetricKey, {
clusterId: 16,
shard: 32,
}),
],
wakuMessage => {
this.client.handleWakuMessage(wakuMessage)

Expand All @@ -109,7 +114,12 @@ export class Community {

private observe = async () => {
await this.client.waku.filter.subscribe(
[createDecoder(this.contentTopic, this.symmetricKey)],
[
createDecoder(this.contentTopic, this.symmetricKey, {
clusterId: 16,
shard: 32,
}),
],
this.client.handleWakuMessage
)
}
Expand All @@ -130,7 +140,12 @@ export class Community {
this.chats.set(chatUuid, chat)

const unobserveFn = await this.client.waku.filter.subscribe(
[createDecoder(chat.contentTopic, chat.symmetricKey)],
[
createDecoder(chat.contentTopic, chat.symmetricKey, {
clusterId: 16,
shard: 32,
}),
],
this.client.handleWakuMessage
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ import { mapChatMessage } from './map-chat-message'
import type { Account } from '../account'
import type { Client } from '../client'
import type { Community } from './community'
import type { DecodedMessage } from '@waku/message-encryption/symmetric'
import type { createDecoder } from '@waku/message-encryption/symmetric'

export type DecodedMessage = NonNullable<
Awaited<ReturnType<ReturnType<typeof createDecoder>['fromProtoObj']>>
>

export function handleWakuMessage(
wakuMessage: DecodedMessage,
Expand Down
28 changes: 7 additions & 21 deletions packages/status-js/src/consts/peers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,13 @@
// todo: use "dynamic" discovery protocol instead
// todo?: use a regional map together with an environment variable for the peer selection (e.g. `VERCEL_REGION`, but probably limited to Serverless Functions)
export const peers = {
production: [
// Nim
'/dns4/node-01.ac-cn-hongkong-c.status.prod.statusim.net/tcp/443/wss/p2p/16Uiu2HAkvEZgh3KLwhLwXg95e5ojM8XykJ4Kxi2T7hk22rnA7pJC',
'/dns4/node-01.do-ams3.status.prod.statusim.net/tcp/443/wss/p2p/16Uiu2HAm6HZZr7aToTvEBPpiys4UxajCTU97zj5v7RNR2gbniy1D',
'/dns4/node-01.gc-us-central1-a.status.prod.statusim.net/tcp/443/wss/p2p/16Uiu2HAkwBp8T6G77kQXSNMnxgaMky1JeyML5yqoTHRM8dbeCBNb',
'/dns4/node-02.ac-cn-hongkong-c.status.prod.statusim.net/tcp/443/wss/p2p/16Uiu2HAmFy8BrJhCEmCYrUfBdSNkrPw6VHExtv4rRp1DSBnCPgx8',
'/dns4/node-02.do-ams3.status.prod.statusim.net/tcp/443/wss/p2p/16Uiu2HAmSve7tR5YZugpskMv2dmJAsMUKmfWYEKRXNUxRaTCnsXV',
'/dns4/node-02.gc-us-central1-a.status.prod.statusim.net/tcp/443/wss/p2p/16Uiu2HAmDQugwDHM3YeUp86iGjrUvbdw3JPRgikC7YoGBsT2ymMg',
// Go
// '/dns4/node-01.ac-cn-hongkong-c.go-waku.prod.statusim.net/tcp/443/wss/p2p/16Uiu2HAkwUKwy66nhcSFeW7y5qijNqXC4ZD3TaMMqnoEbh3wK2xU',
// '/dns4/node-01.do-ams3.go-waku.prod.statusim.net/tcp/443/wss/p2p/16Uiu2HAkyScd7DiwgMwzfw8CFFhznH3wRzciqEUfjDzn7vyimR8c',
// '/dns4/node-01.gc-us-central1-a.go-waku.prod.statusim.net/tcp/443/wss/p2p/16Uiu2HAmKTYnoPKebjWy63e1zPKiYRCQvm25W5mNSnCFE8EmzLga',
],
// production: [],
test: [
// Nim
'/dns4/node-01.ac-cn-hongkong-c.status.test.statusim.net/tcp/443/wss/p2p/16Uiu2HAm2BjXxCp1sYFJQKpLLbPbwd5juxbsYofu3TsS3auvT9Yi',
'/dns4/node-01.do-ams3.status.test.statusim.net/tcp/443/wss/p2p/16Uiu2HAkukebeXjTQ9QDBeNDWuGfbaSg79wkkhK4vPocLgR6QFDf',
'/dns4/node-01.gc-us-central1-a.status.test.statusim.net/tcp/443/wss/p2p/16Uiu2HAmGDX3iAFox93PupVYaHa88kULGqMpJ7AEHGwj3jbMtt76',
// Go
// '/dns4/node-01.ac-cn-hongkong-c.go-waku.test.statusim.net/tcp/443/wss/p2p/16Uiu2HAmBDbMWFiG9ki8sDw6fYtraSxo4oHU9HbuN43S2HVyq1FD',
// '/dns4/node-01.do-ams3.go-waku.test.statusim.net/tcp/443/wss/p2p/16Uiu2HAm9vnvCQgCDrynDK1h7GJoEZVGvnuzq84RyDQ3DEdXmcX7',
// '/dns4/node-01.gc-us-central1-a.go-waku.test.statusim.net/tcp/443/wss/p2p/16Uiu2HAmPz63Xc6AuVkDeujz7YeZta18rcdau3Y1BzaxKAfDrBqz',
'/dns4/store-01.do-ams3.shards.test.statusim.net/tcp/443/wss/p2p/16Uiu2HAmAUdrQ3uwzuE4Gy4D56hX6uLKEeerJAnhKEHZ3DxF1EfT',
'/dns4/store-02.do-ams3.shards.test.statusim.net/tcp/443/wss/p2p/16Uiu2HAm9aDJPkhGxc2SFcEACTFdZ91Q5TJjp76qZEhq9iF59x7R',
'/dns4/store-01.gc-us-central1-a.shards.test.statusim.net/tcp/443/wss/p2p/16Uiu2HAmMELCo218hncCtTvC2Dwbej3rbyHQcR8erXNnKGei7WPZ',
'/dns4/store-02.gc-us-central1-a.shards.test.statusim.net/tcp/443/wss/p2p/16Uiu2HAmJnVR7ZzFaYvciPVafUXuYGLHPzSUigqAmeNw9nJUVGeM',
'/dns4/store-01.ac-cn-hongkong-c.shards.test.statusim.net/tcp/443/wss/p2p/16Uiu2HAm2M7xs7cLPc3jamawkEqbr7cUJX11uvY7LxQ6WFUdUKUT',
'/dns4/store-02.ac-cn-hongkong-c.shards.test.statusim.net/tcp/443/wss/p2p/16Uiu2HAm9CQhsuwPR54q27kNj9iaQVfyRzTGKrhFmr94oD8ujU6P',
],
}
28 changes: 21 additions & 7 deletions packages/status-js/src/request-client/request-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ import { mapChannel } from './map-channel'
import { mapCommunity } from './map-community'
import { mapUser } from './map-user'

import type { DecodedMessage } from '../client/community/handle-waku-message'
import type { ChannelInfo } from './map-channel'
import type { CommunityInfo } from './map-community'
import type { UserInfo } from './map-user'
import type { LightNode } from '@waku/interfaces'
import type { DecodedMessage } from '@waku/message-encryption/symmetric'

export interface RequestClientOptions {
environment?: 'production' | 'test'
environment?: 'test' // 'production' | 'test'
}

class RequestClient {
Expand All @@ -46,7 +46,7 @@ class RequestClient {
}

static async start(options: RequestClientOptions): Promise<RequestClient> {
const { environment = 'production' } = options
const { environment = 'test' } = options

let waku: LightNode | undefined
let client: RequestClient | undefined
Expand All @@ -58,8 +58,8 @@ class RequestClient {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
emitSelf: true,
pingKeepAlive: 0,
relayKeepAlive: 0,
// pingKeepAlive: 0,
// relayKeepAlive: 0,
libp2p: {
peerDiscovery: [
bootstrap({
Expand All @@ -70,6 +70,10 @@ class RequestClient {
}),
],
},
shardInfo: {
clusterId: 16,
shards: [32],
},
})
await waku.start()
await waitForRemotePeer(waku, [Protocols.Store], 10 * 1000)
Expand Down Expand Up @@ -150,7 +154,12 @@ class RequestClient {

let communityDescription: CommunityDescription | undefined = undefined
await this.waku.store.queryWithOrderedCallback(
[createDecoder(contentTopic, symmetricKey)],
[
createDecoder(contentTopic, symmetricKey, {
clusterId: 16,
shard: 32,
}),
],
wakuMessage => {
// handle
const message = this.handleWakuMessage(wakuMessage)
Expand Down Expand Up @@ -207,7 +216,12 @@ class RequestClient {
let contactCodeAdvertisement: ContactCodeAdvertisement | undefined =
undefined
await this.waku.store.queryWithOrderedCallback(
[createDecoder(contentTopic, symmetricKey)],
[
createDecoder(contentTopic, symmetricKey, {
clusterId: 16,
shard: 32,
}),
],
wakuMessage => {
// handle
const message = this.handleWakuMessage(wakuMessage)
Expand Down
Loading

0 comments on commit 9adaeb6

Please sign in to comment.