-
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
fix: Add MigrationModuleManager to handle migration of upgrade module before other modules #16583
Changes from 22 commits
1e55c09
5d513a3
3fcd4d6
34d47d1
c21cff7
ea9e96a
721fb8b
3158f6a
e54fc1a
81038ec
36a3944
5e43e65
9c3a25b
5bca160
9f6994d
591d7cf
e3f80d6
26e9624
6e50d86
42fc450
59f4bef
120cdae
74746c9
7c812be
bbf4eef
ca99e59
86bc9c0
1a1b3ce
5400774
2b56da6
95c6ed9
08a9279
6ceebbf
71ea378
ff7f08d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package interfaces | ||
|
||
import ( | ||
tmproto "github.com/cometbft/cometbft/proto/tendermint/types" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
// ConsensusParamsGetter is an interface to retrieve consensus parameters for a given context. | ||
type ConsensusParamsGetter interface { | ||
GetConsensusParams(ctx sdk.Context) tmproto.ConsensusParams | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,6 +50,7 @@ import ( | |
"github.com/cosmos/cosmos-sdk/codec/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
"github.com/cosmos/cosmos-sdk/types/module/interfaces" | ||
) | ||
|
||
// AppModuleBasic is the standard form for basic non-dependant elements of an application module. | ||
|
@@ -67,6 +68,11 @@ type HasName interface { | |
Name() string | ||
} | ||
|
||
// UpgradeModule is the extension interface that upgrade module | ||
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. Can we be more descriptive on the godoc here of why is this needed. |
||
type UpgradeModule interface { | ||
IsUpgradeModule() | ||
} | ||
|
||
// HasGenesisBasics is the legacy interface for stateless genesis methods. | ||
type HasGenesisBasics interface { | ||
DefaultGenesis(codec.JSONCodec) json.RawMessage | ||
|
@@ -276,6 +282,7 @@ type Manager struct { | |
OrderPrepareCheckStaters []string | ||
OrderPrecommiters []string | ||
OrderMigrations []string | ||
consensusParamsGetter interfaces.ConsensusParamsGetter | ||
} | ||
|
||
// NewManager creates a new Manager object. | ||
|
@@ -322,6 +329,12 @@ func NewManagerFromMap(moduleMap map[string]appmodule.AppModule) *Manager { | |
} | ||
} | ||
|
||
// WithConsensusParamsGetter sets ConsensusParamsGetter for Manager. | ||
func (m *Manager) WithConsensusParamsGetter(g interfaces.ConsensusParamsGetter) *Manager { | ||
m.consensusParamsGetter = g | ||
return m | ||
} | ||
|
||
// SetOrderInitGenesis sets the order of init genesis calls | ||
func (m *Manager) SetOrderInitGenesis(moduleNames ...string) { | ||
m.assertNoForgottenModules("SetOrderInitGenesis", moduleNames, func(moduleName string) bool { | ||
|
@@ -700,9 +713,31 @@ func (m *Manager) BeginBlock(ctx sdk.Context) (sdk.BeginBlock, error) { | |
|
||
for _, moduleName := range m.OrderBeginBlockers { | ||
if module, ok := m.Modules[moduleName].(appmodule.HasBeginBlocker); ok { | ||
err := module.BeginBlock(ctx) | ||
if err != nil { | ||
return sdk.BeginBlock{}, err | ||
if _, ok := module.(UpgradeModule); ok { | ||
if err := module.BeginBlock(ctx); err != nil { | ||
|
||
return sdk.BeginBlock{}, err | ||
} | ||
if m.consensusParamsGetter != nil { | ||
cp := ctx.ConsensusParams() | ||
// Manager skips this step if Block is non-nil since upgrade module is expected to set this params | ||
// and consensus parameters should not be overwritten. | ||
if cp.Block == nil { | ||
if cp = m.consensusParamsGetter.GetConsensusParams(ctx); cp.Block != nil { | ||
|
||
ctx = ctx.WithConsensusParams(cp) | ||
} | ||
} | ||
} | ||
break | ||
} | ||
} | ||
} | ||
|
||
for _, moduleName := range m.OrderBeginBlockers { | ||
if module, ok := m.Modules[moduleName].(appmodule.HasBeginBlocker); ok { | ||
if _, ok := module.(UpgradeModule); !ok { | ||
if err := module.BeginBlock(ctx); err != nil { | ||
Check warning Code scanning / CodeQL Panic in BeginBock or EndBlock consensus methods
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
|
||
return sdk.BeginBlock{}, err | ||
} | ||
} | ||
} | ||
} | ||
|
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 this is OK @tac0turtle?
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 creating a new package?
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.
it's to avoid directly import cometbft type, sth like allow B get A without import X:
A import X
B import A
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 isn't used anymore right?