Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/upgrade: added consensus version tracking (part of ADR-041) #8743

Merged
merged 42 commits into from
Mar 19, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
e900fb1
-added consensus version tracking to x/upgrade
technicallyty Mar 2, 2021
036db4f
-added interface to module manager -added e2e test for migrations usi…
technicallyty Mar 3, 2021
b640766
Merge branch 'master' into ty-8514-module_tracking
technicallyty Mar 3, 2021
8c7b105
Merge branch 'master' into ty-8514-module_tracking
technicallyty Mar 3, 2021
5c1ae59
Changed MigrationMap identifier to VersionMap
technicallyty Mar 4, 2021
4c48f35
updated docs
technicallyty Mar 4, 2021
6db21e3
forgot this
technicallyty Mar 4, 2021
c9b435a
added line to changelog for this PR
technicallyty Mar 4, 2021
1c5b132
Change set consensus version function to match adr 041 spec
technicallyty Mar 8, 2021
304abfa
add documentation
technicallyty Mar 8, 2021
d06bbbd
Merge branch 'master' into ty-8514-module_tracking
technicallyty Mar 8, 2021
5c75ead
Merge branch 'ty-8514-module_tracking' of https://github.com/technica…
technicallyty Mar 8, 2021
e53423e
remove newline from changelog
technicallyty Mar 8, 2021
c36086f
updated example in simapp for RunMigrations, SetCurrentConsensusVersi…
technicallyty Mar 8, 2021
758c67d
switch TestMigrations to use Require instead of t.Fatal
technicallyty Mar 8, 2021
0dac9c2
Update CHANGELOG.md
technicallyty Mar 10, 2021
8f526ef
docs for SetVersionManager
technicallyty Mar 10, 2021
027740d
-init genesis method added -removed panics/fails from setting consens…
technicallyty Mar 11, 2021
18eaed2
merge master
technicallyty Mar 11, 2021
fc38e5a
update identifiers to be more go-like
technicallyty Mar 12, 2021
28d5c04
Merge branch 'master' into ty-8514-module_tracking
technicallyty Mar 12, 2021
1fca959
update docs and UpgradeHandler fnc sig
technicallyty Mar 15, 2021
d912f4f
Merge branch 'master' into ty-8514-module_tracking
technicallyty Mar 15, 2021
a99c538
Upgrade Keeper now takes a VersionMap instead of a VersionManager int…
technicallyty Mar 15, 2021
e6424ce
upgrade keeper transition to Version Map
technicallyty Mar 16, 2021
9b40fe7
Merge branch 'master' into ty-8514-module_tracking
technicallyty Mar 16, 2021
799b646
cleanup, added versionmap return to RunMigrations
technicallyty Mar 16, 2021
0f9447c
quick fix
technicallyty Mar 16, 2021
a157c48
Merge branch 'master' into ty-8514-module_tracking
technicallyty Mar 17, 2021
b839a59
Update docs/architecture/adr-041-in-place-store-migrations.md
technicallyty Mar 17, 2021
75f8ae5
remove support for versionmap field on upgrade keeper
technicallyty Mar 17, 2021
22ab55e
cleanup
technicallyty Mar 17, 2021
47ce533
merge adr change
technicallyty Mar 17, 2021
7f5b6aa
rename get/set version map keeper functions
technicallyty Mar 18, 2021
8547426
update adr doc to match name changes
technicallyty Mar 18, 2021
1504a2d
Merge branch 'master' into ty-8514-module_tracking
technicallyty Mar 18, 2021
c3072ab
remove redudant line
technicallyty Mar 19, 2021
1f82fff
Merge branch 'ty-8514-module_tracking' of https://github.com/technica…
technicallyty Mar 19, 2021
cf1343f
Merge branch 'master' into ty-8514-module_tracking
technicallyty Mar 19, 2021
3f6bea8
Merge branch 'master' into ty-8514-module_tracking
aaronc Mar 19, 2021
d987555
Merge branch 'master' into ty-8514-module_tracking
technicallyty Mar 19, 2021
5d6e4ab
Merge branch 'master' into ty-8514-module_tracking
mergify[bot] Mar 19, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
cleanup, added versionmap return to RunMigrations
  • Loading branch information
