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

Conversation

amaury1093
Copy link
Contributor

@amaury1093 amaury1093 commented Feb 19, 2021

Description

closes #8532

rendered

Please note that the implementation of this ADR has already started as part of #8345


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against correct branch (see CONTRIBUTING.md)
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the module structure standards.
  • Wrote unit and integration tests
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/)
  • Added relevant godoc comments.
  • Added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • Re-reviewed Files changed in the Github PR explorer
  • Review Codecov Report in the comment section below once CI passes

@amaury1093 amaury1093 added the T: ADR An issue or PR relating to an architectural decision record label Feb 19, 2021
Copy link
Collaborator

@anilcse anilcse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 this is a great addition. Thanks @AmauryM for the ADR.
Just small nits otherwise, looks great

@jgimeno
Copy link
Contributor

jgimeno commented Mar 3, 2021

Just a little idea, instead of per module increasing of protocolVersion that is somehow "arbitrary" wouldn't it be better if there was a fixed general version and the modules that update can subscribe their update to it?

In the end we only migrate when we change version, ex. 2.0.1 to 3, even minor versions too.

So for example staking can subscribe an update to version 2.0.1, but maybe wont subscribe to version 3 when it comes.

@gsora
Copy link
Contributor

gsora commented Mar 3, 2021

wouldn't it be better if there was a fixed general version and the modules that update can subscribe their update to it?

I wonder if we could use the upgrade plan name instead of version numbers, this way it would be even more clear from a administration perspective.

I agree on the subscription idea, it would be easier to maintain in the future.

@aaronc
Copy link
Member

aaronc commented Mar 3, 2021

Just a little idea, instead of per module increasing of protocolVersion that is somehow "arbitrary" wouldn't it be better if there was a fixed general version and the modules that update can subscribe their update to it?

I don't really consider it arbitrary at all. When a module introduces a state machine breaking change it increments its version creating a mechanism for running automatic migrations.

I wonder if we could use the upgrade plan name instead of version numbers, this way it would be even more clear from a administration perspective.

The upgrade plan names live at a totally different level from these module versions. Each chain using modules has their own upgrade names, but modules need a way to track their own state machine version. That's all this is doing.

@jgimeno
Copy link
Contributor

jgimeno commented Mar 3, 2021

Thanks for clarification @aaronc, makes a lot of sense.

Copy link
Member

@aaronc aaronc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally LGTM. Thanks @AmauryM !

Comment on lines 123 to 125
- Fetch the old ConsensusVersion of the module from its `migrationMap` argument (let's call it `M`).
- Fetch the new ConsensusVersion of the module from the `ConsensusVersion()` method on `AppModule` (call it `N`).
- If `N>M`, run all registered migrations for the module sequentially `M -> M+1 -> M+2...` until `N`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's explain that if there is no old ConsensusVersion, no migration is run but the version is set in the new migration map. i.e. if we add module foo to our chain at version 5, no migrations will be run but 5 will be saved as the current version after migrations are run.

Copy link
Contributor Author

@amaury1093 amaury1093 Mar 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. The upgradeKeeper.SetCurrentConsensusVersions() method to store the current module versions is run right after the upgrade handler.

docs/architecture/adr-041-in-place-store-migrations.md Outdated Show resolved Hide resolved
docs/architecture/adr-041-in-place-store-migrations.md Outdated Show resolved Hide resolved
amaury1093 and others added 8 commits March 4, 2021 12:49
Co-authored-by: Aaron Craelius <aaron@regen.network>
Co-authored-by: Robert Zaremba <robert@zaremba.ch>
Co-authored-by: Robert Zaremba <robert@zaremba.ch>
Co-authored-by: Robert Zaremba <robert@zaremba.ch>
Co-authored-by: Robert Zaremba <robert@zaremba.ch>
Co-authored-by: Robert Zaremba <robert@zaremba.ch>
Co-authored-by: Robert Zaremba <robert@zaremba.ch>
@amaury1093
Copy link
Contributor Author

This is a very good improvement, the only thing that I still feel not totally convinced is the pattern of adding a new method every time we want to add a migration to the keeper, couldn't we use more a composition pattern here? Not to make the keepers fat?

to make the keepers not so fat, I added in the latest commits the Migrator wrapper suggested by Robert. lmk if that's a better separation of concerns.

Copy link
Contributor

@alessio alessio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK

Copy link
Contributor

@jgimeno jgimeno left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @AmauryM @aaronc , I love the improvements. ACK!

Copy link
Collaborator

@robert-zaremba robert-zaremba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

Copy link
Member

@aaronc aaronc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 🎉 . Left a few minor comments. Feel free to merge when ready.

amaury1093 and others added 4 commits March 4, 2021 18:21
Co-authored-by: Aaron Craelius <aaron@regen.network>
Co-authored-by: Aaron Craelius <aaron@regen.network>
Co-authored-by: Aaron Craelius <aaron@regen.network>
@amaury1093 amaury1093 added the A:automerge Automatically merge PR once all prerequisites pass. label Mar 4, 2021
@mergify mergify bot merged commit 95fa768 into master Mar 4, 2021
@mergify mergify bot deleted the am/adr-in-place-migrations branch March 4, 2021 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A:automerge Automatically merge PR once all prerequisites pass. T: ADR An issue or PR relating to an architectural decision record
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create spec / ADR for module version upgrade mechanism
9 participants