Skip to content

Commit 6e5f5c4

Browse files
authored
Merge pull request #1527 from scrtlabs/add-cli-for-migration
Add cli for migration
2 parents 3ba2ae3 + 6328635 commit 6e5f5c4

10 files changed

+294
-3
lines changed

docs/upgrades/1.11/contract.wasm

722 KB
Binary file not shown.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# docker compose file that sets up a network for beta testing
2+
3+
version: "3"
4+
5+
services:
6+
bootstrap:
7+
image: ghcr.io/scrtlabs/localsecret:v1.10.0
8+
container_name: bootstrap
9+
volumes:
10+
- /tmp/secretd:/root/.secretd
11+
- /tmp/secretcli:/root/.secretcli
12+
stdin_open: true
13+
tty: true
14+
environment:
15+
- http_proxy
16+
- https_proxy
17+
- SECRET_NODE_TYPE=BOOTSTRAP
18+
- LOG_LEVEL=trace
19+
- CHAINID=secretdev-1
20+
- SGX_MODE=SW
21+
expose:
22+
- 26656
23+
- 26657
24+
ports:
25+
- "5000:5000"
26+
entrypoint: /bin/bash
27+
28+
node:
29+
image: ghcr.io/scrtlabs/localsecret:v1.10.0
30+
container_name: node
31+
depends_on:
32+
- bootstrap
33+
volumes:
34+
- /tmp/secretd:/tmp/.secretd
35+
- /tmp/secretcli:/root/.secretcli
36+
stdin_open: true
37+
tty: true
38+
ports:
39+
- "1317:1317"
40+
- "9091:9091"
41+
environment:
42+
- http_proxy
43+
- https_proxy
44+
- SECRET_NODE_TYPE=node
45+
- LOG_LEVEL=trace
46+
- CHAINID=secretdev-1
47+
- RPC_URL=bootstrap:26657
48+
- PERSISTENT_PEERS=115aa0a629f5d70dd1d464bc7e42799e00f4edae@bootstrap:26656
49+
- FAUCET_URL=bootstrap:5000
50+
- SCRT_SGX_STORAGE=/root
51+
- SGX_MODE=SW
52+
entrypoint: /bin/bash
53+
deploy:
54+
restart_policy:
55+
condition: on-failure
56+
delay: 10s
57+
max_attempts: 10
58+
window: 123s

