diff --git a/Dockerfile-versioned b/Dockerfile-versioned new file mode 100644 index 0000000000..0ec85f149e --- /dev/null +++ b/Dockerfile-versioned @@ -0,0 +1,70 @@ +FROM golang:1.19-alpine + +ENV GOPATH /go +ENV GOOS=linux +ENV CGO_ENABLED=1 + +ARG old_version +ARG new_version + +RUN apk --no-cache add git make build-base jq openssh libusb-dev linux-headers bash curl tmux +RUN ssh-keygen -b 2048 -t rsa -f /root/.ssh/localtest.pem -q -N "" + +WORKDIR /go/delivery/zeta-node + +RUN mkdir -p $GOPATH/bin/old +RUN mkdir -p $GOPATH/bin/new + +ENV NEW_VERSION=${new_version} + +# Checkout and build new binary +RUN git clone https://github.com/zeta-chain/node.git +RUN cd node && git fetch +RUN cd node && git checkout ${new_version} +RUN cd node && make install +RUN cd node && make install-smoketest +RUN cp $GOPATH/bin/zetacored $GOPATH/bin/new/ +RUN cp $GOPATH/bin/zetaclientd $GOPATH/bin/new/ +RUN cp $GOPATH/bin/smoketest $GOPATH/bin/new/ + +# Checkout and build old binary +RUN cd node && git checkout ${old_version} +RUN cd node && git pull +RUN cd node && make install +RUN cd node && make install-smoketest +RUN cp $GOPATH/bin/zetacored $GOPATH/bin/old/ +RUN cp $GOPATH/bin/zetaclientd $GOPATH/bin/old/ +RUN cp $GOPATH/bin/smoketest $GOPATH/bin/old/ + +RUN git clone https://github.com/zeta-chain/cosmos-sdk.git +RUN cd cosmos-sdk && git checkout zetavisor-v0.1.5 +RUN cd cosmos-sdk/cosmovisor && make zetavisor +# +#FROM golang:1.19-alpine + +#RUN apk --no-cache add openssh jq tmux vim curl bash +RUN ssh-keygen -A +WORKDIR /root + +RUN cp /root/.ssh/localtest.pem.pub /root/.ssh/authorized_keys + +RUN cp /go/bin/zetaclientd /usr/local/bin +RUN cp /go/bin/zetacored /usr/local/bin +RUN cp /go/bin/smoketest /usr/local/bin +RUN cp /go/bin/zetavisor /usr/local/bin + +COPY contrib/localnet/scripts /root +COPY contrib/localnet/preparams /root/preparams +COPY contrib/localnet/ssh_config /root/.ssh/config +COPY contrib/localnet/zetacored /root/zetacored +COPY contrib/localnet/tss /root/tss + +RUN chmod 755 /root/*.sh +RUN chmod 700 /root/.ssh +RUN chmod 600 /root/.ssh/* + +WORKDIR /usr/local/bin +ENV SHELL /bin/sh +EXPOSE 22 + +ENTRYPOINT ["/usr/sbin/sshd", "-D"] diff --git a/Makefile b/Makefile index 063540ef86..f6333af275 100644 --- a/Makefile +++ b/Makefile @@ -217,4 +217,13 @@ stress-test: zetanode cd contrib/localnet/ && $(DOCKER) compose -f docker-compose-stresstest.yml up -d stop-stress-test: - cd contrib/localnet/ && $(DOCKER) compose -f docker-compose-stresstest.yml down --remove-orphans \ No newline at end of file + cd contrib/localnet/ && $(DOCKER) compose -f docker-compose-stresstest.yml down --remove-orphans + +stateful-upgrade: + @echo "--> Starting stateful smoketest" + $(DOCKER) build --build-arg old_version=v9.0.0-rc2 --build-arg new_version=v10.0.0 -t zetanode -f ./Dockerfile-versioned . + $(DOCKER) build -t orchestrator -f contrib/localnet/orchestrator/Dockerfile-upgrade.fastbuild . + cd contrib/localnet/ && $(DOCKER) compose -f docker-compose-stateful.yml up -d + +stop-stateful-upgrade: + cd contrib/localnet/ && $(DOCKER) compose -f docker-compose-stateful.yml down --remove-orphans \ No newline at end of file diff --git a/contrib/localnet/docker-compose-stateful.yml b/contrib/localnet/docker-compose-stateful.yml new file mode 100644 index 0000000000..d577d96b2d --- /dev/null +++ b/contrib/localnet/docker-compose-stateful.yml @@ -0,0 +1,109 @@ +version: "3" + +networks: + mynetwork: + ipam: + config: + - subnet: 172.20.0.0/24 + + +services: + zetacore0: + image: zetanode:latest + container_name: zetacore0 + build: + context: ../../. + dockerfile: Dockerfile + hostname: zetacore0 + ports: + - "1317:1317" + - "9545:8545" + - "9546:8546" + networks: + mynetwork: + ipv4_address: 172.20.0.11 + entrypoint: ["/root/genesis-stateful.sh", "2"] # Need to specify that there are 2 nodes + + + zetacore1: + image: zetanode:latest + container_name: zetacore1 + build: + context: ../../. + dockerfile: Dockerfile + hostname: zetacore1 + networks: + mynetwork: + ipv4_address: 172.20.0.12 + entrypoint: ["/root/genesis-stateful.sh", "2"] + + zetaclient0: + image: zetanode:latest + container_name: zetaclient0 + build: + context: ../../. + dockerfile: Dockerfile + hostname: zetaclient0 + networks: + mynetwork: + ipv4_address: 172.20.0.21 + entrypoint: /root/start-zetaclientd-background.sh + environment: + - ETHDEV_ENDPOINT=http://eth:8545 + + zetaclient1: + image: zetanode:latest + container_name: zetaclient1 + build: + context: ../../. + dockerfile: Dockerfile + hostname: zetaclient1 + networks: + mynetwork: + ipv4_address: 172.20.0.22 + entrypoint: /root/start-zetaclientd-background.sh + environment: + - ETHDEV_ENDPOINT=http://eth:8545 + + bitcoin: + image: ruimarinho/bitcoin-core:22 # version 23 is not working with btcd 0.22.0 due to change in createwallet rpc + container_name: bitcoin + hostname: bitcoin + networks: + mynetwork: + ipv4_address: 172.20.0.101 + ports: + - "18443:18443" + command: + -printtoconsole + -regtest=1 + -rpcallowip=172.20.0.0/16 + -rpcbind=0.0.0.0 + -rpcauth=smoketest:63acf9b8dccecce914d85ff8c044b78b$$5892f9bbc84f4364e79f0970039f88bdd823f168d4acc76099ab97b14a766a99 + -txindex=1 + + eth: + image: ethereum/client-go:v1.10.26 + container_name: eth + hostname: eth + ports: + - "8545:8545" + networks: + mynetwork: + ipv4_address: 172.20.0.100 + entrypoint: [ "geth", "--dev", "--http", "--http.addr", "172.20.0.100", "--http.vhosts", "*", "--http.api", "eth,web3,net", "--http.corsdomain", "https://remix.ethereum.org", "--dev.period", "2" ] + + orchestrator: + image: orchestrator:latest + container_name: orchestrator + build: + context: ../../. + dockerfile: contrib/localnet/orchestrator/Dockerfile + depends_on: + - zetacore0 + - eth + hostname: orchestrator + networks: + mynetwork: + ipv4_address: 172.20.0.2 + entrypoint: [ "/work/start-upgrade.sh", "local"] diff --git a/contrib/localnet/orchestrator/Dockerfile b/contrib/localnet/orchestrator/Dockerfile index 5e7c2013c9..e57670b3d6 100644 --- a/contrib/localnet/orchestrator/Dockerfile +++ b/contrib/localnet/orchestrator/Dockerfile @@ -2,7 +2,7 @@ FROM zetanode:latest as zeta FROM ethereum/client-go:v1.10.26 as geth FROM golang:1.20-alpine as orchestrator -RUN apk --no-cache add jq curl bash make git build-base +RUN apk --no-cache add jq curl bash make git build-base openssh COPY --from=zeta /usr/local/bin/zetacored /usr/local/bin/ COPY --from=zeta /usr/local/bin/zetaclientd /usr/local/bin/ @@ -12,7 +12,9 @@ COPY --from=zeta /root/.ssh/localtest.pem.pub /root/.ssh/authorized_keys COPY --from=zeta /root/.ssh/localtest.pem /root/.ssh/localtest.pem COPY contrib/localnet/orchestrator/start.sh /work/ -RUN chmod +x /work/start.sh +COPY contrib/localnet/orchestrator/start-upgrade.sh /work/ +COPY contrib/localnet/orchestrator/restart-zetaclientd.sh /work/ +RUN chmod +x /work/*.sh ENV GOPATH /go ENV GOOS=linux diff --git a/contrib/localnet/orchestrator/Dockerfile-upgrade.fastbuild b/contrib/localnet/orchestrator/Dockerfile-upgrade.fastbuild new file mode 100644 index 0000000000..3fb6b69e67 --- /dev/null +++ b/contrib/localnet/orchestrator/Dockerfile-upgrade.fastbuild @@ -0,0 +1,24 @@ +FROM zetanode:latest as zeta +FROM ethereum/client-go:v1.10.26 as geth +FROM golang:1.20-alpine as orchestrator + +RUN apk --no-cache add jq curl bash make git build-base openssh + +COPY --from=zeta /usr/local/bin/zetacored /usr/local/bin/ +COPY --from=zeta /usr/local/bin/zetaclientd /usr/local/bin/ +COPY --from=geth /usr/local/bin/geth /usr/local/bin/ + +COPY --from=zeta /root/.ssh/localtest.pem.pub /root/.ssh/authorized_keys +COPY --from=zeta /root/.ssh/localtest.pem /root/.ssh/localtest.pem + +COPY contrib/localnet/orchestrator/start.sh /work/ +COPY contrib/localnet/orchestrator/start-upgrade.sh /work/ +COPY contrib/localnet/orchestrator/restart-zetaclientd.sh /work/ +RUN chmod +x /work/*.sh + + +COPY --from=zeta /go/bin/old/smoketest /usr/local/bin/smoketest-old +COPY --from=zeta /go/bin/new/smoketest /usr/local/bin/smoketest-new +RUN chmod +x /usr/local/bin/smoketest-* + +WORKDIR /work diff --git a/contrib/localnet/orchestrator/Dockerfile.fastbuild b/contrib/localnet/orchestrator/Dockerfile.fastbuild index e4c4381be6..20cd3d1f56 100644 --- a/contrib/localnet/orchestrator/Dockerfile.fastbuild +++ b/contrib/localnet/orchestrator/Dockerfile.fastbuild @@ -18,4 +18,4 @@ RUN chmod +x /work/start.sh COPY --from=zeta /usr/local/bin/smoketest /usr/local/bin/ RUN chmod +x /usr/local/bin/smoketest -WORKDIR /work +WORKDIR /work \ No newline at end of file diff --git a/contrib/localnet/orchestrator/restart-zetaclientd.sh b/contrib/localnet/orchestrator/restart-zetaclientd.sh new file mode 100644 index 0000000000..d5f8b1becc --- /dev/null +++ b/contrib/localnet/orchestrator/restart-zetaclientd.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +clibuilder() +{ + echo "" + echo "Usage: $0 -u UPGRADE_HEIGHT" + echo -e "\t-u Height of upgrade, should match governance proposal" + echo -e "\t-n Number of clients in the network" + exit 1 # Exit script after printing help +} + +while getopts "u:n:" opt +do + case "$opt" in + u ) UPGRADE_HEIGHT="$OPTARG" ;; + n ) NUM_OF_NODES="$OPTARG" ;; + ? ) clibuilder ;; # Print cliBuilder in case parameter is non-existent + esac +done + +# generate client list +START=0 +END=$((NUM_OF_NODES-1)) +CLIENT_LIST=() +for i in $(eval echo "{$START..$END}") +do + CLIENT_LIST+=("zetaclient$i") +done + +echo "$UPGRADE_HEIGHT" + +CURRENT_HEIGHT=0 + +while [[ $CURRENT_HEIGHT -lt $UPGRADE_HEIGHT ]] +do + CURRENT_HEIGHT=$(curl zetacore0:26657/status | jq '.result.sync_info.latest_block_height' | tr -d '"') + sleep 5 +done + +echo current height is "$CURRENT_HEIGHT", restarting zetaclients +for NODE in "${CLIENT_LIST[@]}"; do + ssh -o "StrictHostKeyChecking no" "$NODE" -i ~/.ssh/localtest.pem killall zetaclientd + ssh -o "StrictHostKeyChecking no" "$NODE" -i ~/.ssh/localtest.pem "$GOPATH/bin/new/zetaclientd start < /dev/null > $HOME/zetaclient.log 2>&1 &" +done diff --git a/contrib/localnet/orchestrator/smoketest/main.go b/contrib/localnet/orchestrator/smoketest/main.go index 44607b3c22..95ee48389e 100644 --- a/contrib/localnet/orchestrator/smoketest/main.go +++ b/contrib/localnet/orchestrator/smoketest/main.go @@ -67,6 +67,7 @@ var LocalCmd = &cobra.Command{ type localArgs struct { contractsDeployed bool + waitForHeight int64 } var localTestArgs = localArgs{} @@ -74,6 +75,7 @@ var localTestArgs = localArgs{} func init() { RootCmd.AddCommand(LocalCmd) LocalCmd.Flags().BoolVar(&localTestArgs.contractsDeployed, "deployed", false, "set to to true if running smoketest again with existing state") + LocalCmd.Flags().Int64Var(&localTestArgs.waitForHeight, "wait-for", 0, "block height for smoketest to begin, ex. --wait-for 100") } func main() { @@ -94,6 +96,10 @@ func LocalSmokeTest(_ *cobra.Command, _ []string) { os.Exit(1) }() + if localTestArgs.waitForHeight != 0 { + WaitForBlockHeight(localTestArgs.waitForHeight) + } + // set account prefix to zeta cfg := sdk.GetConfig() cfg.SetBech32PrefixForAccount(app.Bech32PrefixAccAddr, app.Bech32PrefixAccPub) diff --git a/contrib/localnet/orchestrator/smoketest/test_deposit_eth.go b/contrib/localnet/orchestrator/smoketest/test_deposit_eth.go index 2a02176ada..5f390560e0 100644 --- a/contrib/localnet/orchestrator/smoketest/test_deposit_eth.go +++ b/contrib/localnet/orchestrator/smoketest/test_deposit_eth.go @@ -6,6 +6,8 @@ package main import ( "context" "fmt" + "github.com/zeta-chain/zetacore/common/ethereum" + observertypes "github.com/zeta-chain/zetacore/x/observer/types" "math/big" "time" @@ -15,9 +17,7 @@ import ( "github.com/ethereum/go-ethereum/crypto" zrc20 "github.com/zeta-chain/protocol-contracts/pkg/contracts/zevm/zrc20.sol" "github.com/zeta-chain/zetacore/common" - "github.com/zeta-chain/zetacore/common/ethereum" "github.com/zeta-chain/zetacore/x/crosschain/types" - observertypes "github.com/zeta-chain/zetacore/x/observer/types" "github.com/zeta-chain/zetacore/zetaclient" ) @@ -93,8 +93,8 @@ func (sm *SmokeTest) TestDepositEtherIntoZRC20() { BlockHash: blockHash.Bytes(), }) if err != nil { - fmt.Printf("WARN: block header not found; retrying...\n") - time.Sleep(2 * time.Second) + fmt.Printf("WARN: block header not found; retrying... error: %s \n", err.Error()) + time.Sleep(5 * time.Second) } else { fmt.Printf("OK: block header found\n") break diff --git a/contrib/localnet/orchestrator/smoketest/utils.go b/contrib/localnet/orchestrator/smoketest/utils.go index 7c4345f536..36afa0d364 100644 --- a/contrib/localnet/orchestrator/smoketest/utils.go +++ b/contrib/localnet/orchestrator/smoketest/utils.go @@ -8,6 +8,8 @@ import ( "encoding/hex" "errors" "fmt" + rpchttp "github.com/tendermint/tendermint/rpc/client/http" + coretypes "github.com/tendermint/tendermint/rpc/core/types" "sync" "time" @@ -113,3 +115,17 @@ func ScriptPKToAddress(scriptPKHex string) string { } return "" } + +func WaitForBlockHeight(height int64) { + // initialize rpc and check status + rpc, err := rpchttp.New("http://zetacore0:26657", "/websocket") + if err != nil { + panic(err) + } + status := &coretypes.ResultStatus{} + for status.SyncInfo.LatestBlockHeight < height { + status, _ = rpc.Status(context.Background()) + time.Sleep(time.Second * 5) + fmt.Printf("waiting for block: %d, current height: %d\n", height, status.SyncInfo.LatestBlockHeight) + } +} diff --git a/contrib/localnet/orchestrator/start-upgrade.sh b/contrib/localnet/orchestrator/start-upgrade.sh new file mode 100644 index 0000000000..b787a5b0da --- /dev/null +++ b/contrib/localnet/orchestrator/start-upgrade.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +SMOKETEST_CMD=$1 + +echo "waiting for geth RPC to start..." +sleep 6 +echo "funding deployer address 0xE5C5367B8224807Ac2207d350E60e1b6F27a7ecC with 100 Ether" +geth --exec 'eth.sendTransaction({from: eth.coinbase, to: "0xE5C5367B8224807Ac2207d350E60e1b6F27a7ecC", value: web3.toWei(100,"ether")})' attach http://eth:8545 +echo "funding TSS address 0xF421292cb0d3c97b90EEEADfcD660B893592c6A2 with 1 Ether" +geth --exec 'eth.sendTransaction({from: eth.coinbase, to: "0xF421292cb0d3c97b90EEEADfcD660B893592c6A2", value: web3.toWei(100,"ether")})' attach http://eth:8545 + +echo "waiting for 6s for the transaction to be mined" +sleep 6 +echo "the new balance of the deployer addrees:" +curl -sS http://eth:8545 \ + -X POST \ + -H "Content-Type: application/json" \ + --data '{"method":"eth_getBalance","params":["0xE5C5367B8224807Ac2207d350E60e1b6F27a7ecC", "latest"],"id":1,"jsonrpc":"2.0"}' +curl -sS http://eth:8545 \ + -X POST \ + -H "Content-Type: application/json" \ + --data '{"method":"eth_getBalance","params":["0xF421292cb0d3c97b90EEEADfcD660B893592c6A2", "latest"],"id":1,"jsonrpc":"2.0"}' +echo "running smoketest..." +smoketest-old "$SMOKETEST_CMD" +SMOKETEST_EXIT_CODE=$? +if [ $SMOKETEST_EXIT_CODE -ne 0 ]; then + echo "smoketest failed" + exit 1 +fi + +# Restart zetaclients at upgrade height +/work/restart-zetaclientd.sh -u 330 -n 2 + +smoketest-new "$SMOKETEST_CMD" --deployed --wait-for 335 + +if [ $SMOKETEST_EXIT_CODE -eq 0 ]; then + echo "smoketest passed" + exit 0 +else + echo "smoketest failed" + exit 1 +fi \ No newline at end of file diff --git a/contrib/localnet/scripts/genesis-stateful.sh b/contrib/localnet/scripts/genesis-stateful.sh new file mode 100755 index 0000000000..5f9f293f1b --- /dev/null +++ b/contrib/localnet/scripts/genesis-stateful.sh @@ -0,0 +1,185 @@ +#!/bin/bash + +/usr/sbin/sshd + +if [ $# -ne 1 ] +then + echo "Usage: genesis.sh " + exit 1 +fi +NUMOFNODES=$1 + +# create keys +CHAINID="athens_101-1" +KEYRING="test" +HOSTNAME=$(hostname) +INDEX=${HOSTNAME:0-1} + +export DAEMON_HOME=$HOME/.zetacored +export DAEMON_NAME=zetacored +export DAEMON_ALLOW_DOWNLOAD_BINARIES=true +export DAEMON_RESTART_AFTER_UPGRADE=true +export CLIENT_DAEMON_NAME=zetaclientd +export CLIENT_DAEMON_ARGS="-enable-chains,GOERLI,-val,operator" +export DAEMON_DATA_BACKUP_DIR=$DAEMON_HOME +export CLIENT_SKIP_UPGRADE=true +export CLIENT_START_PROCESS=false +export UNSAFE_SKIP_BACKUP=true +export UpgradeName=${NEW_VERSION} + +# generate node list +START=1 +# shellcheck disable=SC2100 +END=$((NUMOFNODES - 1)) +NODELIST=() +for i in $(eval echo "{$START..$END}") +do + NODELIST+=("zetacore$i") +done + +echo "HOSTNAME: $HOSTNAME" + +# 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 ~/os-info.sh + +# Pause other nodes so that the primary can node can do the genesis creation +if [ $HOSTNAME != "zetacore0" ] +then + echo "Waiting for zetacore0 to create genesis.json" + sleep $((7*NUMOFNODES)) + echo "genesis.json created" +fi + +# Genesis creation following steps +# 1. Accumulate all the os_info files from other nodes on zetcacore0 and create a genesis.json +# 2. Add the observers , authorizations and required params to the genesis.json +# 3. Copy the genesis.json to all the nodes .And use it to create a gentx for every node +# 4. Collect all the gentx files in zetacore0 and create the final genesis.json +# 5. Copy the final genesis.json to all the nodes and start the nodes +# 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" ] +then + # Misc : Copying the keyring to the client nodes so that they can sign the transactions + ssh zetaclient0 mkdir -p ~/.zetacored/keyring-test/ + scp ~/.zetacored/keyring-test/* zetaclient0:~/.zetacored/keyring-test/ + +# 1. Accumulate all the os_info files from other nodes on zetcacore0 and create a genesis.json + for NODE in "${NODELIST[@]}"; do + INDEX=${NODE:0-1} + ssh zetaclient"$INDEX" mkdir -p ~/.zetacored/ + scp "$NODE":~/.zetacored/os_info/os.json ~/.zetacored/os_info/os_z"$INDEX".json + scp ~/.zetacored/os_info/os_z"$INDEX".json zetaclient"$INDEX":~/.zetacored/os.json + done + + ssh zetaclient0 mkdir -p ~/.zetacored/ + scp ~/.zetacored/os_info/os.json zetaclient0:/root/.zetacored/os.json + +# 2. Add the observers , authorizations and required params to the genesis.json + zetacored collect-observer-info + zetacored add-observer-list + cat $HOME/.zetacored/config/genesis.json | jq '.app_state["staking"]["params"]["bond_denom"]="azeta"' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json + cat $HOME/.zetacored/config/genesis.json | jq '.app_state["crisis"]["constant_fee"]["denom"]="azeta"' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json + cat $HOME/.zetacored/config/genesis.json | jq '.app_state["gov"]["deposit_params"]["min_deposit"][0]["denom"]="azeta"' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json + cat $HOME/.zetacored/config/genesis.json | jq '.app_state["mint"]["params"]["mint_denom"]="azeta"' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json + cat $HOME/.zetacored/config/genesis.json | jq '.app_state["evm"]["params"]["evm_denom"]="azeta"' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json + cat $HOME/.zetacored/config/genesis.json | jq '.consensus_params["block"]["max_gas"]="500000000"' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json + cat $HOME/.zetacored/config/genesis.json | jq '.app_state["gov"]["voting_params"]["voting_period"]="100s"' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json + + # set fungible admin account as admin for fungible token + zetacored add-genesis-account zeta1srsq755t654agc0grpxj4y3w0znktrpr9tcdgk 100000000000000000000000000azeta + cat $HOME/.zetacored/config/genesis.json | jq '.app_state["observer"]["params"]["admin_policy"][2]["address"]="zeta1srsq755t654agc0grpxj4y3w0znktrpr9tcdgk"' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json + + +# 3. Copy the genesis.json to all the nodes .And use it to create a gentx for every node + zetacored gentx operator 1000000000000000000000azeta --chain-id=$CHAINID --keyring-backend=$KEYRING + # Copy host gentx to other nodes + for NODE in "${NODELIST[@]}"; do + ssh $NODE mkdir -p ~/.zetacored/config/gentx/peer/ + scp ~/.zetacored/config/gentx/* $NODE:~/.zetacored/config/gentx/peer/ + done + # Create gentx files on other nodes and copy them to host node + mkdir ~/.zetacored/config/gentx/z2gentx + for NODE in "${NODELIST[@]}"; do + ssh $NODE rm -rf ~/.zetacored/genesis.json + scp ~/.zetacored/config/genesis.json $NODE:~/.zetacored/config/genesis.json + ssh $NODE zetacored gentx operator 1000000000000000000000azeta --chain-id=$CHAINID --keyring-backend=$KEYRING + scp $NODE:~/.zetacored/config/gentx/* ~/.zetacored/config/gentx/ + scp $NODE:~/.zetacored/config/gentx/* ~/.zetacored/config/gentx/z2gentx/ + done + +# 4. Collect all the gentx files in zetacore0 and create the final genesis.json + zetacored collect-gentxs + zetacored validate-genesis +# 5. Copy the final genesis.json to all the nodes + for NODE in "${NODELIST[@]}"; do + ssh $NODE rm -rf ~/.zetacored/genesis.json + scp ~/.zetacored/config/genesis.json $NODE:~/.zetacored/config/genesis.json + done +# 6. Update Config in zetacore0 so that it has the correct persistent peer list + sleep 2 + pp=$(cat $HOME/.zetacored/config/gentx/z2gentx/*.json | jq '.body.memo' ) + pps=${pp:1:58} + sed -i -e "/persistent_peers =/s/=.*/= \"$pps\"/" "$HOME"/.zetacored/config/config.toml +fi +# End of genesis creation steps . The steps below are common to all the nodes + +# Update persistent peers +if [ $HOSTNAME != "zetacore0" ] +then + # Misc : Copying the keyring to the client nodes so that they can sign the transactions + ssh zetaclient"$INDEX" mkdir -p ~/.zetacored/keyring-test/ + scp ~/.zetacored/keyring-test/* "zetaclient$INDEX":~/.zetacored/keyring-test/ + + pp=$(cat $HOME/.zetacored/config/gentx/peer/*.json | jq '.body.memo' ) + pps=${pp:1:58} + sed -i -e "/persistent_peers =/s/=.*/= \"$pps\"/" "$HOME"/.zetacored/config/config.toml +fi + +mkdir -p $DAEMON_HOME/zetavisor/genesis/bin +mkdir -p $DAEMON_HOME/zetavisor/upgrades/"$UpgradeName"/bin + +# Setup zetavisor +# Genesis +cp $GOPATH/bin/old/zetacored $DAEMON_HOME/zetavisor/genesis/bin +cp $GOPATH/bin/zetaclientd $DAEMON_HOME/zetavisor/genesis/bin + +#Upgrades +cp $GOPATH/bin/new/zetacored $DAEMON_HOME/zetavisor/upgrades/$UpgradeName/bin/ + +#Permissions +chmod +x $DAEMON_HOME/zetavisor/genesis/bin/zetacored +chmod +x $DAEMON_HOME/zetavisor/genesis/bin/zetaclientd +chmod +x $DAEMON_HOME/zetavisor/upgrades/$UpgradeName/bin/zetacored + + +# 7 Start the nodes +zetavisor start --pruning=nothing --minimum-gas-prices=0.0001azeta --json-rpc.api eth,txpool,personal,net,debug,web3,miner --api.enable --home /root/.zetacored >> zetanode.log 2>&1 & +sleep 20 +echo + +if [ $HOSTNAME = "zetacore0" ] +then +/root/.zetacored/zetavisor/current/bin/zetacored tx gov submit-legacy-proposal software-upgrade $UpgradeName --from hotkey --deposit 100000000azeta --upgrade-height 320 --title $UpgradeName --description $UpgradeName --keyring-backend test --chain-id $CHAINID --yes --no-validate --fees=200azeta --broadcast-mode block +fi + +sleep 8 +/root/.zetacored/zetavisor/current/bin/zetacored tx gov vote 1 yes --from operator --keyring-backend test --chain-id $CHAINID --yes --fees=200azeta --broadcast-mode block +sleep 7 +/root/.zetacored/zetavisor/current/bin/zetacored query gov proposal 1 + +tail -f zetanode.log \ No newline at end of file diff --git a/contrib/localnet/scripts/start-zetaclientd-background.sh b/contrib/localnet/scripts/start-zetaclientd-background.sh new file mode 100644 index 0000000000..76726958cc --- /dev/null +++ b/contrib/localnet/scripts/start-zetaclientd-background.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +/usr/sbin/sshd + +HOSTNAME=$(hostname) + +cp /root/preparams/PreParams_$HOSTNAME.json /root/preParams.json +num=$(echo $HOSTNAME | tr -dc '0-9') +node="zetacore$num" +#mv /root/zetacored/zetacored_$node /root/.zetacored +#mv /root/tss/$HOSTNAME /root/.tss + +echo "Wait for zetacore to exchange genesis file" +sleep 30 +operator=$(cat $HOME/.zetacored/os.json | jq '.ObserverAddress' ) +operatorAddress=$(echo "$operator" | tr -d '"') +echo "operatorAddress: $operatorAddress" +echo "Start zetaclientd" +if [ $HOSTNAME == "zetaclient0" ] +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" + zetaclientd start > $HOME/zetaclient.log 2>&1 & +else + num=$(echo $HOSTNAME | tr -dc '0-9') + node="zetacore$num" + MYIP=$(/sbin/ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1) + SEED=$(curl --retry 10 --retry-delay 5 --retry-connrefused -s zetaclient0:8123/p2p) + rm ~/.tss/* + zetaclientd init --peer /ip4/172.20.0.21/tcp/6668/p2p/"$SEED" --zetacore-url "$node" --chain-id athens_101-1 --operator "$operatorAddress" --log-format=text --public-ip "$MYIP" --log-level 0 + zetaclientd start > $HOME/zetaclient.log 2>&1 & +fi + +sleep 3 +tail -f $HOME/zetaclient.log \ No newline at end of file diff --git a/standalone-network/upgrade-integration.sh b/standalone-network/upgrade-integration.sh index 4bf9571307..9d421eeaec 100755 --- a/standalone-network/upgrade-integration.sh +++ b/standalone-network/upgrade-integration.sh @@ -117,4 +117,3 @@ sleep 7 zetacored query gov proposal 1 tail -f zetanode.log -