How to launch a testnet with one linux machine!

I made a script to launch a testnet with multiple nodes from one linux machine! you could launch from multiple machines also nut read on!

how to use:

tested in debian 10/11 and manjaro

a. debian: sudo apt-get update && apt-get install -y git or if you dont have sudo from root run first apt install sudo
b. manjaro sudo pacman -Syy && sudo pacman -S --noconfirm git

close and open your terminal ( or exec bash for example)

then clone the git repo

git clone https://github.com/dreamerchris/dream_sn_node_joiner.git

then cd into the new folder

cd dream_sn_node_joiner

here you can launch the dependency scripts for manjaro or debian:

sh dep_installer_debian.sh or sh dep_installer_manjaro.sh

now to launch the testnet in one machine

first see the script and edit it according to your needs:

nano launch_n_multi_joiner.sh

here is the file:

#!/bin/bash

NODE_NUM=35
USER=$(whoami)

ACTIVE_IF=$( ( cd /sys/class/net || exit; echo *)|awk '{print $1;}')
LOCAL_IP=$(echo $(ifdata -pa "$ACTIVE_IF"))
PUBLIC_IP=$(echo $(curl -s ifconfig.me))
SAFE_PORT=12000

mkdir -p $HOME/.safe/node/local_node0/

CURRENT_ROOT_DIR=$HOME/.safe/node/local_node0/
CURRENT_LOG_DIR=$HOME/.safe/node/local_node0/
CURRENT_NODE=0
echo -n "#!/bin/bash
RUST_LOG=safe_network=trace,qp2p=info \
        $HOME/.safe/node/sn_node --first \
        --local-addr '$LOCAL_IP':$SAFE_PORT \
        --public-addr '$PUBLIC_IP':$SAFE_PORT \
        --skip-auto-port-forwarding \
        --root-dir '$CURRENT_ROOT_DIR' \
        --log-dir '$CURRENT_LOG_DIR' & disown" \
| tee $HOME/.safe/node/start-node$CURRENT_NODE.sh

chmod u+x $HOME/.safe/node/start-node$CURRENT_NODE.sh

echo -n "[Unit]
Description=Safe Local Node $CURRENT_NODE
[Service]
User=$USER
ExecStart=$HOME/.safe/node/start-node$CURRENT_NODE.sh
Type=forking
[Install]
WantedBy=multi-user.target"\
| sudo tee /etc/systemd/system/sn_node$CURRENT_NODE.service

sudo systemctl start sn_node$CURRENT_NODE.service
sleep 3
safe networks add mynet
safe networks switch mynet

for CURRENT_NODE in  $(seq $NODE_NUM)
do
SAFE_PORT=$((12000+$CURRENT_NODE))
CURRENT_ROOT_DIR=$HOME/.safe/node/local_node$CURRENT_NODE/
CURRENT_LOG_DIR=$HOME/.safe/node/local_node$CURRENT_NODE/
mkdir $CURRENT_ROOT_DIR

echo -n "#!/bin/bash
RUST_LOG=safe_network=trace,qp2p=info \
        $HOME/.safe/node/sn_node \
        --local-addr '$LOCAL_IP':$SAFE_PORT \
        --public-addr '$PUBLIC_IP':$SAFE_PORT \
        --skip-auto-port-forwarding \
        --root-dir '$CURRENT_ROOT_DIR' \
        --log-dir '$CURRENT_LOG_DIR' & disown" \
| tee $HOME/.safe/node/start-node$CURRENT_NODE.sh

chmod u+x $HOME/.safe/node/start-node$CURRENT_NODE.sh

echo -n "[Unit]
Description=Safe Local Node $CURRENT_NODE
[Service]
User=$USER
ExecStart=$HOME/.safe/node/start-node$CURRENT_NODE.sh
Type=forking
[Install]
WantedBy=multi-user.target"\
| sudo tee /etc/systemd/system/sn_node$CURRENT_NODE.service

sudo systemctl start sn_node$CURRENT_NODE.service
sleep 3
done
echo ""
echo "End of multi sn node joiner script. Starting vdash!"
echo ""
$HOME/.cargo/bin/vdash $HOME/.safe/node/local_node*/sn_node.log

here you can edit the NODE_NUM which is the number of nodes to start! (make sure you have enough space in disk as the recent removal of max-capacity option has defaulted to 10gb per node)

also you can edit the SAFE_PORT which is the starting port (of the genesis node) please keep this ending in 00 as the other nodes are going to be ending to 01-35 (12001-12035)

you are good to go!
run sh launch_n_multi_joiner.sh

now your new config for your network is in ~/.safe/node/ and its called node_connection_info.config!

so if you want others to join you need to either send then this file or make it available in a static url (I use nextcloud)

and either they should use safe networks add mynet pathToTheConfig.config

or
safe networks add mynet urlToConfigDownload

dont forget to use safe networks switch mynet

and then either use

safe node join --public-addr x.x.x.x:xport --local-addr x.x.x.x:xport --skip-auto-port-forwarding

or you could also use my multi_sn_node_joiner.sh as described in this thread:

12 Likes

Thanks Chris - I’ll give this a try later

5 Likes

Btw, just so you’re aware, this is what the CLI’s node run-baby-fleming command does. Though it’s just running each node as a background process rather than a service.

1 Like