From 82625fe6dbd43f14fcebaf0569a3df422435f65b Mon Sep 17 00:00:00 2001 From: Felicio Mununga Date: Tue, 19 Jul 2022 10:19:46 +0200 Subject: [PATCH] Get peer based on environment (#294) * get peer based on environment * add changeset * default to prod --- .changeset/breezy-zebras-invite.md | 5 +++++ examples/community/.env.example | 1 + examples/community/src/app.tsx | 6 +++++- packages/status-js/src/client/client.ts | 25 +++++++++++++++++++------ 4 files changed, 30 insertions(+), 7 deletions(-) create mode 100644 .changeset/breezy-zebras-invite.md diff --git a/.changeset/breezy-zebras-invite.md b/.changeset/breezy-zebras-invite.md new file mode 100644 index 00000000..ad86e470 --- /dev/null +++ b/.changeset/breezy-zebras-invite.md @@ -0,0 +1,5 @@ +--- +'@status-im/js': patch +--- + +get peer based on environment diff --git a/examples/community/.env.example b/examples/community/.env.example index 67091728..b0b6037c 100644 --- a/examples/community/.env.example +++ b/examples/community/.env.example @@ -1 +1,2 @@ PUBLIC_KEY="" +ENVIRONMENT="" diff --git a/examples/community/src/app.tsx b/examples/community/src/app.tsx index 75beea91..b4671b90 100644 --- a/examples/community/src/app.tsx +++ b/examples/community/src/app.tsx @@ -10,6 +10,10 @@ if (!publicKey) { ) } +const environment = process.env.ENVIRONMENT + export const App = () => { - return + return ( + + ) } diff --git a/packages/status-js/src/client/client.ts b/packages/status-js/src/client/client.ts index 8abd6902..97d53d03 100644 --- a/packages/status-js/src/client/client.ts +++ b/packages/status-js/src/client/client.ts @@ -3,7 +3,12 @@ */ import { hexToBytes } from 'ethereum-cryptography/utils' -import { Waku, WakuMessage } from 'js-waku' +import { + discovery, + getPredefinedBootstrapNodes, + Waku, + WakuMessage, +} from 'js-waku' import { ApplicationMetadataMessage } from '../protos/application-metadata-message' import { Account } from './account' @@ -12,7 +17,7 @@ import { handleWakuMessage } from './community/handle-waku-message' export interface ClientOptions { publicKey: string - env?: 'production' | 'test' + environment?: 'production' | 'test' } class Client { @@ -51,13 +56,21 @@ class Client { static async start(options: ClientOptions) { // Waku + const fleet = + options.environment === 'test' + ? discovery.predefined.Fleet.Test + : discovery.predefined.Fleet.Prod + /** + * >only connects to 1 remote node because of the limited number of nodes + * >run by Status and the limited number of connections provided by these nodes + * > + * >@see https://forum.vac.dev/t/waku-v2-scalability-studies/142/2 + */ + const peers = getPredefinedBootstrapNodes(fleet) const waku = await Waku.create({ bootstrap: { default: false, - peers: [ - '/dns4/node-01.gc-us-central1-a.wakuv2.test.statusim.net/tcp/443/wss/p2p/16Uiu2HAmJb2e28qLXxT5kZxVUUoJt72EMzNGXB47Rxx5hw3q4YjS', - // '/dns4/node-01.do-ams3.wakuv2.test.statusim.net/tcp/8000/wss/p2p/16Uiu2HAmPLe7Mzm8TsYUubgCAW1aJoeFScxrLj8ppHFivPo97bUZ', - ], + peers, }, relayKeepAlive: 15, libp2p: { config: { pubsub: { enabled: true, emitSelf: true } } },