Mainnet-laconic stack fixes for laconicd2 (#904)
Some checks failed
Lint Checks / Run linter (push) Successful in 39s
Publish / Build and publish (push) Successful in 1m13s
Smoke Test / Run basic test suite (push) Successful in 4m7s
Webapp Test / Run webapp test suite (push) Successful in 4m35s
Deploy Test / Run deploy test suite (push) Successful in 4m58s
Fixturenet-Eth-Plugeth-Arm-Test / Run an Ethereum plugeth fixturenet test (push) Failing after 9m58s
Fixturenet-Eth-Plugeth-Test / Run an Ethereum plugeth fixturenet test (push) Failing after 10m55s
K8s Deploy Test / Run deploy test suite on kind/k8s (push) Successful in 7m44s
Database Test / Run database hosting test on kind/k8s (push) Successful in 9m15s
Container Registry Test / Run contaier registry hosting test on kind/k8s (push) Successful in 3m52s
External Stack Test / Run external stack test suite (push) Successful in 4m48s

Reviewed-on: #904
This commit is contained in:
David Boreham 2024-07-31 13:51:28 +00:00
parent 79c1c5ed99
commit 7d18334953
6 changed files with 39 additions and 38 deletions

View File

@ -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,29 +61,13 @@ 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)
return parsed_json['body']['messages'][0]['delegator_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_file_list: str):
node_keys = []
gentx_files = _comma_delimited_to_list(gentx_file_list)
for gentx_file in gentx_files:
node_key = _get_node_key_from_gentx(gentx_file)
if node_key:
node_keys.append(node_key)
return node_keys
def _get_node_keys_from_gentx_files(gentx_address_list: str):
gentx_addresses = _comma_delimited_to_list(gentx_address_list)
return gentx_addresses
def _copy_gentx_files(network_dir: Path, gentx_file_list: str):
@ -178,7 +161,7 @@ def setup(command_context: DeployCommandContext, parameters: LaconicStackSetupCo
options = opts.o
currency = "stake" # Does this need to be a parameter?
currency = "alnt" # Does this need to be a parameter?
if options.debug:
print(f"parameters: {parameters}")
@ -222,7 +205,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 +213,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:
@ -259,15 +242,16 @@ 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?)
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 +259,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 +268,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:

View File

@ -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"

View File

@ -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

View File

@ -13,7 +13,6 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http:#www.gnu.org/licenses/>.
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
@ -83,7 +82,9 @@ 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()}",
# 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
)
# There doesn't seem to be a way to get an exit code from docker.run()

View File

@ -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,
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, genesis_file, network_dir)
gentx_files, gentx_addresses, genesis_file, network_dir)
call_stack_deploy_setup(ctx.obj, parmeters, extra_args)

View File

@ -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..."
@ -57,11 +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++ ));
@ -69,6 +79,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