Skip to content

Commit

Permalink
add helper scripts and add logging for upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
alexh-scrt committed Sep 12, 2024
1 parent c966986 commit a63dbd9
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
docs/upgrades/1.15/bin/
.env
sgx_sk.pem
*.a
Expand Down
2 changes: 2 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ import (
dbm "github.com/cosmos/cosmos-db"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
stakingkeeper "github.com/cosmos/ibc-go/v8/testing/types"

"github.com/gorilla/mux"
"github.com/rakyll/statik/fs"
"github.com/scrtlabs/SecretNetwork/x/compute"
Expand Down Expand Up @@ -539,6 +540,7 @@ func (app *SecretNetworkApp) setupUpgradeStoreLoaders() {

for i := range Upgrades {
if upgradeInfo.Name == Upgrades[i].UpgradeName {
app.Logger().Info(fmt.Sprintf("Upgrade store loader for %s at height %d", upgradeInfo.Name, upgradeInfo.Height))
app.BaseApp.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &Upgrades[i].StoreUpgrades))
}
}
Expand Down
10 changes: 8 additions & 2 deletions app/upgrades/v1.15/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
"github.com/scrtlabs/SecretNetwork/app/upgrades"
)

const upgradeName = "v1.14.0 -> v1.15.0"
const upgradeName = "v1.15"

var Upgrade = upgrades.Upgrade{
UpgradeName: upgradeName,
Expand Down Expand Up @@ -108,6 +108,12 @@ func createUpgradeHandler(mm *module.Manager, appKeepers *keepers.SecretAppKeepe
}
logger.Info(fmt.Sprintf("Running module migrations for %s...", upgradeName))

return mm.RunMigrations(ctx, configurator, vm)
m, e := mm.RunMigrations(ctx, configurator, vm)
if e != nil {
logger.Error(fmt.Sprintf("[x] Run migration error: %s", e))
} else {
logger.Info(fmt.Sprintf("[v] Successful migration run for %s", upgradeName))
}
return m, e
}
}
7 changes: 7 additions & 0 deletions docs/upgrades/1.15/cleanup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
set -o xtrace

sudo rm -fr /tmp/secretd
sudo rm -fr /tmp/secretcli
mkdir /tmp/secretd
mkdir /tmp/secretcli
11 changes: 11 additions & 0 deletions docs/upgrades/1.15/init_proposal.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
set -o xtrace

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.15 --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}"
2 changes: 1 addition & 1 deletion docs/upgrades/1.15/test-v1.15-upgrade-handler.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ docker exec secret-0.50.x:/usr/lib/tendermint_enclave.signed.so ./bin
```

```bash
# Copy binaries from host to current v1.8 chain
# Copy binaries from host to current v1.14 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'
Expand Down
28 changes: 28 additions & 0 deletions docs/upgrades/1.15/update_binaries.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash
set -o xtrace

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'
# update bootstrap
docker cp ./bin/secretd bootstrap:/tmp/upgrade-bin
docker cp ./bin/librust_cosmwasm_enclave.signed.so bootstrap:/tmp/upgrade-bin
docker cp ./bin/libgo_cosmwasm.so bootstrap:/tmp/upgrade-bin
# update node
docker cp ./bin/secretd node:/tmp/upgrade-bin
docker cp ./bin/librust_cosmwasm_enclave.signed.so node:/tmp/upgrade-bin
docker cp ./bin/libgo_cosmwasm.so node:/tmp/upgrade-bin
docker cp ./bin/librandom_api.so node:/tmp/upgrade-bin
docker cp ./bin/tendermint_enclave.signed.so node:/tmp/upgrade-bin
# stop node's secretd
docker exec node bash -c 'pkill -9 secretd'
# copy over updated binaries
docker exec bootstrap bash -c 'cp /tmp/upgrade-bin/librust_cosmwasm_enclave.signed.so /usr/lib/'
docker exec bootstrap bash -c 'cp /tmp/upgrade-bin/libgo_cosmwasm.so /usr/lib/'
docker exec node bash -c 'cp /tmp/upgrade-bin/secretd /usr/bin/'
docker exec node bash -c 'cp /tmp/upgrade-bin/librust_cosmwasm_enclave.signed.so /usr/lib/'
docker exec node bash -c 'cp /tmp/upgrade-bin/libgo_cosmwasm.so /usr/lib/'

# prepare a tmp dir to store validator's private key
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

0 comments on commit a63dbd9

Please sign in to comment.