-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Add in-place store migrations #8485
Merged
Merged
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
10d72d7
Add 1st version of migrate
amaury1093 8036fca
Merge branch 'master' of ssh://github.com/cosmos/cosmos-sdk into am-8…
amaury1093 a9a406e
Put migration logic into Configurator
amaury1093 9ed3987
add test to bank store migration
amaury1093 a095d3a
add test for configurator
amaury1093 d550bff
Merge branch 'master' into am-8345-migration
amaury1093 b7141f9
Error if no migration found
amaury1093 2d554ce
Remove RunMigrations from Configurator interface
amaury1093 3df3f44
Update spec
amaury1093 ba6bd44
Rename folders
amaury1093 197b7ce
Merge branch 'master' into am-8345-migration
amaury1093 424932c
copy-paste from keys.go
amaury1093 254a71f
Merge branch 'am-8345-migration' of ssh://github.com/cosmos/cosmos-sd…
amaury1093 b6c0714
Fix nil map
amaury1093 9ab7f13
rename function
amaury1093 fc076f5
Update simapp/app.go
amaury1093 ae7b7dc
Update simapp/app_test.go
amaury1093 2c26734
Adderss reviews
amaury1093 eb15047
Merge branch 'am-8345-migration' of ssh://github.com/cosmos/cosmos-sd…
amaury1093 291a9e6
Fix tests
amaury1093 41d29ed
Update testutil/context.go
amaury1093 33494dc
Update docs for ConsensusVersion
amaury1093 e3a2412
Rename to forVersion
amaury1093 6db31d4
Merge branch 'am-8345-migration' of ssh://github.com/cosmos/cosmos-sd…
amaury1093 55f547e
Fix tests
amaury1093 8f3b9d4
Check error early
amaury1093 29b85b7
Return 1 for intiial version
amaury1093 41e0339
Use MigrationKeeper
amaury1093 d922003
Fix test
amaury1093 f422b93
Revert adding marshaler to Configurator
amaury1093 8cf88fe
Godoc updates
amaury1093 5add13a
Update docs
amaury1093 2cef291
Merge branch 'master' into am-8345-migration
aaronc 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
Rename folders
- Loading branch information
commit ba6bd446b8da68cae18d324c07a19f666ac229bd
There are no files selected for viewing
File renamed without changes.
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,28 @@ | ||
package v042 | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/types/address" | ||
) | ||
|
||
// KVStore keys | ||
var ( | ||
// BalancesPrefix is the for the account balances store. We use a byte | ||
// (instead of say `[]]byte("balances")` to save some disk space). | ||
BalancesPrefix = []byte{0x02} | ||
) | ||
|
||
// AddressFromBalancesStore returns an account address from a balances prefix | ||
// store. The key must not contain the perfix BalancesPrefix as the prefix store | ||
// iterator discards the actual prefix. | ||
func AddressFromBalancesStore(key []byte) sdk.AccAddress { | ||
addrLen := key[0] | ||
addr := key[1 : addrLen+1] | ||
|
||
return sdk.AccAddress(addr) | ||
} | ||
|
||
// CreateAccountBalancesPrefix creates the prefix for an account's balances. | ||
func CreateAccountBalancesPrefix(addr []byte) []byte { | ||
return append(BalancesPrefix, address.MustLengthPrefix(addr)...) | ||
} |
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
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.
The store key and codec are in the keeper already so they can be passed from the keeper to the migration handler closure not from the module manager into the handler.
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.
And even if the keeper didn't have this stuff already we can add it to
Configurator
so that all services have it rather than separately to each migration handler. Does that make sense? I think it will be much cleaner this way. Otherwise every time we need some new bit of configuration stuff then we keep adding more params to migration handler. Instead we can keep the migration handler params minimal and pass around other static configuration higher up.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.
Re store key: it is in the keeper yes, but not accessible by the
AppModule
at this line (cannot doam.keeper.storeKey
).Happy to discuss it today (or feel free to push to this PR if it's faster).
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.
Yeah, so I think the right way is to make the migration a keeper method.
Basically:
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.
Ah, ok, yeah that works, but it also pollutes the keeper. In bank, the Keeper is an interface, so we'd need to put it as a public method there, and it'd also be exposed to other modules.
I also like the fact that migration scripts are in each module's
legacy
folder.I prefer the current approach, but if you think the keeper's way is cleaner, I'm okay to change it. (cc @robert-zaremba, maybe you have an opinion, since you reviewed this PR?)
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.
In ADR 033, we include both
StoreKey
andMarshaler
onConfigurator
and we could explore that step. An alternative to polluting the keeper is just to put the storeKey and codec inAppModule
when it gets created. Or we can just make aMigrationKeeper
interface and castKeeper
to that and we still keep the scripts in legacy but import them from the keeper... But I really am pretty strongly opposed to making these parameters on the migration handler, it's just not the right place.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.
I went with this in 41e0339. I feel strongly about having those scripts in legacy, because I am copy/pasting legacy code into those folders.
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.
Yeah, I agree they should be in legacy.
What do you think about having StoreKey and Marshaler on Configurator?
One big thing I'm trying to pay attention to with APIs is not trying to pass too many things with function params. What ends up happening is that people say, oh we need just one more parameter and then the function signature changes. It's much less breaking to add fields to structs and methods to interfaces.
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.
This is worth keeping in mind: https://blog.golang.org/module-compatibility
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.
Having
Marshaler
on Configurator is useless imo (for migrations), because most (all?) AppModuleBasics already have acdc
.Would StoreKey on Configurator look like
func StoreKey(moduleName string) sdk.StoreKey
? How do you avoid moduleA doing in its AppModule:b:=configurator.StoreKey("moduleB")
?