docs/upgrades/1.11/node_init.sh

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/usr/bin/env bash
2+
3+
set -euvo pipefail
4+
5+
# init the node
6+
# rm -rf ~/.secret*
7+
#secretd config chain-id enigma-testnet
8+
secretd config output json
9+
#secretd config indent true
10+
#secretd config trust-node true
11+
#secretd config keyring-backend test
12+
# rm -rf ~/.secretd
13+
14+
mkdir -p /root/.secretd/.node
15+
secretd config keyring-backend test
16+
secretd config node http://bootstrap:26657
17+
secretd config chain-id secretdev-1
18+
19+
mkdir -p /root/.secretd/.node
20+
21+
secretd init "$(hostname)" --chain-id secretdev-1 || true
22+
23+
PERSISTENT_PEERS=115aa0a629f5d70dd1d464bc7e42799e00f4edae@bootstrap:26656
24+
25+
sed -i 's/persistent_peers = ""/persistent_peers = "'$PERSISTENT_PEERS'"/g' ~/.secretd/config/config.toml
26+
sed -i 's/trust_period = "168h0m0s"/trust_period = "168h"/g' ~/.secretd/config/config.toml
27+
echo "Set persistent_peers: $PERSISTENT_PEERS"
28+
29+
echo "Waiting for bootstrap to start..."
30+
sleep 20
31+
32+
secretd q block 1
33+
34+
cp /tmp/.secretd/keyring-test /root/.secretd/ -r
35+
36+
# MASTER_KEY="$(secretd q register secret-network-params 2> /dev/null | cut -c 3- )"
37+
38+
#echo "Master key: $MASTER_KEY"
39+
40+
SGX_MODE=SW secretd init-enclave --reset
41+
42+
PUBLIC_KEY=$(SGX_MODE=SW secretd parse /root/attestation_cert.der | cut -c 3- )
43+
44+
echo "Public key: $PUBLIC_KEY"
45+
46+
SGX_MODE=SW secretd parse /root/attestation_cert.der
47+
cat /root/attestation_cert.der
48+
tx_hash="$(SGX_MODE=SW secretd tx register auth /root/attestation_cert.der -y --from a --gas-prices 0.25uscrt | jq -r '.txhash')"
49+
50+
#secretd q tx "$tx_hash"
51+
sleep 15
52+
SGX_MODE=SW secretd q tx "$tx_hash"
53+
54+
SEED="$(SGX_MODE=SW secretd q register seed "$PUBLIC_KEY" | cut -c 3-)"
55+
echo "SEED: $SEED"
56+
#exit
57+
58+
SGX_MODE=SW secretd q register secret-network-params
59+
60+
SGX_MODE=SW secretd configure-secret node-master-key.txt "$SEED"
61+
62+
cp /tmp/.secretd/config/genesis.json /root/.secretd/config/genesis.json
63+
64+
SGX_MODE=SW secretd validate-genesis
65+
66+
RUST_BACKTRACE=1 SGX_MODE=SW secretd start --rpc.laddr tcp://0.0.0.0:26657
67+
68+
# ./wasmi-sgx-test.sh
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
# How to test the v1.11 upgrade with LocalSecret
2+
3+
Always work in docs directory
4+
5+
## Step 1
6+
7+
Start a v1.10.0 chain.
8+
9+
```bash
10+
docker compose -f docker-compose-111.yml up -d
11+
docker cp node_init.sh node:/root/
12+
```
13+
14+
On one terminal window:
15+
16+
```bash
17+
docker exec -it bootstrap bash
18+
./bootstrap_init.sh
19+
```
20+
21+
On another terminal window
22+
23+
```bash
24+
docker exec -it node bash
25+
chmod 0777 node_init.sh
26+
./node_init.sh
27+
```
28+
29+
## Step 2 (Test basic contract)
30+
31+
### Copy the suplied contract to the docker
32+
33+
```bash
34+
docker cp ./contract.wasm node:/root/
35+
```
36+
37+
### Access node docker
38+
39+
```bash
40+
docker exec -it node bash
41+
```
42+
43+
### Instantiate a contract and interact with him
44+
45+
```bash
46+
secretd config node http://0.0.0.0:26657
47+
secretd tx compute store contract.wasm --from a --gas 5000000 -y
48+
sleep 5
49+
INIT='{"counter":{"counter":10, "expires":100000}}'
50+
secretd tx compute instantiate 1 "$INIT" --from a --label "c" -y
51+
sleep 5
52+
ADDR=`secretd q compute list-contract-by-code 1 | jq -r '.[0].contract_address'`
53+
54+
secretd tx compute execute $ADDR '{"increment":{"addition": 13}}' --from a -y
55+
sleep 5
56+
secretd query compute query $ADDR '{"get": {}}'
57+
```
58+
59+
Expected result should be:
60+
{"get":{"count":23}}
61+
62+
## Step 4
63+
64+
Propose a software upgrade on the v1.10 chain.
65+
66+
```bash
67+
# 30 blocks (3 minutes) until upgrade block
68+
UPGRADE_BLOCK="$(docker exec node bash -c 'secretd status | jq "(.SyncInfo.latest_block_height | tonumber) + 30"')"
69+
70+
# Propose upgrade
71+
PROPOSAL_ID="$(docker exec node bash -c "secretd tx gov submit-proposal software-upgrade v1.11 --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'")"
72+
73+
# Vote yes (voting period is 90 seconds)
74+
docker exec node bash -c "secretd tx gov vote ${PROPOSAL_ID} yes --from a -y -b block"
75+
76+
echo "PROPOSAL_ID = ${PROPOSAL_ID}"
77+
echo "UPGRADE_BLOCK = ${UPGRADE_BLOCK}"
78+
```
79+
80+
## Step 5
81+
82+
Apply the upgrade.
83+
84+
Wait until you see `ERR CONSENSUS FAILURE!!! err="UPGRADE \"v1.11\" NEEDED at height` in BOTH of the logs,
85+
then, from the root directory of the project, run:
86+
87+
```bash
88+
FEATURES="light-client-validation,random" SGX_MODE=SW make build-linux
89+
90+
# Copy binaries from host to current v1.8 chain
91+
92+
docker exec bootstrap bash -c 'rm -rf /tmp/upgrade-bin && mkdir -p /tmp/upgrade-bin'
93+
docker exec node bash -c 'rm -rf /tmp/upgrade-bin && mkdir -p /tmp/upgrade-bin'
94+
95+
docker cp usr/local/bin/secretd bootstrap:/tmp/upgrade-bin
96+
docker cp usr/lib/librust_cosmwasm_enclave.signed.so bootstrap:/tmp/upgrade-bin
97+
docker cp usr/lib/libgo_cosmwasm.so bootstrap:/tmp/upgrade-bin
98+
docker cp usr/local/bin/secretd node:/tmp/upgrade-bin
99+
docker cp usr/lib/librust_cosmwasm_enclave.signed.so node:/tmp/upgrade-bin
100+
docker cp usr/lib/libgo_cosmwasm.so node:/tmp/upgrade-bin
101+
# These two should be brought from the external repo or from a previous localsecret
102+
docker cp usr/lib/librandom_api.so node:/usr/lib
103+
docker cp usr/lib/tendermint_enclave.signed.so node:/usr/lib
104+
105+
docker exec node bash -c 'pkill -9 secretd'
106+
107+
docker exec bootstrap bash -c 'cat /tmp/upgrade-bin/librust_cosmwasm_enclave.signed.so > /usr/lib/librust_cosmwasm_enclave.signed.so'
108+
docker exec bootstrap bash -c 'cat /tmp/upgrade-bin/libgo_cosmwasm.so > /usr/lib/libgo_cosmwasm.so'
109+
docker exec node bash -c 'cat /tmp/upgrade-bin/secretd > /usr/bin/secretd'
110+
docker exec node bash -c 'cat /tmp/upgrade-bin/librust_cosmwasm_enclave.signed.so > /usr/lib/librust_cosmwasm_enclave.signed.so'
111+
docker exec node bash -c 'cat /tmp/upgrade-bin/libgo_cosmwasm.so > /usr/lib/libgo_cosmwasm.so'
112+
113+
114+
rm -rf /tmp/upgrade-bin && mkdir -p /tmp/upgrade-bin
115+
docker cp bootstrap:/root/.secretd/config/priv_validator_key.json /tmp/upgrade-bin/.
116+
docker cp /tmp/upgrade-bin/priv_validator_key.json node:/root/.secretd/config/priv_validator_key.json
117+
```
118+
119+
Then, restart secretd from the node you just killed:
120+
121+
```bash
122+
source /opt/sgxsdk/environment && RUST_BACKTRACE=1 LOG_LEVEL="trace" secretd start --rpc.laddr tcp://0.0.0.0:26657
123+
```
124+
125+
You should see `INF applying upgrade "v1.11" at height` in the logs, following by blocks continute to stream.
126+
127+
## Test that the contract is still there
128+
129+
### Query the value of the counter
130+
131+
```bash
132+
secretd query compute query $ADDR '{"get": {}}'
133+
```
134+
135+
Expected result should be:
136+
{"get":{"count":23}}
137+
138+
## Test contract upgrade
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

