From 7d611f5d4930045540857c2fc7581e86621eb0d9 Mon Sep 17 00:00:00 2001 From: Youngtaek Yoon Date: Tue, 8 Aug 2023 03:14:02 +0000 Subject: [PATCH] feat: set upgrade handler for v2-Daisy (#250) * Set the upgrade handler for v2-Daisy * Update CHANGELOG.md * Check upgrade name * Add the test into CI --- .github/workflows/tests.yml | 8 ++++++++ CHANGELOG.md | 1 + Makefile | 2 ++ app/app.go | 8 ++++++++ contrib/check-upgrade-name.sh | 27 +++++++++++++++++++++++++++ 5 files changed, 46 insertions(+) create mode 100644 contrib/check-upgrade-name.sh diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 37c09088..9f319a40 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -335,3 +335,11 @@ jobs: if [ ${{ steps.test-blocks.outcome }} == 'failure' ] ; then exit 1 fi + + test-upgrade-name: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Test upgrade name + run: | + make test-upgrade-name diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ac75f54..dd2a8feb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (feat) [\#243](https://github.com/Finschia/finschia/pull/243) Bump github.com/Finschia/finschia-sdk from v0.47.0 to v0.47.1-rc1 * (ibc) [\#246](https://github.com/Finschia/finschia/pull/246) Update ibc-go to v4 * (build) [\#248](https://github.com/Finschia/finschia/pull/248) Rename namespace to v2 +* (app) [\#250](https://github.com/Finschia/finschia/pull/250) Set upgrade handler for v2-Daisy ### Improvements * (build) [\#221](https://github.com/Finschia/finschia/pull/221) compile static binary as release assets and docker image diff --git a/Makefile b/Makefile index b2f463ef..2de82c0e 100644 --- a/Makefile +++ b/Makefile @@ -283,6 +283,8 @@ test-integration: build test-integration-multi-node: docker-build @go test -mod=readonly -p 4 `go list ./cli_test/...` $(CLI_MULTI_BUILD_FLAGS) -v +test-upgrade-name: + @sh contrib/check-upgrade-name.sh ############################################################################### ### Docker ### diff --git a/app/app.go b/app/app.go index 4d6deb25..20ccca46 100644 --- a/app/app.go +++ b/app/app.go @@ -131,6 +131,7 @@ import ( ) const appName = "Finschia" +const upgradeName = "v2-Daisy" var ( // DefaultNodeHome default home directories for the application daemon @@ -660,6 +661,13 @@ func NewLinkApp( app.SetAnteHandler(anteHandler) app.SetEndBlocker(app.EndBlocker) + // upgrade + app.UpgradeKeeper.SetUpgradeHandler( + upgradeName, + func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { + return app.mm.RunMigrations(ctx, app.configurator, fromVM) + }) + // must be before loading version // requires the snapshot store to be created and registered as a BaseAppOptions // see cmd/fnsad/cmd/root.go: 257-265 diff --git a/contrib/check-upgrade-name.sh b/contrib/check-upgrade-name.sh new file mode 100644 index 00000000..0ca56d6d --- /dev/null +++ b/contrib/check-upgrade-name.sh @@ -0,0 +1,27 @@ +#!/bin/sh + +set -e + +# get module version from go.mod +module_version=$(grep -E '^module github\.com/Finschia/finschia/v.*$' go.mod | cut -d / -f 4) +if [ -z "$module_version" ] +then + echo module version not found: you must update the script >&2 + false +fi + +# get upgrade version from the upgrade name +upgrade_name=$(sed -nE -e 's/^(const)?[[:blank:]]+upgradeName[[:blank:]]+=[[:blank:]]+"([[:digit:][:alpha:]-]+)"$/\2/p' app/app.go) +upgrade_version=$(printf $upgrade_name | cut -d - -f 1) +if [ -z "$upgrade_version" ] +then + echo upgrade version not found: you must update the script >&2 + false +fi + +if [ $upgrade_version != $module_version ] +then + echo different upgrade version found: you must update the upgrade name >&2 + echo wanted: $module_version-Xxx, got: $upgrade_name + false +fi