diff --git a/README.md b/README.md index 119c00052..ce352d6f5 100644 --- a/README.md +++ b/README.md @@ -110,11 +110,19 @@ source env.sh ``` If everything went well, you should see your prompt suffixed with `[Nimbus env]$`. Now you can run `nim` commands as usual. -### Waku Protocol Test Suite +### Test Suite ```bash # Run all the Waku tests make test + +# Run a specific test file +make test +# e.g. : make test tests/wakunode2/test_all.nim + +# Run a specific test name from a specific test file +make test +# e.g. : make test tests/wakunode2/test_all.nim "node setup is successful with default configuration" ``` ### Building single test files diff --git a/apps/liteprotocoltester/docker-compose.yml b/apps/liteprotocoltester/docker-compose.yml index 0effbf8f0..16b544644 100644 --- a/apps/liteprotocoltester/docker-compose.yml +++ b/apps/liteprotocoltester/docker-compose.yml @@ -9,7 +9,7 @@ x-logging: &logging x-eth-client-address: ð_client_address ${ETH_CLIENT_ADDRESS:-} # Add your ETH_CLIENT_ADDRESS after the "-" x-rln-environment: &rln_env - RLN_RELAY_CONTRACT_ADDRESS: ${RLN_RELAY_CONTRACT_ADDRESS:-0xF471d71E9b1455bBF4b85d475afb9BB0954A29c4} + RLN_RELAY_CONTRACT_ADDRESS: ${RLN_RELAY_CONTRACT_ADDRESS:-0xB9cd878C90E49F797B4431fBF4fb333108CB90e6} RLN_RELAY_CRED_PATH: ${RLN_RELAY_CRED_PATH:-} # Optional: Add your RLN_RELAY_CRED_PATH after the "-" RLN_RELAY_CRED_PASSWORD: ${RLN_RELAY_CRED_PASSWORD:-} # Optional: Add your RLN_RELAY_CRED_PASSWORD after the "-" diff --git a/apps/liteprotocoltester/liteprotocoltester.nim b/apps/liteprotocoltester/liteprotocoltester.nim index 939332cff..d528efa90 100644 --- a/apps/liteprotocoltester/liteprotocoltester.nim +++ b/apps/liteprotocoltester/liteprotocoltester.nim @@ -122,7 +122,7 @@ when isMainModule: error "Issue converting toWakuConf", error = $error quit(QuitFailure) - var waku = Waku.new(wakuConf).valueOr: + var waku = (waitFor Waku.new(wakuConf)).valueOr: error "Waku initialization failed", error = error quit(QuitFailure) diff --git a/apps/sonda/.env.example b/apps/sonda/.env.example index 2423d06cb..ea769b329 100644 --- a/apps/sonda/.env.example +++ b/apps/sonda/.env.example @@ -1,12 +1,20 @@ # RPC URL for accessing testnet via HTTP. -# e.g. https://sepolia.infura.io/v3/123aa110320f4aec179150fba1e1b1b1 +# e.g. https://linea-sepolia.infura.io/v3/123aa110320f4aec179150fba1e1b1b1 RLN_RELAY_ETH_CLIENT_ADDRESS= -# Private key of testnet where you have sepolia ETH that would be staked into RLN contract. +# Account of testnet where you have Linea Sepolia ETH that would be staked into RLN contract. +ETH_TESTNET_ACCOUNT= + +# Private key of testnet where you have Linea Sepolia ETH that would be staked into RLN contract. # Note: make sure you don't use the '0x' prefix. # e.g. 0116196e9a8abed42dd1a22eb63fa2a5a17b0c27d716b87ded2c54f1bf192a0b ETH_TESTNET_KEY= +# Address of the RLN contract on Linea Sepolia. +RLN_CONTRACT_ADDRESS=0xB9cd878C90E49F797B4431fBF4fb333108CB90e6 +# Address of the RLN Membership Token contract on Linea Sepolia used to pay for membership. +TOKEN_CONTRACT_ADDRESS=0x185A0015aC462a0aECb81beCc0497b649a64B9ea + # Password you would like to use to protect your RLN membership. RLN_RELAY_CRED_PASSWORD= @@ -15,7 +23,8 @@ NWAKU_IMAGE= NODEKEY= DOMAIN= EXTRA_ARGS= -RLN_RELAY_CONTRACT_ADDRESS= +STORAGE_SIZE= + # -------------------- SONDA CONFIG ------------------ METRICS_PORT=8004 diff --git a/apps/sonda/README.md b/apps/sonda/README.md index 75342c3cb..459f6fe69 100644 --- a/apps/sonda/README.md +++ b/apps/sonda/README.md @@ -30,13 +30,13 @@ It works by running a `nwaku` node, publishing a message from it every fixed int 2. If you want to query nodes in `cluster-id` 1, then you have to follow the steps of registering an RLN membership. Otherwise, you can skip this step. For it, you need: - * Ethereum Sepolia WebSocket 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). + * Ethereum Linea Sepolia WebSocket endpoint. Get one free from [Infura](https://linea-sepolia.infura.io/). + * Ethereum Linea Sepolia account with minimum 0.01ETH. Get some [here](https://docs.metamask.io/developer-tools/faucet/). * A password to protect your rln membership. Fill the `RLN_RELAY_ETH_CLIENT_ADDRESS`, `ETH_TESTNET_KEY` and `RLN_RELAY_CRED_PASSWORD` env variables and run - ``` + ``` ./register_rln.sh ``` diff --git a/apps/wakunode2/wakunode2.nim b/apps/wakunode2/wakunode2.nim index 5e6cbb700..54ecb1c43 100644 --- a/apps/wakunode2/wakunode2.nim +++ b/apps/wakunode2/wakunode2.nim @@ -56,7 +56,7 @@ when isMainModule: error "Waku configuration failed", error = error quit(QuitFailure) - var waku = Waku.new(conf).valueOr: + var waku = (waitFor Waku.new(conf)).valueOr: error "Waku initialization failed", error = error quit(QuitFailure) diff --git a/docs/operators/how-to/run-with-rln.md b/docs/operators/how-to/run-with-rln.md index f56af0146..ef1a6c208 100644 --- a/docs/operators/how-to/run-with-rln.md +++ b/docs/operators/how-to/run-with-rln.md @@ -33,8 +33,8 @@ make wakunode2 Follow [Step 10](../droplet-quickstart.md#10-run-nwaku) of the [droplet quickstart](../droplet-quickstart.md) guide, while replacing the run command with - ```bash -export SEPOLIA_HTTP_NODE_ADDRESS= -export RLN_RELAY_CONTRACT_ADDRESS="0xF471d71E9b1455bBF4b85d475afb9BB0954A29c4" # Replace this with any compatible implementation +export LINEA_SEPOLIA_HTTP_NODE_ADDRESS= +export RLN_RELAY_CONTRACT_ADDRESS="0xB9cd878C90E49F797B4431fBF4fb333108CB90e6" # Replace this with any compatible implementation $WAKUNODE_DIR/wakunode2 \ --store:true \ --persist-messages \ @@ -44,7 +44,7 @@ $WAKUNODE_DIR/wakunode2 \ --rln-relay:true \ --rln-relay-dynamic:true \ --rln-relay-eth-contract-address:"$RLN_RELAY_CONTRACT_ADDRESS" \ ---rln-relay-eth-client-address:"$SEPOLIA_HTTP_NODE_ADDRESS" +--rln-relay-eth-client-address:"$LINEA_SEPOLIA_HTTP_NODE_ADDRESS" ``` OR @@ -53,9 +53,9 @@ If you are running the nwaku node within docker, follow [Step 2](../docker-quick ```bash export WAKU_FLEET= -export SEPOLIA_HTTP_NODE_ADDRESS= -export RLN_RELAY_CONTRACT_ADDRESS="0xF471d71E9b1455bBF4b85d475afb9BB0954A29c4" # Replace this with any compatible implementation -docker run -i -t -p 60000:60000 -p 9000:9000/udp wakuorg/nwaku:v0.20.0 \ +export LINEA_SEPOLIA_HTTP_NODE_ADDRESS= +export RLN_RELAY_CONTRACT_ADDRESS="0xB9cd878C90E49F797B4431fBF4fb333108CB90e6" # Replace this with any compatible implementation +docker run -i -t -p 60000:60000 -p 9000:9000/udp wakuorg/nwaku:v0.36.0 \ --dns-discovery:true \ --dns-discovery-url:"$WAKU_FLEET" \ --discv5-discovery \ @@ -63,7 +63,7 @@ docker run -i -t -p 60000:60000 -p 9000:9000/udp wakuorg/nwaku:v0.20.0 \ --rln-relay:true \ --rln-relay-dynamic:true \ --rln-relay-eth-contract-address:"$RLN_RELAY_CONTRACT_ADDRESS" \ - --rln-relay-eth-client-address:"$SEPOLIA_HTTP_NODE_ADDRESS" + --rln-relay-eth-client-address:"$LINEA_SEPOLIA_HTTP_NODE_ADDRESS" ``` > Note: You can choose to keep connections to other nodes alive by adding the `--keep-alive` flag. @@ -74,7 +74,7 @@ runtime arguments - 1. `--rln-relay`: Allows waku-rln-relay to be mounted into the setup of the nwaku node 2. `--rln-relay-dynamic`: Enables waku-rln-relay to connect to an ethereum node to fetch the membership group 3. `--rln-relay-eth-contract-address`: The contract address of an RLN membership group -4. `--rln-relay-eth-client-address`: The HTTP url to a Sepolia ethereum node +4. `--rln-relay-eth-client-address`: The HTTP url to a Linea Sepolia ethereum node You should now have nwaku running, with RLN enabled! diff --git a/docs/tutorial/onchain-rln-relay-chat2.md b/docs/tutorial/onchain-rln-relay-chat2.md index 6748fc516..ac2bdc307 100644 --- a/docs/tutorial/onchain-rln-relay-chat2.md +++ b/docs/tutorial/onchain-rln-relay-chat2.md @@ -1,7 +1,7 @@ # Spam-protected chat2 application with on-chain group management This document is a tutorial on how to run the chat2 application in the spam-protected mode using the Waku-RLN-Relay protocol and with dynamic/on-chain group management. -In the on-chain/dynamic group management, the state of the group members i.e., their identity commitment keys is moderated via a membership smart contract deployed on the Sepolia network which is one of the Ethereum test-nets. +In the on-chain/dynamic group management, the state of the group members i.e., their identity commitment keys is moderated via a membership smart contract deployed on the Linea Sepolia network which is one of the test-nets. Members can be dynamically added to the group and the group size can grow up to 2^20 members. This differs from the prior test scenarios in which the RLN group was static and the set of members' keys was hardcoded and fixed. @@ -45,7 +45,7 @@ Run the following command to set up your chat2 client. --content-topic:/toy-chat/3/mingde/proto \ --rln-relay:true \ --rln-relay-dynamic:true \ ---rln-relay-eth-contract-address:0xF471d71E9b1455bBF4b85d475afb9BB0954A29c4 \ +--rln-relay-eth-contract-address:0xB9cd878C90E49F797B4431fBF4fb333108CB90e6 \ --rln-relay-cred-path:xxx/xx/rlnKeystore.json \ --rln-relay-cred-password:xxxx \ --rln-relay-eth-client-address:xxxx \ @@ -58,11 +58,11 @@ In this command - the `rln-relay` flag is set to `true` to enable the Waku-RLN-Relay protocol for spam protection. - the `--rln-relay-dynamic` flag is set to `true` to enable the on-chain mode of Waku-RLN-Relay protocol with dynamic group management. - the `--rln-relay-eth-contract-address` option gets the address of the membership contract. - The current address of the contract is `0xF471d71E9b1455bBF4b85d475afb9BB0954A29c4`. - You may check the state of the contract on the [Sepolia testnet](https://sepolia.etherscan.io/address/0xF471d71E9b1455bBF4b85d475afb9BB0954A29c4). + The current address of the contract is `0xB9cd878C90E49F797B4431fBF4fb333108CB90e6`. + You may check the state of the contract on the [Linea Sepolia testnet](https://sepolia.lineascan.build/address/0xB9cd878C90E49F797B4431fBF4fb333108CB90e6). - the `--rln-relay-cred-path` option denotes the path to the keystore file described above - the `--rln-relay-cred-password` option denotes the password to the keystore -- the `rln-relay-eth-client-address` is the WebSocket address of the hosted node on the Sepolia testnet. +- the `rln-relay-eth-client-address` is the WebSocket address of the hosted node on the Linea Sepolia testnet. You need to replace the `xxxx` with the actual node's address. For `rln-relay-eth-client-address`, if you do not know how to obtain it, you may use the following tutorial on the [prerequisites of running on-chain spam-protected chat2](./pre-requisites-of-running-on-chain-spam-protected-chat2.md). @@ -166,7 +166,7 @@ You can check this fact by looking at `Bob`'s console, where `message3` is missi **Alice** ```bash -./build/chat2 --fleet:test --content-topic:/toy-chat/3/mingde/proto --rln-relay:true --rln-relay-dynamic:true --rln-relay-eth-contract-address:0xF471d71E9b1455bBF4b85d475afb9BB0954A29c4 --rln-relay-cred-path:rlnKeystore.json --rln-relay-cred-password:password --rln-relay-eth-client-address:https://sepolia.infura.io/v3/12345678901234567890123456789012 --ports-shift=1 +./build/chat2 --fleet:test --content-topic:/toy-chat/3/mingde/proto --rln-relay:true --rln-relay-dynamic:true --rln-relay-eth-contract-address:0xB9cd878C90E49F797B4431fBF4fb333108CB90e6 --rln-relay-cred-path:rlnKeystore.json --rln-relay-cred-password:password --rln-relay-eth-client-address:https://sepolia.infura.io/v3/12345678901234567890123456789012 --ports-shift=1 ``` ``` @@ -209,7 +209,7 @@ your rln identity commitment key is: bd093cbf14fb933d53f596c33f98b3df83b7e9f7a19 **Bob** ```bash -./build/chat2 --fleet:test --content-topic:/toy-chat/3/mingde/proto --rln-relay:true --rln-relay-dynamic:true --rln-relay-eth-contract-address:0xF471d71E9b1455bBF4b85d475afb9BB0954A29c4 --rln-relay-cred-path:rlnKeystore.json --rln-relay-cred-index:1 --rln-relay-cred-password:password --rln-relay-eth-client-address:https://sepolia.infura.io/v3/12345678901234567890123456789012 --ports-shift=2 +./build/chat2 --fleet:test --content-topic:/toy-chat/3/mingde/proto --rln-relay:true --rln-relay-dynamic:true --rln-relay-eth-contract-address:0xB9cd878C90E49F797B4431fBF4fb333108CB90e6 --rln-relay-cred-path:rlnKeystore.json --rln-relay-cred-index:1 --rln-relay-cred-password:password --rln-relay-eth-client-address:https://sepolia.infura.io/v3/12345678901234567890123456789012 --ports-shift=2 ``` ``` diff --git a/docs/tutorial/rln-keystore-generator.md b/docs/tutorial/rln-keystore-generator.md index a9643ffb5..4ce7008dc 100644 --- a/docs/tutorial/rln-keystore-generator.md +++ b/docs/tutorial/rln-keystore-generator.md @@ -21,9 +21,9 @@ It is meant to be used to generate and persist a set of valid RLN credentials to 2. Define the arguments you wish to use ```bash - export RPC_URL="https://sepolia.infura.io/v3/..." + export RPC_URL="https://linea-sepolia.infura.io/v3/..." export PRIVATE_KEY="0x..." - export RLN_CONTRACT_ADDRESS="0xF471d71E9b1455bBF4b85d475afb9BB0954A29c4" + export RLN_CONTRACT_ADDRESS="0xB9cd878C90E49F797B4431fBF4fb333108CB90e6" export RLN_CREDENTIAL_PATH="rlnKeystore.json" export RLN_CREDENTIAL_PASSWORD="xxx" ``` diff --git a/examples/filter_subscriber.nim b/examples/filter_subscriber.nim index 5554966d4..af40d21c3 100644 --- a/examples/filter_subscriber.nim +++ b/examples/filter_subscriber.nim @@ -77,7 +77,7 @@ proc setupAndSubscribe(rng: ref HmacDrbgContext) {.async.} = let node = builder.build().tryGet() node.mountMetadata(clusterId).expect("failed to mount waku metadata protocol") - waitFor node.mountFilterClient() + await node.mountFilterClient() await node.start() diff --git a/examples/wakustealthcommitments/node_spec.nim b/examples/wakustealthcommitments/node_spec.nim index c3468ccde..1af949314 100644 --- a/examples/wakustealthcommitments/node_spec.nim +++ b/examples/wakustealthcommitments/node_spec.nim @@ -46,7 +46,7 @@ proc setup*(): Waku = conf.rlnRelay = twnNetworkConf.rlnRelay debug "Starting node" - var waku = Waku.new(conf).valueOr: + var waku = (waitFor Waku.new(conf)).valueOr: error "Waku initialization failed", error = error quit(QuitFailure) diff --git a/library/waku_context.nim b/library/waku_context.nim index 2dd9e9c95..6716013c9 100644 --- a/library/waku_context.nim +++ b/library/waku_context.nim @@ -118,8 +118,12 @@ proc watchdogThreadBody(ctx: ptr WakuContext) {.thread.} = ## Watchdog thread that monitors the Waku thread and notifies the library user if it hangs. let watchdogRun = proc(ctx: ptr WakuContext) {.async.} = + const WatchdogStartDelay = 10.seconds const WatchdogTimeinterval = 1.seconds const WakuNotRespondingTimeout = 3.seconds + + # Give time for the node to be created and up before sending watchdog requests + await sleepAsync(WatchdogStartDelay) while true: await sleepAsync(WatchdogTimeinterval) @@ -166,13 +170,13 @@ proc wakuThreadBody(ctx: ptr WakuContext) {.thread.} = error "waku thread could not receive a request" continue + ## Handle the request + asyncSpawn WakuThreadRequest.process(request, addr waku) + let fireRes = ctx.reqReceivedSignal.fireSync() if fireRes.isErr(): error "could not fireSync back to requester thread", error = fireRes.error - ## Handle the request - asyncSpawn WakuThreadRequest.process(request, addr waku) - waitFor wakuRun(ctx) proc createWakuContext*(): Result[ptr WakuContext, string] = diff --git a/library/waku_thread_requests/requests/node_lifecycle_request.nim b/library/waku_thread_requests/requests/node_lifecycle_request.nim index 21765838e..6bc613406 100644 --- a/library/waku_thread_requests/requests/node_lifecycle_request.nim +++ b/library/waku_thread_requests/requests/node_lifecycle_request.nim @@ -79,7 +79,7 @@ proc createWaku( wakuConf.restServerConf = none(RestServerConf) ## don't want REST in libwaku - let wakuRes = Waku.new(wakuConf, appCallbacks).valueOr: + let wakuRes = (await Waku.new(wakuConf, appCallbacks)).valueOr: error "waku initialization failed", error = error return err("Failed setting up Waku: " & $error) diff --git a/tests/factory/test_node_factory.nim b/tests/factory/test_node_factory.nim index f3d11b1a2..08149db08 100644 --- a/tests/factory/test_node_factory.nim +++ b/tests/factory/test_node_factory.nim @@ -9,10 +9,10 @@ import waku/factory/conf_builder/conf_builder suite "Node Factory": - test "Set up a node based on default configurations": + asynctest "Set up a node based on default configurations": let conf = defaultTestWakuConf() - let node = setupNode(conf, relay = Relay.new()).valueOr: + let node = (await setupNode(conf, relay = Relay.new())).valueOr: raiseAssert error check: @@ -23,13 +23,13 @@ suite "Node Factory": not node.wakuStoreClient.isNil() not node.wakuRendezvous.isNil() - test "Set up a node with Store enabled": + asynctest "Set up a node with Store enabled": var confBuilder = defaultTestWakuConfBuilder() confBuilder.storeServiceConf.withEnabled(true) confBuilder.storeServiceConf.withDbUrl("sqlite://store.sqlite3") let conf = confBuilder.build().value - let node = setupNode(conf, relay = Relay.new()).valueOr: + let node = (await setupNode(conf, relay = Relay.new())).valueOr: raiseAssert error check: @@ -37,28 +37,28 @@ suite "Node Factory": not node.wakuStore.isNil() not node.wakuArchive.isNil() -test "Set up a node with Filter enabled": +asynctest "Set up a node with Filter enabled": var confBuilder = defaultTestWakuConfBuilder() confBuilder.filterServiceConf.withEnabled(true) let conf = confBuilder.build().value - let node = setupNode(conf, relay = Relay.new()).valueOr: + let node = (await setupNode(conf, relay = Relay.new())).valueOr: raiseAssert error check: not node.isNil() not node.wakuFilter.isNil() -test "Start a node based on default configurations": +asynctest "Start a node based on default configurations": let conf = defaultTestWakuConf() - let node = setupNode(conf, relay = Relay.new()).valueOr: + let node = (await setupNode(conf, relay = Relay.new())).valueOr: raiseAssert error assert not node.isNil(), "Node can't be nil" let startRes = catch: - (waitFor startNode(node, conf)) + (await startNode(node, conf)) assert not startRes.isErr(), "Exception starting node" assert startRes.get().isOk(), "Error starting node " & startRes.get().error @@ -67,4 +67,4 @@ test "Start a node based on default configurations": node.started == true ## Cleanup - waitFor node.stop() + await node.stop() diff --git a/tests/waku_discv5/test_waku_discv5.nim b/tests/waku_discv5/test_waku_discv5.nim index 79913ce92..734ea4bf9 100644 --- a/tests/waku_discv5/test_waku_discv5.nim +++ b/tests/waku_discv5/test_waku_discv5.nim @@ -429,7 +429,7 @@ suite "Waku Discovery v5": let conf = confBuilder.build().valueOr: raiseAssert error - let waku0 = Waku.new(conf).valueOr: + let waku0 = (await Waku.new(conf)).valueOr: raiseAssert error (waitFor startWaku(addr waku0)).isOkOr: raiseAssert error @@ -444,7 +444,7 @@ suite "Waku Discovery v5": let conf1 = confBuilder.build().valueOr: raiseAssert error - let waku1 = Waku.new(conf1).valueOr: + let waku1 = (await Waku.new(conf1)).valueOr: raiseAssert error (waitFor startWaku(addr waku1)).isOkOr: raiseAssert error @@ -461,7 +461,7 @@ suite "Waku Discovery v5": let conf2 = confBuilder.build().valueOr: raiseAssert error - let waku2 = Waku.new(conf2).valueOr: + let waku2 = (await Waku.new(conf2)).valueOr: raiseAssert error (waitFor startWaku(addr waku2)).isOkOr: raiseAssert error @@ -492,7 +492,7 @@ suite "Waku Discovery v5": let conf = confBuilder.build().valueOr: raiseAssert error - let waku = Waku.new(conf).valueOr: + let waku = (await Waku.new(conf)).valueOr: raiseAssert error discard setupDiscoveryV5( @@ -523,7 +523,7 @@ suite "Waku Discovery v5": let conf = confBuilder.build().valueOr: raiseAssert error - let waku = Waku.new(conf).valueOr: + let waku = (await Waku.new(conf)).valueOr: raiseAssert error discard setupDiscoveryV5( diff --git a/tests/wakunode2/test_app.nim b/tests/wakunode2/test_app.nim index 2d62d4956..b16880787 100644 --- a/tests/wakunode2/test_app.nim +++ b/tests/wakunode2/test_app.nim @@ -17,7 +17,7 @@ suite "Wakunode2 - Waku": ## Given let conf = defaultTestWakuConf() - let waku = Waku.new(conf).valueOr: + let waku = (waitFor Waku.new(conf)).valueOr: raiseAssert error ## When @@ -33,7 +33,7 @@ suite "Wakunode2 - Waku initialization": var conf = defaultTestWakuConf() conf.peerPersistence = true - let waku = Waku.new(conf).valueOr: + let waku = (waitFor Waku.new(conf)).valueOr: raiseAssert error check: @@ -44,7 +44,7 @@ suite "Wakunode2 - Waku initialization": var conf = defaultTestWakuConf() ## When - var waku = Waku.new(conf).valueOr: + var waku = (waitFor Waku.new(conf)).valueOr: raiseAssert error (waitFor startWaku(addr waku)).isOkOr: @@ -68,7 +68,7 @@ suite "Wakunode2 - Waku initialization": conf.endpointConf.p2pTcpPort = Port(0) ## When - var waku = Waku.new(conf).valueOr: + var waku = (waitFor Waku.new(conf)).valueOr: raiseAssert error (waitFor startWaku(addr waku)).isOkOr: diff --git a/waku/factory/internal_config.nim b/waku/factory/internal_config.nim index 9fc3602a0..60b319e0d 100644 --- a/waku/factory/internal_config.nim +++ b/waku/factory/internal_config.nim @@ -65,7 +65,7 @@ proc networkConfiguration*( dnsAddrsNameServers: seq[IpAddress], portsShift: uint16, clientId: string, -): NetConfigResult = +): Future[NetConfigResult] {.async.} = ## `udpPort` is only supplied to satisfy underlying APIs but is not ## actually a supported transport for libp2p traffic. let natRes = setupNat( @@ -99,7 +99,7 @@ proc networkConfiguration*( # Resolve and use DNS domain IP if conf.dns4DomainName.isSome() and extIp.isNone(): try: - let dnsRes = waitFor dnsResolve(conf.dns4DomainName.get(), dnsAddrsNameServers) + let dnsRes = await dnsResolve(conf.dns4DomainName.get(), dnsAddrsNameServers) if dnsRes.isErr(): return err($dnsRes.error) # Pass error down the stack diff --git a/waku/factory/node_factory.nim b/waku/factory/node_factory.nim index 063ffc22f..eda385cc7 100644 --- a/waku/factory/node_factory.nim +++ b/waku/factory/node_factory.nim @@ -180,7 +180,7 @@ proc setupProtocols( if conf.storeServiceConf.isSome(): let storeServiceConf = conf.storeServiceConf.get() if storeServiceConf.supportV2: - let archiveDriverRes = waitFor legacy_driver.ArchiveDriver.new( + let archiveDriverRes = await legacy_driver.ArchiveDriver.new( storeServiceConf.dbUrl, storeServiceConf.dbVacuum, storeServiceConf.dbMigration, storeServiceConf.maxNumDbConnections, onFatalErrorAction, ) @@ -214,7 +214,7 @@ proc setupProtocols( else: storeServiceConf.dbMigration - let archiveDriverRes = waitFor driver.ArchiveDriver.new( + let archiveDriverRes = await driver.ArchiveDriver.new( storeServiceConf.dbUrl, storeServiceConf.dbVacuum, migrate, storeServiceConf.maxNumDbConnections, onFatalErrorAction, ) @@ -368,7 +368,7 @@ proc setupProtocols( ) try: - waitFor node.mountRlnRelay(rlnConf) + await node.mountRlnRelay(rlnConf) except CatchableError: return err("failed to mount waku RLN relay protocol: " & getCurrentExceptionMsg()) @@ -511,11 +511,13 @@ proc startNode*( proc setupNode*( wakuConf: WakuConf, rng: ref HmacDrbgContext = crypto.newRng(), relay: Relay -): Result[WakuNode, string] = - let netConfig = networkConfiguration( - wakuConf.clusterId, wakuConf.endpointConf, wakuConf.discv5Conf, - wakuConf.webSocketConf, wakuConf.wakuFlags, wakuConf.dnsAddrsNameServers, - wakuConf.portsShift, clientId, +): Future[Result[WakuNode, string]] {.async.} = + let netConfig = ( + await networkConfiguration( + wakuConf.clusterId, wakuConf.endpointConf, wakuConf.discv5Conf, + wakuConf.webSocketConf, wakuConf.wakuFlags, wakuConf.dnsAddrsNameServers, + wakuConf.portsShift, clientId, + ) ).valueOr: error "failed to create internal config", error = error return err("failed to create internal config: " & error) @@ -546,7 +548,7 @@ proc setupNode*( debug "Mounting protocols" try: - (waitFor node.setupProtocols(wakuConf)).isOkOr: + (await node.setupProtocols(wakuConf)).isOkOr: error "Mounting protocols failed", error = error return err("Mounting protocols failed: " & error) except CatchableError: diff --git a/waku/factory/waku.nim b/waku/factory/waku.nim index 137e3531c..27c9437ff 100644 --- a/waku/factory/waku.nim +++ b/waku/factory/waku.nim @@ -162,7 +162,7 @@ proc setupAppCallbacks( proc new*( T: type Waku, wakuConf: WakuConf, appCallbacks: AppCallbacks = nil -): Result[Waku, string] = +): Future[Result[Waku, string]] {.async.} = let rng = crypto.newRng() logging.setupLog(wakuConf.logLevel, wakuConf.logFormat) @@ -186,7 +186,7 @@ proc new*( var relay = newCircuitRelay(wakuConf.circuitRelayClient) - let node = setupNode(wakuConf, rng, relay).valueOr: + let node = (await setupNode(wakuConf, rng, relay)).valueOr: error "Failed setting up node", error = $error return err("Failed setting up node: " & $error) @@ -248,7 +248,7 @@ proc getPorts( return ok((tcpPort: tcpPort, websocketPort: websocketPort)) -proc getRunningNetConfig(waku: ptr Waku): Result[NetConfig, string] = +proc getRunningNetConfig(waku: ptr Waku): Future[Result[NetConfig, string]] {.async.} = var conf = waku[].conf let (tcpPort, websocketPort) = getPorts(waku[].node.switch.peerInfo.listenAddrs).valueOr: return err("Could not retrieve ports: " & error) @@ -260,16 +260,18 @@ proc getRunningNetConfig(waku: ptr Waku): Result[NetConfig, string] = conf.webSocketConf.get().port = websocketPort.get() # Rebuild NetConfig with bound port values - let netConf = networkConfiguration( - conf.clusterId, conf.endpointConf, conf.discv5Conf, conf.webSocketConf, - conf.wakuFlags, conf.dnsAddrsNameServers, conf.portsShift, clientId, + let netConf = ( + await networkConfiguration( + conf.clusterId, conf.endpointConf, conf.discv5Conf, conf.webSocketConf, + conf.wakuFlags, conf.dnsAddrsNameServers, conf.portsShift, clientId, + ) ).valueOr: return err("Could not update NetConfig: " & error) return ok(netConf) -proc updateEnr(waku: ptr Waku): Result[void, string] = - let netConf: NetConfig = getRunningNetConfig(waku).valueOr: +proc updateEnr(waku: ptr Waku): Future[Result[void, string]] {.async.} = + let netConf: NetConfig = (await getRunningNetConfig(waku)).valueOr: return err("error calling updateNetConfig: " & $error) let record = enrConfiguration(waku[].conf, netConf).valueOr: return err("ENR setup failed: " & error) @@ -309,11 +311,11 @@ proc updateAddressInENR(waku: ptr Waku): Result[void, string] = return ok() -proc updateWaku(waku: ptr Waku): Result[void, string] = +proc updateWaku(waku: ptr Waku): Future[Result[void, string]] {.async.} = let conf = waku[].conf if conf.endpointConf.p2pTcpPort == Port(0) or (conf.websocketConf.isSome() and conf.websocketConf.get.port == Port(0)): - updateEnr(waku).isOkOr: + (await updateEnr(waku)).isOkOr: return err("error calling updateEnr: " & $error) ?updateAnnouncedAddrWithPrimaryIpAddr(waku[].node) @@ -381,7 +383,7 @@ proc startWaku*(waku: ptr Waku): Future[Result[void, string]] {.async.} = return err("error while calling startNode: " & $error) ## Update waku data that is set dynamically on node start - updateWaku(waku).isOkOr: + (await updateWaku(waku)).isOkOr: return err("Error in updateApp: " & $error) ## Discv5 @@ -424,8 +426,12 @@ proc startWaku*(waku: ptr Waku): Future[Result[void, string]] {.async.} = return err ("Starting protocols support REST server failed: " & $error) if conf.metricsServerConf.isSome(): - waku[].metricsServer = waku_metrics.startMetricsServerAndLogging( - conf.metricsServerConf.get(), conf.portsShift + waku[].metricsServer = ( + await ( + waku_metrics.startMetricsServerAndLogging( + conf.metricsServerConf.get(), conf.portsShift + ) + ) ).valueOr: return err("Starting monitoring and external interfaces failed: " & error) diff --git a/waku/node/waku_metrics.nim b/waku/node/waku_metrics.nim index ba61f6ef8..8d38624c1 100644 --- a/waku/node/waku_metrics.nim +++ b/waku/node/waku_metrics.nim @@ -59,14 +59,14 @@ proc startMetricsLog*() = proc startMetricsServer( serverIp: IpAddress, serverPort: Port -): Result[MetricsHttpServerRef, string] = +): Future[Result[MetricsHttpServerRef, string]] {.async.} = info "Starting metrics HTTP server", serverIp = $serverIp, serverPort = $serverPort let server = MetricsHttpServerRef.new($serverIp, serverPort).valueOr: return err("metrics HTTP server start failed: " & $error) try: - waitFor server.start() + await server.start() except CatchableError: return err("metrics HTTP server start failed: " & getCurrentExceptionMsg()) @@ -75,10 +75,12 @@ proc startMetricsServer( proc startMetricsServerAndLogging*( conf: MetricsServerConf, portsShift: uint16 -): Result[MetricsHttpServerRef, string] = +): Future[Result[MetricsHttpServerRef, string]] {.async.} = var metricsServer: MetricsHttpServerRef - metricsServer = startMetricsServer( - conf.httpAddress, Port(conf.httpPort.uint16 + portsShift) + metricsServer = ( + await ( + startMetricsServer(conf.httpAddress, Port(conf.httpPort.uint16 + portsShift)) + ) ).valueOr: return err("Starting metrics server failed. Continuing in current state:" & $error) diff --git a/waku/node/waku_node.nim b/waku/node/waku_node.nim index 59d128171..9d2d4c95c 100644 --- a/waku/node/waku_node.nim +++ b/waku/node/waku_node.nim @@ -1248,7 +1248,7 @@ proc mountRlnRelay*( CatchableError, "WakuRelay protocol is not mounted, cannot mount WakuRlnRelay" ) - let rlnRelayRes = waitFor WakuRlnRelay.new(rlnConf, registrationHandler) + let rlnRelayRes = await WakuRlnRelay.new(rlnConf, registrationHandler) if rlnRelayRes.isErr(): raise newException(CatchableError, "failed to mount WakuRlnRelay: " & rlnRelayRes.error)