Skip to content

Commit

Permalink
fix upgrade test
Browse files Browse the repository at this point in the history
  • Loading branch information
nghuyenthevinh2000 committed Nov 1, 2023
1 parent 673cf03 commit 2c64e20
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 15 deletions.
2 changes: 1 addition & 1 deletion contrib/updates/prepare_cosmovisor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# These fields should be fetched automatically in the future
# Need to do more upgrade to see upgrade patterns
OLD_VERSION=v2.0.1
OLD_VERSION=v2.2.1
# this command will retrieve the folder with the largest number in format v<number>
SOFTWARE_UPGRADE_NAME=$(ls -d -- ./app/upgrades/v* | sort -Vr | head -n 1 | xargs basename)
BUILDDIR=$1
Expand Down
13 changes: 12 additions & 1 deletion contrib/updates/upgrade-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,18 @@ CHAIN_ID=${STATUS_INFO[0]}
UPGRADE_HEIGHT=$((STATUS_INFO[1] + 20))
echo $UPGRADE_HEIGHT

$BINARY_OLD tx gov submit-proposal software-upgrade "$SOFTWARE_UPGRADE_NAME" --upgrade-height $UPGRADE_HEIGHT --upgrade-info "temp" --title "upgrade" --description "upgrade" --from node1 --keyring-backend test --chain-id $CHAIN_ID --home $NODE1_HOME -y
docker exec terradnode1 tar -cf ./terrad.tar -C . terrad
SUM=$(docker exec terradnode1 sha256sum ./terrad.tar | cut -d ' ' -f1)
DOCKER_BASE_PATH=$(docker exec terradnode1 pwd)
echo $SUM
UPGRADE_INFO=$(jq -n '
{
"binaries": {
"linux/amd64": "file://'$DOCKER_BASE_PATH'/terrad.tar?checksum=sha256:'"$SUM"'",
}
}')

$BINARY_OLD tx gov submit-legacy-proposal software-upgrade "$SOFTWARE_UPGRADE_NAME" --upgrade-height $UPGRADE_HEIGHT --upgrade-info "$UPGRADE_INFO" --title "upgrade" --description "upgrade" --from node1 --keyring-backend test --chain-id $CHAIN_ID --home $NODE1_HOME -y

sleep 5

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ go 1.20
module github.com/classic-terra/core/v2

require (
cosmossdk.io/math v1.0.0-rc.0
github.com/CosmWasm/wasmd v0.30.0
github.com/CosmWasm/wasmvm v1.1.2
github.com/cosmos/cosmos-sdk v0.46.14
Expand Down Expand Up @@ -33,7 +34,6 @@ require (
cloud.google.com/go/iam v1.1.1 // indirect
cloud.google.com/go/storage v1.30.1 // indirect
cosmossdk.io/errors v1.0.0-beta.7 // indirect
cosmossdk.io/math v1.0.0-rc.0 // indirect
filippo.io/edwards25519 v1.0.0-rc.1 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
github.com/99designs/keyring v1.2.1 // indirect
Expand Down
3 changes: 2 additions & 1 deletion scripts/run-node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
BINARY=$1
CONTINUE=${CONTINUE:-"false"}
HOME_DIR=mytestnet
ENV=${ENV:-""}

if [ "$CONTINUE" == "true" ]; then
$BINARY start --home $HOME_DIR
$BINARY start --home $HOME_DIR --log_level debug
exit 0
fi

Expand Down
22 changes: 15 additions & 7 deletions scripts/upgrade-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,16 @@ fi
mkdir -p _build/gocache
export GOMODCACHE=$ROOT/_build/gocache

# install old binary
if ! command -v _build/old/terrad &> /dev/null
# install old binary if not exist
if [ ! -f "_build/$OLD_VERSION.zip" ] &> /dev/null
then
mkdir -p _build/old
wget -c "https://github.com/classic-terra/core/archive/refs/tags/${OLD_VERSION}.zip" -O _build/${OLD_VERSION}.zip
unzip _build/${OLD_VERSION}.zip -d _build
cd ./_build/core-${OLD_VERSION:1}
GOBIN="$ROOT/_build/old" go install -mod=readonly ./...
cd ../..
fi

# reinstall old binary
if [ $# -eq 1 ] && [ $1 == "--reinstall-old" ]; then
if [ $# -eq 1 ] && [ $1 == "--reinstall-old" ] || ! command -v _build/old/terrad &> /dev/null; then
cd ./_build/core-${OLD_VERSION:1}
GOBIN="$ROOT/_build/old" go install -mod=readonly ./...
cd ../..
Expand All @@ -43,7 +40,9 @@ fi
# install new binary
if ! command -v _build/new/terrad &> /dev/null
then
cd ./_build/core-${NEW_VERSION:1}
GOBIN="$ROOT/_build/new" go install -mod=readonly ./...
cd ../..
fi

# run old node
Expand Down Expand Up @@ -95,7 +94,16 @@ run_upgrade () {

tar -cf ./_build/new/terrad.tar -C ./_build/new terrad
SUM=$(shasum -a 256 ./_build/new/terrad.tar | cut -d ' ' -f1)
./_build/old/terrad tx gov submit-legacy-proposal software-upgrade "$SOFTWARE_UPGRADE_NAME" --upgrade-height $UPGRADE_HEIGHT --upgrade-info "{\"binaries\":{\"linux/amd64\":\"file://"$(pwd)"/_build/new/terrad.tar?checksum=sha256:"$SUM"\"}}" --title "upgrade" --description "upgrade" --from test1 --keyring-backend test --chain-id $CHAIN_ID --home $HOME -y
UPGRADE_INFO=$(jq -n '
{
"binaries": {
"linux/amd64": "file://'$(pwd)'/_build/new/terrad.tar?checksum=sha256:'"$SUM"'",
}
}')

./_build/old/terrad keys list --home $HOME --keyring-backend test

./_build/old/terrad tx gov submit-legacy-proposal software-upgrade "$SOFTWARE_UPGRADE_NAME" --upgrade-height $UPGRADE_HEIGHT --upgrade-info "$UPGRADE_INFO" --title "upgrade" --description "upgrade" --from test1 --keyring-backend test --chain-id $CHAIN_ID --home $HOME -y

sleep 5

Expand Down
3 changes: 2 additions & 1 deletion x/dyncomm/keeper/dyncomm.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,11 @@ func (k Keeper) UpdateValidatorMinRates(ctx sdk.Context, validator stakingtypes.

k.StakingKeeper.SetValidator(ctx, newValidator)
k.SetDynCommissionRate(ctx, validator.OperatorAddress, minRate)
k.SetTargetCommissionRate(ctx, validator.OperatorAddress, newRate)

// Debug
targetRate = k.GetTargetCommissionRate(ctx, validator.OperatorAddress)
ctx.Logger().Info("dyncomm:", "val", validator.OperatorAddress, "min_rate", minRate, "target_rate", targetRate)
ctx.Logger().Debug("dyncomm:", "val", validator.OperatorAddress, "min_rate", minRate, "new target_rate", targetRate)
}

func (k Keeper) UpdateAllBondedValidatorRates(ctx sdk.Context) (err error) {
Expand Down
6 changes: 3 additions & 3 deletions x/dyncomm/post/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (dd DyncommDecorator) ProcessEditValidator(ctx sdk.Context, msg sdk.Msg) {
func (dd DyncommDecorator) ProcessCreateValidator(ctx sdk.Context, msg sdk.Msg) {
// post handler runs after successfully
// calling runMsgs -> we can set state changes here!
msgEditValidator := msg.(*stakingtypes.MsgCreateValidator)
newIntendedRate := msgEditValidator.Commission.Rate
dd.dyncommKeeper.SetTargetCommissionRate(ctx, msgEditValidator.ValidatorAddress, newIntendedRate)
msgCreateValidator := msg.(*stakingtypes.MsgCreateValidator)
newIntendedRate := msgCreateValidator.Commission.Rate
dd.dyncommKeeper.SetTargetCommissionRate(ctx, msgCreateValidator.ValidatorAddress, newIntendedRate)
}

0 comments on commit 2c64e20

Please sign in to comment.