forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 34
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 migrator to the commit abci call #387
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,7 +130,7 @@ func (app *BaseApp) SetOption(req abci.RequestSetOption) (res abci.ResponseSetOp | |
func (app *BaseApp) Info(req abci.RequestInfo) abci.ResponseInfo { | ||
lastCommitID := app.cms.LastCommitID() | ||
// load the app version for a non zero height and zero app hash | ||
if lastCommitID.Version > 0 && app.appVersion == 0 { | ||
if lastCommitID.Version > 0 { | ||
cmwaters marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ctx, err := app.createQueryContext(lastCommitID.Version, false) | ||
if err != nil { | ||
panic(err) | ||
|
@@ -343,6 +343,36 @@ func (app *BaseApp) Commit() abci.ResponseCommit { | |
// The write to the DeliverTx state writes all state transitions to the root | ||
// MultiStore (app.cms) so when Commit() is called is persists those values. | ||
app.deliverState.ms.Write() | ||
|
||
// Check if there has been an app version change. If so and there is a migrator | ||
// set, begin to run migrations. This needs to be done before the commit so | ||
// that the migrations are part of the app hash | ||
if header.Version.App < app.appVersion && | ||
app.migrator.storeMigrator != nil && | ||
app.migrator.moduleMigrator != nil { | ||
|
||
// first update the stores themselves by adding and removing them as necessary | ||
storeMigrations, err := app.migrator.storeMigrator(header.Version.App, app.appVersion) | ||
if err != nil { | ||
panic(fmt.Sprintf("failed to get store migrations: %v", err)) | ||
} | ||
app.MountKVStores(storeMigrations.Added) | ||
err = app.cms.LoadLatestVersionAndUpgrade(storeMigrations.ToStoreUpgrades()) | ||
if err != nil { | ||
panic(fmt.Sprintf("failed to upgrade stores: %v", err)) | ||
} | ||
|
||
// create a new cached branch of the store to apply migrations to | ||
app.setDeliverState(header) | ||
err = app.migrator.moduleMigrator(app.deliverState.ctx, header.Version.App, app.appVersion) | ||
if err != nil { | ||
panic(fmt.Sprintf("failed to migrate modules: %v", err)) | ||
} | ||
Comment on lines
+355
to
+370
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. We need to be careful about atomicity here. I need to double check how CometBFT would handle this panic but iirc, we should also revert all the transactions previously committed |
||
|
||
// write the new state to the branch | ||
app.deliverState.ms.Write() | ||
} | ||
|
||
commitID := app.cms.Commit() | ||
|
||
res := abci.ResponseCommit{ | ||
|
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
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.
[optional] this comment seems confusing b/c it doesn't immediately apply to the conditional below it
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 think it still applies because you are still loading the app version if it hasn't been set