2024-07-08 12:22:16 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -e
|
|
|
|
if [ -n "$CERC_SCRIPT_DEBUG" ]; then
|
|
|
|
set -x
|
|
|
|
fi
|
|
|
|
|
2024-07-12 15:38:36 +00:00
|
|
|
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
|
|
|
|
source ${SCRIPT_DIR}/lib.sh
|
|
|
|
|
2024-07-08 12:22:16 +00:00
|
|
|
if [[ -n "$1" ]]; then
|
|
|
|
machine_name_prefix=$1
|
|
|
|
else
|
|
|
|
echo "Usage: $0 <machine-name-prefix>"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
gentx_dir=${node_network_dir}/config/gentx
|
2024-07-31 17:34:16 +00:00
|
|
|
genesis_json_file=${node_network_dir}/config/genesis.json
|
2024-07-08 12:22:16 +00:00
|
|
|
local_gentx_dir=gentx-${machine_name_prefix}
|
|
|
|
|
|
|
|
echo "Fetch node ids and node ips for persistent-peers"
|
|
|
|
for (( i=1 ; i<=$node_count ; i++ ));
|
|
|
|
do
|
|
|
|
node_name=${machine_name_prefix}-${i}
|
|
|
|
node_host_name=${node_name}.${machine_domain}
|
2024-07-13 18:51:40 +00:00
|
|
|
gentx_file_name=$(ssh ${ssh_user}@${node_host_name} ls /home/laconic/${gentx_dir} | head -1)
|
2024-07-08 12:22:16 +00:00
|
|
|
node_id=$(echo ${gentx_file_name} | sed -e 's/^gentx-//' -e 's/.json$//')
|
|
|
|
node_ip=$(dig +short ${node_host_name})
|
|
|
|
peer=${node_id}@${node_ip}:${p2p_port}
|
|
|
|
persistent_peers+=${peer}
|
|
|
|
if [[ ${i} -lt ${node_count} ]]; then
|
|
|
|
persistent_peers+=','
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
echo "Copying gentx from all nodes except 1"
|
|
|
|
rm -rf ${local_gentx_dir}
|
|
|
|
mkdir ${local_gentx_dir}
|
|
|
|
# Note: start at node 2 here because we're going to copy to node 1
|
|
|
|
for (( i=2 ; i<=$node_count ; i++ ));
|
|
|
|
do
|
|
|
|
node_name=${machine_name_prefix}-${i}
|
|
|
|
node_host_name=${node_name}.${machine_domain}
|
|
|
|
echo "Copying ${gentx_dir} on ${node_name} to ${local_gentx_dir}"
|
|
|
|
scp laconic@${node_host_name}:~/${gentx_dir}/* ${local_gentx_dir}
|
2024-07-31 17:34:16 +00:00
|
|
|
scp laconic@${node_host_name}:~/${genesis_json_file} ${local_gentx_dir}/${node_name}-genesis.json
|
|
|
|
done
|
|
|
|
|
|
|
|
# Extract the peer node validator addresses from their genesis.json files
|
|
|
|
gentx_addresses=""
|
|
|
|
for (( i=2 ; i<=$node_count ; i++ ));
|
|
|
|
do
|
|
|
|
node_name=${machine_name_prefix}-${i}
|
|
|
|
node_genesis_file=${local_gentx_dir}/${node_name}-genesis.json
|
|
|
|
node_gentx_address=$(grep address ${node_genesis_file} | head -1 | cut -d '"' -f 4)
|
|
|
|
gentx_addresses+=${delimeter}${node_gentx_address}
|
|
|
|
delimeter=","
|
2024-07-08 12:22:16 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
echo "Copying gentx files to node 1"
|
|
|
|
node_1_host_name=${machine_name_prefix}-1.${machine_domain}
|
2024-07-13 18:51:40 +00:00
|
|
|
ssh ${ssh_user}@${node_1_host_name} rm -rf ${local_gentx_dir}
|
|
|
|
ssh ${ssh_user}@${node_1_host_name} mkdir ${local_gentx_dir}
|
2024-07-31 17:34:16 +00:00
|
|
|
scp ${local_gentx_dir}/gentx-* laconic@${node_1_host_name}:~/${local_gentx_dir}
|
2024-07-08 12:22:16 +00:00
|
|
|
|
2024-07-31 17:34:16 +00:00
|
|
|
gentx_file_list=$(ssh laconic@${node_1_host_name} ls -m ${local_gentx_dir}/gentx-*)
|
2024-07-08 12:22:16 +00:00
|
|
|
echo "Node 1 now has: ${gentx_file_list}"
|
|
|
|
|
|
|
|
gentx_files=$(echo ${gentx_file_list} | tr -d ' ' | tr -d '\n')
|
|
|
|
|
|
|
|
echo "Generate genesis on node 1"
|
2024-07-31 17:34:16 +00:00
|
|
|
ssh ${ssh_user}@${node_1_host_name} ${so_command} --stack mainnet-laconic deploy setup --network-dir ${node_network_dir} --create-network --gentx-files ${gentx_files} --gentx-addresses ${gentx_addresses}
|
|
|
|
# Change file ownership in the network dir to work around root-only container issue
|
|
|
|
change_dir_ownership ${node_1_host_name} ${node_network_dir}
|
2024-07-08 12:22:16 +00:00
|
|
|
|
|
|
|
echo "Fetching genesis file from node 1"
|
|
|
|
local_genesis_file=${local_gentx_dir}/genesis.json
|
2024-07-13 18:51:40 +00:00
|
|
|
scp ${ssh_user}@${node_1_host_name}:~/${node_network_dir}/config/genesis.json ${local_gentx_dir}
|
2024-07-08 12:22:16 +00:00
|
|
|
|
|
|
|
echo "Copying genesis file to other nodes"
|
2024-07-31 17:34:16 +00:00
|
|
|
# Note: we should be using --create-network --genesis-file ${genesis_file} for this rather than copying directly into the network dir
|
2024-07-08 12:22:16 +00:00
|
|
|
# Note: start at node 2 here because we're going to copy to node 1
|
|
|
|
for (( i=2 ; i<=$node_count ; i++ ));
|
|
|
|
do
|
|
|
|
node_name=${machine_name_prefix}-${i}
|
|
|
|
node_host_name=${node_name}.${machine_domain}
|
|
|
|
echo "Copying ${local_genesis_file} to ${node_name} to ${node_name}"
|
2024-07-13 18:51:40 +00:00
|
|
|
scp ${local_genesis_file} ${ssh_user}@${node_host_name}:~/${node_network_dir}/config
|
2024-07-08 12:22:16 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
echo "Use this for persistent_peers:"
|
|
|
|
echo ${persistent_peers}
|
|
|
|
|