Skip to content

Commit

Permalink
Added phase 2 - waku-simulatior integration in README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
NagyZoltanPeter committed Aug 2, 2024
1 parent 6485550 commit 78ed6a7
Show file tree
Hide file tree
Showing 12 changed files with 557 additions and 46 deletions.
12 changes: 12 additions & 0 deletions apps/liteprotocoltester/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
NWAKU_IMAGE=quay.io/wakuorg/nwaku-pr:2800-rln-v2

START_PUBLISHING_AFTER=30 # seconds
NUM_MESSAGES=250
DELAY_MESSAGES=200 # gap between messages

MIN_MESSAGE_SIZE=1Kb
MAX_MESSAGE_SIZE=120Kb

# PUBSUB=/waku/2/rs/66/0
# CONTENT_TOPIC=/tester/1/light-pubsub-example/proto

63 changes: 63 additions & 0 deletions apps/liteprotocoltester/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ At this stage we can only configure number of messages and fixed frequency of th

### Phase 1

> NOTICE: This part is obsolate due integration with waku-simulator.
> It needs some rework to make it work again standalone.
Lite Protocol Tester application is built under name `liteprotocoltester` in apps/liteprotocoltester folder.

Starting from nwaku repository root:
Expand All @@ -48,6 +51,51 @@ docker compose up -d
docker compose logs -f receivernode
```

### Phase 2

> Integration with waku-simulator!
- For convenient integration is done in cooperation with waku-simulator repository, but nothing is tightly coupled.
- waku-simulator must be started separately with its own configuration.
- To enable waku-simulator working without RLN currently a separate branch is to be used.
- When waku-simulator is configured and up and running, lite-protocol-tester composite docker setup can be started.

```bash

# Start waku-simulator

git clone https://github.com/waku-org/waku-simulator.git ../waku-simulator
cd ../waku-simulator
git checkout chore-integrate-liteprotocoltester

# optionally edit .env file

docker compose -f docker-compose-norln.yml up -d

# navigate localhost:30001 to see the waku-simulator dashboard

cd ../{your-repository}

make LOG_LEVEL=DEBUG liteprotocoltester

cd apps/liteprotocoltester

# optionally edit .env file