technicallyty committed Mar 16, 2021
commit 799b646a97f46c6e2d1c8fbf727806b11c91d866
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* [\#8629](https://github.com/cosmos/cosmos-sdk/pull/8629) Deprecated `SetFullFundraiserPath` from `Config` in favor of `SetPurpose` and `SetCoinType`.
* (x/upgrade) [\#8673](https://github.com/cosmos/cosmos-sdk/pull/8673) Remove IBC logic from x/upgrade. Deprecates IBC fields in an Upgrade Plan. IBC upgrade logic moved to 02-client and an IBC UpgradeProposal is added.
* (x/bank) [\#8517](https://github.com/cosmos/cosmos-sdk/pull/8517) `SupplyI` interface and `Supply` are removed and uses `sdk.Coins` for supply tracking
* (x/upgrade) [\#8743](https://github.com/cosmos/cosmos-sdk/pull/8743) `UpgradeHandler` includes a new argument `VersionManager` which retreives module consensus versions from upgrade's new store.
* (x/upgrade) [\#8743](https://github.com/cosmos/cosmos-sdk/pull/8743) `UpgradeHandler` includes a new argument `VersionMap` which helps facilitate in-place migrations.
* (x/auth) [\#8129](https://github.com/cosmos/cosmos-sdk/pull/8828) Updated `SigVerifiableTx.GetPubKeys` method signature to return error.


Expand Down
8 changes: 4 additions & 4 deletions docs/architecture/adr-041-in-place-store-migrations.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,23 +85,23 @@ We introduce a new prefix store in `x/upgrade`'s store. This store will track ea
0x2 | {bytes(module_name)} => BigEndian(module_consensus_version)
```

We add a new private field `versionMap` of type `VersionMap` to `x/upgrade`'s keeper, where `VersionManager` is:
We add a new private field `versionMap` of type `VersionMap` to `x/upgrade`'s keeper, where `VersionMap` is:

```go
// Map of module name => new module Consensus Version.
type VersionMap map[string]uint64
```

This `versionMap` field can be modified via the `SetInitialVersionMap` field, and will allow the upgrade keeper to know the current versions of loaded modules. `SetInitialVersionMap` MUST be called as early as possible in the app initialization; in the SDK's `simapp`, it is called in the `NewSimApp` constructor function.
This `versionMap` field can be modified via the `SetInitialVersionMap` field, and will allow the upgrade keeper to know the current versions of loaded modules. `SetInitialVersionMap` MUST be called AFTER the `module.NewManager()` is called; in the SDK's `simapp`, it is called in the `NewSimApp` constructor function.
technicallyty marked this conversation as resolved.
Show resolved Hide resolved

The UpgradeHandler signature needs to be updated to take a `VersionMap`, as well as return a new `VersionMap` and an error:
The UpgradeHandler signature needs to be updated to take a `VersionMap`, as well as return an upgraded `VersionMap` and an error:

```diff
- type UpgradeHandler func(ctx sdk.Context, plan Plan)
+ type UpgradeHandler func(ctx sdk.Context, plan Plan, versionMap VersionMap) (VersionMap, error)
```

To apply an upgrade, we query the `VersionMap` from the `x/upgrade` store and pass it into the handler. The handler runs the actual migration functions (see next section), and if successful, returns the updated ConsensusVersions of the modules to be stored in state.
To apply an upgrade, we query the `VersionMap` from the `x/upgrade` store and pass it into the handler. The handler runs the actual migration functions (see next section), and if successful, returns an updated `VersionMap` to be stored in state.

```diff
func (k UpgradeKeeper) ApplyUpgrade(ctx sdk.Context, plan types.Plan) {
Expand Down
2 changes: 1 addition & 1 deletion docs/run-node/cosmovisor.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ In `simapp/app.go`, find the line containing the upgrade Keeper initialisation,
After that line, add the following snippet:

```
app.UpgradeKeeper.SetUpgradeHandler("test1", func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) {
app.UpgradeKeeper.SetUpgradeHandler("test1", func(ctx sdk.Context, plan upgradetypes.Plan) {
// Add some coins to a random account
addr, err := sdk.AccAddressFromBech32("cosmos18cgkqduwuh253twzmhedesw3l7v3fm37sppt58")
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ func (app *SimApp) RegisterTendermintService(clientCtx client.Context) {
// app.UpgradeKeeper.SetUpgradeHandler("store-migration", func(ctx sdk.Context, plan upgradetypes.Plan, versionMap module.VersionMap) {
// return app.RunMigrations(ctx, versionMap)
// })
func (app *SimApp) RunMigrations(ctx sdk.Context, migrateFromVersions module.VersionMap) error {
func (app *SimApp) RunMigrations(ctx sdk.Context, migrateFromVersions module.VersionMap) (module.VersionMap, error) {
return app.mm.RunMigrations(ctx, app.configurator, migrateFromVersions)
}

Expand Down
2 changes: 1 addition & 1 deletion simapp/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func TestRunMigrations(t *testing.T) {
// Run migrations only for bank. That's why we put the initial
// version for bank as 1, and for all other modules, we put as
// their latest ConsensusVersion.
err = app.RunMigrations(
_, err = app.RunMigrations(
app.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()}),
module.VersionMap{
"bank": 1,
Expand Down
12 changes: 7 additions & 5 deletions types/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,20 +338,22 @@ type MigrationHandler func(sdk.Context) error
type VersionMap map[string]uint64

// RunMigrations performs in-place store migrations for all modules.
func (m Manager) RunMigrations(ctx sdk.Context, cfg Configurator, vm VersionMap) error {
func (m Manager) RunMigrations(ctx sdk.Context, cfg Configurator, fromVM VersionMap) (VersionMap, error) {
c, ok := cfg.(configurator)
if !ok {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "expected %T, got %T", configurator{}, cfg)
return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "expected %T, got %T", configurator{}, cfg)
}

updatedVM := make(VersionMap)
for moduleName, module := range m.Modules {
err := c.runModuleMigrations(ctx, moduleName, vm[moduleName], module.ConsensusVersion())
err := c.runModuleMigrations(ctx, moduleName, fromVM[moduleName], module.ConsensusVersion())
updatedVM[moduleName] = module.ConsensusVersion()
if err != nil {
return err
return nil, err
}
}

return nil
return updatedVM, nil
}

// BeginBlock performs begin block functionality for all modules. It creates a
Expand Down
1 change: 0 additions & 1 deletion x/upgrade/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ func NewKeeper(skipUpgradeHeights map[int64]bool, storeKey sdk.StoreKey, cdc cod
storeKey: storeKey,
cdc: cdc,
upgradeHandlers: map[string]types.UpgradeHandler{},
versionMap: module.VersionMap{},
}
}

Expand Down
2 changes: 1 addition & 1 deletion x/upgrade/spec/02_state.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ by the corresponding module name of type `string`.
- ConsensusVersion: `0x2 | byte(module name) -> BigEndian(Module Consensus Version)`


The `x/upgrade` module contains no genesis state.
The `x/upgrade` module contains no genesis state.