Skip to content

Commit

Permalink
Added upgrade-chain CLI and updated instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
ancazamfir committed Mar 23, 2021
1 parent 959f8dd commit 42b326a
Show file tree
Hide file tree
Showing 11 changed files with 769 additions and 170 deletions.
324 changes: 157 additions & 167 deletions guide/src/upgrade_test.md
Original file line number Diff line number Diff line change
@@ -1,176 +1,166 @@
## Prerequisites

- gaiad
```
- gaiad `(v4.1.*)`, for example:

```shell
$ gaiad version --long | head -n4
name: gaia
server_name: gaiad
version: 4.0.0
commit: a279d091c6f66f8a91c87943139ebaecdd84f689
```

- Go relayer

```shell
$ rly version
version: 0.8.2
commit: 489607fa6de093d90fd2f8ac8eb52be3ccf3f145
cosmos-sdk: v0.41.3
go: go1.15.6 darwin/amd64
version: 4.1.2
commit: 95b07e641d1f69ee12dd911e92b1679f2c64d385
```

## Testing procedure

1. Patch the `one-chain` script of the Go relayer.

```shell
cd ~/go/src/github.com/cosmos/relayer/
```

This patching step is necessary to short-circuit the upgrading of a chain.
With the changes below, a chain will be able to undergo an upgrade within
~200 seconds of the upgrade proposal (instead of the default of 2 days).
With this patch, we can test the upgrade functionality in a matter of minutes.

Note this only works for MacOS ("Darwin" platform), not tests on Linux.

```diff
diff --git a/scripts/one-chain b/scripts/one-chain
index d0995fe..3702a88 100755
--- a/scripts/one-chain
+++ b/scripts/one-chain
@@ -99,6 +99,7 @@ if [ $platform = 'linux' ]; then
sed -i 's/index_all_keys = false/index_all_keys = true/g' $CHAINDIR/$CHAINID/config/config.toml
# sed -i '' 's#index-events = \[\]#index-events = \["message.action","send_packet.packet_src_channel","send_packet.packet_sequence"\]#g' $CHAINDIR/$CHAINID/config/app.toml
else
+ sed -i '' 's#"172800s"#"200s"#g' $CHAINDIR/$CHAINID/config/genesis.json
sed -i '' 's#"tcp://127.0.0.1:26657"#"tcp://0.0.0.0:'"$RPCPORT"'"#g' $CHAINDIR/$CHAINID/config/config.toml
sed -i '' 's#"tcp://0.0.0.0:26656"#"tcp://0.0.0.0:'"$P2PPORT"'"#g' $CHAINDIR/$CHAINID/config/config.toml
sed -i '' 's#"localhost:6060"#"localhost:'"$P2PPORT"'"#g' $CHAINDIR/$CHAINID/config/config.toml
```

2. Start two gaia instances using the patched developer environment in the Go relayer codebase:

```shell
./scripts/two-chainz
```

3. Setup the Go relayer for these chains:
```shell
$ rly tx link demo -d -o 3s
```

Check that everything went fine so far:

```shell
$ rly paths list
0: demo -> chns(✔) clnts(✔) conn(✔) chan(✔) (ibc-0:transfer<>ibc-1:transfer)
```

4. Create the upgrade plan for chain ibc-0:

It's important that we parametrize the upgrade plan with a height parameter that
is at least 300 heights ahead of the current height of chain ibc-0.

First, obtain the current height:
```shell
gaiad query block | jq | grep height
"height": "470",
```

Now create the upgrade plan for height 800:
```shell
echo '{
"Name": "test",
"Height": 800,
"Info": ""
}' > ./upgrade-plan.json
```


5. Submit the upgrade plan

```shell
rly tx upgrade-chain demo ibc-0 400h 10000000stake ./upgrade-plan.json
```

Query for the upgrade plan, check that it was submitted correctly:

```shell
$ gaiad query gov proposal 1 --home data/ibc-0/

