-
Notifications
You must be signed in to change notification settings - Fork 672
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 and genesis migrations #205
Merged
Merged
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
4f874d9
add in-place migrations
colin-axner f8ca013
update migrations
colin-axner 29c1c48
migrate solomachine from v1 to v2 during in place migration
colin-axner db0db21
fix build
colin-axner 972ca3c
add genesis migration
colin-axner 314aaba
code cleanup
colin-axner 40a30fa
Merge branch 'main' into colin/11-migration-scripts
colin-axner 863fdbd
add store migration test for expired tendermint consensus states
colin-axner a36801f
Merge branch 'colin/11-migration-scripts' of github.com:cosmos/ibc-go…
colin-axner 863b50a
finish adding in place migration store tests
colin-axner 545056e
add genesis test for solo machines
colin-axner 40484bb
fix genesis migration bug, add tendermint tests
colin-axner a24618d
test fix, changelog, migration docs
colin-axner 6d9bcdd
Apply suggestions from code review
colin-axner 6c6fc52
Merge branch 'main' into colin/11-migration-scripts
colin-axner a67102f
Update docs/migrations/ibc-migration-043.md
AdityaSripal 7e1f40f
apply Aditya's review suggestions
colin-axner 3896a2a
Merge branch 'colin/11-migration-scripts' of github.com:cosmos/ibc-go…
colin-axner 7edac1e
fix tests
colin-axner e326f74
add genesis json unmarshal test
colin-axner a970700
Merge branch 'main' into colin/11-migration-scripts
colin-axner 7ceca61
add migration support for max expected time per block
colin-axner ca070bd
Merge branch 'colin/11-migration-scripts' of github.com:cosmos/ibc-go…
colin-axner 0fcd0c4
fix docs
colin-axner 900b907
fix bug found by Aditya
colin-axner fed9443
remove unnecessary code
colin-axner e595b11
apply Aditya review suggestions, fix bug
colin-axner 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
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 |
---|---|---|
|
@@ -118,88 +118,114 @@ func (suite *LegacyTestSuite) TestMigrateStoreSolomachine() { | |
// ensure all expired consensus states are removed from tendermint client stores | ||
func (suite *LegacyTestSuite) TestMigrateStoreTendermint() { | ||
// create path and setup clients | ||
path := ibctesting.NewPath(suite.chainA, suite.chainB) | ||
suite.coordinator.SetupClients(path) | ||
path1 := ibctesting.NewPath(suite.chainA, suite.chainB) | ||
suite.coordinator.SetupClients(path1) | ||
|
||
// collect all heights expected to be pruned | ||
var pruneHeights []exported.Height | ||
pruneHeights = append(pruneHeights, path.EndpointA.GetClientState().GetLatestHeight()) | ||
path2 := ibctesting.NewPath(suite.chainA, suite.chainB) | ||
suite.coordinator.SetupClients(path2) | ||
pruneHeightMap := make(map[*ibctesting.Path][]exported.Height) | ||
unexpiredHeightMap := make(map[*ibctesting.Path][]exported.Height) | ||
|
||
// these heights will be expired and also pruned | ||
for i := 0; i < 3; i++ { | ||
path.EndpointA.UpdateClient() | ||
for _, path := range []*ibctesting.Path{path1, path2} { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just added an extra for loop to test multiple paths at the same time |
||
// collect all heights expected to be pruned | ||
var pruneHeights []exported.Height | ||
pruneHeights = append(pruneHeights, path.EndpointA.GetClientState().GetLatestHeight()) | ||
} | ||
|
||
// double chedck all information is currently stored | ||
for _, pruneHeight := range pruneHeights { | ||
consState, ok := path.EndpointA.Chain.GetConsensusState(path.EndpointA.ClientID, pruneHeight) | ||
suite.Require().True(ok) | ||
suite.Require().NotNil(consState) | ||
// these heights will be expired and also pruned | ||
for i := 0; i < 3; i++ { | ||
path.EndpointA.UpdateClient() | ||
pruneHeights = append(pruneHeights, path.EndpointA.GetClientState().GetLatestHeight()) | ||
} | ||
|
||
ctx := path.EndpointA.Chain.GetContext() | ||
clientStore := path.EndpointA.Chain.App.GetIBCKeeper().ClientKeeper.ClientStore(ctx, path.EndpointA.ClientID) | ||
// double chedck all information is currently stored | ||
for _, pruneHeight := range pruneHeights { | ||
consState, ok := path.EndpointA.Chain.GetConsensusState(path.EndpointA.ClientID, pruneHeight) | ||
suite.Require().True(ok) | ||
suite.Require().NotNil(consState) | ||
|
||
processedTime, ok := ibctmtypes.GetProcessedTime(clientStore, pruneHeight) | ||
suite.Require().True(ok) | ||
suite.Require().NotNil(processedTime) | ||
ctx := path.EndpointA.Chain.GetContext() | ||
clientStore := path.EndpointA.Chain.App.GetIBCKeeper().ClientKeeper.ClientStore(ctx, path.EndpointA.ClientID) | ||
|
||
processedHeight, ok := ibctmtypes.GetProcessedHeight(clientStore, pruneHeight) | ||
suite.Require().True(ok) | ||
suite.Require().NotNil(processedHeight) | ||
processedTime, ok := ibctmtypes.GetProcessedTime(clientStore, pruneHeight) | ||
suite.Require().True(ok) | ||
suite.Require().NotNil(processedTime) | ||
|
||
expectedConsKey := ibctmtypes.GetIterationKey(clientStore, pruneHeight) | ||
suite.Require().NotNil(expectedConsKey) | ||
processedHeight, ok := ibctmtypes.GetProcessedHeight(clientStore, pruneHeight) | ||
suite.Require().True(ok) | ||
suite.Require().NotNil(processedHeight) | ||
|
||
expectedConsKey := ibctmtypes.GetIterationKey(clientStore, pruneHeight) | ||
suite.Require().NotNil(expectedConsKey) | ||
} | ||
pruneHeightMap[path] = pruneHeights | ||
} | ||
|
||
// Increment the time by a week | ||
suite.coordinator.IncrementTimeBy(7 * 24 * time.Hour) | ||
|
||
// create the consensus state that can be used as trusted height for next update | ||
path.EndpointA.UpdateClient() | ||
for _, path := range []*ibctesting.Path{path1, path2} { | ||
// create the consensus state that can be used as trusted height for next update | ||
var unexpiredHeights []exported.Height | ||
path.EndpointA.UpdateClient() | ||
unexpiredHeights = append(unexpiredHeights, path.EndpointA.GetClientState().GetLatestHeight()) | ||
path.EndpointA.UpdateClient() | ||
unexpiredHeights = append(unexpiredHeights, path.EndpointA.GetClientState().GetLatestHeight()) | ||
|
||
// remove processed height and iteration keys since these were missing from previous version of ibc module | ||
clientStore := path.EndpointA.Chain.App.GetIBCKeeper().ClientKeeper.ClientStore(path.EndpointA.Chain.GetContext(), path.EndpointA.ClientID) | ||
for _, height := range unexpiredHeights { | ||
clientStore.Delete(ibctmtypes.ProcessedHeightKey(height)) | ||
clientStore.Delete(ibctmtypes.IterationKey(height)) | ||
} | ||
Comment on lines
+173
to
+179
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this now enforces a check on the metadata being added |
||
|
||
unexpiredHeightMap[path] = unexpiredHeights | ||
} | ||
|
||
// Increment the time by another week, then update the client. | ||
// This will cause the consensus states created before the first time increment | ||
// to be expired | ||
suite.coordinator.IncrementTimeBy(7 * 24 * time.Hour) | ||
err := v100.MigrateStore(path.EndpointA.Chain.GetContext(), path.EndpointA.Chain.GetSimApp().GetKey(host.StoreKey), path.EndpointA.Chain.App.AppCodec()) | ||
err := v100.MigrateStore(path1.EndpointA.Chain.GetContext(), path1.EndpointA.Chain.GetSimApp().GetKey(host.StoreKey), path1.EndpointA.Chain.App.AppCodec()) | ||
suite.Require().NoError(err) | ||
|
||
ctx := path.EndpointA.Chain.GetContext() | ||
clientStore := path.EndpointA.Chain.App.GetIBCKeeper().ClientKeeper.ClientStore(ctx, path.EndpointA.ClientID) | ||
for _, path := range []*ibctesting.Path{path1, path2} { | ||
ctx := path.EndpointA.Chain.GetContext() | ||
clientStore := path.EndpointA.Chain.App.GetIBCKeeper().ClientKeeper.ClientStore(ctx, path.EndpointA.ClientID) | ||
|
||
// ensure everything has been pruned | ||
for i, pruneHeight := range pruneHeights { | ||
consState, ok := path.EndpointA.Chain.GetConsensusState(path.EndpointA.ClientID, pruneHeight) | ||
suite.Require().False(ok, i) | ||
suite.Require().Nil(consState, i) | ||
// ensure everything has been pruned | ||
for i, pruneHeight := range pruneHeightMap[path] { | ||
consState, ok := path.EndpointA.Chain.GetConsensusState(path.EndpointA.ClientID, pruneHeight) | ||
suite.Require().False(ok, i) | ||
suite.Require().Nil(consState, i) | ||
|
||
processedTime, ok := ibctmtypes.GetProcessedTime(clientStore, pruneHeight) | ||
suite.Require().False(ok, i) | ||
suite.Require().Equal(uint64(0), processedTime, i) | ||
processedTime, ok := ibctmtypes.GetProcessedTime(clientStore, pruneHeight) | ||
suite.Require().False(ok, i) | ||
suite.Require().Equal(uint64(0), processedTime, i) | ||
|
||
processedHeight, ok := ibctmtypes.GetProcessedHeight(clientStore, pruneHeight) | ||
suite.Require().False(ok, i) | ||
suite.Require().Nil(processedHeight, i) | ||
processedHeight, ok := ibctmtypes.GetProcessedHeight(clientStore, pruneHeight) | ||
suite.Require().False(ok, i) | ||
suite.Require().Nil(processedHeight, i) | ||
|
||
expectedConsKey := ibctmtypes.GetIterationKey(clientStore, pruneHeight) | ||
suite.Require().Nil(expectedConsKey, i) | ||
} | ||
expectedConsKey := ibctmtypes.GetIterationKey(clientStore, pruneHeight) | ||
suite.Require().Nil(expectedConsKey, i) | ||
} | ||
|
||
// ensure metadata is set for unexpired consensus state | ||
height := path.EndpointA.GetClientState().GetLatestHeight() | ||
consState, ok := path.EndpointA.Chain.GetConsensusState(path.EndpointA.ClientID, height) | ||
suite.Require().True(ok) | ||
suite.Require().NotNil(consState) | ||
// ensure metadata is set for unexpired consensus state | ||
for _, height := range unexpiredHeightMap[path] { | ||
consState, ok := path.EndpointA.Chain.GetConsensusState(path.EndpointA.ClientID, height) | ||
suite.Require().True(ok) | ||
suite.Require().NotNil(consState) | ||
|
||
processedTime, ok := ibctmtypes.GetProcessedTime(clientStore, height) | ||
suite.Require().True(ok) | ||
suite.Require().NotEqual(uint64(0), processedTime) | ||
processedTime, ok := ibctmtypes.GetProcessedTime(clientStore, height) | ||
suite.Require().True(ok) | ||
suite.Require().NotEqual(uint64(0), processedTime) | ||
|
||
processedHeight, ok := ibctmtypes.GetProcessedHeight(clientStore, height) | ||
suite.Require().True(ok) | ||
suite.Require().Equal(types.GetSelfHeight(path.EndpointA.Chain.GetContext()), processedHeight) | ||
processedHeight, ok := ibctmtypes.GetProcessedHeight(clientStore, height) | ||
suite.Require().True(ok) | ||
suite.Require().Equal(types.GetSelfHeight(path.EndpointA.Chain.GetContext()), processedHeight) | ||
|
||
consKey := ibctmtypes.GetIterationKey(clientStore, height) | ||
suite.Require().Equal(host.ConsensusStateKey(height), consKey) | ||
consKey := ibctmtypes.GetIterationKey(clientStore, height) | ||
suite.Require().Equal(host.ConsensusStateKey(height), consKey) | ||
} | ||
} | ||
} |
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.
I decided not to modify
PruneAllExpiredConsensusStates
as that seems like a useful ibctmtypes function by itself. Since the insertion of the iteration key and processed height key is logic specific to this migration, I decided to iterate the consensus state again and do it in a separate iteration. It is less efficient, but I think better code wise. Open to changing if efficiency is a big concern