From 046a6308ef46943d6a4994b24cd948461a662c2e Mon Sep 17 00:00:00 2001 From: David Boreham Date: Tue, 30 Jul 2024 06:48:53 -0600 Subject: [PATCH 1/5] Support laconicd2 in mainnet stack --- .../stacks/mainnet-laconic/deploy/commands.py | 18 +++++++++++------- .../test/run-mainnet-laconic-test.sh | 7 +++++-- stack_orchestrator/deploy/deploy_util.py | 2 +- tests/laconic-network/run-test.sh | 11 ++++++++++- 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/stack_orchestrator/data/stacks/mainnet-laconic/deploy/commands.py b/stack_orchestrator/data/stacks/mainnet-laconic/deploy/commands.py index 13309ac3..3c350e54 100644 --- a/stack_orchestrator/data/stacks/mainnet-laconic/deploy/commands.py +++ b/stack_orchestrator/data/stacks/mainnet-laconic/deploy/commands.py @@ -67,7 +67,8 @@ def _get_node_key_from_gentx(gentx_file_name: str): if gentx_file_path.exists(): with open(Path(gentx_file_name), "rb") as f: parsed_json = json.load(f) - return parsed_json['body']['messages'][0]['delegator_address'] + print(f"parsed_json: {parsed_json}") + return parsed_json['body']['messages'][0]['validator_address'] else: print(f"Error: gentx file: {gentx_file_name} does not exist") sys.exit(1) @@ -80,8 +81,10 @@ def _comma_delimited_to_list(list_str: str): def _get_node_keys_from_gentx_files(gentx_file_list: str): node_keys = [] gentx_files = _comma_delimited_to_list(gentx_file_list) + print(f"gentx_files: {gentx_files}") for gentx_file in gentx_files: node_key = _get_node_key_from_gentx(gentx_file) + print(f"node_key: {node_key}") if node_key: node_keys.append(node_key) return node_keys @@ -178,7 +181,7 @@ def setup(command_context: DeployCommandContext, parameters: LaconicStackSetupCo options = opts.o - currency = "stake" # Does this need to be a parameter? + currency = "photon" # Does this need to be a parameter? if options.debug: print(f"parameters: {parameters}") @@ -222,7 +225,7 @@ def setup(command_context: DeployCommandContext, parameters: LaconicStackSetupCo output2, status2 = run_container_command( command_context, "laconicd", - f"laconicd add-genesis-account {parameters.key_name} 12900000000000000000000{currency}\ + f"laconicd genesis add-genesis-account {parameters.key_name} 12900000000000000000000{currency}\ --home {laconicd_home_path_in_container} --keyring-backend test", mounts) if options.debug: @@ -230,7 +233,7 @@ def setup(command_context: DeployCommandContext, parameters: LaconicStackSetupCo output3, status3 = run_container_command( command_context, "laconicd", - f"laconicd gentx {parameters.key_name} 90000000000{currency} --home {laconicd_home_path_in_container}\ + f"laconicd genesis gentx {parameters.key_name} 90000000000{currency} --home {laconicd_home_path_in_container}\ --chain-id {chain_id} --keyring-backend test", mounts) if options.debug: @@ -265,9 +268,10 @@ def setup(command_context: DeployCommandContext, parameters: LaconicStackSetupCo # First look in the supplied gentx files for the other nodes' keys other_node_keys = _get_node_keys_from_gentx_files(parameters.gentx_file_list) # Add those keys to our genesis, with balances we determine here (why?) + print(f"other_node_keys: {other_node_keys}") for other_node_key in other_node_keys: outputk, statusk = run_container_command( - command_context, "laconicd", f"laconicd add-genesis-account {other_node_key} 12900000000000000000000{currency}\ + command_context, "laconicd", f"laconicd genesis add-genesis-account {other_node_key} 12900000000000000000000{currency}\ --home {laconicd_home_path_in_container} --keyring-backend test", mounts) if options.debug: print(f"Command output: {outputk}") @@ -275,7 +279,7 @@ def setup(command_context: DeployCommandContext, parameters: LaconicStackSetupCo _copy_gentx_files(network_dir, parameters.gentx_file_list) # Now we can run collect-gentxs output1, status1 = run_container_command( - command_context, "laconicd", f"laconicd collect-gentxs --home {laconicd_home_path_in_container}", mounts) + command_context, "laconicd", f"laconicd genesis collect-gentxs --home {laconicd_home_path_in_container}", mounts) if options.debug: print(f"Command output: {output1}") print(f"Generated genesis file, please copy to other nodes as required: \ @@ -284,7 +288,7 @@ def setup(command_context: DeployCommandContext, parameters: LaconicStackSetupCo _remove_persistent_peers(network_dir) # In both cases we validate the genesis file now output2, status1 = run_container_command( - command_context, "laconicd", f"laconicd validate-genesis --home {laconicd_home_path_in_container}", mounts) + command_context, "laconicd", f"laconicd genesis validate-genesis --home {laconicd_home_path_in_container}", mounts) print(f"validate-genesis result: {output2}") else: diff --git a/stack_orchestrator/data/stacks/mainnet-laconic/test/run-mainnet-laconic-test.sh b/stack_orchestrator/data/stacks/mainnet-laconic/test/run-mainnet-laconic-test.sh index 3e25f5dc..1b714f73 100755 --- a/stack_orchestrator/data/stacks/mainnet-laconic/test/run-mainnet-laconic-test.sh +++ b/stack_orchestrator/data/stacks/mainnet-laconic/test/run-mainnet-laconic-test.sh @@ -8,8 +8,11 @@ echo "Environment variables:" env # Test laconic stack echo "Running laconic stack test" -# Bit of a hack, test the most recent package -TEST_TARGET_SO=$( ls -t1 ./package/laconic-so* | head -1 ) +if [ "$1" == "from-path" ]; then + TEST_TARGET_SO="laconic-so" +else + TEST_TARGET_SO=$( ls -t1 ./package/laconic-so* | head -1 ) +fi # Set a non-default repo dir export CERC_REPO_BASE_DIR=~/stack-orchestrator-test/repo-base-dir echo "Testing this package: $TEST_TARGET_SO" diff --git a/stack_orchestrator/deploy/deploy_util.py b/stack_orchestrator/deploy/deploy_util.py index 9ee09619..8b910d7b 100644 --- a/stack_orchestrator/deploy/deploy_util.py +++ b/stack_orchestrator/deploy/deploy_util.py @@ -83,7 +83,7 @@ def run_container_command(ctx: DeployCommandContext, service: str, command: str, docker_output = deployer.run( container_image, ["-c", command], entrypoint="sh", - user=f"{os.getuid()}:{os.getgid()}", + # user=f"{os.getuid()}:{os.getgid()}", volumes=docker_volumes ) # There doesn't seem to be a way to get an exit code from docker.run() diff --git a/tests/laconic-network/run-test.sh b/tests/laconic-network/run-test.sh index 019121a1..fd58ca72 100755 --- a/tests/laconic-network/run-test.sh +++ b/tests/laconic-network/run-test.sh @@ -4,6 +4,10 @@ if [ -n "$CERC_SCRIPT_DEBUG" ]; then set -x fi +set_ownership () { + sudo chown $USER: -R $1 +} + node_count=4 node_dir_prefix="laconic-network-dir" chain_id="laconic_81337-6" @@ -15,7 +19,7 @@ do node_network_dir=${node_dir_prefix}${i} if [[ -d $node_network_dir ]]; then echo "Deleting ${node_network_dir}" - rm -rf ${node_network_dir} + sudo rm -rf ${node_network_dir} fi done echo "Deleting any existing deployments..." @@ -39,6 +43,7 @@ do node_network_dir=${node_dir_prefix}${i} node_moniker=${node_moniker_prefix}${i} laconic-so --stack mainnet-laconic deploy setup --network-dir ${node_network_dir} --initialize-network --chain-id ${chain_id} --node-moniker ${node_moniker} + set_ownership ${node_network_dir} done echo "Joining ${node_count} nodes to the network..." @@ -47,6 +52,7 @@ do node_network_dir=${node_dir_prefix}${i} node_moniker=${node_moniker_prefix}${i} laconic-so --stack mainnet-laconic deploy setup --network-dir ${node_network_dir} --join-network --key-name ${node_moniker} + set_ownership ${node_network_dir} done echo "Merging ${node_count} nodes genesis txns..." @@ -60,6 +66,8 @@ do gentx_files+=${delimeter}${node_gentx_file} delimeter="," done +echo "gentx files:" +echo ${gentx_files} # Generate the genesis file on node 1 laconic-so --stack mainnet-laconic deploy setup --network-dir ${node_dir_prefix}1 --create-network --gentx-files ${gentx_files} genesis_file=${node_dir_prefix}1/config/genesis.json @@ -69,6 +77,7 @@ do echo "Importing genesis.json into node ${i}" node_network_dir=${node_dir_prefix}${i} laconic-so --stack mainnet-laconic deploy setup --network-dir ${node_network_dir} --create-network --genesis-file ${genesis_file} + set_ownership ${node_network_dir} done # Create deployments -- 2.45.2 From adb012f51f79d369392999db92c6a67f32b4fbc3 Mon Sep 17 00:00:00 2001 From: David Boreham Date: Tue, 30 Jul 2024 07:19:56 -0600 Subject: [PATCH 2/5] Pass in peer validator addresses --- .../stacks/mainnet-laconic/deploy/commands.py | 19 +++++++------------ stack_orchestrator/deploy/deploy_types.py | 1 + .../deploy/deployment_create.py | 5 +++-- tests/laconic-network/run-test.sh | 4 +++- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/stack_orchestrator/data/stacks/mainnet-laconic/deploy/commands.py b/stack_orchestrator/data/stacks/mainnet-laconic/deploy/commands.py index 3c350e54..e4838798 100644 --- a/stack_orchestrator/data/stacks/mainnet-laconic/deploy/commands.py +++ b/stack_orchestrator/data/stacks/mainnet-laconic/deploy/commands.py @@ -78,16 +78,11 @@ def _comma_delimited_to_list(list_str: str): return list_str.split(",") if list_str else [] -def _get_node_keys_from_gentx_files(gentx_file_list: str): +def _get_node_keys_from_gentx_files(gentx_address_list: str): node_keys = [] - gentx_files = _comma_delimited_to_list(gentx_file_list) - print(f"gentx_files: {gentx_files}") - for gentx_file in gentx_files: - node_key = _get_node_key_from_gentx(gentx_file) - print(f"node_key: {node_key}") - if node_key: - node_keys.append(node_key) - return node_keys + gentx_addresses = _comma_delimited_to_list(gentx_address_list) + print(f"gentx_files: {gentx_addresses}") + return gentx_addresses def _copy_gentx_files(network_dir: Path, gentx_file_list: str): @@ -262,11 +257,11 @@ def setup(command_context: DeployCommandContext, parameters: LaconicStackSetupCo copyfile(genesis_file_path, os.path.join(network_dir, "config", os.path.basename(genesis_file_path))) else: # We're generating the genesis file - if not parameters.gentx_file_list: - print("Error: --gentx-files must be supplied") + if not (parameters.gentx_file_list and parameters.gentx_address_list) : + print("Error: --gentx-files and --gentx-addresses must be supplied") sys.exit(1) # First look in the supplied gentx files for the other nodes' keys - other_node_keys = _get_node_keys_from_gentx_files(parameters.gentx_file_list) + other_node_keys = _get_node_keys_from_gentx_files(parameters.gentx_address_list) # Add those keys to our genesis, with balances we determine here (why?) print(f"other_node_keys: {other_node_keys}") for other_node_key in other_node_keys: diff --git a/stack_orchestrator/deploy/deploy_types.py b/stack_orchestrator/deploy/deploy_types.py index f97b2649..2ecf07aa 100644 --- a/stack_orchestrator/deploy/deploy_types.py +++ b/stack_orchestrator/deploy/deploy_types.py @@ -52,6 +52,7 @@ class LaconicStackSetupCommand: join_network: bool create_network: bool gentx_file_list: str + gentx_address_list: str genesis_file: str network_dir: str diff --git a/stack_orchestrator/deploy/deployment_create.py b/stack_orchestrator/deploy/deployment_create.py index 5f565854..a587e75a 100644 --- a/stack_orchestrator/deploy/deployment_create.py +++ b/stack_orchestrator/deploy/deployment_create.py @@ -535,6 +535,7 @@ def create_operation(deployment_command_context, spec_file, deployment_dir, netw @click.option("--chain-id", help="The new chain id") @click.option("--key-name", help="Name for new node key") @click.option("--gentx-files", help="List of comma-delimited gentx filenames from other nodes") +@click.option("--gentx-addresses", help="List of comma-delimited validator addresses for other nodes") @click.option("--genesis-file", help="Genesis file for the network") @click.option("--initialize-network", is_flag=True, default=False, help="Initialize phase") @click.option("--join-network", is_flag=True, default=False, help="Join phase") @@ -542,8 +543,8 @@ def create_operation(deployment_command_context, spec_file, deployment_dir, netw @click.option("--network-dir", help="Directory for network files") @click.argument('extra_args', nargs=-1) @click.pass_context -def setup(ctx, node_moniker, chain_id, key_name, gentx_files, genesis_file, initialize_network, join_network, create_network, +def setup(ctx, node_moniker, chain_id, key_name, gentx_files, gentx_addresses, genesis_file, initialize_network, join_network, create_network, network_dir, extra_args): parmeters = LaconicStackSetupCommand(chain_id, node_moniker, key_name, initialize_network, join_network, create_network, - gentx_files, genesis_file, network_dir) + gentx_files, gentx_addresses, genesis_file, network_dir) call_stack_deploy_setup(ctx.obj, parmeters, extra_args) diff --git a/tests/laconic-network/run-test.sh b/tests/laconic-network/run-test.sh index fd58ca72..47a8de03 100755 --- a/tests/laconic-network/run-test.sh +++ b/tests/laconic-network/run-test.sh @@ -63,13 +63,15 @@ for (( i=2 ; i<=$node_count ; i++ )); do node_network_dir=${node_dir_prefix}${i} node_gentx_file=$(ls ${node_network_dir}/config/gentx/*.json) + node_gentx_address=$(grep address ${node_network_dir}/config/genesis.json | head -1 | cut -d '"' -f 4) gentx_files+=${delimeter}${node_gentx_file} + gentx_addresses+=${delimeter}${node_gentx_address} delimeter="," done echo "gentx files:" echo ${gentx_files} # Generate the genesis file on node 1 -laconic-so --stack mainnet-laconic deploy setup --network-dir ${node_dir_prefix}1 --create-network --gentx-files ${gentx_files} +laconic-so --stack mainnet-laconic deploy setup --network-dir ${node_dir_prefix}1 --create-network --gentx-files ${gentx_files} --gentx-addresses ${gentx_addresses} genesis_file=${node_dir_prefix}1/config/genesis.json # Now import the genesis file to the other nodes for (( i=2 ; i<=$node_count ; i++ )); -- 2.45.2 From ad64ad8720476c099086bf06845411fec89710af Mon Sep 17 00:00:00 2001 From: David Boreham Date: Tue, 30 Jul 2024 07:29:49 -0600 Subject: [PATCH 3/5] Remove test code, lint fixes --- .../stacks/mainnet-laconic/deploy/commands.py | 19 ++----------------- stack_orchestrator/deploy/deploy_util.py | 1 - .../deploy/deployment_create.py | 4 ++-- 3 files changed, 4 insertions(+), 20 deletions(-) diff --git a/stack_orchestrator/data/stacks/mainnet-laconic/deploy/commands.py b/stack_orchestrator/data/stacks/mainnet-laconic/deploy/commands.py index e4838798..e4c48cc0 100644 --- a/stack_orchestrator/data/stacks/mainnet-laconic/deploy/commands.py +++ b/stack_orchestrator/data/stacks/mainnet-laconic/deploy/commands.py @@ -22,7 +22,6 @@ from stack_orchestrator.opts import opts from enum import Enum from pathlib import Path from shutil import copyfile, copytree -import json import os import sys import tomli @@ -62,26 +61,12 @@ def _get_node_moniker_from_config(network_dir: Path): return moniker -def _get_node_key_from_gentx(gentx_file_name: str): - gentx_file_path = Path(gentx_file_name) - if gentx_file_path.exists(): - with open(Path(gentx_file_name), "rb") as f: - parsed_json = json.load(f) - print(f"parsed_json: {parsed_json}") - return parsed_json['body']['messages'][0]['validator_address'] - else: - print(f"Error: gentx file: {gentx_file_name} does not exist") - sys.exit(1) - - def _comma_delimited_to_list(list_str: str): return list_str.split(",") if list_str else [] def _get_node_keys_from_gentx_files(gentx_address_list: str): - node_keys = [] gentx_addresses = _comma_delimited_to_list(gentx_address_list) - print(f"gentx_files: {gentx_addresses}") return gentx_addresses @@ -263,10 +248,10 @@ def setup(command_context: DeployCommandContext, parameters: LaconicStackSetupCo # First look in the supplied gentx files for the other nodes' keys other_node_keys = _get_node_keys_from_gentx_files(parameters.gentx_address_list) # Add those keys to our genesis, with balances we determine here (why?) - print(f"other_node_keys: {other_node_keys}") for other_node_key in other_node_keys: outputk, statusk = run_container_command( - command_context, "laconicd", f"laconicd genesis add-genesis-account {other_node_key} 12900000000000000000000{currency}\ + command_context, "laconicd", f"laconicd genesis add-genesis-account {other_node_key} \ + 12900000000000000000000{currency}\ --home {laconicd_home_path_in_container} --keyring-backend test", mounts) if options.debug: print(f"Command output: {outputk}") diff --git a/stack_orchestrator/deploy/deploy_util.py b/stack_orchestrator/deploy/deploy_util.py index 8b910d7b..3b8da913 100644 --- a/stack_orchestrator/deploy/deploy_util.py +++ b/stack_orchestrator/deploy/deploy_util.py @@ -13,7 +13,6 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -import os from typing import List, Any from stack_orchestrator.deploy.deploy_types import DeployCommandContext, VolumeMapping from stack_orchestrator.util import get_parsed_stack_config, get_yaml, get_pod_list, resolve_compose_file diff --git a/stack_orchestrator/deploy/deployment_create.py b/stack_orchestrator/deploy/deployment_create.py index a587e75a..fa00feea 100644 --- a/stack_orchestrator/deploy/deployment_create.py +++ b/stack_orchestrator/deploy/deployment_create.py @@ -543,8 +543,8 @@ def create_operation(deployment_command_context, spec_file, deployment_dir, netw @click.option("--network-dir", help="Directory for network files") @click.argument('extra_args', nargs=-1) @click.pass_context -def setup(ctx, node_moniker, chain_id, key_name, gentx_files, gentx_addresses, genesis_file, initialize_network, join_network, create_network, - network_dir, extra_args): +def setup(ctx, node_moniker, chain_id, key_name, gentx_files, gentx_addresses, genesis_file, initialize_network, join_network, + create_network, network_dir, extra_args): parmeters = LaconicStackSetupCommand(chain_id, node_moniker, key_name, initialize_network, join_network, create_network, gentx_files, gentx_addresses, genesis_file, network_dir) call_stack_deploy_setup(ctx.obj, parmeters, extra_args) -- 2.45.2 From c718f82d46c596d3881c0a8c78a7a8c68592e8d2 Mon Sep 17 00:00:00 2001 From: David Boreham Date: Tue, 30 Jul 2024 07:42:29 -0600 Subject: [PATCH 4/5] Change currency symbol --- .../data/stacks/mainnet-laconic/deploy/commands.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stack_orchestrator/data/stacks/mainnet-laconic/deploy/commands.py b/stack_orchestrator/data/stacks/mainnet-laconic/deploy/commands.py index e4c48cc0..f2cbe9a4 100644 --- a/stack_orchestrator/data/stacks/mainnet-laconic/deploy/commands.py +++ b/stack_orchestrator/data/stacks/mainnet-laconic/deploy/commands.py @@ -161,7 +161,7 @@ def setup(command_context: DeployCommandContext, parameters: LaconicStackSetupCo options = opts.o - currency = "photon" # Does this need to be a parameter? + currency = "alnt" # Does this need to be a parameter? if options.debug: print(f"parameters: {parameters}") -- 2.45.2 From a0bb90fd50527afb3ac4d680785ac7b7216ec0dd Mon Sep 17 00:00:00 2001 From: David Boreham Date: Wed, 31 Jul 2024 07:26:41 -0600 Subject: [PATCH 5/5] Add comment --- stack_orchestrator/deploy/deploy_util.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/stack_orchestrator/deploy/deploy_util.py b/stack_orchestrator/deploy/deploy_util.py index 3b8da913..9e204baa 100644 --- a/stack_orchestrator/deploy/deploy_util.py +++ b/stack_orchestrator/deploy/deploy_util.py @@ -82,6 +82,8 @@ def run_container_command(ctx: DeployCommandContext, service: str, command: str, docker_output = deployer.run( container_image, ["-c", command], entrypoint="sh", + # Current laconicd container has a bug where it crashes when run not as root + # Commented out line below is a workaround. Created files end up owned by root on the host # user=f"{os.getuid()}:{os.getgid()}", volumes=docker_volumes ) -- 2.45.2