diff --git a/.gitignore b/.gitignore index 79b5594..87d7420 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ **/.DS_Store +keystore +postgresql +rln_tree \ No newline at end of file diff --git a/README.md b/README.md index 401f6df..7642e11 100644 --- a/README.md +++ b/README.md @@ -1,38 +1,67 @@ # nwaku-compose -Ready to use docker-compose to run your own [nwaku](https://github.com/waku-org/nwaku) full node. Description: +Ready to use docker-compose to run your own [nwaku](https://github.com/waku-org/nwaku) full node: * nwaku node running relay and store protocols with RLN enabled. * Simple frontend to interact with your node and the network, to publish and receive messages. * Grafana dashboard for advanced users or node operators. * Requires `docker-compose` and `git`. -**1. Get the code:** -```console -git clone git@github.com:waku-org/nwaku-compose.git -cd nwaku-compose + +**📝 0. Prerequisites** + +You need: +* Ethereum Sepolia ws endpoint. Get one free from [Infura](https://www.infura.io/). +* Ethereum Sepolia account with some balance <0.01 Eth. Get some [here](https://www.infura.io/faucet/sepolia). +* A password to protect your rln membership. + +``` +export ETH_CLIENT_ADDRESS=wss://sepolia.infura.io/ws/v3/YOUR_INFURA_KEY +export ETH_TESTNET_KEY=REPLACE_BY_YOUR_KEY +export KEYSTORE_PASSWORD=PICK_A_PASSWORD ``` -**2. Provide your Ethereum node** -Waku needs an Ethereum Sepolia node, either yours or from a third party. Provide a websockets endpoint. You can get one for free from [Infura](https://www.infura.io/). +**🔑 1. Register RLN membership** + +The RLN membership is your access key to The Waku Network. Its registration is done onchain, and allows your nwaku node to publish messages in a decentralized and private way, respecting some rate limits. This command will register it and store in `keystore/keystore.json`. Note that if you just want to relay traffic (not publish), you don't need one. + ``` -export ETH_CLIENT_ADDRESS=wss://sepolia.infura.io/ws/v3/USE_YOUR_INFURA_KEY_HERE +./register_rln.sh ``` -**3. Start everything** +**🖥️ 2. Start your node** + +Start all processes: nwaku node, database and grafana for metrics. Your RLN membership is loaded into nwaku under the hood. ```console docker-compose up -d ``` -**4. Register your RLN membership** -If you just want to relay traffic in the network, you are all set. But if you want to publish messages, you need an RLN membership. Its a simple onchain transaction, you need: -* A wallet with some Sepolia Eth, <0.1 Eth. -* Go to [localhost:4000](http://localhost:4000) and `Register Credentials`. Set a `password` and `Export` it as `keystore.json` -* In your nwaku node, set. TODO: Improve manual process. - * `rln-relay-cred-password` to the `password` you chose. - * `rln-relay-cred-path` to `keystore.json` +**🏄🏼‍♂️ 3. Interact with your nwaku node** +* See [localhost:3000](http://localhost:3000) for node metrics. +* See [localhost:4000](http://localhost:4000). Under development 🚧 -**5. Interact with your nwaku node** -* See [localhost:4000](http://localhost:4000) to interact with your node -* See [localhost:3000](http://localhost:3000) for advanced metrics. +**📬 4. Use the REST API** + +Your nwaku node exposes a [REST API](https://waku-org.github.io/waku-rest-api/) to interact with it. + +``` +# get nwaku version +curl http://127.0.0.1:8645/debug/v1/version +# get nwaku info +curl http://127.0.0.1:8645/debug/v1/info +``` + +**Publish a message to a `contentTopic`**. Everyone subscribed to it will receive it. Note that `payload` is base64 encoded. + +``` +curl -X POST "http://127.0.0.1:8645/relay/v1/auto/messages" \ + -H "content-type: application/json" \ + -d '{"payload":"XaaabsQ==","contentTopic":"/my-app/2/chatroom-1/proto"}' +``` + +**Get messages sent to a `contentTopic`**. Note that any store node in the network is used to reply. +``` +curl -X GET "http://127.0.0.1:8645/store/v1/messages?contentTopics=%2Fmy-app%2F2%2Fchatroom-1%2Fproto&pageSize=50&ascending=true" \ + -H "accept: application/json" +``` For advanced documentation, refer to [ADVANCED.md](https://github.com/waku-org/nwaku-compose/blob/master/ADVANCED.md). \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 3ebf1f3..0acdb76 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -31,23 +31,6 @@ x-pg-exporter-env: &pg_exp_env # Services definitions services: nwaku: - # Provide the image using any of these methods - - # Method 1. Custom build - # For a custom build, requires building your image - # from nwaku repo: docker build -t nwaku:mytag . - #image: nwaku:mytag - - # Method 2. Pre-built image (master commit) - # For a pre-built image, use the firt 8 digits of the commit hash - # all commits in nwaku master al built and pushed to dockerhub - # See: hub.docker.com/r/statusteam/nim-waku - #image: statusteam/nim-waku:982cd282 - - # Method 3. Pre-built release - # For a pre-built release. See available releases: - # github.com/waku-org/nwaku/releases - image: ${NWAKU_IMAGE:-wakuorg/nwaku:v0.21.2-rc.0} restart: on-failure ports: @@ -64,6 +47,7 @@ services: environment: DOMAIN: ${DOMAIN} NODEKEY: ${NODEKEY} + KEYSTORE_PASSWORD: ${KEYSTORE_PASSWORD} ETH_CLIENT_ADDRESS: *eth_client_address EXTRA_ARGS: ${EXTRA_ARGS} <<: @@ -73,22 +57,24 @@ services: - ./run_node.sh:/opt/run_node.sh:Z - ./certs:/etc/letsencrypt/:Z - ./rln_tree:/etc/rln_tree/:Z + - ./keystore/keystore.json:/keystore/keystore.json/:Z entrypoint: sh command: - /opt/run_node.sh depends_on: - postgres - waku-frontend: - # TODO: migrate to waku-org - image: docker.io/alrevuelta/waku-frontend:latest - #command: - # - xxx - ports: - - 127.0.0.1:4000:3000 - restart: on-failure:5 - depends_on: - - nwaku + # TODO: Commented until ready + #waku-frontend: + # # TODO: migrate to waku-org + # image: docker.io/alrevuelta/waku-frontend:latest + # #command: + # # - xxx + # ports: + # - 127.0.0.1:4000:3000 + # restart: on-failure:5 + # depends_on: + # - nwaku prometheus: image: docker.io/prom/prometheus:latest @@ -133,6 +119,8 @@ services: - ./postgres_cfg/db.sql:/docker-entrypoint-initdb.d/db.sql:Z - ${PG_DATA_DIR:-./postgresql}:/var/lib/postgresql/data:Z command: postgres -c config_file=/etc/postgresql/postgresql.conf + ports: + - 127.0.0.1:5432:5432 healthcheck: test: ["CMD-SHELL", "pg_isready -d db_prod"] interval: 30s diff --git a/register_rln.sh b/register_rln.sh new file mode 100755 index 0000000..7750a21 --- /dev/null +++ b/register_rln.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +if test -f ./keystore/keystore.json; then + echo "keystore/keystore.json alredy exists. Use it instead of creating a new one." + echo "Exiting" + exit 1 +fi + +# TODO: Set nwaku release when ready instead of quay + +docker run -v ./keystore:/keystore/:Z quay.io/wakuorg/nwaku-pr:2189 generateRlnKeystore \ +--rln-relay-eth-client-address=$ETH_CLIENT_ADDRESS \ +--rln-relay-eth-private-key=$ETH_TESTNET_KEY \ +--rln-relay-eth-contract-address=0xF471d71E9b1455bBF4b85d475afb9BB0954A29c4 \ +--rln-relay-cred-path=/keystore/keystore.json \ +--rln-relay-cred-password=$KEYSTORE_PASSWORD \ +--execute \ No newline at end of file diff --git a/run_node.sh b/run_node.sh index 1594be1..25fa8c6 100644 --- a/run_node.sh +++ b/run_node.sh @@ -56,8 +56,14 @@ fi exec /usr/bin/wakunode\ --relay=true\ - --topic=/waku/2/default-waku/proto\ - --topic=/waku/2/dev-waku/proto\ + --topic=/waku/2/rs/1/0\ + --topic=/waku/2/rs/1/1\ + --topic=/waku/2/rs/1/2\ + --topic=/waku/2/rs/1/3\ + --topic=/waku/2/rs/1/4\ + --topic=/waku/2/rs/1/5\ + --topic=/waku/2/rs/1/6\ + --topic=/waku/2/rs/1/7\ --filter=true\ --lightpush=true\ --rpc-admin=true\ @@ -89,6 +95,8 @@ exec /usr/bin/wakunode\ --rln-relay-eth-contract-address="${RLN_RELAY_CONTRACT_ADDRESS}"\ --rln-relay-eth-client-address="${ETH_CLIENT_ADDRESS}"\ --rln-relay-tree-path="/etc/rln_tree"\ + --rln-relay-cred-password="${KEYSTORE_PASSWORD}"\ + --rln-relay-cred-path="/keystore/keystore.json"\ ${RLN_RELAY_CRED_PATH}\ ${RLN_RELAY_CRED_PASSWORD}\ ${DNS_WSS_CMD}\