From 9ae14e0d4e7088255fa66522d856a856d4f2ac78 Mon Sep 17 00:00:00 2001 From: Lior Bondarevsky Date: Mon, 1 May 2023 08:24:01 +0300 Subject: [PATCH 1/2] Upgrade test instructions for version 1.9 --- docs/docker-compose-19-testnet.yml | 58 +++++++ docs/docker-compose-19.yml | 58 +++++++ docs/test-v1.9-upgrade-handler-testnet.md | 185 ++++++++++++++++++++++ docs/test-v1.9-upgrade-handler.md | 185 ++++++++++++++++++++++ 4 files changed, 486 insertions(+) create mode 100644 docs/docker-compose-19-testnet.yml create mode 100644 docs/docker-compose-19.yml create mode 100644 docs/test-v1.9-upgrade-handler-testnet.md create mode 100644 docs/test-v1.9-upgrade-handler.md diff --git a/docs/docker-compose-19-testnet.yml b/docs/docker-compose-19-testnet.yml new file mode 100644 index 000000000..72f99086f --- /dev/null +++ b/docs/docker-compose-19-testnet.yml @@ -0,0 +1,58 @@ +# docker compose file that sets up a network for beta testing + +version: "3" + +services: + bootstrap: + image: ghcr.io/scrtlabs/localsecret:v!.!.! + container_name: bootstrap + volumes: + - /tmp/secretd:/root/.secretd + - /tmp/secretcli:/root/.secretcli + stdin_open: true + tty: true + environment: + - http_proxy + - https_proxy + - SECRET_NODE_TYPE=BOOTSTRAP + - LOG_LEVEL=trace + - CHAINID=secretdev-1 + - SGX_MODE=SW + expose: + - 26656 + - 26657 + ports: + - "5000:5000" + entrypoint: /bin/bash + + node: + image: ghcr.io/scrtlabs/localsecret:v!.!.! + container_name: node + depends_on: + - bootstrap + volumes: + - /tmp/secretd:/tmp/.secretd + - /tmp/secretcli:/root/.secretcli + stdin_open: true + tty: true + ports: + - "1317:1317" + - "9091:9091" + environment: + - http_proxy + - https_proxy + - SECRET_NODE_TYPE=node + - LOG_LEVEL=trace + - CHAINID=secretdev-1 + - RPC_URL=bootstrap:26657 + - PERSISTENT_PEERS=115aa0a629f5d70dd1d464bc7e42799e00f4edae@bootstrap:26656 + - FAUCET_URL=bootstrap:5000 + - SCRT_SGX_STORAGE=/root + - SGX_MODE=SW + entrypoint: /bin/bash + deploy: + restart_policy: + condition: on-failure + delay: 10s + max_attempts: 10 + window: 123s diff --git a/docs/docker-compose-19.yml b/docs/docker-compose-19.yml new file mode 100644 index 000000000..9372db7e6 --- /dev/null +++ b/docs/docker-compose-19.yml @@ -0,0 +1,58 @@ +# docker compose file that sets up a network for beta testing + +version: "3" + +services: + bootstrap: + image: ghcr.io/scrtlabs/localsecret:v1.8.0 + container_name: bootstrap + volumes: + - /tmp/secretd:/root/.secretd + - /tmp/secretcli:/root/.secretcli + stdin_open: true + tty: true + environment: + - http_proxy + - https_proxy + - SECRET_NODE_TYPE=BOOTSTRAP + - LOG_LEVEL=trace + - CHAINID=secretdev-1 + - SGX_MODE=SW + expose: + - 26656 + - 26657 + ports: + - "5000:5000" + entrypoint: /bin/bash + + node: + image: ghcr.io/scrtlabs/localsecret:v1.8.0 + container_name: node + depends_on: + - bootstrap + volumes: + - /tmp/secretd:/tmp/.secretd + - /tmp/secretcli:/root/.secretcli + stdin_open: true + tty: true + ports: + - "1317:1317" + - "9091:9091" + environment: + - http_proxy + - https_proxy + - SECRET_NODE_TYPE=node + - LOG_LEVEL=trace + - CHAINID=secretdev-1 + - RPC_URL=bootstrap:26657 + - PERSISTENT_PEERS=115aa0a629f5d70dd1d464bc7e42799e00f4edae@bootstrap:26656 + - FAUCET_URL=bootstrap:5000 + - SCRT_SGX_STORAGE=/root + - SGX_MODE=SW + entrypoint: /bin/bash + deploy: + restart_policy: + condition: on-failure + delay: 10s + max_attempts: 10 + window: 123s diff --git a/docs/test-v1.9-upgrade-handler-testnet.md b/docs/test-v1.9-upgrade-handler-testnet.md new file mode 100644 index 000000000..0e152d019 --- /dev/null +++ b/docs/test-v1.9-upgrade-handler-testnet.md @@ -0,0 +1,185 @@ +# How to test the v1.9 upgrade with LocalSecret + +Always work in docs directory + +## Step 1 + +Start a v1.7.0-rc.2 chain. + +```bash + docker compose -f docker-compose-19-testnet.yml up -d + docker cp node_init.sh node:/root/ +``` + +On one terminal window: + +```bash +docker exec -it bootstrap bash +./bootstrap_init.sh +``` + +On another terminal window + +```bash +docker exec -it node bash +chmod 0777 node_init.sh +./node_init.sh +``` + +## Step 2 (Test basic contract) + +### Copy the suplied contract to the docker + +```bash +docker cp ./contract.wasm node:/root/ +``` + +### Access node docker + +```bash +docker exec -it node bash +``` + +### Instantiate a contract and interact with him + +```bash +secretd config node http://0.0.0.0:26657 +secretd tx compute store contract.wasm --from a --gas 5000000 -y +sleep 5 +INIT='{"counter":{"counter":10, "expires":100000}}' +secretd tx compute instantiate 1 "$INIT" --from a --label "c" -y +sleep 5 + +secretd tx compute execute secret18vd8fpwxzck93qlwghaj6arh4p7c5n8978vsyg '{"increment":{"addition": 13}}' --from a -y +sleep 5 +secretd query compute query secret18vd8fpwxzck93qlwghaj6arh4p7c5n8978vsyg '{"get": {}}' +``` + +Expected result should be: +{"get":{"count":23}} + +## Step 3 + +Run the secret.js tests from the `master` branch on the `secret.js` repo. +This will create state on the chain before the upgrade. + +First delete `globalSetup` & `globalTeardown` (because we already launched the chain manually): + +```bash +echo 'import { SecretNetworkClient } from "../src"; +import { sleep } from "./utils"; + +require("ts-node").register({ transpileOnly: true }); + +module.exports = async () => { + await waitForBlocks(); + console.log(`LocalSecret is running`); +}; + +async function waitForBlocks() { + while (true) { + const secretjs = new SecretNetworkClient({ + url: "http://localhost:1317", + chainId: "secretdev-1", + }); + + try { + const { block } = await secretjs.query.tendermint.getLatestBlock({}); + + if (Number(block?.header?.height) >= 1) { + break; + } + } catch (e) { + // console.eerror(e); + } + await sleep(250); + } +} +' > test/globalSetup.ts +``` + +```bash +echo '//@ts-ignore +require("ts-node").register({ transpileOnly: true }); + +module.exports = async () => {};' > test/globalTeardown.js +``` + +Then run the tests: + +```bash +yarn test +``` + +## Step 4 + +Propose a software upgrade on the v1.7 chain. + +```bash +# 30 blocks (3 minutes) until upgrade block +UPGRADE_BLOCK="$(docker exec node bash -c 'secretd status | jq "(.SyncInfo.latest_block_height | tonumber) + 30"')" + +# Propose upgrade +PROPOSAL_ID="$(docker exec node bash -c "secretd tx gov submit-proposal software-upgrade v1.9 --upgrade-height $UPGRADE_BLOCK --title blabla --description yolo --deposit 100000000uscrt --from a -y -b block | jq '.logs[0].events[] | select(.type == \"submit_proposal\") | .attributes[] | select(.key == \"proposal_id\") | .value | tonumber'")" + +# Vote yes (voting period is 90 seconds) +docker exec node bash -c "secretd tx gov vote ${PROPOSAL_ID} yes --from a -y -b block" + +echo "PROPOSAL_ID = ${PROPOSAL_ID}" +echo "UPGRADE_BLOCK = ${UPGRADE_BLOCK}" +``` + +## Step 5 + +Apply the upgrade. + +Wait until you see `ERR CONSENSUS FAILURE!!! err="UPGRADE \"v1.9\" NEEDED at height` in BOTH of the logs, then run: + +Copy binaries from v1.9 chain to v1.7 chain. + +```bash +FEATURES="verify-validator-whitelist,light-client-validation,random" SGX_MODE=SW make build-linux + +# Copy binaries from host to current v1.7 chain + +docker exec bootstrap bash -c 'rm -rf /tmp/upgrade-bin && mkdir -p /tmp/upgrade-bin' +docker exec node bash -c 'rm -rf /tmp/upgrade-bin && mkdir -p /tmp/upgrade-bin' + +docker cp secretd bootstrap:/tmp/upgrade-bin +docker cp go-cosmwasm/librust_cosmwasm_enclave.signed.so bootstrap:/tmp/upgrade-bin +docker cp go-cosmwasm/api/libgo_cosmwasm.so bootstrap:/tmp/upgrade-bin +docker cp secretd node:/tmp/upgrade-bin +docker cp go-cosmwasm/librust_cosmwasm_enclave.signed.so node:/tmp/upgrade-bin +docker cp go-cosmwasm/api/libgo_cosmwasm.so node:/tmp/upgrade-bin +docker cp docs/librandom_api.so node:/usr/lib +docker cp docs/tendermint_enclave.signed.so node:/usr/lib + +docker exec node bash -c 'pkill -9 secretd' + +docker exec bootstrap bash -c 'cat /tmp/upgrade-bin/librust_cosmwasm_enclave.signed.so > /usr/lib/librust_cosmwasm_enclave.signed.so' +docker exec bootstrap bash -c 'cat /tmp/upgrade-bin/libgo_cosmwasm.so > /usr/lib/libgo_cosmwasm.so' +docker exec node bash -c 'cat /tmp/upgrade-bin/secretd > /usr/bin/secretd' +docker exec node bash -c 'cat /tmp/upgrade-bin/librust_cosmwasm_enclave.signed.so > /usr/lib/librust_cosmwasm_enclave.signed.so' +docker exec node bash -c 'cat /tmp/upgrade-bin/libgo_cosmwasm.so > /usr/lib/libgo_cosmwasm.so' + + +rm -rf /tmp/upgrade-bin && mkdir -p /tmp/upgrade-bin +docker cp bootstrap:/root/.secretd/config/priv_validator_key.json /tmp/upgrade-bin/. +docker cp /tmp/upgrade-bin/priv_validator_key.json node:/root/.secretd/config/priv_validator_key.json + +source /opt/sgxsdk/environment && RUST_BACKTRACE=1 LOG_LEVEL="trace" secretd start --rpc.laddr tcp://0.0.0.0:26657 + +``` + +You should see `INF applying upgrade "v1.9" at height` in the logs, following by blocks continute to stream. + +## Test that the contract is still there + +### Query the value of the counter + +```bash +secretd query compute query secret18vd8fpwxzck93qlwghaj6arh4p7c5n8978vsyg '{"get": {}}' +``` + +Expected result should be: +{"get":{"count":23}} diff --git a/docs/test-v1.9-upgrade-handler.md b/docs/test-v1.9-upgrade-handler.md new file mode 100644 index 000000000..a8441be3f --- /dev/null +++ b/docs/test-v1.9-upgrade-handler.md @@ -0,0 +1,185 @@ +# How to test the v1.9 upgrade with LocalSecret + +Always work in docs directory + +## Step 1 + +Start a v1.8.0 chain. + +```bash + docker compose -f docker-compose-19.yml up -d + docker cp node_init.sh node:/root/ +``` + +On one terminal window: + +```bash +docker exec -it bootstrap bash +./bootstrap_init.sh +``` + +On another terminal window + +```bash +docker exec -it node bash +chmod 0777 node_init.sh +./node_init.sh +``` + +## Step 2 (Test basic contract) + +### Copy the suplied contract to the docker + +```bash +docker cp ./contract.wasm node:/root/ +``` + +### Access node docker + +```bash +docker exec -it node bash +``` + +### Instantiate a contract and interact with him + +```bash +secretd config node http://0.0.0.0:26657 +secretd tx compute store contract.wasm --from a --gas 5000000 -y +sleep 5 +INIT='{"counter":{"counter":10, "expires":100000}}' +secretd tx compute instantiate 1 "$INIT" --from a --label "c" -y +sleep 5 + +secretd tx compute execute secret18vd8fpwxzck93qlwghaj6arh4p7c5n8978vsyg '{"increment":{"addition": 13}}' --from a -y +sleep 5 +secretd query compute query secret18vd8fpwxzck93qlwghaj6arh4p7c5n8978vsyg '{"get": {}}' +``` + +Expected result should be: +{"get":{"count":23}} + +## Step 3 + +Run the secret.js tests from the `master` branch on the `secret.js` repo. +This will create state on the chain before the upgrade. + +First delete `globalSetup` & `globalTeardown` (because we already launched the chain manually): + +```bash +echo 'import { SecretNetworkClient } from "../src"; +import { sleep } from "./utils"; + +require("ts-node").register({ transpileOnly: true }); + +module.exports = async () => { + await waitForBlocks(); + console.log(`LocalSecret is running`); +}; + +async function waitForBlocks() { + while (true) { + const secretjs = new SecretNetworkClient({ + url: "http://localhost:1317", + chainId: "secretdev-1", + }); + + try { + const { block } = await secretjs.query.tendermint.getLatestBlock({}); + + if (Number(block?.header?.height) >= 1) { + break; + } + } catch (e) { + // console.eerror(e); + } + await sleep(250); + } +} +' > test/globalSetup.ts +``` + +```bash +echo '//@ts-ignore +require("ts-node").register({ transpileOnly: true }); + +module.exports = async () => {};' > test/globalTeardown.js +``` + +Then run the tests: + +```bash +yarn test +``` + +## Step 4 + +Propose a software upgrade on the v1.8 chain. + +```bash +# 30 blocks (3 minutes) until upgrade block +UPGRADE_BLOCK="$(docker exec node bash -c 'secretd status | jq "(.SyncInfo.latest_block_height | tonumber) + 30"')" + +# Propose upgrade +PROPOSAL_ID="$(docker exec node bash -c "secretd tx gov submit-proposal software-upgrade v1.9 --upgrade-height $UPGRADE_BLOCK --title blabla --description yolo --deposit 100000000uscrt --from a -y -b block | jq '.logs[0].events[] | select(.type == \"submit_proposal\") | .attributes[] | select(.key == \"proposal_id\") | .value | tonumber'")" + +# Vote yes (voting period is 90 seconds) +docker exec node bash -c "secretd tx gov vote ${PROPOSAL_ID} yes --from a -y -b block" + +echo "PROPOSAL_ID = ${PROPOSAL_ID}" +echo "UPGRADE_BLOCK = ${UPGRADE_BLOCK}" +``` + +## Step 5 + +Apply the upgrade. + +Wait until you see `ERR CONSENSUS FAILURE!!! err="UPGRADE \"v1.9\" NEEDED at height` in BOTH of the logs, then run: + +Copy binaries from v1.9 chain to v1.8 chain. + +```bash +FEATURES="verify-validator-whitelist,light-client-validation,random" SGX_MODE=SW make build-linux + +# Copy binaries from host to current v1.8 chain + +docker exec bootstrap bash -c 'rm -rf /tmp/upgrade-bin && mkdir -p /tmp/upgrade-bin' +docker exec node bash -c 'rm -rf /tmp/upgrade-bin && mkdir -p /tmp/upgrade-bin' + +docker cp secretd bootstrap:/tmp/upgrade-bin +docker cp go-cosmwasm/librust_cosmwasm_enclave.signed.so bootstrap:/tmp/upgrade-bin +docker cp go-cosmwasm/api/libgo_cosmwasm.so bootstrap:/tmp/upgrade-bin +docker cp secretd node:/tmp/upgrade-bin +docker cp go-cosmwasm/librust_cosmwasm_enclave.signed.so node:/tmp/upgrade-bin +docker cp go-cosmwasm/api/libgo_cosmwasm.so node:/tmp/upgrade-bin +docker cp docs/librandom_api.so node:/usr/lib +docker cp docs/tendermint_enclave.signed.so node:/usr/lib + +docker exec node bash -c 'pkill -9 secretd' + +docker exec bootstrap bash -c 'cat /tmp/upgrade-bin/librust_cosmwasm_enclave.signed.so > /usr/lib/librust_cosmwasm_enclave.signed.so' +docker exec bootstrap bash -c 'cat /tmp/upgrade-bin/libgo_cosmwasm.so > /usr/lib/libgo_cosmwasm.so' +docker exec node bash -c 'cat /tmp/upgrade-bin/secretd > /usr/bin/secretd' +docker exec node bash -c 'cat /tmp/upgrade-bin/librust_cosmwasm_enclave.signed.so > /usr/lib/librust_cosmwasm_enclave.signed.so' +docker exec node bash -c 'cat /tmp/upgrade-bin/libgo_cosmwasm.so > /usr/lib/libgo_cosmwasm.so' + + +rm -rf /tmp/upgrade-bin && mkdir -p /tmp/upgrade-bin +docker cp bootstrap:/root/.secretd/config/priv_validator_key.json /tmp/upgrade-bin/. +docker cp /tmp/upgrade-bin/priv_validator_key.json node:/root/.secretd/config/priv_validator_key.json + +source /opt/sgxsdk/environment && RUST_BACKTRACE=1 LOG_LEVEL="trace" secretd start --rpc.laddr tcp://0.0.0.0:26657 + +``` + +You should see `INF applying upgrade "v1.9" at height` in the logs, following by blocks continute to stream. + +## Test that the contract is still there + +### Query the value of the counter + +```bash +secretd query compute query secret18vd8fpwxzck93qlwghaj6arh4p7c5n8978vsyg '{"get": {}}' +``` + +Expected result should be: +{"get":{"count":23}} From 176db42076f36bc4ad6a5fd56f8dd441b9e28c38 Mon Sep 17 00:00:00 2001 From: liorbond Date: Mon, 1 May 2023 11:32:43 +0300 Subject: [PATCH 2/2] Update docker-compose-19-testnet.yml --- docs/docker-compose-19-testnet.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/docker-compose-19-testnet.yml b/docs/docker-compose-19-testnet.yml index 72f99086f..be15cf5bd 100644 --- a/docs/docker-compose-19-testnet.yml +++ b/docs/docker-compose-19-testnet.yml @@ -4,7 +4,7 @@ version: "3" services: bootstrap: - image: ghcr.io/scrtlabs/localsecret:v!.!.! + image: ghcr.io/scrtlabs/localsecret:v1.7.0-rc.2 container_name: bootstrap volumes: - /tmp/secretd:/root/.secretd @@ -26,7 +26,7 @@ services: entrypoint: /bin/bash node: - image: ghcr.io/scrtlabs/localsecret:v!.!.! + image: ghcr.io/scrtlabs/localsecret:v1.7.0-rc.2 container_name: node depends_on: - bootstrap