From 0c87d889fe4ce8cff37cde46c7d07b509d1f9067 Mon Sep 17 00:00:00 2001 From: DaMandal0rian <3614052+DaMandal0rian@users.noreply.github.com> Date: Tue, 30 Jul 2024 16:00:07 +0300 Subject: [PATCH] add dedicated consensus RPC and Nova RPC for squids (#326) * add rpc and nova squids infra terraform * change prefix * remove relayer ids --- resources/README.md | 6 +- resources/gemini-3h/main.tf | 25 ++- resources/gemini-3h/outputs.tf | 11 +- resources/gemini-3h/variables.tf | 6 +- .../create_domain_node_compose_file.sh | 2 +- .../scripts/create_full_node_compose_file.sh | 106 ---------- .../scripts/create_rpc_node_compose_file.sh | 2 +- .../bootstrap_node_evm_provisioner.tf | 8 - templates/terraform/network-primitives/dns.tf | 27 +-- .../domain_node_provisioner.tf | 8 - .../terraform/network-primitives/instances.tf | 78 +++++++- .../nova_squid_node_provisioner.tf | 185 ++++++++++++++++++ .../terraform/network-primitives/outputs.tf | 35 +++- .../rpc_node_provisioner.tf | 6 - ...ioner.tf => rpc_squid_node_provisioner.tf} | 72 ++++--- .../terraform/network-primitives/variables.tf | 46 ++++- 16 files changed, 415 insertions(+), 208 deletions(-) delete mode 100755 templates/scripts/create_full_node_compose_file.sh create mode 100644 templates/terraform/network-primitives/nova_squid_node_provisioner.tf rename templates/terraform/network-primitives/{full_node_provisioner.tf => rpc_squid_node_provisioner.tf} (60%) diff --git a/resources/README.md b/resources/README.md index 2948ab10..d969ac63 100644 --- a/resources/README.md +++ b/resources/README.md @@ -53,7 +53,7 @@ Clone the repository and navigate to the testing framework directory **resources │ ├── dns.tf │ ├── domain_node_provisioner.tf │ ├── farmer_node_provisioner.tf -│ ├── full_node_provisioner.tf +│ ├── rpc-squid_node_provisioner.tf │ ├── instances.tf │ ├── network.tf │ ├── outputs.tf @@ -64,7 +64,7 @@ Clone the repository and navigate to the testing framework directory **resources │ │ ├── create_bootstrap_node_evm_compose_file.sh │ │ ├── create_domain_node_compose_file.sh │ │ ├── create_farmer_node_compose_file.sh -│ │ ├── create_full_node_compose_file.sh +│ │ ├── create_rpc-squid_node_compose_file.sh │ │ ├── create_rpc_node_compose_file.sh │ │ ├── installer.sh │ │ └── prune_docker_system.sh @@ -97,7 +97,7 @@ Each network will need it's own keys, which you can gather from bitwarden, and e ├── domain_node_keys.txt ├── dsn_bootstrap_node_keys.txt ├── farmer_node_keys.txt -├── full_node_keys.txt +├── rpc-squid_node_keys.txt ├── keystore ├── relayer_ids.txt └── rpc_node_keys.txt diff --git a/resources/gemini-3h/main.tf b/resources/gemini-3h/main.tf index 3d15d12b..9589c395 100644 --- a/resources/gemini-3h/main.tf +++ b/resources/gemini-3h/main.tf @@ -36,13 +36,14 @@ module "gemini-3h" { disk-volume-type = var.disk_volume_type } - full-node-config = { - instance-type = var.instance_type["full"] + rpc-squid-node-config = { + instance-type = var.instance_type["rpc-squid"] deployment-version = 0 regions = var.aws_region - instance-count = var.instance_count["full"] + instance-count = var.instance_count["rpc-squid"] docker-org = "subspace" docker-tag = "gemini-3h-2024-jul-16" + domain-prefix = "rpc-squid" reserved-only = false prune = false node-dsn-port = 30433 @@ -50,6 +51,24 @@ module "gemini-3h" { disk-volume-type = var.disk_volume_type } + nova-squid-node-config = { + instance-type = var.instance_type["nova-squid"] + deployment-version = 0 + regions = var.aws_region + instance-count = var.instance_count["nova-squid"] + docker-org = "subspace" + docker-tag = "gemini-3h-2024-jul-16" + domain-prefix = "nova-squid" + reserved-only = false + prune = false + node-dsn-port = 30433 + enable-domains = true + domain-id = var.domain_id + domain-labels = var.domain_labels + disk-volume-size = var.disk_volume_size + disk-volume-type = var.disk_volume_type + } + rpc-node-config = { instance-type = var.instance_type["rpc"] deployment-version = 0 diff --git a/resources/gemini-3h/outputs.tf b/resources/gemini-3h/outputs.tf index 8b146729..62af86ee 100644 --- a/resources/gemini-3h/outputs.tf +++ b/resources/gemini-3h/outputs.tf @@ -1,7 +1,12 @@ //output -output "full-node-ipv4-addresses" { - value = module.gemini-3h.full_node_public_ip - description = "Full node IPv4 Addresses" +output "rpc-squid-node-ipv4-addresses" { + value = module.gemini-3h.rpc-squid_node_public_ip + description = "RPC squid node IPv4 Addresses" +} + +output "nova-squid-node-ipv4-addresses" { + value = module.gemini-3h.nova-squid_node_public_ip + description = "Nova Squid node IPv4 Addresses" } output "farmer-node-ipv4-addresses" { diff --git a/resources/gemini-3h/variables.tf b/resources/gemini-3h/variables.tf index 01853cec..956275b2 100644 --- a/resources/gemini-3h/variables.tf +++ b/resources/gemini-3h/variables.tf @@ -29,7 +29,8 @@ variable "instance_type" { bootstrap = "c7a.4xlarge" rpc = "m6a.xlarge" domain = "m6a.xlarge" - full = "c7a.2xlarge" + rpc-squid = "c7a.2xlarge" + nova-squid = "c7a.2xlarge" farmer = "c7a.2xlarge" evm_bootstrap = "c7a.xlarge" } @@ -56,7 +57,8 @@ variable "instance_count" { bootstrap = 2 rpc = 2 domain = 2 - full = 1 + rpc-squid = 1 + nova-squid = 1 farmer = 0 evm_bootstrap = 1 } diff --git a/templates/scripts/create_domain_node_compose_file.sh b/templates/scripts/create_domain_node_compose_file.sh index 8bd96b3b..0ae9a8f2 100755 --- a/templates/scripts/create_domain_node_compose_file.sh +++ b/templates/scripts/create_domain_node_compose_file.sh @@ -42,7 +42,7 @@ services: - "/var/run/docker.sock:/var/run/docker.sock" environment: NRIA_LICENSE_KEY: "\${NR_API_KEY}" - NRIA_DISPLAY_NAME: "\${NETWORK_NAME}-domain-node-\${NODE_ID}" + NRIA_DISPLAY_NAME: "\${NETWORK_NAME}-\${DOMAIN_PREFIX}-node-\${NODE_ID}" restart: unless-stopped # traefik reverse proxy with automatic tls management using let encrypt diff --git a/templates/scripts/create_full_node_compose_file.sh b/templates/scripts/create_full_node_compose_file.sh deleted file mode 100755 index 6514b3ab..00000000 --- a/templates/scripts/create_full_node_compose_file.sh +++ /dev/null @@ -1,106 +0,0 @@ -#!/bin/bash - -EXTERNAL_IP=`curl -s -4 https://ifconfig.me` -EXTERNAL_IP_V6=`curl -s -6 https://ifconfig.me` - -cat > ~/subspace/docker-compose.yml << EOF -version: "3.7" - -volumes: - archival_node_data: {} - vmagentdata: {} - -services: - vmagent: - container_name: vmagent - image: victoriametrics/vmagent:latest - depends_on: - - "archival-node" - ports: - - 8429:8429 - volumes: - - vmagentdata:/vmagentdata - - ./prometheus.yml:/etc/prometheus/prometheus.yml:ro - command: - - "--httpListenAddr=0.0.0.0:8429" - - "--promscrape.config=/etc/prometheus/prometheus.yml" - - "--remoteWrite.url=http://vmetrics.subspace.network:8428/api/v1/write" - - agent: - container_name: newrelic-infra - image: newrelic/infrastructure:latest - cap_add: - - SYS_PTRACE - network_mode: bridge - pid: host - privileged: true - volumes: - - "/:/host:ro" - - "/var/run/docker.sock:/var/run/docker.sock" - environment: - NRIA_LICENSE_KEY: "\${NR_API_KEY}" - NRIA_DISPLAY_NAME: "\${NETWORK_NAME}-full-node-\${NODE_ID}" - restart: unless-stopped - - archival-node: - image: ghcr.io/\${NODE_ORG}/node:\${NODE_TAG} - volumes: - - archival_node_data:/var/subspace:rw - restart: unless-stopped - ports: - - "30333:30333/udp" - - "30333:30333/tcp" - - "30433:30433/udp" - - "30433:30433/tcp" - - "9615:9615" - logging: - driver: loki - options: - loki-url: "https://logging.subspace.network/loki/api/v1/push" - command: [ - "run", - "--chain", "\${NETWORK_NAME}", - "--base-path", "/var/subspace", - "--state-pruning", "archive", - "--blocks-pruning", "256", - "--pot-external-entropy", "\${POT_EXTERNAL_ENTROPY}", - "--listen-on", "/ip4/0.0.0.0/tcp/30333", - "--listen-on", "/ip6/::/tcp/30333", - "--dsn-external-address", "/ip4/$EXTERNAL_IP/udp/30433/quic-v1", - "--dsn-external-address", "/ip4/$EXTERNAL_IP/tcp/30433", - "--dsn-external-address", "/ip6/$EXTERNAL_IP_V6/udp/30433/quic-v1", - "--dsn-external-address", "/ip6/$EXTERNAL_IP_V6/tcp/30433", - "--node-key", "\${NODE_KEY}", - "--in-peers", "1000", - "--out-peers", "1000", - "--dsn-in-connections", "1000", - "--dsn-out-connections", "1000", - "--dsn-pending-in-connections", "1000", - "--dsn-pending-out-connections", "1000", - "--rpc-max-connections", "10000", - "--prometheus-listen-on", "0.0.0.0:9615", -EOF - -reserved_only=${1} -node_count=${2} -current_node=${3} -bootstrap_node_count=${4} -dsn_bootstrap_node_count=${4} - -for (( i = 0; i < bootstrap_node_count; i++ )); do - addr=$(sed -nr "s/NODE_${i}_MULTI_ADDR_TCP=//p" ~/subspace//bootstrap_node_keys.txt) - echo " \"--reserved-nodes\", \"${addr}\"," >> ~/subspace/docker-compose.yml - echo " \"--bootstrap-nodes\", \"${addr}\"," >> ~/subspace/docker-compose.yml -done - -for (( i = 0; i < dsn_bootstrap_node_count; i++ )); do - dsn_addr=$(sed -nr "s/NODE_${i}_SUBSPACE_MULTI_ADDR=//p" ~/subspace/dsn_bootstrap_node_keys.txt) - echo " \"--dsn-reserved-peers\", \"${dsn_addr}\"," >> ~/subspace/docker-compose.yml - echo " \"--dsn-bootstrap-nodes\", \"${dsn_addr}\"," >> ~/subspace/docker-compose.yml -done - -if [ "${reserved_only}" == true ]; then - echo " \"--reserved-only\"," >> ~/subspace/docker-compose.yml -fi - -echo ' ]' >> ~/subspace/docker-compose.yml diff --git a/templates/scripts/create_rpc_node_compose_file.sh b/templates/scripts/create_rpc_node_compose_file.sh index 24fcc942..3b6ac2c7 100755 --- a/templates/scripts/create_rpc_node_compose_file.sh +++ b/templates/scripts/create_rpc_node_compose_file.sh @@ -42,7 +42,7 @@ services: - "/var/run/docker.sock:/var/run/docker.sock" environment: NRIA_LICENSE_KEY: "\${NR_API_KEY}" - NRIA_DISPLAY_NAME: "\${NETWORK_NAME}-rpc-node-\${NODE_ID}" + NRIA_DISPLAY_NAME: "\${NETWORK_NAME}-\${DOMAIN_PREFIX}-node-\${NODE_ID}" restart: unless-stopped # traefik reverse proxy with automatic tls management using let encrypt diff --git a/templates/terraform/network-primitives/bootstrap_node_evm_provisioner.tf b/templates/terraform/network-primitives/bootstrap_node_evm_provisioner.tf index 79850d37..42ea06c9 100644 --- a/templates/terraform/network-primitives/bootstrap_node_evm_provisioner.tf +++ b/templates/terraform/network-primitives/bootstrap_node_evm_provisioner.tf @@ -126,12 +126,6 @@ resource "null_resource" "start-bootstrap-nodes-evm" { destination = "/home/${var.ssh_user}/subspace/dsn_bootstrap_node_keys.txt" } - # copy relayer ids - provisioner "file" { - source = "./relayer_ids.txt" - destination = "/home/${var.ssh_user}/subspace/relayer_ids.txt" - } - # copy compose file creation script provisioner "file" { source = "${var.path_to_scripts}/create_bootstrap_node_evm_compose_file.sh" @@ -155,8 +149,6 @@ resource "null_resource" "start-bootstrap-nodes-evm" { "echo NODE_KEY=$(sed -nr 's/NODE_${count.index}_KEY=//p' /home/${var.ssh_user}/subspace/node_keys.txt) >> /home/${var.ssh_user}/subspace/.env", "echo DOMAIN_LABEL=${var.domain-node-config.domain-labels[0]} >> /home/${var.ssh_user}/subspace/.env", "echo DOMAIN_ID=${var.domain-node-config.domain-id[0]} >> /home/${var.ssh_user}/subspace/.env", - "echo RELAYER_SYSTEM_ID=$(sed -nr 's/NODE_${count.index}_RELAYER_SYSTEM_ID=//p' /home/${var.ssh_user}/subspace/relayer_ids.txt) >> /home/${var.ssh_user}/subspace/.env", - "echo RELAYER_DOMAIN_ID=$(sed -nr 's/NODE_${count.index}_RELAYER_DOMAIN_ID=//p' /home/${var.ssh_user}/subspace/relayer_ids.txt) >> /home/${var.ssh_user}/subspace/.env", "echo NR_API_KEY=${var.nr_api_key} >> /home/${var.ssh_user}/subspace/.env", "echo PIECE_CACHE_SIZE=${var.piece_cache_size} >> /home/${var.ssh_user}/subspace/.env", "echo DSN_NODE_ID=${count.index} >> /home/${var.ssh_user}/subspace/.env", diff --git a/templates/terraform/network-primitives/dns.tf b/templates/terraform/network-primitives/dns.tf index 50b0e28f..87a7a520 100644 --- a/templates/terraform/network-primitives/dns.tf +++ b/templates/terraform/network-primitives/dns.tf @@ -10,29 +10,20 @@ resource "cloudflare_record" "rpc" { type = "A" } -# Remove system domain -# resource "cloudflare_record" "system-domain" { -# count = length(local.domain_node_ip_v4) -# zone_id = data.cloudflare_zone.cloudflare_zone.id -# name = "${var.domain-node-config.domain-prefix}-${count.index}.system.${var.network_name}" -# value = local.domain_node_ip_v4[count.index] -# type = "A" -# } - -resource "cloudflare_record" "core-domain" { - count = length(local.domain_nodes_ip_v4) +resource "cloudflare_record" "rpc-squid" { + count = length(local.rpc_squid_nodes_ip_v4) zone_id = data.cloudflare_zone.cloudflare_zone.id - name = "${var.domain-node-config.domain-prefix}.${var.network_name}" - value = local.domain_nodes_ip_v4[count.index] + name = "${var.rpc-squid-node-config.domain-prefix}-${count.index}.${var.network_name}" + value = local.rpc_squid_nodes_ip_v4[count.index] type = "A" } -resource "cloudflare_record" "core-domain_ipv6" { - count = length(local.domain_nodes_ip_v4) +resource "cloudflare_record" "nova-squid-rpc" { + count = length(local.nova_squid_nodes_ip_v4) zone_id = data.cloudflare_zone.cloudflare_zone.id - name = "${var.domain-node-config.domain-prefix}.${var.network_name}" - value = local.domain_nodes_ip_v6[count.index] - type = "AAAA" + name = "${var.nova-squid-node-config.domain-prefix}-${count.index}.${var.network_name}" + value = local.nova_squid_nodes_ip_v4[count.index] + type = "A" } resource "cloudflare_record" "nova" { diff --git a/templates/terraform/network-primitives/domain_node_provisioner.tf b/templates/terraform/network-primitives/domain_node_provisioner.tf index fbaefb1c..ed0688a1 100644 --- a/templates/terraform/network-primitives/domain_node_provisioner.tf +++ b/templates/terraform/network-primitives/domain_node_provisioner.tf @@ -145,12 +145,6 @@ resource "null_resource" "start-domain-nodes" { destination = "/home/${var.ssh_user}/subspace/keystore/" } - # copy relayer ids - provisioner "file" { - source = "./relayer_ids.txt" - destination = "/home/${var.ssh_user}/subspace/relayer_ids.txt" - } - # copy compose file creation script provisioner "file" { source = "${var.path_to_scripts}/create_domain_node_compose_file.sh" @@ -176,8 +170,6 @@ resource "null_resource" "start-domain-nodes" { "echo DOMAIN_ID=${var.domain-node-config.domain-id[0]} >> /home/${var.ssh_user}/subspace/.env", "echo NODE_ID=${count.index} >> /home/${var.ssh_user}/subspace/.env", "echo NODE_KEY=$(sed -nr 's/NODE_${count.index}_KEY=//p' /home/${var.ssh_user}/subspace/node_keys.txt) >> /home/${var.ssh_user}/subspace/.env", - "echo RELAYER_SYSTEM_ID=$(sed -nr 's/NODE_${count.index}_RELAYER_SYSTEM_ID=//p' /home/${var.ssh_user}/subspace/relayer_ids.txt) >> /home/${var.ssh_user}/subspace/.env", - "echo RELAYER_DOMAIN_ID=$(sed -nr 's/NODE_${count.index}_RELAYER_DOMAIN_ID=//p' /home/${var.ssh_user}/subspace/relayer_ids.txt) >> /home/${var.ssh_user}/subspace/.env", "echo NR_API_KEY=${var.nr_api_key} >> /home/${var.ssh_user}/subspace/.env", "echo PIECE_CACHE_SIZE=${var.piece_cache_size} >> /home/${var.ssh_user}/subspace/.env", "echo NODE_DSN_PORT=${var.domain-node-config.node-dsn-port} >> /home/${var.ssh_user}/subspace/.env", diff --git a/templates/terraform/network-primitives/instances.tf b/templates/terraform/network-primitives/instances.tf index 9b55a5ce..4818799e 100644 --- a/templates/terraform/network-primitives/instances.tf +++ b/templates/terraform/network-primitives/instances.tf @@ -126,10 +126,10 @@ resource "aws_instance" "bootstrap_node_evm" { } -resource "aws_instance" "full_node" { - count = length(var.aws_region) * var.full-node-config.instance-count +resource "aws_instance" "rpc_squid_node" { + count = length(var.aws_region) * var.rpc-squid-node-config.instance-count ami = data.aws_ami.ubuntu_amd64.image_id - instance_type = var.full-node-config.instance-type + instance_type = var.rpc-squid-node-config.instance-type subnet_id = element(aws_subnet.public_subnets.*.id, 0) availability_zone = var.azs ipv6_address_count = 1 @@ -141,16 +141,16 @@ resource "aws_instance" "full_node" { ebs_optimized = true ebs_block_device { device_name = "/dev/sda1" - volume_size = var.full-node-config.disk-volume-size - volume_type = var.full-node-config.disk-volume-type + volume_size = var.rpc-squid-node-config.disk-volume-size + volume_type = var.rpc-squid-node-config.disk-volume-type iops = 3000 throughput = 250 } tags = { - Name = "${var.network_name}-full-${count.index}" - name = "${var.network_name}-full-${count.index}" - role = "full node" + Name = "${var.network_name}-rpc-squid-${count.index}" + name = "${var.network_name}-rpc-squid-${count.index}" + role = "rpc-squid node" os_name = "ubuntu" os_version = "22.04" arch = "x86_64" @@ -189,6 +189,68 @@ resource "aws_instance" "full_node" { } +resource "aws_instance" "nova_squid_node" { + count = length(var.aws_region) * var.nova-squid-node-config.instance-count + ami = data.aws_ami.ubuntu_amd64.image_id + instance_type = var.nova-squid-node-config.instance-type + subnet_id = element(aws_subnet.public_subnets.*.id, 0) + availability_zone = var.azs + ipv6_address_count = 1 + # Security Group + vpc_security_group_ids = ["${aws_security_group.network_sg.id}"] + # the Public SSH key + key_name = var.aws_key_name + associate_public_ip_address = true + ebs_optimized = true + ebs_block_device { + device_name = "/dev/sda1" + volume_size = var.nova-squid-node-config.disk-volume-size + volume_type = var.nova-squid-node-config.disk-volume-type + iops = 3000 + throughput = 250 + } + + tags = { + Name = "${var.network_name}-nova-squid-${count.index}" + name = "${var.network_name}-nova-squid-${count.index}" + role = "nova-squid node" + os_name = "ubuntu" + os_version = "22.04" + arch = "x86_64" + } + + depends_on = [ + aws_subnet.public_subnets, + #aws_nat_gateway.nat_gateway, + aws_internet_gateway.gw + ] + + lifecycle { + + ignore_changes = [ami, ipv6_address_count] + + } + + provisioner "remote-exec" { + inline = [ + "cloud-init status --wait", + "sudo apt update -y", + ] + + on_failure = continue + + } + + # Setting up the ssh connection + connection { + type = "ssh" + host = element(self.*.public_ip, count.index) + user = var.ssh_user + private_key = file("${var.private_key_path}") + timeout = "300s" + } + +} resource "aws_instance" "rpc_node" { count = length(var.aws_region) * var.rpc-node-config.instance-count diff --git a/templates/terraform/network-primitives/nova_squid_node_provisioner.tf b/templates/terraform/network-primitives/nova_squid_node_provisioner.tf new file mode 100644 index 00000000..1076774d --- /dev/null +++ b/templates/terraform/network-primitives/nova_squid_node_provisioner.tf @@ -0,0 +1,185 @@ +locals { + nova_squid_nodes_ip_v4 = flatten([ + [aws_instance.nova_squid_node.*.public_ip] + ] + ) + nova_squid_nodes_ip_v6 = flatten([ + [aws_instance.nova_squid_node.*.ipv6_addresses] + ] + ) +} + +resource "null_resource" "setup-nova-squid-nodes" { + count = length(local.nova_squid_nodes_ip_v4) + + depends_on = [aws_instance.nova_squid_node] + + # trigger on node ip changes + triggers = { + cluster_instance_ipv4s = join(",", local.nova_squid_nodes_ip_v4) + } + + connection { + host = local.nova_squid_nodes_ip_v4[count.index] + user = var.ssh_user + type = "ssh" + agent = true + private_key = file("${var.private_key_path}") + timeout = "300s" + } + + # create subspace dir + provisioner "remote-exec" { + inline = [ + "sudo mkdir -p /home/${var.ssh_user}/subspace/", + "sudo chown -R ${var.ssh_user}:${var.ssh_user} /home/${var.ssh_user}/subspace/ && sudo chmod -R 750 /home/${var.ssh_user}/subspace/" + ] + } + + # copy install file + provisioner "file" { + source = "${var.path_to_scripts}/installer.sh" + destination = "/home/${var.ssh_user}/subspace/installer.sh" + } + + # copy config files + provisioner "file" { + source = "${var.path_to_configs}/" + destination = "/home/${var.ssh_user}/subspace/" + } + + # copy LE script + provisioner "file" { + source = "${var.path_to_scripts}/acme.sh" + destination = "/home/${var.ssh_user}/subspace/acme.sh" + } + + # install docker and docker compose and LE script + provisioner "remote-exec" { + inline = [ + "sudo bash /home/${var.ssh_user}/subspace/installer.sh", + "bash /home/${var.ssh_user}/subspace/acme.sh", + ] + } + +} + +resource "null_resource" "prune-nova-squid-nodes" { + count = var.nova-squid-node-config.prune ? length(local.nova_squid_nodes_ip_v4) : 0 + depends_on = [null_resource.setup-nova-squid-nodes] + + triggers = { + prune = var.nova-squid-node-config.prune + } + + connection { + host = local.nova_squid_nodes_ip_v4[count.index] + user = var.ssh_user + type = "ssh" + agent = true + private_key = file("${var.private_key_path}") + timeout = "300s" + } + + provisioner "file" { + source = "${var.path_to_scripts}/prune_docker_system.sh" + destination = "/home/${var.ssh_user}/subspace/prune_docker_system.sh" + } + + # prune network + provisioner "remote-exec" { + inline = [ + "sudo bash /home/${var.ssh_user}/subspace/prune_docker_system.sh" + ] + } +} + +resource "null_resource" "start-nova-squid-nodes" { + count = length(local.nova_squid_nodes_ip_v4) + + depends_on = [null_resource.setup-nova-squid-nodes] + + # trigger on node deployment version change + triggers = { + deployment_version = var.nova-squid-node-config.deployment-version + reserved_only = var.nova-squid-node-config.reserved-only + } + + connection { + host = local.nova_squid_nodes_ip_v4[count.index] + user = var.ssh_user + type = "ssh" + agent = true + private_key = file("${var.private_key_path}") + timeout = "300s" + } + + # copy node keys file + provisioner "file" { + source = "./nova_squid_node_keys.txt" + destination = "/home/${var.ssh_user}/subspace/node_keys.txt" + } + + # copy boostrap node keys file + provisioner "file" { + source = "./bootstrap_node_keys.txt" + destination = "/home/${var.ssh_user}/subspace/bootstrap_node_keys.txt" + } + + + # copy boostrap node keys file + provisioner "file" { + source = "./bootstrap_node_evm_keys.txt" + destination = "/home/${var.ssh_user}/subspace/bootstrap_node_evm_keys.txt" + } + + # copy dsn_boostrap node keys file + provisioner "file" { + source = "./dsn_bootstrap_node_keys.txt" + destination = "/home/${var.ssh_user}/subspace/dsn_bootstrap_node_keys.txt" + } + + # copy keystore + provisioner "file" { + source = "./keystore" + destination = "/home/${var.ssh_user}/subspace/keystore/" + } + + # copy compose file creation script + provisioner "file" { + source = "${var.path_to_scripts}/create_nova_squid_node_compose_file.sh" + destination = "/home/${var.ssh_user}/subspace/create_compose_file.sh" + } + + # start docker containers + provisioner "remote-exec" { + inline = [ + # stop any running service + "sudo docker compose -f /home/${var.ssh_user}/subspace/docker-compose.yml down ", + + # set hostname + "sudo hostnamectl set-hostname ${var.network_name}-nova-squid-node-${count.index}", + + # create .env file + "echo NODE_ORG=${var.nova-squid-node-config.docker-org} > /home/${var.ssh_user}/subspace/.env", + "echo NODE_TAG=${var.nova-squid-node-config.docker-tag} >> /home/${var.ssh_user}/subspace/.env", + "echo NETWORK_NAME=${var.network_name} >> /home/${var.ssh_user}/subspace/.env", + "echo DOMAIN_PREFIX=${var.nova-squid-node-config.nova-squid-prefix} >> /home/${var.ssh_user}/subspace/.env", + # //todo use a map for domain id and labels + "echo DOMAIN_LABEL=${var.nova-squid-node-config.nova-squid-labels[0]} >> /home/${var.ssh_user}/subspace/.env", + "echo DOMAIN_ID=${var.nova-squid-node-config.nova-squid-id[0]} >> /home/${var.ssh_user}/subspace/.env", + "echo NODE_ID=${count.index} >> /home/${var.ssh_user}/subspace/.env", + "echo NODE_KEY=$(sed -nr 's/NODE_${count.index}_KEY=//p' /home/${var.ssh_user}/subspace/node_keys.txt) >> /home/${var.ssh_user}/subspace/.env", + "echo NR_API_KEY=${var.nr_api_key} >> /home/${var.ssh_user}/subspace/.env", + "echo PIECE_CACHE_SIZE=${var.piece_cache_size} >> /home/${var.ssh_user}/subspace/.env", + "echo NODE_DSN_PORT=${var.nova-squid-node-config.node-dsn-port} >> /home/${var.ssh_user}/subspace/.env", + "echo POT_EXTERNAL_ENTROPY=${var.pot_external_entropy} >> /home/${var.ssh_user}/subspace/.env", + + # create docker compose file + "bash /home/${var.ssh_user}/subspace/create_compose_file.sh ${var.bootstrap-node-config.reserved-only} ${length(local.nova_squid_nodes_ip_v4)} ${count.index} ${length(local.bootstrap_nodes_ip_v4)} ${length(local.bootstrap_nodes_evm_ip_v4)} ${var.nova-squid-node-config.enable-domains} ${var.nova-squid-node-config.nova-squid-id[0]}", + + # start subspace node + "sudo docker compose -f /home/${var.ssh_user}/subspace/docker-compose.yml up -d", + ] + } +} diff --git a/templates/terraform/network-primitives/outputs.tf b/templates/terraform/network-primitives/outputs.tf index 884931d3..246dc7c6 100644 --- a/templates/terraform/network-primitives/outputs.tf +++ b/templates/terraform/network-primitives/outputs.tf @@ -32,20 +32,36 @@ output "bootstrap_node_evm_ami" { value = aws_instance.bootstrap_node_evm.*.ami } -output "full_node_server_id" { - value = aws_instance.full_node.*.id +output "rpc_squid_node_server_id" { + value = aws_instance.rpc_squid_node.*.id } -output "full_node_private_ip" { - value = aws_instance.full_node.*.private_ip +output "rpc_squid_node_private_ip" { + value = aws_instance.rpc_squid_node.*.private_ip } -output "full_node_public_ip" { - value = aws_instance.full_node.*.public_ip +output "rpc_squid_node_public_ip" { + value = aws_instance.rpc_squid_node.*.public_ip } -output "full_node_ami" { - value = aws_instance.full_node.*.ami +output "rpc_squid_node_ami" { + value = aws_instance.rpc_squid_node.*.ami +} + +output "nova_squid_node_server_id" { + value = aws_instance.nova_squid_node.*.id +} + +output "nova_squid_node_private_ip" { + value = aws_instance.nova_squid_node.*.private_ip +} + +output "nova_squid_node_public_ip" { + value = aws_instance.nova_squid_node.*.public_ip +} + +output "nova_squid_node_ami" { + value = aws_instance.nova_squid_node.*.ami } @@ -103,7 +119,8 @@ output "dns-records" { value = [ cloudflare_record.bootstrap.*.hostname, cloudflare_record.rpc.*.hostname, - cloudflare_record.core-domain.*.hostname, + cloudflare_record.rpc-squid.*.hostname, + cloudflare_record.nova-squid-rpc.*.hostname, cloudflare_record.nova.*.hostname, ] } diff --git a/templates/terraform/network-primitives/rpc_node_provisioner.tf b/templates/terraform/network-primitives/rpc_node_provisioner.tf index 59038f3e..a6171b0f 100644 --- a/templates/terraform/network-primitives/rpc_node_provisioner.tf +++ b/templates/terraform/network-primitives/rpc_node_provisioner.tf @@ -137,12 +137,6 @@ resource "null_resource" "start-rpc-nodes" { destination = "/home/${var.ssh_user}/subspace/keystore/" } - # copy relayer ids - provisioner "file" { - source = "./relayer_ids.txt" - destination = "/home/${var.ssh_user}/subspace/relayer_ids.txt" - } - # copy compose file creation script provisioner "file" { source = "${var.path_to_scripts}/create_rpc_node_compose_file.sh" diff --git a/templates/terraform/network-primitives/full_node_provisioner.tf b/templates/terraform/network-primitives/rpc_squid_node_provisioner.tf similarity index 60% rename from templates/terraform/network-primitives/full_node_provisioner.tf rename to templates/terraform/network-primitives/rpc_squid_node_provisioner.tf index 39155dbb..d2fd25b3 100644 --- a/templates/terraform/network-primitives/full_node_provisioner.tf +++ b/templates/terraform/network-primitives/rpc_squid_node_provisioner.tf @@ -1,26 +1,26 @@ locals { - full_nodes_ip_v4 = flatten([ - [aws_instance.full_node.*.public_ip] + rpc_squid_nodes_ip_v4 = flatten([ + [aws_instance.rpc_squid_node.*.public_ip] ] ) - full_nodes_ip_v6 = flatten([ - [aws_instance.full_node.*.ipv6_addresses] + rpc_squid_nodes_ip_v6 = flatten([ + [aws_instance.rpc_squid_node.*.ipv6_addresses] ] ) } -resource "null_resource" "setup-full-nodes" { - count = length(local.full_nodes_ip_v4) +resource "null_resource" "setup-rpc-squid-nodes" { + count = length(local.rpc_squid_nodes_ip_v4) - depends_on = [aws_instance.full_node] + depends_on = [aws_instance.rpc_squid_node] # trigger on node ip changes triggers = { - cluster_instance_ipv4s = join(",", local.full_nodes_ip_v4) + cluster_instance_ipv4s = join(",", local.rpc_squid_nodes_ip_v4) } connection { - host = local.full_nodes_ip_v4[count.index] + host = local.rpc_squid_nodes_ip_v4[count.index] user = var.ssh_user type = "ssh" agent = true @@ -48,25 +48,31 @@ resource "null_resource" "setup-full-nodes" { destination = "/home/${var.ssh_user}/subspace/" } - # install docker and docker compose + # copy LE script + provisioner "file" { + source = "${var.path_to_scripts}/acme.sh" + destination = "/home/${var.ssh_user}/subspace/acme.sh" + } + + # install docker and docker compose and LE script provisioner "remote-exec" { inline = [ "sudo bash /home/${var.ssh_user}/subspace/installer.sh", + "bash /home/${var.ssh_user}/subspace/acme.sh", ] } - } -resource "null_resource" "prune-full-nodes" { - count = var.full-node-config.prune ? length(local.full_nodes_ip_v4) : 0 - depends_on = [null_resource.setup-full-nodes] +resource "null_resource" "prune-rpc-squid-nodes" { + count = var.rpc-squid-node-config.prune ? length(local.rpc_squid_nodes_ip_v4) : 0 + depends_on = [null_resource.setup-rpc-squid-nodes] triggers = { - prune = var.full-node-config.prune + prune = var.rpc-squid-node-config.prune } connection { - host = local.full_nodes_ip_v4[count.index] + host = local.rpc_squid_nodes_ip_v4[count.index] user = var.ssh_user type = "ssh" agent = true @@ -87,19 +93,19 @@ resource "null_resource" "prune-full-nodes" { } } -resource "null_resource" "start-full-nodes" { - count = length(local.full_nodes_ip_v4) +resource "null_resource" "start-rpc-squid-nodes" { + count = length(local.rpc_squid_nodes_ip_v4) - depends_on = [null_resource.setup-full-nodes] + depends_on = [null_resource.setup-rpc-squid-nodes] # trigger on node deployment version change triggers = { - deployment_version = var.full-node-config.deployment-version - reserved_only = var.full-node-config.reserved-only + deployment_version = var.rpc-squid-node-config.deployment-version + reserved_only = var.rpc-squid-node-config.reserved-only } connection { - host = local.full_nodes_ip_v4[count.index] + host = local.rpc_squid_nodes_ip_v4[count.index] user = var.ssh_user type = "ssh" agent = true @@ -109,7 +115,7 @@ resource "null_resource" "start-full-nodes" { # copy node keys file provisioner "file" { - source = "./full_node_keys.txt" + source = "./rpc_squid_node_keys.txt" destination = "/home/${var.ssh_user}/subspace/node_keys.txt" } @@ -125,9 +131,15 @@ resource "null_resource" "start-full-nodes" { destination = "/home/${var.ssh_user}/subspace/dsn_bootstrap_node_keys.txt" } + # copy keystore + provisioner "file" { + source = "./keystore" + destination = "/home/${var.ssh_user}/subspace/keystore/" + } + # copy compose file creation script provisioner "file" { - source = "${var.path_to_scripts}/create_full_node_compose_file.sh" + source = "${var.path_to_scripts}/create_rpc_squid_node_compose_file.sh" destination = "/home/${var.ssh_user}/subspace/create_compose_file.sh" } @@ -136,22 +148,24 @@ resource "null_resource" "start-full-nodes" { inline = [ # stop any running service "sudo docker compose -f /home/${var.ssh_user}/subspace/docker-compose.yml down ", + # set hostname - "sudo hostnamectl set-hostname ${var.network_name}-full-node-${count.index}", + "sudo hostnamectl set-hostname ${var.network_name}-rpc-squid-node-${count.index}", # create .env file - "echo NODE_ORG=${var.full-node-config.docker-org} > /home/${var.ssh_user}/subspace/.env", - "echo NODE_TAG=${var.full-node-config.docker-tag} >> /home/${var.ssh_user}/subspace/.env", + "echo NODE_ORG=${var.rpc-squid-node-config.docker-org} > /home/${var.ssh_user}/subspace/.env", + "echo NODE_TAG=${var.rpc-squid-node-config.docker-tag} >> /home/${var.ssh_user}/subspace/.env", "echo NETWORK_NAME=${var.network_name} >> /home/${var.ssh_user}/subspace/.env", + "echo DOMAIN_PREFIX=${var.rpc-squid-node-config.domain-prefix} >> /home/${var.ssh_user}/subspace/.env", "echo NODE_ID=${count.index} >> /home/${var.ssh_user}/subspace/.env", "echo NODE_KEY=$(sed -nr 's/NODE_${count.index}_KEY=//p' /home/${var.ssh_user}/subspace/node_keys.txt) >> /home/${var.ssh_user}/subspace/.env", "echo NR_API_KEY=${var.nr_api_key} >> /home/${var.ssh_user}/subspace/.env", "echo PIECE_CACHE_SIZE=${var.piece_cache_size} >> /home/${var.ssh_user}/subspace/.env", - "echo NODE_DSN_PORT=${var.full-node-config.node-dsn-port} >> /home/${var.ssh_user}/subspace/.env", + "echo NODE_DSN_PORT=${var.rpc-squid-node-config.node-dsn-port} >> /home/${var.ssh_user}/subspace/.env", "echo POT_EXTERNAL_ENTROPY=${var.pot_external_entropy} >> /home/${var.ssh_user}/subspace/.env", # create docker compose file - "bash /home/${var.ssh_user}/subspace/create_compose_file.sh ${var.bootstrap-node-config.reserved-only} ${length(local.full_nodes_ip_v4)} ${count.index} ${length(local.bootstrap_nodes_ip_v4)}", + "bash /home/${var.ssh_user}/subspace/create_compose_file.sh ${var.bootstrap-node-config.reserved-only} ${length(local.rpc_squid_nodes_ip_v4)} ${count.index} ${length(local.bootstrap_nodes_ip_v4)}", # start subspace node "sudo docker compose -f /home/${var.ssh_user}/subspace/docker-compose.yml up -d", diff --git a/templates/terraform/network-primitives/variables.tf b/templates/terraform/network-primitives/variables.tf index 8ca2a4df..a66566ee 100644 --- a/templates/terraform/network-primitives/variables.tf +++ b/templates/terraform/network-primitives/variables.tf @@ -13,7 +13,7 @@ variable "cloudflare_email" { variable "cloudflare_api_token" { type = string description = "cloudflare api token" - sensitive = true + sensitive = true } variable "instance_type" { @@ -40,7 +40,8 @@ variable "instance_count" { bootstrap = 2 rpc = 2 domain = 2 - full = 1 + rpc-squid = 1 + nova-squid = 1 farmer = 1 evm_bootstrap = 1 } @@ -98,7 +99,7 @@ variable "piece_cache_size" { default = "1GiB" } -variable "full-node-config" { +variable "rpc-squid-node-config" { description = "Full node deployment config" type = object({ instance-type = string @@ -133,6 +134,24 @@ variable "rpc-node-config" { }) } +variable "rpc-squid-node-config" { + description = "RPC squid node deployment config" + type = object({ + instance-type = string + deployment-version = number + regions = list(string) + instance-count = number + docker-org = string + docker-tag = string + domain-prefix = string + reserved-only = bool + prune = bool + node-dsn-port = number + disk-volume-size = number + disk-volume-type = string + }) +} + variable "domain-node-config" { description = "Domain node deployment config" type = object({ @@ -154,6 +173,27 @@ variable "domain-node-config" { }) } +variable "nova-squid-node-config" { + description = "Nova squid node deployment config" + type = object({ + instance-type = string + deployment-version = number + regions = list(string) + instance-count = number + docker-org = string + docker-tag = string + domain-prefix = string + reserved-only = bool + prune = bool + node-dsn-port = number + enable-domains = bool + domain-id = list(number) + domain-labels = list(string) + disk-volume-size = number + disk-volume-type = string + }) +} + variable "bootstrap-node-config" { description = "Bootstrap node deployment config" type = object({