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

fix: Add MigrationModuleManager to handle migration of upgrade module before other modules #16583

Merged
merged 35 commits into from
Aug 11, 2023

Conversation

mmsqe
Copy link
Contributor

@mmsqe mmsqe commented Jun 16, 2023

Description

Closes: #16494


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)

CHANGELOG.md Outdated Show resolved Hide resolved
@mmsqe mmsqe marked this pull request as ready for review June 16, 2023 02:15
@mmsqe mmsqe requested a review from a team as a code owner June 16, 2023 02:15
types/module/module.go Fixed Show fixed Hide fixed
errorsmod "cosmossdk.io/errors"

storetypes "cosmossdk.io/store/types"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
Copy link
Contributor

Choose a reason for hiding this comment

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

@tac0turtle is there any harm on depending on cometbft types in types/module?

Copy link
Member

Choose a reason for hiding this comment

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

ideally we dont do this, this seems like a bandaid that we will have to clean up later on. i think we should identify how to fix this problem without allowing modules to override consensus params.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We must be doing this within BeginBlock of Manager since the consensus params is accessed by other modules right after migration within the same block execution.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I guess there's no way around it it seems :/

Copy link
Contributor

Choose a reason for hiding this comment

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

We could perhaps return an any instead and then type cast where needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not sure if get params by consensusKeeper is better, but we need add module one by one (not to mention module outside sdk)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tac0turtle May I ask if you have any better idea beside these two approaches?

Copy link
Collaborator

@yihuang yihuang Aug 9, 2023

Choose a reason for hiding this comment

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

I think the core issue here is the migration is "system" level functionalities, probably shouldn't happen in a module in the first place, it should be executed before all the module logics. is it possible to move the migration logic into baseapp somehow?

Copy link
Member

Choose a reason for hiding this comment

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

sorry for delay, the dependency is fine. agree with @yihuang. Maybe for this version of baseapp this is fine but for later on we can change it. Im not sure we have a clean alternative

Copy link
Contributor

Choose a reason for hiding this comment

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

100% agree 👍

types/module/module.go Outdated Show resolved Hide resolved
types/module/module.go Outdated Show resolved Hide resolved
types/module/module.go Fixed Show fixed Hide fixed
@@ -261,6 +262,11 @@ func (GenesisOnlyAppModule) EndBlock(sdk.Context) ([]abci.ValidatorUpdate, error
return []abci.ValidatorUpdate{}, nil
}

// ConsensusParamsGetter is an interface to retrieve consensus parameters for a given context.
type ConsensusParamsGetter interface {
GetConsensusParams(ctx sdk.Context) tmproto.ConsensusParams
Copy link
Contributor

Choose a reason for hiding this comment

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

what if we just return an any here and then type cast? Then we can avoid the CometBFT dependency.

Copy link
Contributor Author

@mmsqe mmsqe Jun 27, 2023

Choose a reason for hiding this comment

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

since need use as cp := getter.GetConsensusParams(ctx).(tmproto.ConsensusParams), we can't use any for WithConsensusParams, or can we add a separate package to avoid import cometbft type directly

@@ -0,0 +1,12 @@
package interfaces
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is OK @tac0turtle?

Copy link
Member

Choose a reason for hiding this comment

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

Why creating a new package?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's to avoid directly import cometbft type, sth like allow B get A without import X:
A import X
B import A

Copy link
Member

Choose a reason for hiding this comment

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

This isn't used anymore right?

CHANGELOG.md Outdated Show resolved Hide resolved
Copy link
Member

@julienrbrt julienrbrt left a comment

Choose a reason for hiding this comment

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

Lgtm!

@julienrbrt julienrbrt added the backport/v0.50.x PR scheduled for inclusion in the v0.50's next stable release label Aug 11, 2023
@julienrbrt
Copy link
Member

Thanks for adding the godoc and tests!
One last thing to get it 100% would be to describe this new behavior in the docs:
somewhere here

* `BeginBlock(ctx context.Context) error`: At the beginning of each block, this function is called from [`BaseApp`](../core/00-baseapp.md#beginblock) and, in turn, calls the [`BeginBlock`](./05-beginblock-endblock.md) function of each modules implementing the `BeginBlockAppModule` interface, in the order defined in `OrderBeginBlockers`. It creates a child [context](../core/02-context.md) with an event manager to aggregate [events](../core/08-events.md) emitted from all modules.
.
Possibly as well here
#### BeginBlock

UPGRADING.md Outdated Show resolved Hide resolved
@julienrbrt julienrbrt added this pull request to the merge queue Aug 11, 2023
Merged via the queue into cosmos:main with commit 0c1f6fc Aug 11, 2023
43 of 45 checks passed
mergify bot pushed a commit that referenced this pull request Aug 11, 2023
… before other modules (#16583)

Co-authored-by: Aleksandr Bezobchuk <[email protected]>
Co-authored-by: Julien Robert <[email protected]>
(cherry picked from commit 0c1f6fc)
julienrbrt pushed a commit that referenced this pull request Aug 12, 2023
@yihuang yihuang added the backport/v0.47.x PR scheduled for inclusion in the v0.47's next stable release label Aug 16, 2023
mergify bot pushed a commit that referenced this pull request Aug 16, 2023
… before other modules (#16583)

Co-authored-by: Aleksandr Bezobchuk <[email protected]>
Co-authored-by: Julien Robert <[email protected]>
(cherry picked from commit 0c1f6fc)

# Conflicts:
#	CHANGELOG.md
#	UPGRADING.md
#	baseapp/baseapp.go
#	docs/docs/building-modules/01-module-manager.md
#	docs/docs/core/00-baseapp.md
#	testutil/mock/types_mock_appmodule.go
#	types/module/module.go
#	types/module/module_test.go
@julienrbrt julienrbrt removed the backport/v0.47.x PR scheduled for inclusion in the v0.47's next stable release label Aug 16, 2023
mmsqe added a commit to mmsqe/cosmos-sdk that referenced this pull request Aug 17, 2023
… before other modules (cosmos#16583)

Co-authored-by: Aleksandr Bezobchuk <[email protected]>
Co-authored-by: Julien Robert <[email protected]>
(cherry picked from commit 0c1f6fc)
julienrbrt added a commit that referenced this pull request Aug 18, 2023
…e module before other modules (backport #16583) (#17370)"

This reverts commit 27f5db2.
mmsqe added a commit to crypto-org-chain/cosmos-sdk that referenced this pull request Sep 5, 2023
… before other modules (cosmos#16583)

Co-authored-by: Aleksandr Bezobchuk <[email protected]>
Co-authored-by: Julien Robert <[email protected]>
(cherry picked from commit 0c1f6fc)

# Conflicts:
#	CHANGELOG.md
#	UPGRADING.md
#	baseapp/baseapp.go
#	docs/docs/building-modules/01-module-manager.md
#	docs/docs/core/00-baseapp.md
#	testutil/mock/types_mock_appmodule.go
#	types/module/module.go
#	types/module/module_test.go
@faddat faddat mentioned this pull request Nov 8, 2024
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/v0.50.x PR scheduled for inclusion in the v0.50's next stable release C:x/upgrade
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: unable to add ConsensusParams into ctx within the same block execution containing migration
5 participants