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

ADR 041: In-Place Store Migrations #8646

Merged
merged 26 commits into from
Mar 4, 2021
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
a23b5fa
Initial draft
amaury1093 Feb 17, 2021
6f69bc5
Draft
amaury1093 Feb 19, 2021
9f24445
Add x/upgrade stuff
amaury1093 Feb 19, 2021
f153843
Tweaks
amaury1093 Feb 19, 2021
6993093
Merge branch 'master' into am/adr-in-place-migrations
jgimeno Mar 3, 2021
0eea75b
Update docs/architecture/adr-041-in-place-store-migrations.md
amaury1093 Mar 4, 2021
151149b
Reviews
amaury1093 Mar 4, 2021
01c3507
Merge branch 'am/adr-in-place-migrations' of ssh://github.com/cosmos/…
amaury1093 Mar 4, 2021
6dc29f9
Use migrator
amaury1093 Mar 4, 2021
94c0475
Update docs/architecture/adr-041-in-place-store-migrations.md
amaury1093 Mar 4, 2021
2f7fede
Update docs/architecture/adr-041-in-place-store-migrations.md
amaury1093 Mar 4, 2021
8494883
Update docs/architecture/adr-041-in-place-store-migrations.md
amaury1093 Mar 4, 2021
aaa991b
Update docs/architecture/adr-041-in-place-store-migrations.md
amaury1093 Mar 4, 2021
3579a10
Update docs/architecture/adr-041-in-place-store-migrations.md
amaury1093 Mar 4, 2021
865713e
Update docs/architecture/adr-041-in-place-store-migrations.md
amaury1093 Mar 4, 2021
cb361b7
Update docs/architecture/adr-041-in-place-store-migrations.md
amaury1093 Mar 4, 2021
1f1d4ce
Update docs/architecture/adr-041-in-place-store-migrations.md
amaury1093 Mar 4, 2021
cbda00b
Merge branch 'am/adr-in-place-migrations' of ssh://github.com/cosmos/…
amaury1093 Mar 4, 2021
31357e6
More fixes
amaury1093 Mar 4, 2021
0fc97c5
Add grpc, use functions
amaury1093 Mar 4, 2021
53a13ab
Add special case with 0 version
amaury1093 Mar 4, 2021
9e07b4d
Update docs/architecture/adr-041-in-place-store-migrations.md
amaury1093 Mar 4, 2021
41386ca
Update docs/architecture/adr-041-in-place-store-migrations.md
amaury1093 Mar 4, 2021
606aec1
Update docs/architecture/adr-041-in-place-store-migrations.md
amaury1093 Mar 4, 2021
633d07b
Remove useless err return
amaury1093 Mar 4, 2021
dd2b62c
Merge branch 'master' into am/adr-in-place-migrations
mergify[bot] Mar 4, 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
Use migrator
  • Loading branch information
amaury1093 committed Mar 4, 2021
commit 6dc29f96ea69e72d7d26f0240a3b3e43b3b0b8ca
23 changes: 10 additions & 13 deletions docs/architecture/adr-041-in-place-store-migrations.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,21 @@ func (am AppModule) RegisterServices(cfg module.Configurator) {

For example, if the current ConsensusVersion of a module is `N` , then `N-1` migration scripts MUST be registered in the configurator.
amaury1093 marked this conversation as resolved.
Show resolved Hide resolved

In the SDK, the migration scripts are handled by each module's keeper, because the keeper holds the `sdk.StoreKey` used to perform in-place store migrations. A `MigrationKeeper` interface is implemented by each keeper:
In the SDK, the migration scripts are handled by each module's keeper, because the keeper holds the `sdk.StoreKey` used to perform in-place store migrations. To not overload the keeper, a `Migrator` wrapper is used by each module to handle the migration scripts:

```go
// MigrationKeeper is an interface that the keeper implements for handling
// in-place store migrations.
type MigrationKeeper interface {
// Migrate1 migrates the store from version 1 to 2.
Migrate1(ctx sdk.Context) error

// ...Add more MigrateN scripts here.
// Migrator is a struct for handling in-place store migrations.
type Migrator struct {
keeper BaseKeeper
amaury1093 marked this conversation as resolved.
Show resolved Hide resolved
}
```

Since migration scripts manipulate legacy code, they should live inside the `legacy/` folder of each module, and be called by the keeper's implementation of `MigrationKeeper`.
Since migration scripts manipulate legacy code, they should live inside the `legacy/` folder of each module, and be called by the Migrator's methods. We propose the format `Migrate{M}to{N}` for method names.

```go
func (keeper BankKeeper) Migrate1(ctx sdk.Context) error {
return v042bank.MigrateStore(ctx, keeper.storeKey) // v042bank is package `x/bank/legacy/v042`.
// Migrate1to2 migrates from version 1 to 2.
func (m Migrator) Migrate1to2(ctx sdk.Context) error {
return v042bank.MigrateStore(ctx, m.keeper.storeKey) // v042bank is package `x/bank/legacy/v042`.
}
```

Expand All @@ -89,10 +86,10 @@ We introduce a new prefix store in `x/upgrade`'s store. This store will track ea
```

s
We add a new parameter `ModuleManager` `x/upgrade`'s `NewKeeper` constructor, where ModuleManager is:
We add a new field `VersionManager` `x/upgrade`'s keeper, where `VersionManager` is:

```go
type ModuleManager interface {
type VersionManager interface {
GetConsensusVersions() MigrationMap
}

Expand Down