Add genesis import

This commit is contained in:
David Boreham 2023-08-22 15:20:41 -06:00
parent c2e006d0c3
commit 8b8e95d52f
4 changed files with 41 additions and 18 deletions

View File

@ -180,21 +180,33 @@ def setup(command_context: DeployCommandContext, parameters: LaconicStackSetupCo
print(f"Error: network directory {network_dir} doesn't exist") print(f"Error: network directory {network_dir} doesn't exist")
sys.exit(1) sys.exit(1)
# First look in the supplied gentx files for the other nodes' keys # In the CREATE phase, we are either a "coordinator" node, generating the genesis.json file ourselves
other_node_keys = _get_node_keys_from_gentx_files(options, parameters.gentx_file_list) # OR we are a "not-coordinator" node, consuming a genesis file we got from the coordinator node.
# Add those keys to our genesis, with balances we determine here (why?) if parameters.genesis_file:
for other_node_key in other_node_keys: # We got the genesis file from elsewhere
outputk, statusk = run_container_command( # Copy it into our network dir
command_context, "laconicd", f"laconicd add-genesis-account {other_node_key} 12900000000000000000000achk\ genesis_file_path = Path(parameters.genesis_file)
--home {laconicd_home_path_in_container} --keyring-backend test", mounts) if not os.path.exists(genesis_file_path):
print(f"Command output: {outputk}") print(f"Error: supplied genesis file: {parameters.genesis_file} does not exist.")
# Copy the gentx json files into our network dir sys.exit(1)
_copy_gentx_files(options, network_dir, parameters.gentx_file_list) copyfile(genesis_file_path, os.path.join(network_dir, "config", os.path.basename(genesis_file_path)))
# Now we can run collect-gentxs else:
# We're generating the genesis file
output1, status1 = run_container_command( # First look in the supplied gentx files for the other nodes' keys
command_context, "laconicd", f"laconicd collect-gentxs --home {laconicd_home_path_in_container}", mounts) other_node_keys = _get_node_keys_from_gentx_files(options, parameters.gentx_file_list)
print(f"Command output: {output1}") # 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} 12900000000000000000000achk\
--home {laconicd_home_path_in_container} --keyring-backend test", mounts)
print(f"Command output: {outputk}")
# Copy the gentx json files into our network dir
_copy_gentx_files(options, 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)
print(f"Command output: {output1}")
# In both cases we validate the genesis file now
output2, status1 = run_container_command( output2, status1 = run_container_command(
command_context, "laconicd", f"laconicd validate-genesis --home {laconicd_home_path_in_container}", mounts) command_context, "laconicd", f"laconicd validate-genesis --home {laconicd_home_path_in_container}", mounts)
print(f"Command output: {output2}") print(f"Command output: {output2}")

View File

@ -58,6 +58,7 @@ class LaconicStackSetupCommand:
join_network: bool join_network: bool
create_network: bool create_network: bool
gentx_file_list: str gentx_file_list: str
genesis_file: str
network_dir: str network_dir: str

View File

@ -258,14 +258,15 @@ def create(ctx, spec_file, deployment_dir):
@click.option("--chain-id", help="The new chain id") @click.option("--chain-id", help="The new chain id")
@click.option("--key-name", help="Name for new node key") @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-files", help="List of comma-delimited gentx filenames from 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("--initialize-network", is_flag=True, default=False, help="Initialize phase")
@click.option("--join-network", is_flag=True, default=False, help="Join phase") @click.option("--join-network", is_flag=True, default=False, help="Join phase")
@click.option("--create-network", is_flag=True, default=False, help="Create phase") @click.option("--create-network", is_flag=True, default=False, help="Create phase")
@click.option("--network-dir", required=True, help="Directory for network files") @click.option("--network-dir", required=True, help="Directory for network files")
@click.argument('extra_args', nargs=-1) @click.argument('extra_args', nargs=-1)
@click.pass_context @click.pass_context
def setup(ctx, node_moniker, chain_id, key_name, gentx_files, initialize_network, join_network, create_network, network_dir, def setup(ctx, node_moniker, chain_id, key_name, gentx_files, genesis_file, initialize_network, join_network, create_network,
extra_args): network_dir, extra_args):
parmeters = LaconicStackSetupCommand(chain_id, node_moniker, key_name, initialize_network, join_network, create_network, parmeters = LaconicStackSetupCommand(chain_id, node_moniker, key_name, initialize_network, join_network, create_network,
gentx_files, network_dir) gentx_files, genesis_file, network_dir)
call_stack_deploy_setup(ctx.obj, parmeters, extra_args) call_stack_deploy_setup(ctx.obj, parmeters, extra_args)

View File

@ -46,4 +46,13 @@ do
gentx_files+=${delimeter}${node_gentx_file} gentx_files+=${delimeter}${node_gentx_file}
delimeter="," delimeter=","
done done
# 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}
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++ ));
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}
done