diff --git a/deploy_rln_contract.sh b/deploy_rln_contract.sh old mode 100644 new mode 100755 diff --git a/docker-compose.yml b/docker-compose.yml index d15b013..3743c0e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -46,7 +46,7 @@ services: command: - '/opt/deploy_rln_contract.sh' volumes: - - ./deploy_rln_contract.sh:/opt/deploy_rln_contract.sh + - ./deploy_rln_contract.sh:/opt/deploy_rln_contract.sh:Z depends_on: - foundry networks: @@ -100,7 +100,7 @@ services: rest-traffic: image: alrevuelta/rest-traffic:6992bb5 command: - --multiple-nodes=http://waku-simulator_nwaku_[1..${NUM_NWAKU_NODES:-5}]:8645 + --multiple-nodes=http://waku-simulator_nwaku_[1..${TRAFFIC_NUM_NWAKU_NODES:-5}]:8645 --msg-size-kbytes=${MSG_SIZE_KBYTES:-10} --delay-seconds=${TRAFFIC_DELAY_SECONDS:-15} networks: @@ -154,6 +154,7 @@ services: - /var/run:/var/run:rw - /sys:/sys:ro - /var/lib/docker/:/var/lib/docker:ro + - /dev:/dev depends_on: - redis networks: @@ -234,4 +235,5 @@ services: - simulation volumes: - privatekeys-volume: \ No newline at end of file + privatekeys-volume: + diff --git a/inject_spam.sh b/inject_spam.sh new file mode 100755 index 0000000..4c90910 --- /dev/null +++ b/inject_spam.sh @@ -0,0 +1,77 @@ +#!/bin/bash + +# Function to print the usage of the script +usage() { + echo "Usage: $0 --static-node <> --delay-milliseconds <>" + exit 1 +} + +# Default values +DEFAULT_DELAY_MILLISECONDS=200 + +# Initialize variables +DELAY_MILLISECONDS=$DEFAULT_DELAY_MILLISECONDS +STATIC_NODE="" + +# Parse named parameters +while [[ "$#" -gt 0 ]]; do + case $1 in + --delay-milliseconds) + DELAY_MILLISECONDS="$2" + shift 2 + ;; + --static-node) + STATIC_NODE="$2" + shift 2 + ;; + *) + echo "Unknown parameter passed: $1" + usage + ;; + esac +done + +# Validate required parameters +if [[ -z "$STATIC_NODE" ]]; then + echo "Error: --static-node is required." + usage +fi + +# Validate delay-seconds is an integer +if ! [[ "$DELAY_MILLISECONDS" =~ ^[0-9]+$ ]]; then + echo "Error: --delay-milliseconds must be an integer." + exit 1 +fi + +# Check if default values are used and warn +if [[ "$DELAY_MILLISECONDS" -eq $DEFAULT_DELAY_MILLISECONDS ]]; then + echo "Warning: Using default value for --delay-milliseconds: $DEFAULT_DELAY_MILLISECONDS" +fi + +# Output the parameters as a summary +echo "=====================================" +echo " Summary of Parameters " +echo "=====================================" +echo "- Delay: ${DELAY_MILLISECONDS}ms" +echo "- Static Node: ${STATIC_NODE}" +echo "=====================================" + +# Run the command +docker run -it --network waku-simulator_simulation quay.io/wakuorg/nwaku-pr:2821 \ + --relay=true \ + --rln-relay=true \ + --rln-relay-dynamic=true \ + --rln-relay-eth-client-address=http://foundry:8545 \ + --rln-relay-eth-contract-address=0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9 \ + --rln-relay-epoch-sec=1 \ + --rln-relay-user-message-limit=1 \ + --log-level=DEBUG \ + --staticnode=${STATIC_NODE} \ + --pubsub-topic=/waku/2/rs/66/0 \ + --cluster-id=66 \ + --rln-relay-eth-private-key=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 \ + --rln-relay-cred-path=/keystore.json \ + --rln-relay-cred-password=password123 \ + --spammer=true \ + --spammer-delay-between-msg=${DELAY_MILLISECONDS} + diff --git a/inject_traffic.sh b/inject_traffic.sh new file mode 100755 index 0000000..e5e8c17 --- /dev/null +++ b/inject_traffic.sh @@ -0,0 +1,94 @@ +#!/bin/bash + +# Function to print the usage of the script +usage() { + echo "Usage: $0 --delay-seconds --msg-size-kbytes --pubsub-topic --nodes " + exit 1 +} + +# Default values +DEFAULT_MSG_SIZE=10 +DEFAULT_PUBSUB_TOPIC="/waku/2/rs/66/0" + +# Initialize variables +DELAY_SECONDS="" +MSG_SIZE_KBYTES=$DEFAULT_MSG_SIZE +PUBSUB_TOPIC=$DEFAULT_PUBSUB_TOPIC +NODES="" + +# Parse named parameters +while [[ "$#" -gt 0 ]]; do + case $1 in + --delay-seconds) + DELAY_SECONDS="$2" + shift 2 + ;; + --msg-size-kbytes) + MSG_SIZE_KBYTES="$2" + shift 2 + ;; + --pubsub-topic) + PUBSUB_TOPIC="$2" + shift 2 + ;; + --nodes) + NODES="$2" + shift 2 + ;; + *) + echo "Unknown parameter passed: $1" + usage + ;; + esac +done + +# Validate required parameters +if [[ -z "$DELAY_SECONDS" || -z "$NODES" ]]; then + echo "Error: --delay-seconds and --nodes are required." + usage +fi + +# Validate delay-seconds is an integer +if ! [[ "$DELAY_SECONDS" =~ ^[0-9]+$ ]]; then + echo "Error: --delay-seconds must be an integer." + exit 1 +fi + +# Validate msg-size-kbytes is an integer +if ! [[ "$MSG_SIZE_KBYTES" =~ ^[0-9]+$ ]]; then + echo "Error: --msg-size-kbytes must be an integer." + exit 1 +fi + +# Validate nodes format +if ! [[ "$NODES" =~ ^[0-9]+\.\.[0-9]+$ ]]; then + echo "Error: --nodes must be a range of integers." + exit 1 +fi + +# Check if default values are used and warn +if [[ "$MSG_SIZE_KBYTES" -eq $DEFAULT_MSG_SIZE ]]; then + echo "Warning: Using default value for --msg-size-kbytes: $DEFAULT_MSG_SIZE" +fi + +if [[ "$PUBSUB_TOPIC" == "$DEFAULT_PUBSUB_TOPIC" ]]; then + echo "Warning: Using default value for --pubsub-topic: $DEFAULT_PUBSUB_TOPIC" +fi + +# Output the parameters as a summary +echo "=====================================" +echo " Summary of Parameters " +echo "=====================================" +echo "- Delay: ${DELAY_SECONDS}s" +echo "- Msg Size: ${MSG_SIZE_KBYTES}KB" +echo "- Pubsub Topic: ${PUBSUB_TOPIC}" +echo "- Nodes: ${NODES}" +echo "=====================================" + +# Run the command +docker run -it --network waku-simulator_simulation alrevuelta/rest-traffic:d936446 \ +--delay-seconds=$DELAY_SECONDS \ +--msg-size-kbytes=$MSG_SIZE_KBYTES \ +--pubsub-topic=$PUBSUB_TOPIC \ +--multiple-nodes="http://waku-simulator_nwaku_[$NODES]:8645" + diff --git a/run_compose.sh b/run_compose.sh new file mode 100755 index 0000000..f7e8c53 --- /dev/null +++ b/run_compose.sh @@ -0,0 +1,214 @@ +#!/bin/bash + +# Function to print the usage of the script +usage() { + echo "Usage: $0 --nwaku-image --num-nwaku-nodes --traffic-delay-seconds --message-size-kbytes --private-key --eth-from --rln-relay-epoch-seconds --rln-relay-messages-limit " + exit 1 +} + +# Default values +DEFAULT_NWAKU_IMAGE="harbor.status.im/wakuorg/nwaku:v0.30.0-rc.0" +DEFAULT_NUM_NWAKU_NODES=5 +DEFAULT_TRAFFIC_NUM_NWAKU_NODES=$DEFAULT_NUM_NWAKU_NODES +DEFAULT_SPAM_NUM_NWAKU_NODES=0 +DEFAULT_TRAFFIC_DELAY_SECONDS=60 +DEFAULT_MSG_SIZE_KBYTES=10 +DEFAULT_PRIVATE_KEY="0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" +DEFAULT_ETH_FROM="0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266" +DEFAULT_RLN_RELAY_EPOCH_SEC=60 +DEFAULT_RLN_RELAY_MSG_LIMIT=1 + +# Initialize variables +NWAKU_IMAGE=$DEFAULT_NWAKU_IMAGE +NUM_NWAKU_NODES=$DEFAULT_NUM_NWAKU_NODES +SPAM_NUM_NWAKU_NODES=$DEFAULT_SPAM_NUM_NWAKU_NODES +TRAFFIC_NUM_NWAKU_NODES=$DEFAULT_TRAFFIC_NUM_NWAKU_NODES +TRAFFIC_DELAY_SECONDS=$DEFAULT_TRAFFIC_DELAY_SECONDS +MSG_SIZE_KBYTES=$DEFAULT_MSG_SIZE_KBYTES +PRIVATE_KEY=$DEFAULT_PRIVATE_KEY +ETH_FROM=$DEFAULT_ETH_FROM +RLN_RELAY_EPOCH_SEC=$DEFAULT_RLN_RELAY_EPOCH_SEC +RLN_RELAY_MSG_LIMIT=$DEFAULT_RLN_RELAY_MSG_LIMIT + +# Parse named parameters +while [[ "$#" -gt 0 ]]; do + case $1 in + --nwaku-image) + NWAKU_IMAGE="$2" + shift 2 + ;; + --num-nwaku-nodes) + NUM_NWAKU_NODES="$2" + shift 2 + ;; + --traffic-num-nwaku-nodes) + TRAFFIC_NUM_NWAKU_NODES="$2" + shift 2 + ;; + --spam-num-nwaku-nodes) + SPAM_NUM_NWAKU_NODES="$2" + shift 2 + ;; + --traffic-delay-seconds) + TRAFFIC_DELAY_SECONDS="$2" + shift 2 + ;; + --message-size-kbytes) + MSG_SIZE_KBYTES="$2" + shift 2 + ;; + --private-key) + PRIVATE_KEY="$2" + shift 2 + ;; + --eth-from) + ETH_FROM="$2" + shift 2 + ;; + --rln-relay-epoch-seconds) + RLN_RELAY_EPOCH_SEC="$2" + shift 2 + ;; + --rln-relay-messages-limit) + RLN_RELAY_MSG_LIMIT="$2" + shift 2 + ;; + *) + echo "Unknown parameter passed: $1" + usage + ;; + esac +done + +# Validate num-nwaku-nodes is an integer +if ! [[ "$NUM_NWAKU_NODES" =~ ^[0-9]+$ ]]; then + echo "Error: --num-nwaku-nodes must be an integer." + exit 1 +fi + +# Validate traffic-num-nwaku-nodes is an integer +if ! [[ "$TRAFFIC_NUM_NWAKU_NODES" =~ ^[0-9]+$ ]]; then + echo "Error: --num-nwaku-nodes must be an integer." + exit 1 +fi + +# Validate traffic-num-nwaku-nodes is less or equal than num-nwaku-nodes +if ! [[ "$TRAFFIC_NUM_NWAKU_NODES" -le "$NUM_NWAKU_NODES" ]]; then + echo "Error: --traffic-num-nwaku-nodes must be less or equal than --num-nwaku-nodes." + exit 1 +fi + +# Validate spam-num-nwaku-nodes is an integer +if ! [[ "$SPAM_NUM_NWAKU_NODES" =~ ^[0-9]+$ ]]; then + echo "Error: --spam-num-nwaku-nodes must be an integer." + exit 1 +fi + +# Validate spam-num-nwaku-nodoes is less or equal than num-nwaku-nodes +if ! [[ "$SPAM_NUM_NWAKU_NODES" -le "$NUM_NWAKU_NODES" ]]; then + echo "Error: --spam-num-nwaku-nodes must be less or equal than --num-nwaku-nodes." + exit 1 +fi + +# Validate traffic-delay-seconds is an integer +if ! [[ "$TRAFFIC_DELAY_SECONDS" =~ ^[0-9]+$ ]]; then + echo "Error: --traffic-delay-seconds must be an integer." + exit 1 +fi + +# Validate msg-size-kbytes +if ! [[ "$MSG_SIZE_KBYTES" =~ ^[0-9]+$ ]]; then + echo "Error: --msg-size-kbytes must be an integer." + exit 1 +fi + +# Validate rln-relay-epoch-seconds +if ! [[ "$RLN_RELAY_EPOCH_SEC" =~ ^[0-9]+$ ]]; then + echo "Error: --rln-relay-epoch-seconds must be an integer." + exit 1 +fi + +# Validate rln-relay-messages-limit +if ! [[ "$RLN_RELAY_MSG_LIMIT" =~ ^[0-9]+$ ]]; then + echo "Error: --rln-relay-messages-limit must be an integer." + exit 1 +fi + +# Check if default values are used and warn +if [[ "$NWAKU_IMAGE" == "$DEFAULT_NWAKU_IMAGE" ]]; then + echo "Warning: Using default value for --nwaku-image: $DEFAULT_NWAKU_IMAGE" +fi + +if [[ "$NUM_NWAKU_NODES" -eq "$DEFAULT_NUM_NWAKU_NODES" ]]; then + echo "Warning: Using default value for --num-nwaku-nodes: $DEFAULT_NUM_NWAKU_NODES" +fi + +if [[ "$TRAFFIC_NUM_NWAKU_NODES" -eq "$DEFAULT_TRAFFIC_NUM_NWAKU_NODES" ]]; then + echo "Warning: Using default value for --num-nwaku-nodes: $DEFAULT_TRAFFIC_NUM_NWAKU_NODES" +fi + +if [[ "$SPAM_NUM_NWAKU_NODES" -eq "$DEFAULT_SPAM_NUM_NWAKU_NODES" ]]; then + echo "Warning: Using default value for --spam-num-nwaku-nodes: $DEFAULT_SPAM_NUM_NWAKU_NODES" +fi + +if [[ "$TRAFFIC_DELAY_SECONDS" -eq "$DEFAULT_TRAFFIC_DELAY_SECONDS" ]]; then + echo "Warning: Using default value for --traffic-delay-seconds: $DEFAULT_TRAFFIC_DELAY_SECONDS" +fi + +if [[ "$MSG_SIZE_KBYTES" -eq "$DEFAULT_MSG_SIZE_KBYTES" ]]; then + echo "Warning: Using default value for --message-size-kbytes: $DEFAULT_MSG_SIZE_KBYTES" +fi + +if [[ "$PRIVATE_KEY" == "$DEFAULT_PRIVATE_KEY" ]]; then + echo "Warning: Using default value for --private-key: $DEFAULT_PRIVATE_KEY" +fi + +if [[ "$ETH_FROM" == "$DEFAULT_ETH_FROM" ]]; then + echo "Warning: Using default value for --eth-from: $DEFAULT_ETH_FROM" +fi + +if [[ "$RLN_RELAY_EPOCH_SEC" -eq "$DEFAULT_RLN_RELAY_EPOCH_SEC" ]]; then + echo "Warning: Using default value for --rln-relay-epoch-seconds: $DEFAULT_RLN_RELAY_EPOCH_SEC" +fi + +if [[ "$RLN_RELAY_MSG_LIMIT" -eq "$DEFAULT_RLN_RELAY_MSG_LIMIT" ]]; then + echo "Warning: Using default value for --rln-relay-messages-limit: $DEFAULT_RLN_RELAY_MSG_LIMIT" +fi + +# Output the parameters as a summary +echo "" +echo "=================================================================================================" +echo " Summary of Parameters " +echo "=================================================================================================" +echo "- Nwaku Image: ${NWAKU_IMAGE}" +echo "- Nodes" +echo " | Total: ${NUM_NWAKU_NODES}" +echo " | Traffic Injection: ${TRAFFIC_NUM_NWAKU_NODES}" +echo " | Spam Injection: ${SPAM_NUM_NWAKU_NODES}" +echo "- Message Publishing Delay: ${TRAFFIC_DELAY_SECONDS}s" +echo "- Message Size: ${MSG_SIZE_KBYTES}KB" +echo "- Private Key: ${PRIVATE_KEY}" +echo "- ETH From: ${ETH_FROM}" +echo "- RLN Relay Epoch: ${RLN_RELAY_EPOCH_SEC}s" +echo "- RLN Relay Messages Limit: ${RLN_RELAY_MSG_LIMIT}" +echo "=================================================================================================" +echo "" + +# Confirm Parameters +read -n 1 -s -r -p "Press any key to launch docker compose with the specified parameters" +echo "" + +# Export parameters and run compose +export NWAKU_IMAGE +export NUM_NWAKU_NODES +export TRAFFIC_NUM_NWAKU_NODES +export SPAM_NUM_NWAKU_NODES +export TRAFFIC_DELAY_SECONDS +export MSG_SIZE_KBYTES +export PRIVATE_KEY +export ETH_FROM +export RLN_RELAY_EPOCH_SEC +export RLN_RELAY_MSG_LIMIT + +docker compose --compatibility up + diff --git a/run_nwaku.sh b/run_nwaku.sh index 3b2eb5a..98ba334 100755 --- a/run_nwaku.sh +++ b/run_nwaku.sh @@ -81,6 +81,7 @@ get_private_key(){ current_index=1 for key in $private_keys do + # INDEX=`echo $INDEX | sed -n "1p" | awk '{print $1}'` # Podman Fix: Get only the first value of the first line if [ $current_index -eq $INDEX ]; then pk=$key echo $key @@ -158,4 +159,5 @@ exec /usr/bin/wakunode\ --discv5-bootstrap-node=${BOOTSTRAP_ENR}\ --nat=extip:${IP}\ --pubsub-topic=/waku/2/rs/66/0\ - --cluster-id=66 \ No newline at end of file + --cluster-id=66 +