-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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: Add x/gov v043->v046 migrations #11036
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
093f48e
Add proposal migration
amaury1093 eaa94fd
Add conversion functions
amaury1093 933cf8f
Add JSON migration and tests
amaury1093 341a777
Add store tests
amaury1093 736d96b
Merge branch 'master' of ssh://github.com/cosmos/cosmos-sdk into am/1…
amaury1093 0a26300
Merge branch 'master' of ssh://github.com/cosmos/cosmos-sdk into am/1…
amaury1093 9ed859f
Move all conversion functions inside one file
amaury1093 eab183f
fix build
amaury1093 eaae9ad
Update cl
amaury1093 2b88cd6
Update x/genutil/migrations/v046/migrate.go
amaury1093 89cd20c
Handle old vote Option field
amaury1093 8c125af
Merge branch 'am/10869-migrations' of ssh://github.com/cosmos/cosmos-…
amaury1093 06c2ac6
Update x/gov/migrations/v046/convert.go
atheeshp 5fd3948
Merge branch 'master' into am/10869-migrations
atheeshp 345d526
Merge branch 'master' into am/10869-migrations
amaury1093 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package v046 | ||
|
||
import ( | ||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/x/genutil/types" | ||
v043gov "github.com/cosmos/cosmos-sdk/x/gov/migrations/v043" | ||
v046gov "github.com/cosmos/cosmos-sdk/x/gov/migrations/v046" | ||
gov "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" | ||
) | ||
|
||
// Migrate migrates exported state from v0.43 to a v0.46 genesis state. | ||
func Migrate(appState types.AppMap, clientCtx client.Context) types.AppMap { | ||
// Migrate x/gov. | ||
if appState[v043gov.ModuleName] != nil { | ||
// unmarshal relative source genesis application state | ||
var oldGovState gov.GenesisState | ||
clientCtx.Codec.MustUnmarshalJSON(appState[v043gov.ModuleName], &oldGovState) | ||
|
||
// delete deprecated x/gov genesis state | ||
delete(appState, v043gov.ModuleName) | ||
|
||
// Migrate relative source genesis application state and marshal it into | ||
// the respective key. | ||
newGovState, err := v046gov.MigrateJSON(&oldGovState) | ||
if err != nil { | ||
panic(err) | ||
} | ||
appState[v046gov.ModuleName] = clientCtx.Codec.MustMarshalJSON(newGovState) | ||
} | ||
|
||
return appState | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package v046 | ||
|
||
import ( | ||
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" | ||
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta2" | ||
) | ||
|
||
// MigrateJSON accepts exported v0.43 x/gov genesis state and migrates it to | ||
// v0.46 x/gov genesis state. The migration includes: | ||
// | ||
// - Updating everything to v1beta2. | ||
// - Migrating proposals to be Msg-based. | ||
func MigrateJSON(oldState *v1beta1.GenesisState) (*v1beta2.GenesisState, error) { | ||
newProps, err := convertToNewProposals(oldState.Proposals) | ||
if err != nil { | ||
return nil, err | ||
} | ||
newVotes, err := convertToNewVotes(oldState.Votes) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
depParams, votingParms, tallyParams := convertToNewDepParams(oldState.DepositParams), convertToNewVotingParams(oldState.VotingParams), convertToNewTallyParams(oldState.TallyParams) | ||
|
||
return &v1beta2.GenesisState{ | ||
StartingProposalId: oldState.StartingProposalId, | ||
Deposits: convertToNewDeposits(oldState.Deposits), | ||
Votes: newVotes, | ||
Proposals: newProps, | ||
DepositParams: &depParams, | ||
VotingParams: &votingParms, | ||
TallyParams: &tallyParams, | ||
}, nil | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we use 1, 2, and 3 version numbers - do they relate to anything. Might it be more intuitive to specify SDK version migrations?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We decided in adr-041 to use uint here. I guess the idea back then was to prepare when modules will have their own go.mods. It might be that this ConsensusVersion == the major version in go.mod. Or not. Anyways, I think it's better for modules to have independent consensus versions than be tied up to SDK versions.
(note the
v04*
migration folders could probably be renamed though).