content:
'@type': /cosmos.upgrade.v1beta1.SoftwareUpgradeProposal
description: upgrade the chain's software and unbonding period
plan:
height: "800"
info: ""
name: test
....
proposal_id: "1"
status: PROPOSAL_STATUS_VOTING_PERIOD
submit_time: "2021-03-08T13:07:01.417163Z"
total_deposit:
- amount: "10000000"
denom: stake
voting_end_time: "2021-03-08T13:10:21.417163Z"
voting_start_time: "2021-03-08T13:07:01.417163Z"
```
6. Vote on the proposal
The parameter "1" should match the "proposal_id:" from the upgrade proposal
we submitted at step 5.
```shell
gaiad tx gov vote 1 yes --home data/ibc-0/data/ --keyring-backend test --keyring-dir data/ibc-0/ --chain-id ibc-0 --from validator
```
Once ibc-0 reaches height 800 (the upgrade height specified in the plan at step 4), the chain should stop executing.
7. Initialize and test Hermes
```shell
cd ~/rust/ibc-rs
```
Patch the developer env of Hermes, to redirect to the correct Gaia directory:
```diff
diff --git a/scripts/init-clients b/scripts/init-clients
index 6cf1a674..bfff9721 100755
--- a/scripts/init-clients
+++ b/scripts/init-clients
@@ -49,7 +49,7 @@ if ! grep -q -s "$CHAIN_1_ID" "$CONFIG_FILE"; then
usage
fi
-GAIA_DATA="$(pwd)/data"
+GAIA_DATA="~/go/src/github.com/cosmos/relayer/data"
CHAIN_0_RPC_PORT=26657
CHAIN_0_RPC_ADDR="localhost:$CHAIN_0_RPC_PORT"
```
Now setup the clients for Hermes to use:
```shell
$ ./scripts/init-clients ~/.hermes/config.toml ibc-0 ibc-1
Building the Rust relayer...
Removing light client peers from configuration...
Adding primary peers to light client configuration...
Adding secondary peers to light client configuration...
Importing keys...
Done!
```
8. Test the `upgrade-client` CLI
The following command will perform the upgrade for client `07-tendermint-0`. It
will output two events, one for the updated client state, and another for the
upgraded state.
```shell
hermes tx raw upgrade-client ibc-1 ibc-0 07-tendermint-0
```
1. Start two gaia instances and initialize hermes:

```shell
$ ./scripts/dev-env ~/.hermes/config.toml ibc-0 ibc-1
```
The `one-chain` script is invoked for each chain and modifies the `genesis.json` file to use a short window for governance proposals (`200s` for `max_deposit_period` and `voting_period`). Therefore, an upgrade proposal can be submitted, voted on and accepted within a short time.

2. Create one client on `ibc-1` for `ibc-0`:

```shell
$ hermes tx raw create-client ibc-1 ibc-0
```

3. Create and submit an upgrade plan for chain `ibc-0`:

Use the hermes test command to make an upgrade proposal. In the example below a software upgrade proposal is made for `ibc-0`, for the height `300` blocks from latest height. `10000000stake` is deposited.
The proposal includes the upgraded client state constructed from the state of `07-tendermint-0` client on `ibc-1` that was created in the previous step. In addition, the `unbonding_period` of the client is set to some new value (`400h`)

```shell
$ hermes tx raw upgrade-chain ibc-0 ibc-1 07-tendermint-0 10000000 300
```

Note that the height offset should be picked such that the proposal plan height is reached after the `200s` voting period.

4. Verify that the proposal was accepted:

Query the upgrade plan to check that it was submitted correctly. Note the `height` at which the proposal will take effect (chain halts). Also `status: PROPOSAL_STATUS_VOTING_PERIOD`.

```shell
$ gaiad query gov proposal 1 --home data/ibc-0/
content:
'@type': /cosmos.upgrade.v1beta1.SoftwareUpgradeProposal
description: upgrade the chain software and unbonding period
plan:
height: "382"
info: upgrade the chain software and unbonding period
name: test
time: "0001-01-01T00:00:00Z"
upgraded_client_state:
'@type': /ibc.lightclients.tendermint.v1.ClientState
allow_update_after_expiry: false
allow_update_after_misbehaviour: false
chain_id: ibc-0
frozen_height:
revision_height: "0"
revision_number: "0"
latest_height:
revision_height: "383"
revision_number: "0"
max_clock_drift: 0s
proof_specs:
...
trust_level:
denominator: "0"
numerator: "0"
trusting_period: 0s
unbonding_period: 1440000s
upgrade_path:
- upgrade
- upgradedIBCState
title: upgrade_ibc_clients
deposit_end_time: "2021-03-23T17:25:42.543572Z"
final_tally_result:
abstain: "0"
"no": "0"
no_with_veto: "0"
"yes": "0"
proposal_id: "1"
status: PROPOSAL_STATUS_VOTING_PERIOD
submit_time: "2021-03-23T17:22:22.543572Z"
total_deposit:
- amount: "10000000"
denom: stake
voting_end_time: "2021-03-23T17:25:42.543572Z"
voting_start_time: "2021-03-23T17:22:22.543572Z"
```

5. Vote on the proposal

The parameter `1` should match the `proposal_id:` from the upgrade proposal submitted at step 3. This command must be issued while the proposal status is `PROPOSAL_STATUS_VOTING_PERIOD`.

```shell
gaiad tx gov vote 1 yes --home data/ibc-0/data/ --keyring-backend test --keyring-dir data/ibc-0/ --chain-id ibc-0 --from validator
```

Wait approximately 200 seconds until the proposal changes status to `PROPOSAL_STATUS_PASSED`. Note the `final tally_result` that includes the vote submitted in previous step.

```shell
$ gaiad query gov proposal 1 --home data/ibc-0/
content:
'@type': /cosmos.upgrade.v1beta1.SoftwareUpgradeProposal
description: upgrade the chain software and unbonding period
plan:
...
final_tally_result:
abstain: "0"
"no": "0"
no_with_veto: "0"
"yes": "100000000000"
proposal_id: "1"
status: PROPOSAL_STATUS_PASSED
submit_time: "2021-03-23T17:22:22.543572Z"
total_deposit:
- amount: "10000000"
denom: stake
voting_end_time: "2021-03-23T17:25:42.543572Z"
voting_start_time: "2021-03-23T17:22:22.543572Z"
```

6. Test the `upgrade-client` CLI

The following command performs the upgrade for client `07-tendermint-0`. It outputs two events, one for the updated client state, and another for the upgraded state.

```shell
$ hermes tx raw upgrade-client ibc-1 ibc-0 07-tendermint-0
{
"status": "success",
"result": [
{
"UpdateClient": {
"client_id": "07-tendermint-0",
"client_type": "Tendermint",
"consensus_height": {
"revision_height": 332,
"revision_number": 0
},
"height": {
"revision_height": 404,
"revision_number": 1
}
}
},
{
"UpgradeClient": {
"client_id": "07-tendermint-0",
"client_type": "Tendermint",
"consensus_height": {
"revision_height": 333,
"revision_number": 0
},
"height": {
"revision_height": 404,
"revision_number": 1
}
}
}
]
}
```
20 changes: 19 additions & 1 deletion modules/src/ics07_tendermint/client_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ use std::convert::{TryFrom, TryInto};
use std::time::Duration;

use serde::Serialize;
use tendermint::trust_threshold::TrustThresholdFraction as TrustThreshold;
use tendermint::trust_threshold::{
TrustThresholdFraction as TrustThreshold, TrustThresholdFraction,
};
use tendermint_proto::Protobuf;

use ibc_proto::ibc::lightclients::tendermint::v1::{ClientState as RawClientState, Fraction};
Expand Down Expand Up @@ -103,6 +105,22 @@ impl ClientState {
..self
}
}

// Helper function to verify the upgrade client procedure, it resets all fields except the
// blockchain specific ones.
pub fn zero_custom_fields(&self) -> ClientState {
let mut client_state = self.clone();
client_state.trusting_period = Duration::default();
client_state.trust_level = TrustThresholdFraction {
numerator: 0,
denominator: 0,
};
client_state.allow_update_after_expiry = false;
client_state.allow_update_after_misbehaviour = false;
client_state.frozen_height = Height::zero();
client_state.max_clock_drift = Duration::default();
client_state
}
}

impl crate::ics02_client::client_state::ClientState for ClientState {
Expand Down
1 change: 1 addition & 0 deletions proto-compiler/src/cmd/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ impl CompileCmd {
let proto_paths = [
format!("{}/../proto/definitions/mock", root),
format!("{}/proto/cosmos/auth", sdk_dir.display()),
format!("{}/proto/cosmos/gov", sdk_dir.display()),
format!("{}/proto/cosmos/tx", sdk_dir.display()),
format!("{}/proto/cosmos/base", sdk_dir.display()),
format!("{}/proto/cosmos/staking", sdk_dir.display()),
Expand Down
5 changes: 5 additions & 0 deletions proto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ pub mod cosmos {
include!("prost/cosmos.upgrade.v1beta1.rs");
}
}
pub mod gov {
pub mod v1beta1 {
include!("prost/cosmos.gov.v1beta1.rs");
}
}
}

pub mod ibc {
Expand Down
Loading

0 comments on commit 42b326a

Please sign in to comment.