From 146949f7a40b3a20f2dc25eaf2bfcc5d10977557 Mon Sep 17 00:00:00 2001 From: LordGhostX <47832826+LordGhostX@users.noreply.github.com> Date: Thu, 3 Aug 2023 06:40:57 +0100 Subject: [PATCH] add js-waku discovery (#100) * add js-waku discovery * implement feedback * update logos preset --- docs/guides/js-waku/configure-discovery.md | 189 ++++++++++++++++++ docs/guides/js-waku/index.md | 7 +- docs/guides/js-waku/light-send-receive.md | 2 +- .../guides/js-waku/store-retrieve-messages.md | 2 +- docs/guides/nwaku/configure-discovery.md | 4 +- package.json | 2 +- sidebars.js | 1 + yarn.lock | 28 +-- 8 files changed, 213 insertions(+), 22 deletions(-) create mode 100644 docs/guides/js-waku/configure-discovery.md diff --git a/docs/guides/js-waku/configure-discovery.md b/docs/guides/js-waku/configure-discovery.md new file mode 100644 index 0000000..33d4abe --- /dev/null +++ b/docs/guides/js-waku/configure-discovery.md @@ -0,0 +1,189 @@ +--- +title: Bootstrap Nodes and Discover Peers +--- + +This guide provides detailed steps to bootstrap your your node using [Static Peers](/overview/concepts/static-peers) and discover peers in the Waku Network using [DNS Discovery](/overview/concepts/dns-discovery). + +:::tip +Until [node incentivisation](/overview/reference/research-in-progress#prevention-of-denial-of-service-dos-and-node-incentivisation) is in place, you should [operate extra nodes](/guides/nodes-and-sdks#run-a-waku-node) alongside the ones provided by the Waku Network. When running a node, we recommend using the [DNS Discovery and Static Peers](/guides/js-waku/configure-discovery#configure-dns-discovery-and-static-peers) configuration to connect to both the Waku Network and your node. +::: + +## Default Bootstrap Method + +The `@waku/sdk` package provides a built-in bootstrapping method that uses [DNS Discovery](/overview/concepts/dns-discovery) to locate peers from the `waku v2.prod` `ENR` tree. + +```js +import { createLightNode } from "@waku/sdk"; + +// Bootstrap node using the default bootstrap method +const node = await createLightNode({ defaultBootstrap: true }); +``` + +## Configure Static Peers + +To bootstrap a node using [static peers](/overview/concepts/static-peers), first install the `@libp2p/bootstrap` package: + +```mdx-code-block +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; +``` + + + + +```shell +npm install @libp2p/bootstrap +``` + + + + +```shell +yarn add @libp2p/bootstrap +``` + + + + +Then, use the `bootstrap()` function to provide a list of `multiaddr` to bootstrap the node: + +```js +import { createLightNode } from "@waku/sdk"; +import { bootstrap } from "@libp2p/bootstrap"; + +// Bootstrap node using static peers +const node = await createLightNode({ + libp2p: { + peerDiscovery: [ + bootstrap({ list: ["[PEER MULTIADDR]"] }), + ], + }, +}); +``` + +For example, consider a node that connects to two static peers on the same local host (IP: `0.0.0.0`) using TCP ports `60002` and `60003`: + +```js +// Define the list of static peers to bootstrap +const peers = [ + "/ip4/0.0.0.0/tcp/60002/p2p/16Uiu2HAkzjwwgEAXfeGNMKFPSpc6vGBRqCdTLG5q3Gmk2v4pQw7H", + "/ip4/0.0.0.0/tcp/60003/p2p/16Uiu2HAmFBA7LGtwY5WVVikdmXVo3cKLqkmvVtuDu63fe8safeQJ", +]; + +// Bootstrap node using the static peers +const node = await createLightNode({ + libp2p: { + peerDiscovery: [ + bootstrap({ list: peers }), + ], + }, +}); +``` + +## Configure DNS Discovery + +To bootstrap a node using [DNS Discovery](/overview/concepts/dns-discovery), first install the `@waku/dns-discovery` package: + + + + +```shell +npm install @waku/dns-discovery +``` + + + + +```shell +yarn add @waku/dns-discovery +``` + + + + +Then, use the `wakuDnsDiscovery()` function to provide a list of URLs for DNS node list in the format `enrtree://@`: + +```js +import { createLightNode } from "@waku/sdk"; +import { wakuDnsDiscovery } from "@waku/dns-discovery"; + +// Define DNS node list +const enrTree = "enrtree://[PUBLIC KEY]@[DOMAIN NAME]"; + +// Define node requirements +const NODE_REQUIREMENTS = { + store: 3, + lightPush: 3, + filter: 3, +}; + +// Bootstrap node using DNS Discovery +const node = await createLightNode({ + libp2p: { + peerDiscovery: [ + wakuDnsDiscovery( + [enrTree], + NODE_REQUIREMENTS, + ), + ], + }, +}); +``` + +For example, consider a node that uses the `waku v2.prod` and `waku v2.test` `ENR` trees for `DNS Discovery`: + +```js +import { enrTree } from "@waku/dns-discovery"; + +// Bootstrap node using DNS Discovery +const node = await createLightNode({ + libp2p: { + peerDiscovery: [ + wakuDnsDiscovery( + [enrTree["PROD"], enrTree["TEST"]], + NODE_REQUIREMENTS, + ), + ], + }, +}); +``` + +## Configure DNS Discovery and Static Peers + +You can also bootstrap your node using [DNS Discovery](/overview/concepts/dns-discovery) and [Static Peers](/overview/concepts/static-peers) simultaneously: + +```js +import { createLightNode } from "@waku/sdk"; +import { bootstrap } from "@libp2p/bootstrap"; +import { enrTree, wakuDnsDiscovery } from "@waku/dns-discovery"; + +// Define the list of static peers to bootstrap +const peers = [ + "/ip4/0.0.0.0/tcp/60002/p2p/16Uiu2HAkzjwwgEAXfeGNMKFPSpc6vGBRqCdTLG5q3Gmk2v4pQw7H", + "/ip4/0.0.0.0/tcp/60003/p2p/16Uiu2HAmFBA7LGtwY5WVVikdmXVo3cKLqkmvVtuDu63fe8safeQJ", +]; + +// Define node requirements +const NODE_REQUIREMENTS = { + store: 3, + lightPush: 3, + filter: 3, +}; + +// Bootstrap node using DNS Discovery +const node = await createLightNode({ + libp2p: { + peerDiscovery: [ + bootstrap({ list: peers }), + wakuDnsDiscovery( + [enrTree["PROD"]], + NODE_REQUIREMENTS, + ), + ], + }, +}); +``` + +:::info +If you do not set up a bootstrap node or discovery mechanism, your node will not connect to any remote peer. +::: \ No newline at end of file diff --git a/docs/guides/js-waku/index.md b/docs/guides/js-waku/index.md index f557d72..a9f1fc5 100644 --- a/docs/guides/js-waku/index.md +++ b/docs/guides/js-waku/index.md @@ -13,7 +13,7 @@ import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; ``` - + ```shell @@ -46,7 +46,7 @@ We recommend creating a message structure for your application using [Protocol B To get started, install the `protobufjs` package using your preferred package manager: - + ```shell @@ -82,8 +82,9 @@ Have a look at the quick start guide and comprehensive tutorials to learn how to | Guide | Description | | - | - | | [Send and Receive Messages Using Light Push and Filter](/guides/js-waku/light-send-receive) | Learn how to send and receive messages on light nodes using the [Light Push](/overview/concepts/protocols#light-push) and [Filter](/overview/concepts/protocols#filter) protocols | -| [Retrieve Messages Using Store](/guides/js-waku/store-retrieve-messages) | Learn how to retrieve and filter historical messages on light nodes using the [Store](/overview/concepts/protocols#store) protocol | +| [Retrieve Messages Using Store Protocol](/guides/js-waku/store-retrieve-messages) | Learn how to retrieve and filter historical messages on light nodes using the [Store protocol](/overview/concepts/protocols#store) | | [Bootstrap DApps Using @waku/create-app](/guides/js-waku/use-waku-create-app) | Learn how to use the [@waku/create-app](https://www.npmjs.com/package/@waku/create-app) package to bootstrap your next `@waku/sdk` project from various example templates | +| [Bootstrap Nodes and Discover Peers](/guides/js-waku/configure-discovery) | Learn how to bootstrap your node using [Static Peers](/overview/concepts/static-peers) and discover peers using [DNS Discovery](/overview/concepts/dns-discovery) | diff --git a/docs/guides/js-waku/light-send-receive.md b/docs/guides/js-waku/light-send-receive.md index 5a044e4..bceef66 100644 --- a/docs/guides/js-waku/light-send-receive.md +++ b/docs/guides/js-waku/light-send-receive.md @@ -20,7 +20,7 @@ await node.start(); ``` :::info -When the `defaultBootstrap` flag is set to `true`, your node will be bootstrapped using [DNS Discovery](/overview/concepts/dns-discovery). The node does not connect to any remote peer or bootstrap node if omitted. +When the `defaultBootstrap` option is set to `true`, your node will be bootstrapped using the [default bootstrap method](/guides/js-waku/configure-discovery#default-bootstrap-method). Have a look at the [Bootstrap Nodes and Discover Peers](/guides/js-waku/configure-discovery) guide to learn more methods to bootstrap nodes. ::: ## Connect to Remote Peers diff --git a/docs/guides/js-waku/store-retrieve-messages.md b/docs/guides/js-waku/store-retrieve-messages.md index 0d9c976..19aa520 100644 --- a/docs/guides/js-waku/store-retrieve-messages.md +++ b/docs/guides/js-waku/store-retrieve-messages.md @@ -1,5 +1,5 @@ --- -title: Retrieve Messages Using Store +title: Retrieve Messages Using Store Protocol --- This guide provides detailed steps to create a Light Node for retrieving and filtering historical messages using the [Store protocol](/overview/concepts/protocols#store). diff --git a/docs/guides/nwaku/configure-discovery.md b/docs/guides/nwaku/configure-discovery.md index 8f1765f..9be4a98 100644 --- a/docs/guides/nwaku/configure-discovery.md +++ b/docs/guides/nwaku/configure-discovery.md @@ -10,7 +10,7 @@ You can configure a `nwaku` node to use multiple peer discovery mechanisms simul ## Configure Static Peers -You can provide static peers to a `nwaku` node during startup using the `staticnode` configuration option. To connect to multiple peers on startup, repeat the `staticnode` option: +You can provide [static peers](/overview/concepts/static-peers) to a `nwaku` node during startup using the `staticnode` configuration option. To connect to multiple peers on startup, repeat the `staticnode` option: ```bash ./build/wakunode2 \ @@ -37,7 +37,7 @@ To enable [DNS Discovery](/overview/concepts/dns-discovery) in a `nwaku` node, u ```bash ./build/wakunode2 \ --dns-discovery=true \ - --dns-discovery-url=[DNS NODE LIST] \ + --dns-discovery-url=enrtree://[PUBLIC KEY]@[DOMAIN NAME] \ --dns-discovery-name-server=[DNS NAME SERVER IP] ``` diff --git a/package.json b/package.json index 59f6ff7..9db7b37 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ }, "dependencies": { "@acid-info/docusaurus-fathom": "^1.0.0-alpha.61", - "@acid-info/logos-docusaurus-preset": "^1.0.0-alpha.81", + "@acid-info/logos-docusaurus-preset": "^1.0.0-alpha.97", "@docusaurus/core": "^2.4.1", "@docusaurus/preset-classic": "^2.4.1", "@docusaurus/theme-mermaid": "^2.4.1", diff --git a/sidebars.js b/sidebars.js index 19ec5ef..68a7503 100644 --- a/sidebars.js +++ b/sidebars.js @@ -74,6 +74,7 @@ const sidebars = { "guides/js-waku/light-send-receive", "guides/js-waku/store-retrieve-messages", "guides/js-waku/use-waku-create-app", + "guides/js-waku/configure-discovery", { type: 'html', value: 'Examples', diff --git a/yarn.lock b/yarn.lock index 36a2cbc..07b2633 100644 --- a/yarn.lock +++ b/yarn.lock @@ -33,14 +33,14 @@ "@easyops-cn/docusaurus-search-local" "^0.33.6" lodash "^4.17.21" -"@acid-info/logos-docusaurus-preset@^1.0.0-alpha.81": - version "1.0.0-alpha.81" - resolved "https://registry.yarnpkg.com/@acid-info/logos-docusaurus-preset/-/logos-docusaurus-preset-1.0.0-alpha.81.tgz#8a654fd676dd2bfacf42ec39f850bfa4ccbbe507" - integrity sha512-pZNWhiTdaHWyJlncBL37xjaoOMd76FXFcAq0glqPGKqcRLbyq+tBBuSh0JRo86SKNkFW8ZAgGl3XlmSDwCAgyQ== +"@acid-info/logos-docusaurus-preset@^1.0.0-alpha.97": + version "1.0.0-alpha.97" + resolved "https://registry.yarnpkg.com/@acid-info/logos-docusaurus-preset/-/logos-docusaurus-preset-1.0.0-alpha.97.tgz#96d29bd2f75cf427de8e537616c7f8852e52d760" + integrity sha512-Cs0w3pFfrE2jmroaleedGakb8LoEyH8iN5q0Q+WsDLt2qz3xFIXvIW4fiQc5eM37NbHpGgGgvrm7YcB2Fp0ySg== dependencies: "@acid-info/docusaurus-og" "^1.0.0-alpha.76" "@acid-info/logos-docusaurus-search-local" "^1.0.0-alpha.47" - "@acid-info/logos-docusaurus-theme" "^1.0.0-alpha.81" + "@acid-info/logos-docusaurus-theme" "^1.0.0-alpha.97" "@docusaurus/core" "^2.4.1" "@docusaurus/module-type-aliases" "^2.4.1" "@docusaurus/preset-classic" "^2.4.1" @@ -70,13 +70,13 @@ satori "^0.10.1" sharp "^0.32.1" -"@acid-info/logos-docusaurus-theme@^1.0.0-alpha.81": - version "1.0.0-alpha.81" - resolved "https://registry.yarnpkg.com/@acid-info/logos-docusaurus-theme/-/logos-docusaurus-theme-1.0.0-alpha.81.tgz#34ec1cd51f8ec827ae653d24fb92267069bd6a0d" - integrity sha512-cbCcVShPmEW5k+jyYnVGIttDOtHG9ohH5HKjXMc+kXUl2WJN1hUxt4oTo/TJD16b+Rlbe2RuTT+yorzdKyGHlA== +"@acid-info/logos-docusaurus-theme@^1.0.0-alpha.97": + version "1.0.0-alpha.97" + resolved "https://registry.yarnpkg.com/@acid-info/logos-docusaurus-theme/-/logos-docusaurus-theme-1.0.0-alpha.97.tgz#8b7366238cc0cb177f400af82c0086f88f8f0a45" + integrity sha512-iBbH8enlSIhhGZuWWNxRSV5z8rQrO7uxBUq+xjA4PiCrjpbQb90YSuChuTizRUKkawzpswzkcukIdhzIGfc/Eg== dependencies: "@acid-info/docusaurus-og" "^1.0.0-alpha.76" - "@acid-info/lsd-react" "^0.1.0-alpha.15" + "@acid-info/lsd-react" "^0.1.0-alpha.17" "@docusaurus/core" "^2.4.1" "@docusaurus/mdx-loader" "^2.4.1" "@docusaurus/module-type-aliases" "^2.4.1" @@ -117,10 +117,10 @@ three-stdlib "^2.23.4" utility-types "^3.10.0" -"@acid-info/lsd-react@^0.1.0-alpha.15": - version "0.1.0-alpha.16" - resolved "https://registry.yarnpkg.com/@acid-info/lsd-react/-/lsd-react-0.1.0-alpha.16.tgz#cf635df44bc6ec63990d16fee38908d646a47701" - integrity sha512-U91Hp3Km/tAeExsMhAJvsocg37wImXlNN4Xo4R+lVJD3oTTF0cTLsB+32IbyimqELyXluUv2gwsyo2nHtEcY4Q== +"@acid-info/lsd-react@^0.1.0-alpha.17": + version "0.1.0-alpha.17" + resolved "https://registry.yarnpkg.com/@acid-info/lsd-react/-/lsd-react-0.1.0-alpha.17.tgz#4a0da00ad779717bcd6c5771863ec94937c701a0" + integrity sha512-qDnDr4uK7xXulf3StBLhCdq+0zT+6NT1TstQ+qAw3/kLonE2wiQx+w+aRlyaRobSevhtyC+bfR+QDvfFwkG8Rw== dependencies: "@emotion/react" "^11.10.5" "@emotion/styled" "^11.10.5"