Skip to content

Commit

Permalink
feat: enable restarting localnet containers (#2239)
Browse files Browse the repository at this point in the history
  • Loading branch information
gartnera authored May 23, 2024
1 parent b58816e commit 803658d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 33 deletions.
4 changes: 2 additions & 2 deletions contrib/localnet/docker-compose-upgrade.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ services:
image: zetanode:old

zetaclient0:
entrypoint: ["/root/start-zetaclientd.sh", "background"]
entrypoint: ["/root/start-zetaclientd.sh"]
image: zetanode:old

zetaclient1:
entrypoint: ["/root/start-zetaclientd.sh", "background"]
entrypoint: ["/root/start-zetaclientd.sh"]
image: zetanode:old

orchestrator:
Expand Down
20 changes: 7 additions & 13 deletions contrib/localnet/scripts/start-zetaclientd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,22 @@ operator=$(cat $HOME/.zetacored/os.json | jq '.ObserverAddress' )
operatorAddress=$(echo "$operator" | tr -d '"')
echo "operatorAddress: $operatorAddress"
echo "Start zetaclientd"
if [ $HOSTNAME == "zetaclient0" ]
# skip initialization if the config file already exists (zetaclientd init has already been run)
if [[ $HOSTNAME == "zetaclient0" && ! -f ~/.zetacored/config/zetaclient_config.json ]]
then
rm ~/.tss/*
MYIP=$(/sbin/ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1)
zetaclientd init --zetacore-url zetacore0 --chain-id athens_101-1 --operator "$operatorAddress" --log-format=text --public-ip "$MYIP" --keyring-backend "$BACKEND"

# check if the option is additional-evm
# in this case, the additional evm is represented with the sepolia chain, we set manually the eth2 endpoint to the sepolia chain (11155111 -> http://eth2:8545)
# in this case, the additional evm is represented with the sepolia chain, we set manually the eth2 endpoint to the sepolia chain (11155111 -> http://eth2:8545)
# in /root/.zetacored/config/zetaclient_config.json
if [ "$OPTION" == "additional-evm" ]; then
set_sepolia_endpoint
fi

zetaclientd-supervisor start < /root/password.file
else
fi
if [[ $HOSTNAME != "zetaclient0" && ! -f ~/.zetacored/config/zetaclient_config.json ]]
then
num=$(echo $HOSTNAME | tr -dc '0-9')
node="zetacore$num"
MYIP=$(/sbin/ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1)
Expand All @@ -71,13 +72,6 @@ else
if [ "$OPTION" == "additional-evm" ]; then
set_sepolia_endpoint
fi

zetaclientd-supervisor start < /root/password.file
fi

# check if the option is background
# in this case, we tail the zetaclientd log file
if [ "$OPTION" == "background" ]; then
sleep 3
tail -f $HOME/zetaclient.log
fi
zetaclientd-supervisor start < /root/password.file
43 changes: 25 additions & 18 deletions contrib/localnet/scripts/start-zetacored.sh
Original file line number Diff line number Diff line change
Expand Up @@ -121,20 +121,24 @@ while [ ! -f ~/.ssh/authorized_keys ]; do
sleep 1
done

# Init a new node to generate genesis file .
# Copy config files from existing folders which get copied via Docker Copy when building images
mkdir -p ~/.backup/config
zetacored init Zetanode-Localnet --chain-id=$CHAINID
rm -rf ~/.zetacored/config/app.toml
rm -rf ~/.zetacored/config/client.toml
rm -rf ~/.zetacored/config/config.toml
cp -r ~/zetacored/common/app.toml ~/.zetacored/config/
cp -r ~/zetacored/common/client.toml ~/.zetacored/config/
cp -r ~/zetacored/common/config.toml ~/.zetacored/config/
sed -i -e "/moniker =/s/=.*/= \"$HOSTNAME\"/" "$HOME"/.zetacored/config/config.toml
# Skip init if it has already been completed (marked by presence of ~/.zetacored/init_complete file)
if [[ ! -f ~/.zetacored/init_complete ]]
then
# Init a new node to generate genesis file .
# Copy config files from existing folders which get copied via Docker Copy when building images
mkdir -p ~/.backup/config
zetacored init Zetanode-Localnet --chain-id=$CHAINID
rm -rf ~/.zetacored/config/app.toml
rm -rf ~/.zetacored/config/client.toml
rm -rf ~/.zetacored/config/config.toml
cp -r ~/zetacored/common/app.toml ~/.zetacored/config/
cp -r ~/zetacored/common/client.toml ~/.zetacored/config/
cp -r ~/zetacored/common/config.toml ~/.zetacored/config/
sed -i -e "/moniker =/s/=.*/= \"$HOSTNAME\"/" "$HOME"/.zetacored/config/config.toml

# Add two new keys for operator and hotkey and create the required json structure for os_info
source ~/add-keys.sh
# Add two new keys for operator and hotkey and create the required json structure for os_info
source ~/add-keys.sh
fi

# Pause other nodes so that the primary can node can do the genesis creation
if [ $HOSTNAME != "zetacore0" ]
Expand All @@ -143,8 +147,7 @@ then
echo "Waiting for genesis.json file to exist..."
sleep 1
done
# need to wait for zetacore0 to be up otherwise you get
#
# need to wait for zetacore0 to be up
while ! curl -s -o /dev/null zetacore0:26657/status ; do
echo "Waiting for zetacore0 rpc"
sleep 1
Expand All @@ -160,8 +163,9 @@ fi
# 6. Update Config in zetacore0 so that it has the correct persistent peer list
# 7. Start the nodes

# Start of genesis creation . This is done only on zetacore0
if [ $HOSTNAME == "zetacore0" ]
# Start of genesis creation . This is done only on zetacore0.
# Skip genesis if it has already been completed (marked by presence of ~/.zetacored/init_complete file)
if [[ $HOSTNAME == "zetacore0" && ! -f ~/.zetacored/init_complete ]]
then
# Misc : Copying the keyring to the client nodes so that they can sign the transactions
ssh zetaclient0 mkdir -p ~/.zetacored/keyring-test/
Expand Down Expand Up @@ -266,7 +270,7 @@ fi
# End of genesis creation steps . The steps below are common to all the nodes

# Update persistent peers
if [ $HOSTNAME != "zetacore0" ]
if [[ $HOSTNAME != "zetacore0" && ! -f ~/.zetacored/init_complete ]]
then
# Misc : Copying the keyring to the client nodes so that they can sign the transactions
ssh zetaclient"$INDEX" mkdir -p ~/.zetacored/keyring-test/
Expand All @@ -279,4 +283,7 @@ then
sed -i -e "/persistent_peers =/s/=.*/= \"$pps\"/" "$HOME"/.zetacored/config/config.toml
fi

# mark init completed so we skip it if container is restarted
touch ~/.zetacored/init_complete

cosmovisor run start --pruning=nothing --minimum-gas-prices=0.0001azeta --json-rpc.api eth,txpool,personal,net,debug,web3,miner --api.enable --home /root/.zetacored

0 comments on commit 803658d

Please sign in to comment.