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

feat: state migration from IAVL to SMT (ADR-040) #10962

Merged
merged 41 commits into from
Mar 20, 2022

Conversation

gsk967
Copy link
Contributor

@gsk967 gsk967 commented Jan 18, 2022

State migration from iavl to smt

This migration works on upgrade handler

app.registerUpgradeHandlers()


func (app *SimApp) registerUpgradeHandlers() {
	// This is the upgrade plan name we used in the gov proposal.
	upgradeName := "iavl-to-smt-upgrade"
	app.UpgradeKeeper.SetUpgradeHandler(upgradeName, func(ctx sdk.Context, plan upgradetypes.Plan, _ module.VersionMap) (module.VersionMap, error) {
	
	        fromVM := map[string]uint64{
			...
		}
		
	        err := store2.MigrateV2(iavlStore, v2Store)
                if err != nil {
                    return fromVM, err 
                }
		
		return app.mm.RunMigrations(ctx, app.configurator, fromVM)
	})
}

Description

Closes: #XXXX


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title
  • added ! to the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • followed the guidelines for building modules
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • updated the relevant documentation or specification
  • reviewed "Files changed" and left comments if necessary
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage
  • manually tested (if applicable)

State migration from iavl to smt
@i-norden i-norden changed the title feat: add migration for adr40 feat: ADR-040: add migration for adr40 Jan 19, 2022
@i-norden
Copy link
Contributor

For #10803 and #10891

@i-norden i-norden requested a review from aaronc January 19, 2022 15:10
Copy link
Contributor

@roysc roysc left a comment

Choose a reason for hiding this comment

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

This should work, but we should introduce it in the context of the command where it will be used, and include a unit test. We should make the usage clear: the v2 store schema needs to contain all the v1 stores at initialization.

store/v2/multi/migration.go Outdated Show resolved Hide resolved
@gsk967 gsk967 requested a review from roysc January 20, 2022 08:05
Copy link
Contributor

@i-norden i-norden left a comment

Choose a reason for hiding this comment

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

A few comments, thanks!

store/v2/multi/migration.go Outdated Show resolved Hide resolved
store/v2/multi/migration.go Outdated Show resolved Hide resolved
store/v2/multi/migration.go Outdated Show resolved Hide resolved
store/v2/multi/migration.go Outdated Show resolved Hide resolved
store/v2/multi/migration.go Outdated Show resolved Hide resolved
@gsk967
Copy link
Contributor Author

gsk967 commented Jan 27, 2022

@i-norden I address the pr comments, Can you please review it again.

@gsk967 gsk967 requested a review from i-norden January 27, 2022 05:29
@gsk967 gsk967 changed the title feat: ADR-040: add migration for adr40 feat (ADR-040) : state migration from IAVL to SMT Jan 27, 2022
@gsk967 gsk967 marked this pull request as ready for review January 27, 2022 05:31
@gsk967 gsk967 requested a review from alexanderbez as a code owner January 27, 2022 05:31
store/v2/multi/migration.go Outdated Show resolved Hide resolved
store/v2/multi/migration.go Outdated Show resolved Hide resolved
store/v2/multi/migration.go Outdated Show resolved Hide resolved
@gsk967 gsk967 changed the title feat (ADR-040) : state migration from IAVL to SMT feat: state migration from IAVL to SMT (ADR-040) Jan 29, 2022
@gsk967 gsk967 requested a review from roysc January 29, 2022 13:51
@gsk967 gsk967 requested review from robert-zaremba and roysc March 4, 2022 06:35
@gsk967
Copy link
Contributor Author

gsk967 commented Mar 4, 2022

@robert-zaremba @roysc I address the pr comments, can you look into those changesd

Copy link
Contributor

@roysc roysc left a comment

Choose a reason for hiding this comment

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

LGTM

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.

not everything was addressed.

store/rootmulti/store.go Outdated Show resolved Hide resolved
func (rs *Store) GetStores() map[types.StoreKey]types.CommitKVStore {
return rs.stores
// GetStoreNames returns the storeNames and StoreKeys
func (rs *Store) GetStoreNames() map[string]types.StoreKey {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why renaming? If we want to rename then let's be more precise. I suggest: StoreKeysByName (no need for Get prefix)

)

// MigrateV2 will migrate the state from iavl to smt
func MigrateV2(rootMultiStore *v1Store.Store, store2db dbm.DBConnection, storeConfig StoreConfig) (*Store, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
func MigrateV2(rootMultiStore *v1Store.Store, store2db dbm.DBConnection, storeConfig StoreConfig) (*Store, error) {
func MigrateFromV1(rootMultiStore *v1Store.Store, store2db dbm.DBConnection, storeConfig StoreConfig) (*Store, error) {


// iterate through the rootmulti stores and save the key/values into smt tree
for _, store := range stores {
subStore, err := rootStore.getSubstore(store.name)
Copy link
Collaborator

@robert-zaremba robert-zaremba Mar 11, 2022

Choose a reason for hiding this comment

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

shouldn't we make sure that we use the same store key when doing migration?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

store/v2/multi/migration_test.go Outdated Show resolved Hide resolved
@gsk967 gsk967 requested a review from robert-zaremba March 11, 2022 14:03
Copy link
Contributor

@roysc roysc left a comment

Choose a reason for hiding this comment

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

Lgtm except for the remaining renames

@@ -210,7 +210,8 @@ func TestMultistoreSnapshotRestore(t *testing.T) {
require.Equal(t, *dummyExtensionItem.GetExtension(), *nextItem.GetExtension())

assert.Equal(t, source.LastCommitID(), target.LastCommitID())
for key, sourceStore := range source.GetStores() {
for _, key := range source.GetStoreNames() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Need to finish the renames in this file

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

@gsk967 gsk967 requested a review from roysc March 15, 2022 12:18
@robert-zaremba
Copy link
Collaborator

@gsk967 you should "resolve" addressed suggestions, it helps with review.

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.

Approving. Please add Changelog updates.

@gsk967
Copy link
Contributor Author

gsk967 commented Mar 17, 2022

@robert-zaremba Update the changelog and move the migration into alpha1

@robert-zaremba robert-zaremba added the A:automerge Automatically merge PR once all prerequisites pass. label Mar 18, 2022
@robert-zaremba
Copy link
Collaborator

@gsk967 a test is not passing.

@mergify mergify bot merged commit ea672d4 into cosmos:master Mar 20, 2022
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. C:Store
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

5 participants