Skip to content

Commit 49dd0bf

Browse files
authored
Add Relay support (#32)
1 parent f95afc4 commit 49dd0bf

File tree

3 files changed

+220
-25
lines changed

3 files changed

+220
-25
lines changed

bin/set-relay-name

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
set_relay_name() {
4+
echo "If you are operating a relay node you need to set a relay name in accordance with the naming convention."
5+
echo "The relay name should be in the format: <your initials>-<provider-code>-<iso-3166-alpha2-country-code>-<supported-iata-airport-code>-<your-chosen-identifier>"
6+
echo "Example: hs-htz-us-iad-002"
7+
echo "Supported IATA airport codes can be found here: https://github.com/grafana/grafana/blob/main/public/gazetteer/airports.geojson"
8+
# shellcheck disable=SC2162
9+
read -p "Relay name: " VOINETWORK_TELEMETRY_NAME
10+
}
11+
12+
set_relay_name
13+
## Add check to only use if relay profile is running
14+
15+
bash -c "env VOINETWORK_RELAY_NAME=\"${VOINETWORK_TELEMETRY_NAME}\" docker stack deploy -c ${HOME}/voi/docker/relay.yml voinetwork"

docker/relay.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
version: "3.9"
2+
services:
3+
relay:
4+
image: ghcr.io/voinetwork/docker-relay-node:latest
5+
hostname: ${VOINETWORK_RELAY_NAME}
6+
volumes:
7+
- /var/lib/voi/algod/data:/algod/data/:rw
8+
ports:
9+
- published: 5011
10+
target: 8080
11+
protocol: tcp
12+
mode: host
13+
networks:
14+
- notification
15+
deploy:
16+
replicas: 1
17+
restart_policy:
18+
condition: on-failure
19+
node-exporter:
20+
image: ghcr.io/voinetwork/docker-relay-node:latest
21+
hostname: ${VOINETWORK_RELAY_NAME}
22+
environment:
23+
- GOGC=25
24+
volumes:
25+
- /var/lib/voi/algod/metrics:/algod/metrics/:rw
26+
ports:
27+
- published: 9100
28+
target: 8080
29+
protocol: tcp
30+
mode: host
31+
networks:
32+
- notification
33+
deploy:
34+
replicas: 1
35+
restart_policy:
36+
condition: on-failure
37+
entrypoint:
38+
- "/node/bin/start-metrics"
39+
shepherd:
40+
image: containrrr/shepherd
41+
environment:
42+
RUN_ONCE_AND_EXIT: "true"
43+
ROLLBACK_ON_FAILURE: "true"
44+
IMAGE_AUTOCLEAN_LIMIT: "5"
45+
logging:
46+
driver: "local"
47+
volumes:
48+
- /var/run/docker.sock:/var/run/docker.sock
49+
deploy:
50+
replicas: 0
51+
restart_policy:
52+
condition: none
53+
labels:
54+
- swarm.cronjob.enable=false
55+
- swarm.cronjob.schedule=0 */4 * * *
56+
- swarm.cronjob.skip-running=true
57+
placement:
58+
constraints:
59+
- node.role == manager
60+
scheduler:
61+
image: ghcr.io/voinetwork/swarm-cronjob:edge
62+
logging:
63+
driver: "local"
64+
environment:
65+
- "TZ=UTC"
66+
- "LOG_LEVEL=info"
67+
- "LOG_JSON=false"
68+
volumes:
69+
- /var/run/docker.sock:/var/run/docker.sock:ro
70+
deploy:
71+
placement:
72+
constraints:
73+
- node.role == manager
74+
networks:
75+
notification:

install.sh

Lines changed: 130 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ start_docker_swarm() {
8787
if [[ -n ${VOINETWORK_DOCKER_SWARM_INIT_SETTINGS} ]]; then
8888
command+=" ${VOINETWORK_DOCKER_SWARM_INIT_SETTINGS}"
8989
else
90-
command+=" --listen-addr lo --advertise-addr 127.0.0.1"
90+
command+=" --listen-addr lo --advertise-addr lo"
9191
fi
9292

9393
execute_sudo "$command"
@@ -102,7 +102,13 @@ start_docker_swarm() {
102102
}
103103

104104
start_stack() {
105-
command="env VOINETWORK_TELEMETRY_NAME=$VOINETWORK_TELEMETRY_NAME docker stack deploy -c ${voi_home}/docker/compose.yml"
105+
docker_file="${voi_home}/docker/compose.yml"
106+
107+
if [[ ${VOINETWORK_PROFILE} == "relay" ]]; then
108+
echo "Starting relay node stack"
109+
docker_file="${voi_home}/docker/relay.yml"
110+
fi
111+
command="env VOINETWORK_TELEMETRY_NAME=$VOINETWORK_TELEMETRY_NAME docker stack deploy -c ${docker_file}"
106112

107113
if [[ -f "${voi_home}/docker/notification.yml" ]]; then
108114
command+=" -c ${voi_home}/docker/notification.yml"
@@ -444,7 +450,13 @@ docker_swarm_instructions() {
444450
echo "To fix this, set VOINETWORK_DOCKER_SWARM_INIT_SETTINGS to the settings you want to use to initialize Docker Swarm and try again."
445451
echo "Parameters that can be passed to the swarm can be found at: https://docs.docker.com/engine/reference/commandline/swarm_init/"
446452
echo ""
447-
echo "Join #node-resources on Discord (https://discord.com/invite/vnFbrJrHeW) to engage with the community and get help."
453+
if [[ ${VOINETWORK_PROFILE} == "relay" ]]; then
454+
echo "Troubleshoot on your own, and after troubleshooting join #relay-runners on Discord (https://discord.com/invite/vnFbrJrHeW) to engage with the community and get help."
455+
echo "It's crucial to have a strong grasp of technical details, including the ability to execute commands directly on the server, and access and understand cloud resources and logs. Being self-sufficient and having the ability to debug issues independently are key skills for managing this setup."
456+
echo "If this is not for you, consider other means to engage with the community and contribute."
457+
else
458+
echo "Join #node-resources on Discord (https://discord.com/invite/vnFbrJrHeW) to engage with the community and get help by using the Discord ((https://discord.com/invite/vnFbrJrHeW))."
459+
fi
448460
abort "Exiting the program."
449461
}
450462

@@ -469,8 +481,7 @@ joined_network_instructions() {
469481
echo "Account setup skipped. Detected existing account with address: ${account_addr}"
470482
fi
471483

472-
echo ""
473-
echo "To see network participation status use ${HOME}/voi/bin/get-node-status"
484+
echo "To see network participation status use ${HOME}/voi/bin/get-participation-status ${account_addr}"
474485
echo "To go online use ${HOME}/voi/bin/go-online ${account_addr}"
475486
fi
476487

@@ -480,12 +491,23 @@ joined_network_instructions() {
480491
echo "The network is now catching up and will continue to do so in the background."
481492
fi
482493

494+
if [[ ${VOINETWORK_PROFILE} == "relay" ]]; then
495+
echo ""
496+
display_banner "Relay node setup"
497+
echo "Due to the nature of relay nodes, you will not be able to participate in the consensus network on this server."
498+
echo ""
499+
echo "Few things to be mindful of:"
500+
echo " - *BETA*: Utility commands are available in ${voi_home}/bin, however any that assumes participation will not work."
501+
echo " - It is your responsibility to monitor the server and ensure it is running smoothly."
502+
echo " - You're responsible for server security, maintenance, updates, access controls, and monitoring."
503+
fi
504+
483505
echo ""
484506
echo "To easily access commands from ${HOME}/voi/bin, add the following to ${HOME}/.bashrc or ${HOME}/.profile:"
485507
echo "export PATH=\"\$PATH:${HOME}/voi/bin\""
486508
echo ""
487509

488-
if [[ ${skip_account_setup} -eq 0 ]]; then
510+
if [[ ${skip_account_setup} -eq 0 && ${VOINETWORK_PROFILE} != "relay" ]]; then
489511
echo "${bold}*********************************** READ THIS! ***********************************${normal}"
490512
echo "After joining the network, it might take up to 2 hours for your server to appear on telemetry"
491513
echo "tracking services. Initially, you can identify your server using the 12-digit short GUID shown by"
@@ -542,17 +564,50 @@ add_docker_groups() {
542564
}
543565

544566
get_telemetry_name() {
567+
if [[ ${VOINETWORK_PROFILE} == "relay" ]]; then
568+
return
569+
fi
570+
545571
if [[ -f "/var/lib/voi/algod/data/logging.config" ]]; then
546572
VOINETWORK_TELEMETRY_NAME=$(execute_sudo "cat /var/lib/voi/algod/data/logging.config" | jq -r '.Name')
547573
fi
548574
}
549575

576+
set_relay_name() {
577+
if [[ -f "${voi_home}/relay-name.env" ]]; then
578+
VOINETWORK_TELEMETRY_NAME=$(grep telemetry-name "${voi_home}/relay-name.env" | cut -d'=' -f2)
579+
return
580+
fi
581+
582+
echo "If you are operating a relay node you need to set a relay name in accordance with the naming convention."
583+
echo "The relay name should be in the format: <your initials>-<provider-code>-<iso-3166-alpha2-country-code>-<supported-iata-airport-code>-<your-chosen-identifier>"
584+
echo "Example: hs-htz-us-iad-002"
585+
echo "Supported IATA airport codes can be found here: https://github.com/grafana/grafana/blob/main/public/gazetteer/airports.geojson"
586+
# shellcheck disable=SC2162
587+
read -p "Relay name: " VOINETWORK_TELEMETRY_NAME
588+
589+
while [[ ${VOINETWORK_TELEMETRY_NAME} == "" ]]
590+
do
591+
# shellcheck disable=SC2162
592+
read -p "Please enter a relay name: " VOINETWORK_TELEMETRY_NAME
593+
done
594+
595+
# This is quite rudimentary, but it's a start. We can add more validation and better structure later. Remember to clean
596+
# up the file as a migration when this is done.
597+
echo "telemetry-name=${VOINETWORK_TELEMETRY_NAME}" >> "${voi_home}"/relay-name.env
598+
}
599+
550600
set_telemetry_name() {
551601
if [[ ${headless_install} -eq 1 ]]; then
552602
## Allow headless install to skip telemetry name setup in case people bring their own wallets / use CI
553603
return
554604
fi
555605

606+
if [[ ${VOINETWORK_PROFILE} == "relay" ]]; then
607+
set_relay_name
608+
return
609+
fi
610+
556611
detect_existing_host_based_setup
557612

558613
if [[ ${migrate_host_based_setup} -eq 1 ]]; then
@@ -622,6 +677,16 @@ check_minimum_requirements() {
622677
return
623678
fi
624679

680+
minimum_cpus=4
681+
minimum_memory_bytes=6710886
682+
minimum_memory_gigabytes_pretty=8
683+
684+
if [[ -n ${VOINETWORK_PROFILE} && ${VOINETWORK_PROFILE} == "relay" ]]; then
685+
minimum_cpus=8
686+
minimum_memory_bytes=15938355
687+
minimum_memory_gigabytes_pretty=16
688+
fi
689+
625690
echo "Checking system requirements.."
626691
echo ""
627692

@@ -632,27 +697,37 @@ check_minimum_requirements() {
632697
# Check if the number of cores is less than 4 and less (8 GB * 0.8) memory. Reported memory from
633698
# /proc/meminfo prints out accessible memory, not total memory. We use 80% of the total memory as an approximation,
634699
# intentionally going too low to allow variability from various cloud providers.
635-
if [[ ${num_cores} -lt 4 || ${total_memory} -lt 6710886 ]]; then
700+
if [[ ${num_cores} -lt ${minimum_cpus} || ${total_memory} -lt ${minimum_memory_bytes} ]]; then
636701
echo "*************************************************************************************"
637702
echo "* ${bold}WARNING: Your system does not meet the minimum requirements to run Voi Swarm effectively.${normal}"
638703
echo "*************************************************************************************"
639704
echo "*"
640705
echo "* Voi Swarm requires at least 4 CPU cores and 8 GB of memory to run effectively."
641706
echo "*"
642707
echo "* Your system has:"
643-
echo "* - CPU cores: ${bold}${num_cores}${normal} CPU cores. ${bold}4${normal} is required."
644-
echo "* - Memory: ${bold}$((total_memory / 1024 / 1024))${normal} GB of accessible memory. ${bold}8${normal} GB is required."
645-
echo "*"
646-
echo "* You can still proceed, however, it may not be as beneficial to the network or to you,"
647-
echo "* as your node won't be able to contribute or earn rewards effectively."
648-
echo "* You should ${bold}expect poor performance${normal}, and the community may ${bold}not be able to help${normal} you with issues."
649-
echo "* "
650-
echo "* If you are running this on a cloud provider, you should consider upgrading your instance to"
651-
echo "* meet the requirements."
652-
echo "* "
653-
echo "* Read more about other options for running a node on:"
654-
echo "* - https://voinetwork.github.io/voi-swarm/getting-started/introduction/"
655-
echo "*"
708+
echo "* - CPU cores: ${bold}${num_cores}${normal} CPU cores. ${bold}${minimum_cpus}${normal} is required."
709+
echo "* - Memory: ${bold}$((total_memory / 1024 / 1024))${normal} GB of accessible memory. ${bold}${minimum_memory_gigabytes_pretty}${normal} GB is required."
710+
if [[ ${VOINETWORK_PROFILE} == "relay" ]]; then
711+
echo "*"
712+
echo "* You are running a relay node profile. Relay nodes require at least 8 CPU cores and 16 GB of memory."
713+
echo "*"
714+
echo "* Upgrade your system to meet the minimum requirements to run as a relay node."
715+
echo "*"
716+
abort "Exiting the program."
717+
else
718+
echo "*"
719+
echo "* You can still proceed, however, it may not be as beneficial to the network or to you,"
720+
echo "* as your node won't be able to contribute or earn rewards effectively."
721+
echo "* You should ${bold}expect poor performance${normal}, and the community may ${bold}not be able to help${normal} you with issues."
722+
echo "* "
723+
echo "* If you are running this on a cloud provider, you should consider upgrading your instance to"
724+
echo "* meet the requirements."
725+
echo "* "
726+
echo "* Read more about other options for running a node on:"
727+
echo "* - https://voinetwork.github.io/voi-swarm/getting-started/introduction/"
728+
echo "*"
729+
fi
730+
656731
echo "* Find other ways to contribute to the network by joining the Voi Network Discord:"
657732
echo "* - https://discord.com/invite/vnFbrJrHeW"
658733
echo "*"
@@ -669,6 +744,29 @@ check_minimum_requirements() {
669744
fi
670745
}
671746

747+
set_profile() {
748+
mkdir -p "${voi_home}"
749+
750+
# Check if ${voi_home}/profile exists
751+
if [[ -f "${voi_home}/profile" ]]; then
752+
# If it does exist, read the value and save it in the environment variable VOINETWORK_PROFILE
753+
VOINETWORK_PROFILE=$(cat "${voi_home}/profile")
754+
export VOINETWORK_PROFILE
755+
else
756+
# If the file does not exist, check if VOINETWORK_PROFILE is set
757+
if [[ -z ${VOINETWORK_PROFILE} ]]; then
758+
# If VOINETWORK_PROFILE is not set, write "participation" to the file for the default profile
759+
VOINETWORK_PROFILE="participation"
760+
echo "participation" > "${voi_home}/profile"
761+
else
762+
# If VOINETWORK_PROFILE is set, write its value to the file
763+
echo "${VOINETWORK_PROFILE}" > "${voi_home}/profile"
764+
fi
765+
fi
766+
767+
display_banner "Setting up Voi Swarm using profile: ${VOINETWORK_PROFILE}"
768+
}
769+
672770
if [ -z "${BASH_VERSION:-}" ]; then
673771
abort "Bash is required to interpret this script."
674772
fi
@@ -685,7 +783,8 @@ else
685783
abort "This script is only meant to be run on Debian or Ubuntu."
686784
fi
687785

688-
if uname -r | grep -q "Microsoft"; then
786+
# shellcheck disable=SC2143
787+
if [[ $(uname -r | grep -q "Microsoft") ]]; then
689788
abort "WSL 1 is not supported. Please run this script on a native Linux installation (best) or WSL 2 (experimental)."
690789
fi
691790

@@ -710,10 +809,11 @@ fi
710809

711810
display_banner "${bold}Welcome to Voi Swarm${normal}. Let's get started!"
712811

812+
set_profile
813+
713814
check_minimum_requirements
714815

715816
get_telemetry_name
716-
717817
set_telemetry_name
718818

719819
display_banner "Installing Docker"
@@ -756,7 +856,10 @@ start_docker_swarm
756856
if [[ ! -e /var/lib/voi/algod/data ]]; then
757857
execute_sudo "mkdir -p /var/lib/voi/algod/data"
758858
fi
759-
mkdir -p "${voi_home}"
859+
860+
if [[ ! -e /var/lib/voi/algod/metrics ]]; then
861+
execute_sudo "mkdir -p /var/lib/voi/algod/metrics"
862+
fi
760863

761864
display_banner "Fetching the latest Voi Network updates and scripts."
762865
curl -sSL https://api.github.com/repos/VoiNetwork/voi-swarm/tarball/main --output "${voi_home}"/voi-swarm.tar.gz
@@ -769,9 +872,11 @@ start_stack
769872

770873
wait_for_stack_to_be_ready
771874

772-
verify_node_is_running
875+
if [[ ${VOINETWORK_PROFILE} != "relay" ]]; then
876+
verify_node_is_running
877+
fi
773878

774-
if [[ -n ${VOINETWORK_SKIP_WALLET_SETUP} && ${VOINETWORK_SKIP_WALLET_SETUP} -eq 1 ]]; then
879+
if [[ ${VOINETWORK_PROFILE} == "relay" || ( -n ${VOINETWORK_SKIP_WALLET_SETUP} && ${VOINETWORK_SKIP_WALLET_SETUP} -eq 1 ) ]]; then
775880
display_banner "Wallet setup will be skipped."
776881

777882
joined_network_instructions true

0 commit comments

Comments
 (0)