docker compose -f docker-compose-on-simularor.yml build
docker compose -f docker-compose-on-simularor.yml up -d
docker compose -f docker-compose-on-simularor.yml logs -f receivernode
```
#### Current setup

- waku-simulator is configured to run with 25 full node
- liteprotocoltester is configured to run with 3 publisher and 1 receiver
- liteprotocoltester is configured to run 1 lightpush service and a filter service node
- light clients are connected accordingly
- publishers will send 250 messages in every 200ms with size between 1KiB and 120KiB
- Notice there is a configurable wait before start publishing messages as it is noticed time is needed for the service nodes to get connected to full nodes from simulator
- light clients will print report on their and the connected service node's connectivity to the network in every 20 secs.

## Configure

### Environment variables for docker compose runs
Expand All @@ -56,8 +104,16 @@ docker compose logs -f receivernode
| ---: | :--- | :--- |
| NUM_MESSAGES | Number of message to publish | 120 |
| DELAY_MESSAGES | Frequency of messages in milliseconds | 1000 |
<<<<<<< HEAD
| PUBSUB | Used pubsub_topic for testing | /waku/2/rs/0/0 |
=======
| PUBSUB | Used pubsub_topic for testing | /waku/2/rs/66/0 |
>>>>>>> 32cc23ff (Added phase 2 - waku-simulatior integration in README.md)
| CONTENT_TOPIC | content_topic for testing | /tester/1/light-pubsub-example/proto |
| START_PUBLISHING_AFTER | Delay in seconds before starting to publish to let service node connected | 5 |
| MIN_MESSAGE_SIZE | Minimum message size in bytes | 1KiB |
| MAX_MESSAGE_SIZE | Maximum message size in bytes | 120KiB |


### Lite Protocol Tester application cli options

Expand All @@ -67,7 +123,14 @@ docker compose logs -f receivernode
| --service-node| Address of the service node to use for lightpush and/or filter service | - |
| --num-messages | Number of message to publish | 120 |
| --delay-messages | Frequency of messages in milliseconds | 1000 |
<<<<<<< HEAD
| --pubsub-topic | Used pubsub_topic for testing | /waku/2/rs/0/0 |
=======
| --min-message-size | Minimum message size in bytes | 1KiB |
| --max-message-size | Maximum message size in bytes | 120KiB |
| --start-publishing-after | Delay in seconds before starting to publish to let service node connected in seconds | 5 |
| --pubsub-topic | Used pubsub_topic for testing | /waku/2/default-waku/proto |
>>>>>>> 32cc23ff (Added phase 2 - waku-simulatior integration in README.md)
| --content_topic | content_topic for testing | /tester/1/light-pubsub-example/proto |
| --cluster-id | Cluster id for the test | 0 |
| --config-file | TOML configuration file to fine tune the light waku node<br>Note that some configurations (full node services) are not taken into account | - |
Expand Down
96 changes: 96 additions & 0 deletions apps/liteprotocoltester/diagnose_connections.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
when (NimMajor, NimMinor) < (1, 4):
{.push raises: [Defect].}
else:
{.push raises: [].}

import
std/[options, strutils, os, sequtils, net, strformat],
chronicles,
chronos,
metrics,
libbacktrace,
system/ansi_c,
libp2p/crypto/crypto,
confutils,
libp2p/wire

import
../../waku/common/logging,
../../waku/factory/waku,
../../waku/factory/external_config,
../../waku/node/health_monitor,
../../waku/node/waku_metrics,
../../waku/waku_api/rest/builder as rest_server_builder,
../../waku/node/peer_manager,
../../waku/waku_lightpush/common,
../../waku/waku_relay,
../../waku/waku_filter_v2,
../../waku/waku_api/rest/client,
../../waku/waku_api/rest/admin/client,
./tester_config,
./lightpush_publisher,
./filter_subscriber

logScope:
topics = "diagnose connections"

proc logSelfPeersLoop(pm: PeerManager, interval: Duration) {.async.} =
trace "Starting logSelfPeersLoop diagnosys loop"
while true:
let selfLighpushPeers = pm.peerStore.getPeersByProtocol(WakuLightPushCodec)
let selfRelayPeers = pm.peerStore.getPeersByProtocol(WakuRelayCodec)
let selfFilterPeers = pm.peerStore.getPeersByProtocol(WakuFilterSubscribeCodec)

let printable = catch:
"""*------------------------------------------------------------------------------------------*
| Self ({pm.switch.peerInfo}) peers:
*------------------------------------------------------------------------------------------*
| Lightpush peers({selfLighpushPeers.len()}): ${selfLighpushPeers}
*------------------------------------------------------------------------------------------*
| Filter peers({selfFilterPeers.len()}): ${selfFilterPeers}
*------------------------------------------------------------------------------------------*
| Relay peers({selfRelayPeers.len()}): ${selfRelayPeers}
*------------------------------------------------------------------------------------------*""".fmt()

if printable.isErr():
echo "Error while printing statistics: " & printable.error().msg
else:
echo printable.get()

await sleepAsync(interval)

proc logServiceRelayPeers(
pm: PeerManager, codec: string, interval: Duration
) {.async.} =
trace "Starting service node connectivity diagnosys loop"
while true:
echo "*------------------------------------------------------------------------------------------*"
echo "| Service peer connectivity:"
let selfLighpushPeers = pm.selectPeer(codec)
if selfLighpushPeers.isSome():
let ma = selfLighpushPeers.get().addrs[0]
var serviceIp = initTAddress(ma).valueOr:
echo "Error while parsing multiaddress: " & $error
continue

serviceIp.port = Port(8645)
let restClient = newRestHttpClient(initTAddress($serviceIp))

let getPeersRes = await restClient.getPeers()

if getPeersRes.status == 200:
let nrOfPeers = getPeersRes.data.len()
echo "Service node (@" & $ma & ") peers: " & $getPeersRes.data
else:
echo "Error while fetching service node (@" & $ma & ") peers: " &
$getPeersRes.data
else:
echo "No service node peers found"

echo "*------------------------------------------------------------------------------------------*"

await sleepAsync(interval)

proc startPeriodicPeerDiagnostic*(pm: PeerManager, codec: string) {.async.} =
asyncSpawn logSelfPeersLoop(pm, chronos.seconds(20))
asyncSpawn logServiceRelayPeers(pm, codec, chronos.seconds(20))
Loading

0 comments on commit 78ed6a7

Please sign in to comment.