diff --git a/app/config/const.go b/app/config/const.go index 4ffb3447..07476380 100644 --- a/app/config/const.go +++ b/app/config/const.go @@ -228,4 +228,5 @@ const ( Upgrade2_16 = "v2.16" Upgrade2_17 = "v2.17" Upgrade2_18 = "v2.18" + Upgrade2_19 = "v2.19" ) diff --git a/app/upgrade_handler.go b/app/upgrade_handler.go index c0be7ae4..15a5981b 100644 --- a/app/upgrade_handler.go +++ b/app/upgrade_handler.go @@ -15,6 +15,7 @@ import ( v2_16 "github.com/terra-money/core/v2/app/upgrades/v2.16" v2_17 "github.com/terra-money/core/v2/app/upgrades/v2.17" v2_18 "github.com/terra-money/core/v2/app/upgrades/v2.18" + v2_19 "github.com/terra-money/core/v2/app/upgrades/v2.19" v2_2_0 "github.com/terra-money/core/v2/app/upgrades/v2.2.0" v2_3_0 "github.com/terra-money/core/v2/app/upgrades/v2.3.0" v2_4 "github.com/terra-money/core/v2/app/upgrades/v2.4" @@ -174,6 +175,14 @@ func (app *TerraApp) RegisterUpgradeHandlers() { app.Keepers, ), ) + app.Keepers.UpgradeKeeper.SetUpgradeHandler( + terraappconfig.Upgrade2_19, + v2_19.CreateUpgradeHandler( + app.GetModuleManager(), + app.GetConfigurator(), + app.Keepers, + ), + ) } func (app *TerraApp) RegisterUpgradeStores() { diff --git a/app/upgrades/v2.19/upgrade.go b/app/upgrades/v2.19/upgrade.go new file mode 100644 index 00000000..72cb9340 --- /dev/null +++ b/app/upgrades/v2.19/upgrade.go @@ -0,0 +1,20 @@ +package v2_19 + +import ( + "context" + + upgradetypes "cosmossdk.io/x/upgrade/types" + "github.com/cosmos/cosmos-sdk/types/module" + + "github.com/terra-money/core/v2/app/keepers" +) + +func CreateUpgradeHandler( + mm *module.Manager, + cfg module.Configurator, + k keepers.TerraAppKeepers, +) upgradetypes.UpgradeHandler { + return func(ctx context.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { + return mm.RunMigrations(ctx, cfg, vm) + } +} diff --git a/go.mod b/go.mod index 02159982..a43253be 100644 --- a/go.mod +++ b/go.mod @@ -20,12 +20,12 @@ require ( cosmossdk.io/x/upgrade v0.1.4 github.com/CosmWasm/wasmd v0.54.3 github.com/CosmWasm/wasmvm/v2 v2.2.4 - github.com/cometbft/cometbft v0.38.17 + github.com/cometbft/cometbft v0.38.21 github.com/cometbft/cometbft-db v0.14.1 // indirect github.com/cosmos/btcutil v1.0.5 github.com/cosmos/cosmos-db v1.1.1 github.com/cosmos/cosmos-proto v1.0.0-beta.5 - github.com/cosmos/cosmos-sdk v0.50.14 + github.com/cosmos/cosmos-sdk v0.50.15 github.com/cosmos/go-bip39 v1.0.0 github.com/cosmos/gogogateway v1.2.0 // indirect github.com/cosmos/gogoproto v1.7.0 @@ -228,8 +228,7 @@ require ( replace ( github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0 - github.com/cometbft/cometbft => github.com/cometbft/cometbft-sec-tachyon v0.38.21-0.20260113214209-9ac677707f85 - github.com/cosmos/cosmos-sdk => github.com/phoenix-directive/cosmos-sdk v0.50.14-terra.0 + github.com/cosmos/cosmos-sdk => github.com/phoenix-directive/cosmos-sdk v0.50.15-terra.0 github.com/cosmos/ledger-cosmos-go => ./ledger-go github.com/gogo/protobuf => github.com/gogo/protobuf v1.3.2 github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 diff --git a/go.sum b/go.sum index 5bb6d9c1..b396da07 100644 --- a/go.sum +++ b/go.sum @@ -406,10 +406,10 @@ github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE github.com/coinbase/kryptology v1.8.0/go.mod h1:RYXOAPdzOGUe3qlSFkMGn58i3xUA8hmxYHksuq+8ciI= github.com/coinbase/rosetta-sdk-go v0.7.9 h1:lqllBjMnazTjIqYrOGv8h8jxjg9+hJazIGZr9ZvoCcA= github.com/coinbase/rosetta-sdk-go v0.7.9/go.mod h1:0/knutI7XGVqXmmH4OQD8OckFrbQ8yMsUZTG7FXCR2M= +github.com/cometbft/cometbft v0.38.21 h1:qcIJSH9LiwU5s6ZgKR5eRbsLNucbubfraDs5bzgjtOI= +github.com/cometbft/cometbft v0.38.21/go.mod h1:UCu8dlHqvkAsmAFmWDRWNZJPlu6ya2fTWZlDrWsivwo= github.com/cometbft/cometbft-db v0.14.1 h1:SxoamPghqICBAIcGpleHbmoPqy+crij/++eZz3DlerQ= github.com/cometbft/cometbft-db v0.14.1/go.mod h1:KHP1YghilyGV/xjD5DP3+2hyigWx0WTp9X+0Gnx0RxQ= -github.com/cometbft/cometbft-sec-tachyon v0.38.21-0.20260113214209-9ac677707f85 h1:xCfV8uIRpj/O6wwoJhGBdUQYBSaVHyxy+aCxV70hnOI= -github.com/cometbft/cometbft-sec-tachyon v0.38.21-0.20260113214209-9ac677707f85/go.mod h1:UCu8dlHqvkAsmAFmWDRWNZJPlu6ya2fTWZlDrWsivwo= github.com/consensys/bavard v0.1.8-0.20210406032232-f3452dc9b572/go.mod h1:Bpd0/3mZuaj6Sj+PqrmIquiOKy397AKGThQPaGzNXAQ= github.com/consensys/bavard v0.1.8-0.20210915155054-088da2f7f54a/go.mod h1:9ItSMtA/dXMAiL7BG6bqW2m3NdSEObYWoH223nGHukI= github.com/consensys/gnark-crypto v0.4.1-0.20210426202927-39ac3d4b3f1f/go.mod h1:815PAHg3wvysy0SyIqanF8gZ0Y1wjk/hrDHD/iT88+Q= @@ -1062,8 +1062,8 @@ github.com/petermattis/goid v0.0.0-20240813172612-4fcff4a6cae7/go.mod h1:pxMtw7c github.com/philhofer/fwd v1.0.0/go.mod h1:gk3iGcWd9+svBvR0sR+KPcfE+RNWozjowpeBVG3ZVNU= github.com/phoenix-directive/alliance v0.4.5 h1:5F1I9+k4S+qu2lpn6dcothJdqZiW0EQpQ6HZTfSKml8= github.com/phoenix-directive/alliance v0.4.5/go.mod h1:zVKzF0eaaGWU/bLc7eibxZgUtmsIX0iS6mIQifjF+0o= -github.com/phoenix-directive/cosmos-sdk v0.50.14-terra.0 h1:0nHGubjiS1HiyFrn/oUcQHZrzQ1rkEvY70w7vf5c+Dg= -github.com/phoenix-directive/cosmos-sdk v0.50.14-terra.0/go.mod h1:hrWEFMU1eoXqLJeE6VVESpJDQH67FS1nnMrQIjO2daw= +github.com/phoenix-directive/cosmos-sdk v0.50.15-terra.0 h1:V9B8wAkXBl1pI0cTE1AyO+s7gx6aZl4L6aX9eplo5lc= +github.com/phoenix-directive/cosmos-sdk v0.50.15-terra.0/go.mod h1:/dinzXHi7qK0dEPZjS3LI5gMHueKQdqyjbB9chwswo0= github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1/go.mod h1:3/3N9NVKO0jef7pBehbT1qWhCMrIgbYNnFAZCqQ5LRc= github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4= diff --git a/integration-tests/package.json b/integration-tests/package.json index 0ef914d0..f987254d 100644 --- a/integration-tests/package.json +++ b/integration-tests/package.json @@ -14,6 +14,7 @@ "test:chain:upgrade:v16": "bash src/setup/chain-upgrade/upgrade-simulation-16.sh", "test:chain:upgrade:v17": "bash src/setup/chain-upgrade/upgrade-simulation-17.sh", "test:chain:upgrade:v18": "bash src/setup/chain-upgrade/upgrade-simulation-18.sh", + "test:chain:upgrade:v19": "bash src/setup/chain-upgrade/upgrade-simulation-19.sh", "test:start": "jest --runInBand --detectOpenHandles", "start": "npm run test:init && npm run test:relayer && npm run test:start", "test:clean": "rm -rf src/test-data chain-upgrade-data && pkill terrad && pkill terrad && pkill relayer" @@ -47,4 +48,4 @@ "long": "^5.3.1" }, "packageManager": "yarn@1.22.19+sha1.4ba7fc5c6e704fce2066ecbfb0b0d8976fe62447" -} +} \ No newline at end of file diff --git a/integration-tests/src/setup/chain-upgrade/upgrade-simulation-17.sh b/integration-tests/src/setup/chain-upgrade/upgrade-simulation-17.sh index 79f80c1b..7c0a7e8f 100755 --- a/integration-tests/src/setup/chain-upgrade/upgrade-simulation-17.sh +++ b/integration-tests/src/setup/chain-upgrade/upgrade-simulation-17.sh @@ -89,7 +89,7 @@ sleep 5 VALOPER_ADDR_1=$($OLD_BINARY q staking validators --output=json --home $CHAIN_HOME | jq .validators[0].operator_address -r) -echo "Create new periodic vesting account" +echo "Create new periodic vesting account $WALLET_ADDR_2" echo '{ "start_time": '$(date +%s)', "periods":[ diff --git a/integration-tests/src/setup/chain-upgrade/upgrade-simulation-19.sh b/integration-tests/src/setup/chain-upgrade/upgrade-simulation-19.sh new file mode 100755 index 00000000..8bd4a01c --- /dev/null +++ b/integration-tests/src/setup/chain-upgrade/upgrade-simulation-19.sh @@ -0,0 +1,218 @@ +#!/bin/bash + +OLD_VERSION=release/v2.18 +UPGRADE_HEIGHT=30 +CHAIN_ID=test-1 +CHAIN_HOME=$(pwd)/chain-upgrade-data +CONTRACT_PATH=$(pwd)/src/contracts/counter.wasm +DENOM=uluna +SOFTWARE_UPGRADE_NAME="v2.19" +GOV_PERIOD="3s" + +VAL_MNEMONIC_1="clock post desk civil pottery foster expand merit dash seminar song memory figure uniform spice circle try happy obvious trash crime hybrid hood cushion" +VAL_MNEMONIC_2="alley afraid soup fall idea toss can goose become valve initial strong forward bright dish figure check leopard decide warfare hub unusual join cart" +WALLET_MNEMONIC_1="banner spread envelope side kite person disagree path silver will brother under couch edit food venture squirrel civil budget number acquire point work mass" +WALLET_MNEMONIC_2="veteran try aware erosion drink dance decade comic dawn museum release episode original list ability owner size tuition surface ceiling depth seminar capable only" +WALLET_MNEMONIC_3="vacuum burst ordinary enact leaf rabbit gather lend left chase park action dish danger green jeans lucky dish mesh language collect acquire waste load" + +export OLD_BINARY=$CHAIN_HOME/terrad_old +export NEW_BINARY=$CHAIN_HOME/terrad_new + +rm -rf /tmp/terra +rm -r $CHAIN_HOME +mkdir $CHAIN_HOME +killall terrad_old +killall terrad_new + +# install old binary +if ! command -v $OLD_BINARY &> /dev/null +then + mkdir -p /tmp/terra + cd /tmp/terra + git clone https://github.com/terra-money/core + cd core + git checkout $OLD_VERSION + make build + cp /tmp/terra/core/build/terrad $CHAIN_HOME/terrad_old + cd $CHAIN_HOME +fi + +# install new binary +if ! command -v $NEW_BINARY &> /dev/null +then + cd ../.. + make build + cp build/terrad $NEW_BINARY +fi + +# init genesis +$OLD_BINARY init test --home $CHAIN_HOME --chain-id=$CHAIN_ID +echo $VAL_MNEMONIC_1 | $OLD_BINARY keys add val1 --home $CHAIN_HOME --recover --keyring-backend=test +VAL_ADDR_1=$($OLD_BINARY keys show val1 --home $CHAIN_HOME --keyring-backend=test --output=json | jq .address -r) + +echo $WALLET_MNEMONIC_1 | $OLD_BINARY keys add wallet1 --home $CHAIN_HOME --recover --keyring-backend=test +WALLET_ADDR_1=$($OLD_BINARY keys show wallet1 --home $CHAIN_HOME --keyring-backend=test --output=json | jq .address -r) + +echo $WALLET_MNEMONIC_2 | $OLD_BINARY keys add wallet2 --home $CHAIN_HOME --recover --keyring-backend=test +WALLET_ADDR_2=$($OLD_BINARY keys show wallet2 --home $CHAIN_HOME --keyring-backend=test --output=json | jq .address -r) + +echo $WALLET_MNEMONIC_3 | $OLD_BINARY keys add wallet3 --home $CHAIN_HOME --recover --keyring-backend=test +WALLET_ADDR_3=$($OLD_BINARY keys show wallet3 --home $CHAIN_HOME --keyring-backend=test --output=json | jq .address -r) + +$OLD_BINARY genesis add-genesis-account $($OLD_BINARY --home $CHAIN_HOME keys show val1 --keyring-backend test -a) 100000000000uluna --home $CHAIN_HOME + +CURRENT_TIME=$(date +%s) +echo "Current time: $CURRENT_TIME" +$OLD_BINARY genesis add-genesis-account $($OLD_BINARY --home $CHAIN_HOME keys show wallet1 --keyring-backend test -a) 100000000000uluna --vesting-amount 200000000uluna --vesting-start-time $CURRENT_TIME --vesting-end-time $(($CURRENT_TIME + 10000)) --home $CHAIN_HOME + +$OLD_BINARY genesis gentx val1 1000000000uluna --home $CHAIN_HOME --chain-id $CHAIN_ID --keyring-backend test --commission-max-rate 0.01 --commission-rate 0.01 --commission-max-change-rate 0.01 +$OLD_BINARY genesis collect-gentxs --home $CHAIN_HOME + +sed -i -e "s/\"max_deposit_period\": \"172800s\"/\"max_deposit_period\": \"$GOV_PERIOD\"/g" $CHAIN_HOME/config/genesis.json +sed -i -e "s/\"voting_period\": \"172800s\"/\"voting_period\": \"$GOV_PERIOD\"/g" $CHAIN_HOME/config/genesis.json + +sed -i -e 's/timeout_commit = "5s"/timeout_commit = "1s"/g' $CHAIN_HOME/config/config.toml +sed -i -e 's/timeout_propose = "3s"/timeout_propose = "1s"/g' $CHAIN_HOME/config/config.toml +sed -i -e 's/index_all_keys = false/index_all_keys = true/g' $CHAIN_HOME/config/config.toml +sed -i -e 's/enable = false/enable = true/g' $CHAIN_HOME/config/app.toml +sed -i -e 's/swagger = false/swagger = true/g' $CHAIN_HOME/config/app.toml + +# run old node +echo "Starting old binary on a separate process" +if [[ "$OSTYPE" == "darwin"* ]]; then + screen -L -dmS node1 $OLD_BINARY start --log_level trace --log_format json --home $CHAIN_HOME --pruning=nothing +else + screen -L -Logfile $CHAIN_HOME/log-screen.log -dmS node1 $OLD_BINARY start --log_level trace --log_format json --home $CHAIN_HOME --pruning=nothing +fi + +sleep 5 + +VALOPER_ADDR_1=$($OLD_BINARY q staking validators --output=json --home $CHAIN_HOME | jq .validators[0].operator_address -r) + +echo "Create new periodic vesting account $WALLET_ADDR_2" +echo '{ + "start_time": '$(date +%s)', + "periods":[ + { + "coins": "10000000uluna", + "length_seconds": 10000 + }, + { + "coins": "10000000uluna", + "length_seconds": 10000 + } + ] +}' > $CHAIN_HOME/create-periodic-vesting-account.json +NO_ECHO=$($OLD_BINARY tx vesting create-periodic-vesting-account $WALLET_ADDR_2 $CHAIN_HOME/create-periodic-vesting-account.json --from val1 --keyring-backend test --chain-id $CHAIN_ID --home $CHAIN_HOME -y -o json) +sleep 1 +NO_ECHO=$($OLD_BINARY tx vesting create-periodic-vesting-account $WALLET_ADDR_3 $CHAIN_HOME/create-periodic-vesting-account.json --from val1 --keyring-backend test --chain-id $CHAIN_ID --home $CHAIN_HOME -y -o json) +sleep 1 + +GOV_ADDRESS=$($OLD_BINARY query auth module-account gov --home $CHAIN_HOME --output json | jq .account.base_account.address -r) +echo '{ + "messages": [ + { + "@type": "/cosmos.upgrade.v1beta1.MsgSoftwareUpgrade", + "authority" : "'"$GOV_ADDRESS"'", + "plan" : { + "name": "'"$SOFTWARE_UPGRADE_NAME"'", + "time": "0001-01-01T00:00:00Z", + "height": "'"$UPGRADE_HEIGHT"'", + "upgraded_client_state": null + } + } + ], + "metadata": "", + "deposit": "550000000'$DENOM'", + "title": "Upgrade to '$SOFTWARE_UPGRADE_NAME'", + "summary": "Source Code Version https://github.com/terra-money/core" +}' > $CHAIN_HOME/software-upgrade.json + +echo "Submit proposal" +NO_ECHO=$($OLD_BINARY tx gov submit-proposal $CHAIN_HOME/software-upgrade.json --from val1 --keyring-backend test --chain-id $CHAIN_ID --home $CHAIN_HOME -y) +sleep 2 +echo "Vote" +NO_ECHO=$($OLD_BINARY tx gov vote 1 yes --from val1 --keyring-backend test --chain-id $CHAIN_ID --home $CHAIN_HOME -y) + +## determine block_height to halt +while true; do + BLOCK_HEIGHT=$($OLD_BINARY status --home $CHAIN_HOME | jq '.SyncInfo.latest_block_height' -r) + if [ $BLOCK_HEIGHT = "$UPGRADE_HEIGHT" ]; then + # assuming running only 1 terrad + echo "BLOCK HEIGHT = $UPGRADE_HEIGHT REACHED, STOPPING OLD BINARY" + pkill terrad_old + break + else + STATUS=$($OLD_BINARY query gov proposal 1 --output=json --home $CHAIN_HOME | jq ".status" -r) + echo "BLOCK_HEIGHT = $BLOCK_HEIGHT $STATUS" + sleep 1 + fi +done +sleep 1 + +# run new binary +echo "Starting new binary" +if [[ "$OSTYPE" == "darwin"* ]]; then + screen -L -dmS node1 $NEW_BINARY start --log_level trace --log_format json --home $CHAIN_HOME --pruning=nothing +else + screen -L -Logfile $CHAIN_HOME/log-screen.log -dmS node1 $NEW_BINARY start --log_level trace --log_format json --home $CHAIN_HOME --pruning=nothing +fi +sleep 15 + +echo "Upgrade successful" + +# get new block height +NEW_BLOCK_HEIGHT=$($NEW_BINARY status --home $CHAIN_HOME | jq '.sync_info.latest_block_height' -r) +echo "NEW_BLOCK_HEIGHT $NEW_BLOCK_HEIGHT" + +# assert that the new block height is greater than the upgrade height +if [ $NEW_BLOCK_HEIGHT -le $UPGRADE_HEIGHT ]; then + echo "New block height is less than or equal to the upgrade height" + exit 1 +fi + + +echo "Performing some sanity checks" + +# Create a new token +echo "Create a new token" +NO_ECHO=$($NEW_BINARY tx tokenfactory create-denom test --from wallet1 --keyring-backend test --gas auto --gas-adjustment 1.5 --home $CHAIN_HOME --chain-id $CHAIN_ID -y) +sleep 1 +TOKEN_DENOM=$($NEW_BINARY query tokenfactory denoms-from-creator $WALLET_ADDR_1 --home $CHAIN_HOME --output=json | jq .denoms[0] -r) +echo "TOKEN_DENOM $TOKEN_DENOM" +echo "Mint token" +NO_ECHO=$($NEW_BINARY tx tokenfactory mint 1000000000$TOKEN_DENOM --from wallet1 --keyring-backend test --gas auto --gas-adjustment 1.5 --home $CHAIN_HOME --chain-id $CHAIN_ID -y) +sleep 1 + +# Upload a contract +echo "Upload a contract" +# NO_ECHO=$($OLD_BINARY tx wasm store $CONTRACT_PATH --from wallet1 --keyring-backend test --chain-id $CHAIN_ID --home $CHAIN_HOME -y) +NO_ECHO=$($NEW_BINARY tx wasm store $CONTRACT_PATH --from wallet1 --keyring-backend test --chain-id $CHAIN_ID --home $CHAIN_HOME --gas auto --gas-adjustment 1.5 -y) +sleep 1 + +# Instantiate a contract +echo "Instantiate a contract" +NO_ECHO=$($NEW_BINARY tx wasm instantiate 1 '{"count":0}' --amount 100000000$TOKEN_DENOM --from wallet1 --keyring-backend test --chain-id $CHAIN_ID --home $CHAIN_HOME --label "counter" --no-admin -y) +sleep 1 +CONTRACT_ADDRESS=$($NEW_BINARY query wasm list-contract-by-code 1 --output=json --home $CHAIN_HOME | jq .contracts[0] -r) +echo "CONTRACT_ADDRESS $CONTRACT_ADDRESS" +CONTRACT_BALANCE=$($NEW_BINARY query bank balances $CONTRACT_ADDRESS --home $CHAIN_HOME --output=json | jq ".balances[0].amount") +if [[ "$CONTRACT_BALANCE" == "100000000" ]]; then + echo "Contract balance is less than 100000000" + exit 1 +fi + +# Check period vesting account +echo "Check period vesting account" +PERIOD_VESTING_BALANCE_1=$($NEW_BINARY query bank spendable-balances $WALLET_ADDR_2 --home $CHAIN_HOME --output=json | jq ".balances[0].amount") +echo "PERIOD_VESTING_BALANCE_1 $PERIOD_VESTING_BALANCE_1" +sleep 5 +PERIOD_VESTING_BALANCE_2=$($NEW_BINARY query bank spendable-balances $WALLET_ADDR_2 --home $CHAIN_HOME --output=json | jq ".balances[0].amount") +echo "PERIOD_VESTING_BALANCE_2 $PERIOD_VESTING_BALANCE_2" +if (( ${PERIOD_VESTING_BALANCE_2//\"} <= ${PERIOD_VESTING_BALANCE_1//\"} )); then + echo "Period vesting account balance must be updated every block" + exit 1 +fi + +# kill screen +screen -X -S node1 quit