x/compute/client/cli/tx.go

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const (
3232
flagProposalType = "type"
3333
flagIoMasterKey = "enclave-key"
3434
flagCodeHash = "code-hash"
35+
flagAdmin = "admin"
3536
)
3637

3738
// GetTxCmd returns the transaction commands for this module
@@ -127,7 +128,7 @@ func parseStoreCodeArgs(args []string, cliCtx client.Context, flags *flag.FlagSe
127128
// InstantiateContractCmd will instantiate a contract from previously uploaded code.
128129
func InstantiateContractCmd() *cobra.Command {
129130
cmd := &cobra.Command{
130-
Use: "instantiate [code_id_int64] [json_encoded_init_args] --label [text] --amount [coins,optional]",
131+
Use: "instantiate [code_id_int64] [json_encoded_init_args] --label [text] --amount [coins,optional] --admin [admin_addr_bech32,optional]",
131132
Short: "Instantiate a wasm contract",
132133
Aliases: []string{"init"},
133134
Args: cobra.ExactArgs(2),
@@ -153,6 +154,7 @@ func InstantiateContractCmd() *cobra.Command {
153154
"io-master-key.txt file, which you can get using the command `secretcli q register secret-network-params` ")
154155
cmd.Flags().String(flagAmount, "", "Coins to send to the contract during instantiation")
155156
cmd.Flags().String(flagLabel, "", "A human-readable name for this contract in lists")
157+
cmd.Flags().String(flagAdmin, "", "Optional: Bech32 address of the admin of the contract")
156158
flags.AddTxFlagsToCmd(cmd)
157159
return cmd
158160
}
@@ -234,6 +236,11 @@ func parseInstantiateArgs(args []string, cliCtx client.Context, initFlags *flag.
234236
return types.MsgInstantiateContract{}, err
235237
}
236238

239+
admin, err := initFlags.GetString(flagAdmin)
240+
if err != nil {
241+
return types.MsgInstantiateContract{}, fmt.Errorf("Admin: %s", err)
242+
}
243+
237244
// build and sign the transaction, then broadcast to Tendermint
238245
msg := types.MsgInstantiateContract{
239246
Sender: cliCtx.GetFromAddress(),
@@ -243,6 +250,16 @@ func parseInstantiateArgs(args []string, cliCtx client.Context, initFlags *flag.
243250
InitFunds: amount,
244251
InitMsg: encryptedMsg,
245252
}
253+
254+
if admin != "" {
255+
_, err = sdk.AccAddressFromBech32(admin)
256+
if err != nil {
257+
return types.MsgInstantiateContract{}, fmt.Errorf("Admint address is not in bech32 format: %s", err)
258+
}
259+
260+
msg.Admin = admin
261+
}
262+
246263
return msg, nil
247264
}
248265

@@ -445,14 +462,24 @@ func parseMigrateContractArgs(args []string, cliCtx client.Context) (types.MsgMi
445462
if err != nil {
446463
return types.MsgMigrateContract{}, sdkerrors.Wrap(err, "code id")
447464
}
465+
migrateMsg := types.SecretMsg{}
448466

449-
migrateMsg := args[2]
467+
migrateMsg.CodeHash, err = GetCodeHashByCodeId(cliCtx, args[1])
468+
if err != nil {
469+
return types.MsgMigrateContract{}, sdkerrors.Wrap(err, "code hash")
470+
}
450471

472+
migrateMsg.Msg = []byte(args[2])
473+
wasmCtx := wasmUtils.WASMContext{CLIContext: cliCtx}
474+
encryptedMsg, err := wasmCtx.Encrypt(migrateMsg.Serialize())
475+
if err != nil {
476+
return types.MsgMigrateContract{}, sdkerrors.Wrap(err, "encrypt")
477+
}
451478
msg := types.MsgMigrateContract{
452479
Sender: cliCtx.GetFromAddress().String(),
453480
Contract: args[0],
454481
CodeID: codeID,
455-
Msg: []byte(migrateMsg),
482+
Msg: encryptedMsg,
456483
}
457484
return msg, nil
458485
}

0 commit comments

Comments
 (0)