Skip to content

Commit

Permalink
feat: set upgrade handler for v2-Daisy (#250)
Browse files Browse the repository at this point in the history
* Set the upgrade handler for v2-Daisy

* Update CHANGELOG.md

* Check upgrade name

* Add the test into CI
  • Loading branch information
0Tech authored Aug 8, 2023
1 parent ef1cf05 commit 7d611f5
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 ###
Expand Down
8 changes: 8 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ import (
)

const appName = "Finschia"
const upgradeName = "v2-Daisy"

var (
// DefaultNodeHome default home directories for the application daemon
Expand Down Expand Up @@ -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
Expand Down
27 changes: 27 additions & 0 deletions contrib/check-upgrade-name.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 7d611f5

Please sign in to comment.