From 4eb01854139ddf89a6c0bc28203e36f7e45fe5a6 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Wed, 13 Sep 2023 20:30:48 +0800 Subject: [PATCH 01/10] feat: introduce PreBlock (#17421) --- CHANGELOG.md | 2 +- UPGRADING.md | 12 +- baseapp/abci.go | 4 + baseapp/baseapp.go | 52 +++-- baseapp/baseapp_test.go | 3 + baseapp/options.go | 8 + docs/architecture/README.md | 1 + docs/architecture/adr-063-core-module-api.md | 11 ++ docs/architecture/adr-068-preblock.md | 60 ++++++ docs/docs/build/building-apps/01-app-go-v2.md | 2 +- .../build/building-apps/03-app-upgrade.md | 12 +- .../building-modules/01-module-manager.md | 12 +- .../build/building-modules/17-preblock.md | 31 +++ docs/docs/develop/advanced/00-baseapp.md | 9 +- docs/docs/develop/beginner/00-app-anatomy.md | 20 +- go.mod | 2 +- go.sum | 4 +- runtime/app.go | 10 + runtime/builder.go | 2 +- simapp/app.go | 12 +- simapp/app_config.go | 5 +- simapp/go.mod | 2 +- simapp/go.sum | 4 +- simapp/gomod2nix.toml | 4 +- tests/go.mod | 2 +- tests/go.sum | 4 +- tests/starship/tests/go.mod | 2 +- tests/starship/tests/go.sum | 4 +- testutil/configurator/configurator.go | 19 +- testutil/mock/types_mock_appmodule.go | 179 +++--------------- types/abci.go | 11 ++ types/module/mock_appmodule_test.go | 5 - types/module/module.go | 57 ++++-- types/module/module_test.go | 41 ++-- x/circuit/go.mod | 2 +- x/circuit/go.sum | 4 +- x/evidence/go.mod | 2 +- x/evidence/go.sum | 4 +- x/feegrant/go.mod | 2 +- x/feegrant/go.sum | 4 +- x/nft/go.mod | 2 +- x/nft/go.sum | 4 +- x/upgrade/abci.go | 33 ++-- x/upgrade/abci_test.go | 47 ++--- x/upgrade/go.mod | 10 +- x/upgrade/go.sum | 80 +++++--- x/upgrade/module.go | 14 +- 47 files changed, 478 insertions(+), 338 deletions(-) create mode 100644 docs/architecture/adr-068-preblock.md create mode 100644 docs/docs/build/building-modules/17-preblock.md diff --git a/CHANGELOG.md b/CHANGELOG.md index a1c57bc57061..05945b0f3004 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -57,7 +57,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Bug Fixes -* (types) [#16583](https://github.com/cosmos/cosmos-sdk/pull/16583), [#17372](https://github.com/cosmos/cosmos-sdk/pull/17372) Add `MigrationModuleManager` to handle migration of upgrade module before other modules, ensuring access to the updated context with consensus parameters within the same block that executes the migration. +* (types) [#16583](https://github.com/cosmos/cosmos-sdk/pull/16583), [#17372](https://github.com/cosmos/cosmos-sdk/pull/17372), [#17421](https://github.com/cosmos/cosmos-sdk/pull/17421) Introduce `PreBlock`, which runs before begin blocker other modules, and allows to modify consensus parameters, and the changes are visible to the following state machine logics. * (baseapp) [#17518](https://github.com/cosmos/cosmos-sdk/pull/17518) Utilizing voting power from vote extensions (CometBFT) instead of the current bonded tokens (x/staking) to determine if a set of vote extensions are valid. * (config) [#17649](https://github.com/cosmos/cosmos-sdk/pull/17649) Fix `mempool.max-txs` configuration is invalid in `app.config`. * (mempool) [#17668](https://github.com/cosmos/cosmos-sdk/pull/17668) Fix: `PriorityNonceIterator.Next()` nil pointer ref for min priority at the end of iteration. diff --git a/UPGRADING.md b/UPGRADING.md index 921bdb819b93..fcd949e96e6b 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -102,15 +102,21 @@ allows an application to define handlers for these methods via `ExtendVoteHandle and `VerifyVoteExtensionHandler` respectively. Please see [here](https://docs.cosmos.network/v0.50/building-apps/vote-extensions) for more info. -#### Upgrade +#### Set PreBlocker **Users using `depinject` / app v2 do not need any changes, this is abstracted for them.** ```diff -+ app.BaseApp.SetMigrationModuleManager(app.ModuleManager) ++ app.SetPreBlocker(app.PreBlocker) ``` -BaseApp added `SetMigrationModuleManager` for apps to set their ModuleManager which implements `RunMigrationBeginBlock`. This is essential for BaseApp to run `BeginBlock` of upgrade module and inject `ConsensusParams` to context for `beginBlocker` during `beginBlock`. +```diff ++func (app *SimApp) PreBlocker(ctx sdk.Context, req abci.RequestBeginBlock) (sdk.ResponsePreBlock, error) { ++ return app.ModuleManager.PreBlock(ctx, req) ++} +``` + +BaseApp added `SetPreBlocker` for apps. This is essential for BaseApp to run `PreBlock` which runs before begin blocker other modules, and allows to modify consensus parameters, and the changes are visible to the following state machine logics. #### Events diff --git a/baseapp/abci.go b/baseapp/abci.go index cae600d95b5f..dd1ceb5a1f41 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -736,6 +736,10 @@ func (app *BaseApp) FinalizeBlock(req *abci.RequestFinalizeBlock) (*abci.Respons } } + if err := app.preBlock(); err != nil { + return nil, err + } + beginBlock, err := app.beginBlock(req) if err != nil { return nil, err diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index f2e3c4be3e6b..f59ee0d582b4 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -43,12 +43,6 @@ type ( StoreLoader func(ms storetypes.CommitMultiStore) error ) -// MigrationModuleManager is the interface that a migration module manager should implement to handle -// the execution of migration logic during the beginning of a block. -type MigrationModuleManager interface { - RunMigrationBeginBlock(ctx sdk.Context) (bool, error) -} - const ( execModeCheck execMode = iota // Check a transaction execModeReCheck // Recheck a (pending) transaction after a commit @@ -81,6 +75,7 @@ type BaseApp struct { postHandler sdk.PostHandler // post handler, optional, e.g. for tips initChainer sdk.InitChainer // ABCI InitChain handler + preBlocker sdk.PreBlocker // logic to run before BeginBlocker beginBlocker sdk.BeginBlocker // (legacy ABCI) BeginBlock handler endBlocker sdk.EndBlocker // (legacy ABCI) EndBlock handler processProposal sdk.ProcessProposalHandler // ABCI ProcessProposal handler @@ -98,9 +93,6 @@ type BaseApp struct { // manages snapshots, i.e. dumps of app state at certain intervals snapshotManager *snapshots.Manager - // manages migrate module - migrationModuleManager MigrationModuleManager - // volatile states: // // - checkState is set on InitChain and reset on Commit @@ -283,11 +275,6 @@ func (app *BaseApp) SetMsgServiceRouter(msgServiceRouter *MsgServiceRouter) { app.msgServiceRouter = msgServiceRouter } -// SetMigrationModuleManager sets the MigrationModuleManager of a BaseApp. -func (app *BaseApp) SetMigrationModuleManager(migrationModuleManager MigrationModuleManager) { - app.migrationModuleManager = migrationModuleManager -} - // MountStores mounts all IAVL or DB stores to the provided keys in the BaseApp // multistore. func (app *BaseApp) MountStores(keys ...storetypes.StoreKey) { @@ -682,6 +669,26 @@ func (app *BaseApp) cacheTxContext(ctx sdk.Context, txBytes []byte) (sdk.Context return ctx.WithMultiStore(msCache), msCache } +func (app *BaseApp) preBlock() error { + if app.preBlocker != nil { + ctx := app.finalizeBlockState.ctx + rsp, err := app.preBlocker(ctx) + if err != nil { + return err + } + // rsp.ConsensusParamsChanged is true from preBlocker means ConsensusParams in store get changed + // write the consensus parameters in store to context + if rsp.ConsensusParamsChanged { + ctx = ctx.WithConsensusParams(app.GetConsensusParams(ctx)) + // GasMeter must be set after we get a context with updated consensus params. + gasMeter := app.getBlockGasMeter(ctx) + ctx = ctx.WithBlockGasMeter(gasMeter) + app.finalizeBlockState.ctx = ctx + } + } + return nil +} + func (app *BaseApp) beginBlock(req *abci.RequestFinalizeBlock) (sdk.BeginBlock, error) { var ( resp sdk.BeginBlock @@ -689,22 +696,7 @@ func (app *BaseApp) beginBlock(req *abci.RequestFinalizeBlock) (sdk.BeginBlock, ) if app.beginBlocker != nil { - ctx := app.finalizeBlockState.ctx - if app.migrationModuleManager != nil { - if success, err := app.migrationModuleManager.RunMigrationBeginBlock(ctx); success { - 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 = app.GetConsensusParams(ctx); cp.Block != nil { - ctx = ctx.WithConsensusParams(cp) - } - } - } else if err != nil { - return sdk.BeginBlock{}, err - } - } - resp, err = app.beginBlocker(ctx) + resp, err = app.beginBlocker(app.finalizeBlockState.ctx) if err != nil { return resp, err } diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index 0fef6903b776..21043545c7b4 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -427,6 +427,9 @@ func TestBaseAppOptionSeal(t *testing.T) { require.Panics(t, func() { suite.baseApp.SetInitChainer(nil) }) + require.Panics(t, func() { + suite.baseApp.SetPreBlocker(nil) + }) require.Panics(t, func() { suite.baseApp.SetBeginBlocker(nil) }) diff --git a/baseapp/options.go b/baseapp/options.go index aac814642774..29e517899316 100644 --- a/baseapp/options.go +++ b/baseapp/options.go @@ -176,6 +176,14 @@ func (app *BaseApp) SetInitChainer(initChainer sdk.InitChainer) { app.initChainer = initChainer } +func (app *BaseApp) SetPreBlocker(preBlocker sdk.PreBlocker) { + if app.sealed { + panic("SetPreBlocker() on sealed BaseApp") + } + + app.preBlocker = preBlocker +} + func (app *BaseApp) SetBeginBlocker(beginBlocker sdk.BeginBlocker) { if app.sealed { panic("SetBeginBlocker() on sealed BaseApp") diff --git a/docs/architecture/README.md b/docs/architecture/README.md index ce48ce9fc8df..e5d350ff8d53 100644 --- a/docs/architecture/README.md +++ b/docs/architecture/README.md @@ -93,3 +93,4 @@ When writing ADRs, follow the same best practices for writing RFCs. When writing * [ADR 044: Guidelines for Updating Protobuf Definitions](./adr-044-protobuf-updates-guidelines.md) * [ADR 047: Extend Upgrade Plan](./adr-047-extend-upgrade-plan.md) * [ADR 053: Go Module Refactoring](./adr-053-go-module-refactoring.md) +* [ADR 068: Preblock](./adr-068-preblock.md) diff --git a/docs/architecture/adr-063-core-module-api.md b/docs/architecture/adr-063-core-module-api.md index 622e294352b8..743dd5fee539 100644 --- a/docs/architecture/adr-063-core-module-api.md +++ b/docs/architecture/adr-063-core-module-api.md @@ -280,6 +280,17 @@ type HasGenesis interface { } ``` +#### Pre Blockers + +Modules that have functionality that runs before BeginBlock and should implement the has `HasPreBlocker` interfaces: + +```go +type HasPreBlocker interface { + AppModule + PreBlock(context.Context) error +} +``` + #### Begin and End Blockers Modules that have functionality that runs before transactions (begin blockers) or after transactions diff --git a/docs/architecture/adr-068-preblock.md b/docs/architecture/adr-068-preblock.md new file mode 100644 index 000000000000..dc0cd2a24564 --- /dev/null +++ b/docs/architecture/adr-068-preblock.md @@ -0,0 +1,60 @@ +# ADR 068: Preblock + +## Changelog + +* Sept 13, 2023: Initial Draft + +## Status + +DRAFT + +## Abstract + +Introduce `PreBlock`, which runs before begin blocker other modules, and allows to modify consensus parameters, and the changes are visible to the following state machine logics. + +## Context + +When upgrading to sdk 0.47, the storage format for consensus parameters changed, but in the migration block, `ctx.ConsensusParams()` is always `nil`, because it fails to load the old format using new code, it's supposed to be migrated by the `x/upgrade` module first, but unfortunately, the migration happens in `BeginBlocker` handler, which runs after the `ctx` is initialized. +When we try to solve this, we find the `x/upgrade` module can't modify the context to make the consensus parameters visible for the other modules, the context is passed by value, and sdk team want to keep it that way, that's good for isolations between modules. + +## Alternatives + +The first alternative solution introduced a `MigrateModuleManager`, which only includes the `x/upgrade` module right now, and baseapp will run their `BeginBlocker`s before the other modules, and reload context's consensus parameters in between. + +## Decision + +Suggested this new lifecycle method. + +### `PreBlocker` + +There are two semantics around the new lifecycle method: + +- It runs before the `BeginBlocker` of all modules +- It can modify consensus parameters in storage, and signal the caller through the return value. + +When it returns `ConsensusParamsChanged=true`, the caller must refresh the consensus parameter in the finalize context: +``` +app.finalizeBlockState.ctx = app.finalizeBlockState.ctx.WithConsensusParams(app.GetConsensusParams()) +``` + +The new ctx must be passed to all the other lifecycle methods. + + +## Consequences + +### Backwards Compatibility + +### Positive + +### Negative + +### Neutral + +## Further Discussions + +## Test Cases + +## References +* [1] https://github.com/cosmos/cosmos-sdk/issues/16494 +* [2] https://github.com/cosmos/cosmos-sdk/pull/16583 +* [3] https://github.com/cosmos/cosmos-sdk/pull/17421 diff --git a/docs/docs/build/building-apps/01-app-go-v2.md b/docs/docs/build/building-apps/01-app-go-v2.md index c5301413c70a..1be1bb90aa29 100644 --- a/docs/docs/build/building-apps/01-app-go-v2.md +++ b/docs/docs/build/building-apps/01-app-go-v2.md @@ -37,7 +37,7 @@ The `app_config.go` file is the single place to configure all modules parameters https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/simapp/app_config.go#L103-L167 ``` -3. Configure the modules defined in the `BeginBlocker` and `EndBlocker` and the `tx` module: +3. Configure the modules defined in the `PreBlocker`, `BeginBlocker` and `EndBlocker` and the `tx` module: ```go reference https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/simapp/app_config.go#L112-L129 diff --git a/docs/docs/build/building-apps/03-app-upgrade.md b/docs/docs/build/building-apps/03-app-upgrade.md index 11430f8a3490..c0e83555aa34 100644 --- a/docs/docs/build/building-apps/03-app-upgrade.md +++ b/docs/docs/build/building-apps/03-app-upgrade.md @@ -50,16 +50,22 @@ the rest of the block as normal. Once 2/3 of the voting power has upgraded, the resume the consensus mechanism. If the majority of operators add a custom `do-upgrade` script, this should be a matter of minutes and not even require them to be awake at that time. -## Set Migration Module Manager +## Set PreBlocker :::tip Users using `depinject` / app v2 do not need any changes, this is abstracted for them. ::: -After app initiation, call `SetMigrationModuleManager` with ModuleManager to give BaseApp access to `RunMigrationBeginBlock`: +Call `SetPreBlocker` to run `PreBlock`: ```go -app.BaseApp.SetMigrationModuleManager(app.ModuleManager) +app.SetPreBlocker(app.PreBlocker) +``` + +```go +func (app *SimApp) PreBlocker(ctx sdk.Context, req abci.RequestBeginBlock) (sdk.ResponsePreBlock, error) { + return app.ModuleManager.PreBlock(ctx, req) +} ``` ## Integrating With An App diff --git a/docs/docs/build/building-modules/01-module-manager.md b/docs/docs/build/building-modules/01-module-manager.md index 0aa5dc97e81d..7b0cc9974441 100644 --- a/docs/docs/build/building-modules/01-module-manager.md +++ b/docs/docs/build/building-modules/01-module-manager.md @@ -5,7 +5,7 @@ sidebar_position: 1 # Module Manager :::note Synopsis -Cosmos SDK modules need to implement the [`AppModule` interfaces](#application-module-interfaces), in order to be managed by the application's [module manager](#module-manager). The module manager plays an important role in [`message` and `query` routing](../../develop/advanced/00-baseapp.md#routing), and allows application developers to set the order of execution of a variety of functions like [`BeginBlocker` and `EndBlocker`](../../develop/beginner/00-app-anatomy.md#begingblocker-and-endblocker). +Cosmos SDK modules need to implement the [`AppModule` interfaces](#application-module-interfaces), in order to be managed by the application's [module manager](#module-manager). The module manager plays an important role in [`message` and `query` routing](../../develop/advanced/00-baseapp.md#routing), and allows application developers to set the order of execution of a variety of functions like [`PreBlocker`](../../develop/beginner/00-app-anatomy#preblocker) and [`BeginBlocker` and `EndBlocker`](../../develop/beginner/00-app-anatomy.md#begingblocker-and-endblocker). ::: :::note Pre-requisite Readings @@ -36,11 +36,11 @@ The above interfaces are mostly embedding smaller interfaces (extension interfac * [`module.HasGenesis`](#modulehasgenesis) for inter-dependent genesis-related module functionalities. * [`module.HasABCIGenesis`](#modulehasabcigenesis) for inter-dependent genesis-related module functionalities. * [`appmodule.HasGenesis` / `module.HasGenesis`](#appmodulehasgenesis): The extension interface for stateful genesis methods. +* [`appmodule.HasPreBlocker`](#haspreblocker): The extension interface that contains information about the `AppModule` and `PreBlock`. * [`appmodule.HasBeginBlocker`](#hasbeginblocker): The extension interface that contains information about the `AppModule` and `BeginBlock`. * [`appmodule.HasEndBlocker`](#hasendblocker): The extension interface that contains information about the `AppModule` and `EndBlock`. * [`appmodule.HasPrecommit`](#hasprecommit): The extension interface that contains information about the `AppModule` and `Precommit`. * [`appmodule.HasPrepareCheckState`](#haspreparecheckstate): The extension interface that contains information about the `AppModule` and `PrepareCheckState`. -* [`appmodule.UpgradeModule`]: The extension interface that signify if the `AppModule` if the module is an upgrade module. * [`appmodule.HasService` / `module.HasServices`](#hasservices): The extension interface for modules to register services. * [`module.HasABCIEndblock`](#hasabciendblock): The extension interface that contains information about the `AppModule`, `EndBlock` and returns an updated validator set. * (legacy) [`module.HasInvariants`](#hasinvariants): The extension interface for registering invariants. @@ -182,6 +182,10 @@ https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/types/module/module.go * `ConsensusVersion() uint64`: Returns the consensus version of the module. +### `HasPreBlocker` + +The `HasPreBlocker` is an extension interface from `appmodule.AppModule`. All modules that have an `PreBlock` method implement this interface. + ### `HasBeginBlocker` The `HasBeginBlocker` is an extension interface from `appmodule.AppModule`. All modules that have an `BeginBlock` method implement this interface. @@ -292,6 +296,7 @@ The module manager is used throughout the application whenever an action on a co * `SetOrderInitGenesis(moduleNames ...string)`: Sets the order in which the [`InitGenesis`](./08-genesis.md#initgenesis) function of each module will be called when the application is first started. This function is generally called from the application's main [constructor function](../../develop/beginner/00-app-anatomy.md#constructor-function). To initialize modules successfully, module dependencies should be considered. For example, the `genutil` module must occur after `staking` module so that the pools are properly initialized with tokens from genesis accounts, the `genutils` module must also occur after `auth` so that it can access the params from auth, IBC's `capability` module should be initialized before all other modules so that it can initialize any capabilities. * `SetOrderExportGenesis(moduleNames ...string)`: Sets the order in which the [`ExportGenesis`](./08-genesis.md#exportgenesis) function of each module will be called in case of an export. This function is generally called from the application's main [constructor function](../../develop/beginner/00-app-anatomy.md#constructor-function). +* `SetOrderPreBlockers(moduleNames ...string)`: Sets the order in which the `PreBlock()` function of each module will be called before `BeginBlock()` of all modules. This function is generally called from the application's main [constructor function](../../develop/beginner/00-app-anatomy.md#constructor-function). * `SetOrderBeginBlockers(moduleNames ...string)`: Sets the order in which the `BeginBlock()` function of each module will be called at the beginning of each block. This function is generally called from the application's main [constructor function](../../develop/beginner/00-app-anatomy.md#constructor-function). * `SetOrderEndBlockers(moduleNames ...string)`: Sets the order in which the `EndBlock()` function of each module will be called at the end of each block. This function is generally called from the application's main [constructor function](../../develop/beginner/00-app-anatomy.md#constructor-function). * `SetOrderPrecommiters(moduleNames ...string)`: Sets the order in which the `Precommit()` function of each module will be called during commit of each block. This function is generally called from the application's main [constructor function](../../develop/beginner/00-app-anatomy.md#constructor-function). @@ -302,8 +307,7 @@ The module manager is used throughout the application whenever an action on a co * `InitGenesis(ctx context.Context, cdc codec.JSONCodec, genesisData map[string]json.RawMessage)`: Calls the [`InitGenesis`](./08-genesis.md#initgenesis) function of each module when the application is first started, in the order defined in `OrderInitGenesis`. Returns an `abci.ResponseInitChain` to the underlying consensus engine, which can contain validator updates. * `ExportGenesis(ctx context.Context, cdc codec.JSONCodec)`: Calls the [`ExportGenesis`](./08-genesis.md#exportgenesis) function of each module, in the order defined in `OrderExportGenesis`. The export constructs a genesis file from a previously existing state, and is mainly used when a hard-fork upgrade of the chain is required. * `ExportGenesisForModules(ctx context.Context, cdc codec.JSONCodec, modulesToExport []string)`: Behaves the same as `ExportGenesis`, except takes a list of modules to export. -* `RunMigrationBeginBlock(ctx sdk.Context) (bool, error)`: At the beginning of each block, this function is called from [`BaseApp`](../../develop/advanced/00-baseapp.md#beginblock) and, in turn, calls the [`BeginBlock`](./05-beginblock-endblock.md) function of the upgrade module implementing the `HasBeginBlocker` interface. The function returns a boolean value indicating whether the migration was executed or not and an error if fails. -* `BeginBlock(ctx context.Context) error`: At the beginning of each block, this function is called from [`BaseApp`](../../develop/advanced/00-baseapp.md#beginblock) and, in turn, calls the [`BeginBlock`](./05-beginblock-endblock.md) function of each non-upgrade modules implementing the `appmodule.HasBeginBlocker` interface, in the order defined in `OrderBeginBlockers`. It creates a child [context](../../develop/advanced/02-context.md) with an event manager to aggregate [events](../../develop/advanced/08-events.md) emitted from non-upgrade modules. +* `BeginBlock(ctx context.Context) error`: At the beginning of each block, this function is called from [`BaseApp`](../../develop/advanced/00-baseapp.md#beginblock) and, in turn, calls the [`BeginBlock`](./05-beginblock-endblock.md) function of each modules implementing the `appmodule.HasBeginBlocker` interface, in the order defined in `OrderBeginBlockers`. It creates a child [context](../../develop/advanced/02-context.md) with an event manager to aggregate [events](../../develop/advanced/08-events.md) emitted from each modules. * `EndBlock(ctx context.Context) error`: At the end of each block, this function is called from [`BaseApp`](../../develop/advanced/00-baseapp.md#endblock) and, in turn, calls the [`EndBlock`](./05-beginblock-endblock.md) function of each modules implementing the `appmodule.HasEndBlocker` interface, in the order defined in `OrderEndBlockers`. It creates a child [context](../../develop/advanced/02-context.md) with an event manager to aggregate [events](../../develop/advanced/08-events.md) emitted from all modules. The function returns an `abci` which contains the aforementioned events, as well as validator set updates (if any). * `EndBlock(context.Context) ([]abci.ValidatorUpdate, error)`: At the end of each block, this function is called from [`BaseApp`](../../develop/advanced/00-baseapp.md#endblock) and, in turn, calls the [`EndBlock`](./05-beginblock-endblock.md) function of each modules implementing the `module.HasABCIEndblock` interface, in the order defined in `OrderEndBlockers`. It creates a child [context](../../develop/advanced/02-context.md) with an event manager to aggregate [events](../../develop/advanced/08-events.md) emitted from all modules. The function returns an `abci` which contains the aforementioned events, as well as validator set updates (if any). * `Precommit(ctx context.Context)`: During [`Commit`](../../develop/advanced/00-baseapp.md#commit), this function is called from `BaseApp` immediately before the [`deliverState`](../../develop/advanced/00-baseapp.md#state-updates) is written to the underlying [`rootMultiStore`](../../develop/advanced/04-store.md#commitmultistore) and, in turn calls the `Precommit` function of each modules implementing the `HasPrecommit` interface, in the order defined in `OrderPrecommiters`. It creates a child [context](../../develop/advanced/02-context.md) where the underlying `CacheMultiStore` is that of the newly committed block's [`finalizeblockstate`](../../develop/advanced/00-baseapp.md#state-updates). diff --git a/docs/docs/build/building-modules/17-preblock.md b/docs/docs/build/building-modules/17-preblock.md new file mode 100644 index 000000000000..8a0f3baa9280 --- /dev/null +++ b/docs/docs/build/building-modules/17-preblock.md @@ -0,0 +1,31 @@ +--- +sidebar_position: 1 +--- + +# PreBlocker + +:::note Synopsis +`PreBlocker` is optional method module developers can implement in their module. They will be triggered before [`BeginBlock`](../../develop/advanced/00-baseapp.md#beginblock). +::: + +:::note Pre-requisite Readings + +* [Module Manager](./01-module-manager.md) + +::: + +## PreBlocker + +There are two semantics around the new lifecycle method: + +- It runs before the `BeginBlocker` of all modules +- It can modify consensus parameters in storage, and signal the caller through the return value. + +When it returns `ConsensusParamsChanged=true`, the caller must refresh the consensus parameter in the deliver context: +``` +app.finalizeBlockState.ctx = app.finalizeBlockState.ctx.WithConsensusParams(app.GetConsensusParams()) +``` + +The new ctx must be passed to all the other lifecycle methods. + + diff --git a/docs/docs/develop/advanced/00-baseapp.md b/docs/docs/develop/advanced/00-baseapp.md index dacaedd0d464..d80174754d60 100644 --- a/docs/docs/develop/advanced/00-baseapp.md +++ b/docs/docs/develop/advanced/00-baseapp.md @@ -78,8 +78,7 @@ First, the important parameters that are initialized during the bootstrapping of * [`AnteHandler`](#antehandler): This handler is used to handle signature verification, fee payment, and other pre-message execution checks when a transaction is received. It's executed during [`CheckTx/RecheckTx`](#checktx) and [`FinalizeBlock`](#finalizeblock). -* [`InitChainer`](../beginner/00-app-anatomy.md#initchainer), - [`BeginBlocker` and `EndBlocker`](../beginner/00-app-anatomy.md#beginblocker-and-endblocker): These are +* [`InitChainer`](../beginner/00-app-anatomy.md#initchainer), [`PreBlocker`](../beginner/00-app-anatomy.md#preblocker), [`BeginBlocker` and `EndBlocker`](../beginner/00-app-anatomy.md#beginblocker-and-endblocker): These are the functions executed when the application receives the `InitChain` and `FinalizeBlock` ABCI messages from the underlying CometBFT engine. @@ -444,6 +443,10 @@ The [`FinalizeBlock` ABCI message](https://github.com/cometbft/cometbft/blob/v0. https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/baseapp/abci.go#L623 ``` +#### PreBlock + +* Run the application's [`preBlocker()`](../beginner/00-app-anatomy.md#preblocker), which mainly runs the [`PreBlocker()`](../building-modules/17-preblock.md#preblock) method of each of the modules. + #### BeginBlock * Initialize [`finalizeBlockState`](#state-updates) with the latest header using the `req abci.RequestFinalizeBlock` passed as parameter via the `setState` function. @@ -455,7 +458,7 @@ https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/baseapp/abci.go#L623 This function also resets the [main gas meter](../beginner/04-gas-fees.md#main-gas-meter). * Initialize the [block gas meter](../beginner/04-gas-fees.md#block-gas-meter) with the `maxGas` limit. The `gas` consumed within the block cannot go above `maxGas`. This parameter is defined in the application's consensus parameters. -* Run the application's [`beginBlocker()`](../beginner/00-app-anatomy.md#beginblocker-and-endblock), which mainly runs the [`BeginBlocker()`](../../build/building-modules/05-beginblock-endblock.md#beginblock) method of each of the non-upgrade modules. +* Run the application's [`beginBlocker()`](../beginner/00-app-anatomy.md#beginblocker-and-endblocker), which mainly runs the [`BeginBlocker()`](../../build/building-modules/05-beginblock-endblock.md#beginblock) method of each of the modules. * Set the [`VoteInfos`](https://github.com/cometbft/cometbft/blob/v0.37.x/spec/abci/abci++_methods.md#voteinfo) of the application, i.e. the list of validators whose _precommit_ for the previous block was included by the proposer of the current block. This information is carried into the [`Context`](./02-context.md) so that it can be used during transaction execution and EndBlock. #### Transaction Execution diff --git a/docs/docs/develop/beginner/00-app-anatomy.md b/docs/docs/develop/beginner/00-app-anatomy.md index 4d924ba05da9..9208c9ddb828 100644 --- a/docs/docs/develop/beginner/00-app-anatomy.md +++ b/docs/docs/develop/beginner/00-app-anatomy.md @@ -55,7 +55,7 @@ The first thing defined in `app.go` is the `type` of the application. It is gene * **A list of module's `keeper`s.** Each module defines an abstraction called [`keeper`](../../build/building-modules/06-keeper.md), which handles reads and writes for this module's store(s). The `keeper`'s methods of one module can be called from other modules (if authorized), which is why they are declared in the application's type and exported as interfaces to other modules so that the latter can only access the authorized functions. * **A reference to an [`appCodec`](../advanced/05-encoding.md).** The application's `appCodec` is used to serialize and deserialize data structures in order to store them, as stores can only persist `[]bytes`. The default codec is [Protocol Buffers](../advanced/05-encoding.md). * **A reference to a [`legacyAmino`](../advanced/05-encoding.md) codec.** Some parts of the Cosmos SDK have not been migrated to use the `appCodec` above, and are still hardcoded to use Amino. Other parts explicitly use Amino for backwards compatibility. For these reasons, the application still holds a reference to the legacy Amino codec. Please note that the Amino codec will be removed from the SDK in the upcoming releases. -* **A reference to a [module manager](../../build/building-modules/01-module-manager.md#manager)** and a [basic module manager](../../build/building-modules/01-module-manager.md#basicmanager). The module manager is an object that contains a list of the application's modules. It facilitates operations related to these modules, like registering their [`Msg` service](../advanced/00-baseapp.md#msg-services) and [gRPC `Query` service](../advanced/00-baseapp.md#grpc-query-services), or setting the order of execution between modules for various functions like [`InitChainer`](#initchainer), [`BeginBlocker` and `EndBlocker`](#beginblocker-and-endblocker). +* **A reference to a [module manager](../../build/building-modules/01-module-manager.md#manager)** and a [basic module manager](../../build/building-modules/01-module-manager.md#basicmanager). The module manager is an object that contains a list of the application's modules. It facilitates operations related to these modules, like registering their [`Msg` service](../advanced/00-baseapp.md#msg-services) and [gRPC `Query` service](../advanced/00-baseapp.md#grpc-query-services), or setting the order of execution between modules for various functions like [`InitChainer`](#initchainer), [`PreBlocker`](#preblocker) and [`BeginBlocker` and `EndBlocker`](#beginblocker-and-endblocker). See an example of application type definition from `simapp`, the Cosmos SDK's own app used for demo and testing purposes: @@ -79,10 +79,11 @@ Here are the main actions performed by this function: * Instantiate the application's [module manager](../../build/building-modules/01-module-manager.md#manager) with the [`AppModule`](#application-module-interface) object of each of the application's modules. * With the module manager, initialize the application's [`Msg` services](../advanced/00-baseapp.md#msg-services), [gRPC `Query` services](../advanced/00-baseapp.md#grpc-query-services), [legacy `Msg` routes](../advanced/00-baseapp.md#routing), and [legacy query routes](../advanced/00-baseapp.md#query-routing). When a transaction is relayed to the application by CometBFT via the ABCI, it is routed to the appropriate module's [`Msg` service](#msg-services) using the routes defined here. Likewise, when a gRPC query request is received by the application, it is routed to the appropriate module's [`gRPC query service`](#grpc-query-services) using the gRPC routes defined here. The Cosmos SDK still supports legacy `Msg`s and legacy CometBFT queries, which are routed using the legacy `Msg` routes and the legacy query routes, respectively. * With the module manager, register the [application's modules' invariants](../../build/building-modules/07-invariants.md). Invariants are variables (e.g. total supply of a token) that are evaluated at the end of each block. The process of checking invariants is done via a special module called the [`InvariantsRegistry`](../../build/building-modules/07-invariants.md#invariant-registry). The value of the invariant should be equal to a predicted value defined in the module. Should the value be different than the predicted one, special logic defined in the invariant registry is triggered (usually the chain is halted). This is useful to make sure that no critical bug goes unnoticed, producing long-lasting effects that are hard to fix. -* With the module manager, set the order of execution between the `InitGenesis`, `BeginBlocker`, and `EndBlocker` functions of each of the [application's modules](#application-module-interface). Note that not all modules implement these functions. +* With the module manager, set the order of execution between the `InitGenesis`, `PreBlocker`, `BeginBlocker`, and `EndBlocker` functions of each of the [application's modules](#application-module-interface). Note that not all modules implement these functions. * Set the remaining application parameters: * [`InitChainer`](#initchainer): used to initialize the application when it is first started. - * [`BeginBlocker`, `EndBlocker`](#beginblocker-and-endlbocker): called at the beginning and at the end of every block. + * [`PreBlocker`](#preblocker): called before BeginBlock. + * [`BeginBlocker`, `EndBlocker`](#beginblocker-and-endblocker): called at the beginning and at the end of every block. * [`anteHandler`](../advanced/00-baseapp.md#antehandler): used to handle fees and signature verification. * Mount the stores. * Return the application. @@ -107,6 +108,19 @@ See an example of an `InitChainer` from `simapp`: https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/simapp/app.go#L626-L634 ``` +### PreBlocker + +There are two semantics around the new lifecycle method: + +- It runs before the `BeginBlocker` of all modules +- It can modify consensus parameters in storage, and signal the caller through the return value. + +When it returns `ConsensusParamsChanged=true`, the caller must refresh the consensus parameter in the finalize context: +``` +app.finalizeBlockState.ctx = app.finalizeBlockState.ctx.WithConsensusParams(app.GetConsensusParams()) +``` +The new ctx must be passed to all the other lifecycle methods. + ### BeginBlocker and EndBlocker The Cosmos SDK offers developers the possibility to implement automatic execution of code as part of their application. This is implemented through two functions called `BeginBlocker` and `EndBlocker`. They are called when the application receives the `FinalizeBlock` messages from the CometBFT consensus engine, which happens respectively at the beginning and at the end of each block. The application must set the `BeginBlocker` and `EndBlocker` in its [constructor](#constructor-function) via the [`SetBeginBlocker`](https://pkg.go.dev/github.com/cosmos/cosmos-sdk/baseapp#BaseApp.SetBeginBlocker) and [`SetEndBlocker`](https://pkg.go.dev/github.com/cosmos/cosmos-sdk/baseapp#BaseApp.SetEndBlocker) methods. diff --git a/go.mod b/go.mod index 29edcf34eb29..d3f5658e8a31 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ toolchain go1.21.0 module github.com/cosmos/cosmos-sdk require ( - cosmossdk.io/api v0.7.0 + cosmossdk.io/api v0.7.1-0.20230820170544-1bd37053e0c0 cosmossdk.io/collections v0.4.0 cosmossdk.io/core v0.11.0 cosmossdk.io/depinject v1.0.0-alpha.4 diff --git a/go.sum b/go.sum index 373cb3623f70..c136ddf59064 100644 --- a/go.sum +++ b/go.sum @@ -35,8 +35,8 @@ cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohl cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs= cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo= -cosmossdk.io/api v0.7.0 h1:QsEMIWuv9xWDbF2HZnW4Lpu1/SejCztPu0LQx7t6MN4= -cosmossdk.io/api v0.7.0/go.mod h1:kJFAEMLN57y0viszHDPLMmieF0471o5QAwwApa+270M= +cosmossdk.io/api v0.7.1-0.20230820170544-1bd37053e0c0 h1:z1aCAqEXi5fzC5tjanWnkP/zhhuWTX17IiNKxLvXFcw= +cosmossdk.io/api v0.7.1-0.20230820170544-1bd37053e0c0/go.mod h1:h4YT2OHIBT/YIwWrc5L+4dY05ZIqvo89zs6m7j4/RSk= cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= cosmossdk.io/core v0.11.0 h1:vtIafqUi+1ZNAE/oxLOQQ7Oek2n4S48SWLG8h/+wdbo= diff --git a/runtime/app.go b/runtime/app.go index 620b058a1183..ed6de6adb9da 100644 --- a/runtime/app.go +++ b/runtime/app.go @@ -114,6 +114,11 @@ func (a *App) Load(loadLatest bool) error { a.ModuleManager.SetOrderExportGenesis(a.config.InitGenesis...) } + if len(a.config.PreBlockers) != 0 { + a.ModuleManager.SetOrderPreBlockers(a.config.PreBlockers...) + a.SetPreBlocker(a.PreBlocker) + } + if len(a.config.BeginBlockers) != 0 { a.ModuleManager.SetOrderBeginBlockers(a.config.BeginBlockers...) a.SetBeginBlocker(a.BeginBlocker) @@ -147,6 +152,11 @@ func (a *App) Load(loadLatest bool) error { return nil } +// PreBlocker application updates every pre block +func (a *App) PreBlocker(ctx sdk.Context) (sdk.ResponsePreBlock, error) { + return a.ModuleManager.PreBlock(ctx) +} + // BeginBlocker application updates every begin block func (a *App) BeginBlocker(ctx sdk.Context) (sdk.BeginBlock, error) { return a.ModuleManager.BeginBlock(ctx) diff --git a/runtime/builder.go b/runtime/builder.go index 07e16bfcc20d..e3bb56545a3e 100644 --- a/runtime/builder.go +++ b/runtime/builder.go @@ -35,7 +35,7 @@ func (a *AppBuilder) Build(db dbm.DB, traceStore io.Writer, baseAppOptions ...fu bApp.SetVersion(version.Version) bApp.SetInterfaceRegistry(a.app.interfaceRegistry) bApp.MountStores(a.app.storeKeys...) - bApp.SetMigrationModuleManager(a.app.ModuleManager) + bApp.SetPreBlocker(a.app.PreBlocker) a.app.BaseApp = bApp a.app.configurator = module.NewConfigurator(a.app.cdc, a.app.MsgServiceRouter(), a.app.GRPCQueryRouter()) diff --git a/simapp/app.go b/simapp/app.go index 310b0d2dfa1f..1d7ed0776fb8 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -401,7 +401,6 @@ func NewSimApp( consensus.NewAppModule(appCodec, app.ConsensusParamsKeeper), circuit.NewAppModule(appCodec, app.CircuitKeeper), ) - bApp.SetMigrationModuleManager(app.ModuleManager) // BasicModuleManager defines the module BasicManager is in charge of setting up basic, // non-dependant module elements, such as codec registration and genesis verification. @@ -420,12 +419,15 @@ func NewSimApp( app.BasicModuleManager.RegisterLegacyAminoCodec(legacyAmino) app.BasicModuleManager.RegisterInterfaces(interfaceRegistry) + // NOTE: upgrade module is required to be prioritized + app.ModuleManager.SetOrderPreBlockers( + upgradetypes.ModuleName, + ) // During begin block slashing happens after distr.BeginBlocker so that // there is nothing left over in the validator fee pool, so as to keep the // CanWithdrawInvariant invariant. // NOTE: staking module is required if HistoricalEntries param > 0 app.ModuleManager.SetOrderBeginBlockers( - upgradetypes.ModuleName, minttypes.ModuleName, distrtypes.ModuleName, slashingtypes.ModuleName, @@ -498,6 +500,7 @@ func NewSimApp( // initialize BaseApp app.SetInitChainer(app.InitChainer) + app.SetPreBlocker(app.PreBlocker) app.SetBeginBlocker(app.BeginBlocker) app.SetEndBlocker(app.EndBlocker) app.setAnteHandler(txConfig) @@ -579,6 +582,11 @@ func (app *SimApp) setPostHandler() { // Name returns the name of the App func (app *SimApp) Name() string { return app.BaseApp.Name() } +// PreBlocker application updates every pre block +func (app *SimApp) PreBlocker(ctx sdk.Context) (sdk.ResponsePreBlock, error) { + return app.ModuleManager.PreBlock(ctx) +} + // BeginBlocker application updates every begin block func (app *SimApp) BeginBlocker(ctx sdk.Context) (sdk.BeginBlock, error) { return app.ModuleManager.BeginBlock(ctx) diff --git a/simapp/app_config.go b/simapp/app_config.go index 351433f0fece..2b11313e60dd 100644 --- a/simapp/app_config.go +++ b/simapp/app_config.go @@ -105,12 +105,15 @@ var ( Name: runtime.ModuleName, Config: appconfig.WrapAny(&runtimev1alpha1.Module{ AppName: "SimApp", + // NOTE: upgrade module is required to be prioritized + PreBlockers: []string{ + upgradetypes.ModuleName, + }, // During begin block slashing happens after distr.BeginBlocker so that // there is nothing left over in the validator fee pool, so as to keep the // CanWithdrawInvariant invariant. // NOTE: staking module is required if HistoricalEntries param > 0 BeginBlockers: []string{ - upgradetypes.ModuleName, minttypes.ModuleName, distrtypes.ModuleName, slashingtypes.ModuleName, diff --git a/simapp/go.mod b/simapp/go.mod index dbac48dbfda9..acc69f981fec 100644 --- a/simapp/go.mod +++ b/simapp/go.mod @@ -3,7 +3,7 @@ module cosmossdk.io/simapp go 1.21 require ( - cosmossdk.io/api v0.7.0 + cosmossdk.io/api v0.7.1-0.20230820170544-1bd37053e0c0 cosmossdk.io/client/v2 v2.0.0-20230630094428-02b760776860 cosmossdk.io/collections v0.4.0 cosmossdk.io/core v0.11.0 diff --git a/simapp/go.sum b/simapp/go.sum index 1e6a0cbba5d9..4d85d7fa798f 100644 --- a/simapp/go.sum +++ b/simapp/go.sum @@ -187,8 +187,8 @@ cloud.google.com/go/webrisk v1.4.0/go.mod h1:Hn8X6Zr+ziE2aNd8SliSDWpEnSS1u4R9+xX cloud.google.com/go/webrisk v1.5.0/go.mod h1:iPG6fr52Tv7sGk0H6qUFzmL3HHZev1htXuWDEEsqMTg= cloud.google.com/go/workflows v1.6.0/go.mod h1:6t9F5h/unJz41YqfBmqSASJSXccBLtD1Vwf+KmJENM0= cloud.google.com/go/workflows v1.7.0/go.mod h1:JhSrZuVZWuiDfKEFxU0/F1PQjmpnpcoISEXH2bcHC3M= -cosmossdk.io/api v0.7.0 h1:QsEMIWuv9xWDbF2HZnW4Lpu1/SejCztPu0LQx7t6MN4= -cosmossdk.io/api v0.7.0/go.mod h1:kJFAEMLN57y0viszHDPLMmieF0471o5QAwwApa+270M= +cosmossdk.io/api v0.7.1-0.20230820170544-1bd37053e0c0 h1:z1aCAqEXi5fzC5tjanWnkP/zhhuWTX17IiNKxLvXFcw= +cosmossdk.io/api v0.7.1-0.20230820170544-1bd37053e0c0/go.mod h1:h4YT2OHIBT/YIwWrc5L+4dY05ZIqvo89zs6m7j4/RSk= cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= cosmossdk.io/core v0.11.0 h1:vtIafqUi+1ZNAE/oxLOQQ7Oek2n4S48SWLG8h/+wdbo= diff --git a/simapp/gomod2nix.toml b/simapp/gomod2nix.toml index bd22df6353d8..ca5798fc2be5 100644 --- a/simapp/gomod2nix.toml +++ b/simapp/gomod2nix.toml @@ -17,8 +17,8 @@ schema = 3 version = "v1.31.0" hash = "sha256-d59Q6JjMga6/7d1TtFW9GuAq+6O2U4LhNesz3Knmo0E=" [mod."cosmossdk.io/api"] - version = "v0.7.0" - hash = "sha256-PuYJB6k6Vv9nMmaY7pfCnSJTmcARssZvA5oz1Yq4YF4=" + version = "v0.7.1-0.20230820170544-1bd37053e0c0" + hash = "sha256-iASrjR6a28d+feKXAtP4lEoKlx+TBZm/Q7IBJhR6Omo=" [mod."cosmossdk.io/collections"] version = "v0.4.0" hash = "sha256-minFyzgO/D+Oda4E3B1qvOAN5qd65SjS6nmjca4cp/8=" diff --git a/tests/go.mod b/tests/go.mod index a7599db8d58e..f7d9c9203eeb 100644 --- a/tests/go.mod +++ b/tests/go.mod @@ -3,7 +3,7 @@ module github.com/cosmos/cosmos-sdk/tests go 1.21 require ( - cosmossdk.io/api v0.7.0 + cosmossdk.io/api v0.7.1-0.20230820170544-1bd37053e0c0 cosmossdk.io/collections v0.4.0 cosmossdk.io/core v0.11.0 cosmossdk.io/depinject v1.0.0-alpha.4 diff --git a/tests/go.sum b/tests/go.sum index 871cb9ad4428..01af9fa03d78 100644 --- a/tests/go.sum +++ b/tests/go.sum @@ -187,8 +187,8 @@ cloud.google.com/go/webrisk v1.4.0/go.mod h1:Hn8X6Zr+ziE2aNd8SliSDWpEnSS1u4R9+xX cloud.google.com/go/webrisk v1.5.0/go.mod h1:iPG6fr52Tv7sGk0H6qUFzmL3HHZev1htXuWDEEsqMTg= cloud.google.com/go/workflows v1.6.0/go.mod h1:6t9F5h/unJz41YqfBmqSASJSXccBLtD1Vwf+KmJENM0= cloud.google.com/go/workflows v1.7.0/go.mod h1:JhSrZuVZWuiDfKEFxU0/F1PQjmpnpcoISEXH2bcHC3M= -cosmossdk.io/api v0.7.0 h1:QsEMIWuv9xWDbF2HZnW4Lpu1/SejCztPu0LQx7t6MN4= -cosmossdk.io/api v0.7.0/go.mod h1:kJFAEMLN57y0viszHDPLMmieF0471o5QAwwApa+270M= +cosmossdk.io/api v0.7.1-0.20230820170544-1bd37053e0c0 h1:z1aCAqEXi5fzC5tjanWnkP/zhhuWTX17IiNKxLvXFcw= +cosmossdk.io/api v0.7.1-0.20230820170544-1bd37053e0c0/go.mod h1:h4YT2OHIBT/YIwWrc5L+4dY05ZIqvo89zs6m7j4/RSk= cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= cosmossdk.io/core v0.11.0 h1:vtIafqUi+1ZNAE/oxLOQQ7Oek2n4S48SWLG8h/+wdbo= diff --git a/tests/starship/tests/go.mod b/tests/starship/tests/go.mod index 0a5b7d6870eb..b2ef9ae282db 100644 --- a/tests/starship/tests/go.mod +++ b/tests/starship/tests/go.mod @@ -38,7 +38,7 @@ require ( cloud.google.com/go/compute/metadata v0.2.3 // indirect cloud.google.com/go/iam v1.1.1 // indirect cloud.google.com/go/storage v1.31.0 // indirect - cosmossdk.io/api v0.7.0 // indirect + cosmossdk.io/api v0.7.1-0.20230820170544-1bd37053e0c0 // indirect cosmossdk.io/client/v2 v2.0.0-20230630094428-02b760776860 // indirect cosmossdk.io/collections v0.4.0 // indirect cosmossdk.io/core v0.11.0 // indirect diff --git a/tests/starship/tests/go.sum b/tests/starship/tests/go.sum index a51c20608f7d..cbd25ba22cc1 100644 --- a/tests/starship/tests/go.sum +++ b/tests/starship/tests/go.sum @@ -187,8 +187,8 @@ cloud.google.com/go/webrisk v1.4.0/go.mod h1:Hn8X6Zr+ziE2aNd8SliSDWpEnSS1u4R9+xX cloud.google.com/go/webrisk v1.5.0/go.mod h1:iPG6fr52Tv7sGk0H6qUFzmL3HHZev1htXuWDEEsqMTg= cloud.google.com/go/workflows v1.6.0/go.mod h1:6t9F5h/unJz41YqfBmqSASJSXccBLtD1Vwf+KmJENM0= cloud.google.com/go/workflows v1.7.0/go.mod h1:JhSrZuVZWuiDfKEFxU0/F1PQjmpnpcoISEXH2bcHC3M= -cosmossdk.io/api v0.7.0 h1:QsEMIWuv9xWDbF2HZnW4Lpu1/SejCztPu0LQx7t6MN4= -cosmossdk.io/api v0.7.0/go.mod h1:kJFAEMLN57y0viszHDPLMmieF0471o5QAwwApa+270M= +cosmossdk.io/api v0.7.1-0.20230820170544-1bd37053e0c0 h1:z1aCAqEXi5fzC5tjanWnkP/zhhuWTX17IiNKxLvXFcw= +cosmossdk.io/api v0.7.1-0.20230820170544-1bd37053e0c0/go.mod h1:h4YT2OHIBT/YIwWrc5L+4dY05ZIqvo89zs6m7j4/RSk= cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= cosmossdk.io/core v0.11.0 h1:vtIafqUi+1ZNAE/oxLOQQ7Oek2n4S48SWLG8h/+wdbo= diff --git a/testutil/configurator/configurator.go b/testutil/configurator/configurator.go index bec4da0f9685..d671b2d82884 100644 --- a/testutil/configurator/configurator.go +++ b/testutil/configurator/configurator.go @@ -28,6 +28,7 @@ import ( // Config should never need to be instantiated manually and is solely used for ModuleOption. type Config struct { ModuleConfigs map[string]*appv1alpha1.ModuleConfig + PreBlockersOrder []string BeginBlockersOrder []string EndBlockersOrder []string InitGenesisOrder []string @@ -37,8 +38,10 @@ type Config struct { func defaultConfig() *Config { return &Config{ ModuleConfigs: make(map[string]*appv1alpha1.ModuleConfig), - BeginBlockersOrder: []string{ + PreBlockersOrder: []string{ "upgrade", + }, + BeginBlockersOrder: []string{ "mint", "distribution", "slashing", @@ -106,6 +109,12 @@ func defaultConfig() *Config { type ModuleOption func(config *Config) +func WithCustomPreBlockersOrder(preBlockOrder ...string) ModuleOption { + return func(config *Config) { + config.PreBlockersOrder = preBlockOrder + } +} + func WithCustomBeginBlockersOrder(beginBlockOrder ...string) ModuleOption { return func(config *Config) { config.BeginBlockersOrder = beginBlockOrder @@ -315,11 +324,18 @@ func NewAppConfig(opts ...ModuleOption) depinject.Config { opt(cfg) } + preBlockers := make([]string, 0) beginBlockers := make([]string, 0) endBlockers := make([]string, 0) initGenesis := make([]string, 0) overrides := make([]*runtimev1alpha1.StoreKeyConfig, 0) + for _, s := range cfg.PreBlockersOrder { + if _, ok := cfg.ModuleConfigs[s]; ok { + preBlockers = append(preBlockers, s) + } + } + for _, s := range cfg.BeginBlockersOrder { if _, ok := cfg.ModuleConfigs[s]; ok { beginBlockers = append(beginBlockers, s) @@ -344,6 +360,7 @@ func NewAppConfig(opts ...ModuleOption) depinject.Config { runtimeConfig := &runtimev1alpha1.Module{ AppName: "TestApp", + PreBlockers: preBlockers, BeginBlockers: beginBlockers, EndBlockers: endBlockers, OverrideStoreKeys: overrides, diff --git a/testutil/mock/types_mock_appmodule.go b/testutil/mock/types_mock_appmodule.go index f0fc9b537c1a..c1d22f377963 100644 --- a/testutil/mock/types_mock_appmodule.go +++ b/testutil/mock/types_mock_appmodule.go @@ -541,173 +541,44 @@ func (mr *MockCoreAppModuleMockRecorder) ValidateGenesis(arg0 interface{}) *gomo return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidateGenesis", reflect.TypeOf((*MockCoreAppModule)(nil).ValidateGenesis), arg0) } -// MockCoreUpgradeAppModule is a mock of CoreUpgradeAppModule interface. -type MockCoreUpgradeAppModule struct { - ctrl *gomock.Controller - recorder *MockCoreUpgradeAppModuleMockRecorder +// MockCoreModuleWithPreBlock is a mock of CoreModuleWithPreBlock interface. +type MockCoreModuleWithPreBlock struct { + MockCoreAppModule + recorder *MockCoreModuleWithPreBlockMockRecorder } -// MockCoreUpgradeAppModuleMockRecorder is the mock recorder for MockCoreUpgradeAppModule. -type MockCoreUpgradeAppModuleMockRecorder struct { - mock *MockCoreUpgradeAppModule +// MockCoreModuleWithPreBlockMockRecorder is the mock recorder for MockCoreModuleWithPreBlock. +type MockCoreModuleWithPreBlockMockRecorder struct { + mock *MockCoreModuleWithPreBlock } -// NewMockCoreUpgradeAppModule creates a new mock instance. -func NewMockCoreUpgradeAppModule(ctrl *gomock.Controller) *MockCoreUpgradeAppModule { - mock := &MockCoreUpgradeAppModule{ctrl: ctrl} - mock.recorder = &MockCoreUpgradeAppModuleMockRecorder{mock} +// NewMockCoreModuleWithPreBlock creates a new mock instance. +func NewMockCoreModuleWithPreBlock(ctrl *gomock.Controller) *MockCoreModuleWithPreBlock { + mock := &MockCoreModuleWithPreBlock{ + MockCoreAppModule: MockCoreAppModule{ + ctrl: ctrl, + }, + } + mock.recorder = &MockCoreModuleWithPreBlockMockRecorder{mock} return mock } // EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockCoreUpgradeAppModule) EXPECT() *MockCoreUpgradeAppModuleMockRecorder { +func (m *MockCoreModuleWithPreBlock) EXPECT() *MockCoreModuleWithPreBlockMockRecorder { return m.recorder } -// BeginBlock mocks base method. -func (m *MockCoreUpgradeAppModule) BeginBlock(arg0 context.Context) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "BeginBlock", arg0) - ret0, _ := ret[0].(error) - return ret0 -} - -// BeginBlock indicates an expected call of BeginBlock. -func (mr *MockCoreUpgradeAppModuleMockRecorder) BeginBlock(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BeginBlock", reflect.TypeOf((*MockCoreUpgradeAppModule)(nil).BeginBlock), arg0) -} - -// DefaultGenesis mocks base method. -func (m *MockCoreUpgradeAppModule) DefaultGenesis(arg0 appmodule.GenesisTarget) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "DefaultGenesis", arg0) - ret0, _ := ret[0].(error) - return ret0 -} - -// DefaultGenesis indicates an expected call of DefaultGenesis. -func (mr *MockCoreUpgradeAppModuleMockRecorder) DefaultGenesis(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DefaultGenesis", reflect.TypeOf((*MockCoreUpgradeAppModule)(nil).DefaultGenesis), arg0) -} - -// EndBlock mocks base method. -func (m *MockCoreUpgradeAppModule) EndBlock(arg0 context.Context) error { +// PreBlock mocks base method. +func (m *MockCoreModuleWithPreBlock) PreBlock(arg0 context.Context) (appmodule.ResponsePreBlock, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "EndBlock", arg0) - ret0, _ := ret[0].(error) - return ret0 -} - -// EndBlock indicates an expected call of EndBlock. -func (mr *MockCoreUpgradeAppModuleMockRecorder) EndBlock(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EndBlock", reflect.TypeOf((*MockCoreUpgradeAppModule)(nil).EndBlock), arg0) -} - -// ExportGenesis mocks base method. -func (m *MockCoreUpgradeAppModule) ExportGenesis(arg0 context.Context, arg1 appmodule.GenesisTarget) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ExportGenesis", arg0, arg1) - ret0, _ := ret[0].(error) - return ret0 -} - -// ExportGenesis indicates an expected call of ExportGenesis. -func (mr *MockCoreUpgradeAppModuleMockRecorder) ExportGenesis(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ExportGenesis", reflect.TypeOf((*MockCoreUpgradeAppModule)(nil).ExportGenesis), arg0, arg1) -} - -// InitGenesis mocks base method. -func (m *MockCoreUpgradeAppModule) InitGenesis(arg0 context.Context, arg1 appmodule.GenesisSource) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "InitGenesis", arg0, arg1) - ret0, _ := ret[0].(error) - return ret0 -} - -// InitGenesis indicates an expected call of InitGenesis. -func (mr *MockCoreUpgradeAppModuleMockRecorder) InitGenesis(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InitGenesis", reflect.TypeOf((*MockCoreUpgradeAppModule)(nil).InitGenesis), arg0, arg1) -} - -// IsAppModule mocks base method. -func (m *MockCoreUpgradeAppModule) IsAppModule() { - m.ctrl.T.Helper() - m.ctrl.Call(m, "IsAppModule") -} - -// IsAppModule indicates an expected call of IsAppModule. -func (mr *MockCoreUpgradeAppModuleMockRecorder) IsAppModule() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsAppModule", reflect.TypeOf((*MockCoreUpgradeAppModule)(nil).IsAppModule)) -} - -// IsOnePerModuleType mocks base method. -func (m *MockCoreUpgradeAppModule) IsOnePerModuleType() { - m.ctrl.T.Helper() - m.ctrl.Call(m, "IsOnePerModuleType") -} - -// IsOnePerModuleType indicates an expected call of IsOnePerModuleType. -func (mr *MockCoreUpgradeAppModuleMockRecorder) IsOnePerModuleType() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsOnePerModuleType", reflect.TypeOf((*MockCoreUpgradeAppModule)(nil).IsOnePerModuleType)) -} - -// IsUpgradeModule mocks base method. -func (m *MockCoreUpgradeAppModule) IsUpgradeModule() { - m.ctrl.T.Helper() - m.ctrl.Call(m, "IsUpgradeModule") -} - -// IsUpgradeModule indicates an expected call of IsUpgradeModule. -func (mr *MockCoreUpgradeAppModuleMockRecorder) IsUpgradeModule() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsUpgradeModule", reflect.TypeOf((*MockCoreUpgradeAppModule)(nil).IsUpgradeModule)) -} - -// Precommit mocks base method. -func (m *MockCoreUpgradeAppModule) Precommit(arg0 context.Context) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Precommit", arg0) - ret0, _ := ret[0].(error) - return ret0 -} - -// Precommit indicates an expected call of Precommit. -func (mr *MockCoreUpgradeAppModuleMockRecorder) Precommit(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Precommit", reflect.TypeOf((*MockCoreUpgradeAppModule)(nil).Precommit), arg0) -} - -// PrepareCheckState mocks base method. -func (m *MockCoreUpgradeAppModule) PrepareCheckState(arg0 context.Context) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "PrepareCheckState", arg0) - ret0, _ := ret[0].(error) - return ret0 -} - -// PrepareCheckState indicates an expected call of PrepareCheckState. -func (mr *MockCoreUpgradeAppModuleMockRecorder) PrepareCheckState(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PrepareCheckState", reflect.TypeOf((*MockCoreUpgradeAppModule)(nil).PrepareCheckState), arg0) -} - -// ValidateGenesis mocks base method. -func (m *MockCoreUpgradeAppModule) ValidateGenesis(arg0 appmodule.GenesisSource) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ValidateGenesis", arg0) - ret0, _ := ret[0].(error) - return ret0 + ret := m.ctrl.Call(m, "PreBlock", arg0) + ret0, _ := ret[0].(appmodule.ResponsePreBlock) + ret1, _ := ret[1].(error) + return ret0, ret1 } -// ValidateGenesis indicates an expected call of ValidateGenesis. -func (mr *MockCoreUpgradeAppModuleMockRecorder) ValidateGenesis(arg0 interface{}) *gomock.Call { +// PreBlock indicates an expected call of PreBlock. +func (mr *MockCoreModuleWithPreBlockMockRecorder) PreBlock(arg0 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidateGenesis", reflect.TypeOf((*MockCoreUpgradeAppModule)(nil).ValidateGenesis), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PreBlock", reflect.TypeOf((*MockCoreModuleWithPreBlock)(nil).PreBlock), arg0) } diff --git a/types/abci.go b/types/abci.go index 7d567b6e2ce6..ff40d1109a27 100644 --- a/types/abci.go +++ b/types/abci.go @@ -30,6 +30,9 @@ type ExtendVoteHandler func(Context, *abci.RequestExtendVote) (*abci.ResponseExt // pre-commit vote extension. type VerifyVoteExtensionHandler func(Context, *abci.RequestVerifyVoteExtension) (*abci.ResponseVerifyVoteExtension, error) +// PreBlocker runs code before the `BeginBlocker`. +type PreBlocker func(Context) (ResponsePreBlock, error) + // BeginBlocker defines a function type alias for executing application // business logic before transactions are executed. // @@ -66,3 +69,11 @@ type EndBlock struct { type BeginBlock struct { Events []abci.Event } + +type ResponsePreBlock struct { + ConsensusParamsChanged bool +} + +func (r ResponsePreBlock) IsConsensusParamsChanged() bool { + return r.ConsensusParamsChanged +} diff --git a/types/module/mock_appmodule_test.go b/types/module/mock_appmodule_test.go index fb9991d689f2..27049cf54000 100644 --- a/types/module/mock_appmodule_test.go +++ b/types/module/mock_appmodule_test.go @@ -39,8 +39,3 @@ type CoreAppModule interface { appmodule.HasPrecommit appmodule.HasPrepareCheckState } - -type CoreUpgradeAppModule interface { - CoreAppModule - appmodule.UpgradeModule -} diff --git a/types/module/module.go b/types/module/module.go index 4bd6edcc8e95..086e281a7cf6 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -268,6 +268,7 @@ type Manager struct { Modules map[string]interface{} // interface{} is used now to support the legacy AppModule as well as new core appmodule.AppModule. OrderInitGenesis []string OrderExportGenesis []string + OrderPreBlockers []string OrderBeginBlockers []string OrderEndBlockers []string OrderPrepareCheckStaters []string @@ -279,15 +280,20 @@ type Manager struct { func NewManager(modules ...AppModule) *Manager { moduleMap := make(map[string]interface{}) modulesStr := make([]string, 0, len(modules)) + preBlockModulesStr := make([]string, 0) for _, module := range modules { moduleMap[module.Name()] = module modulesStr = append(modulesStr, module.Name()) + if _, ok := module.(appmodule.HasPreBlocker); ok { + preBlockModulesStr = append(preBlockModulesStr, module.Name()) + } } return &Manager{ Modules: moduleMap, OrderInitGenesis: modulesStr, OrderExportGenesis: modulesStr, + OrderPreBlockers: preBlockModulesStr, OrderBeginBlockers: modulesStr, OrderPrepareCheckStaters: modulesStr, OrderPrecommiters: modulesStr, @@ -300,9 +306,13 @@ func NewManager(modules ...AppModule) *Manager { func NewManagerFromMap(moduleMap map[string]appmodule.AppModule) *Manager { simpleModuleMap := make(map[string]interface{}) modulesStr := make([]string, 0, len(simpleModuleMap)) + preBlockModulesStr := make([]string, 0) for name, module := range moduleMap { simpleModuleMap[name] = module modulesStr = append(modulesStr, name) + if _, ok := module.(appmodule.HasPreBlocker); ok { + preBlockModulesStr = append(preBlockModulesStr, name) + } } // Sort the modules by name. Given that we are using a map above we can't guarantee the order. @@ -312,6 +322,7 @@ func NewManagerFromMap(moduleMap map[string]appmodule.AppModule) *Manager { Modules: simpleModuleMap, OrderInitGenesis: modulesStr, OrderExportGenesis: modulesStr, + OrderPreBlockers: preBlockModulesStr, OrderBeginBlockers: modulesStr, OrderEndBlockers: modulesStr, OrderPrecommiters: modulesStr, @@ -355,6 +366,17 @@ func (m *Manager) SetOrderExportGenesis(moduleNames ...string) { m.OrderExportGenesis = moduleNames } +// SetOrderPreBlockers sets the order of set pre-blocker calls +func (m *Manager) SetOrderPreBlockers(moduleNames ...string) { + m.assertNoForgottenModules("SetOrderPreBlockers", moduleNames, + func(moduleName string) bool { + module := m.Modules[moduleName] + _, hasBlock := module.(appmodule.HasPreBlocker) + return !hasBlock + }) + m.OrderPreBlockers = moduleNames +} + // SetOrderBeginBlockers sets the order of set begin-blocker calls func (m *Manager) SetOrderBeginBlockers(moduleNames ...string) { m.assertNoForgottenModules("SetOrderBeginBlockers", moduleNames, @@ -713,32 +735,37 @@ func (m Manager) RunMigrations(ctx context.Context, cfg Configurator, fromVM Ver return updatedVM, nil } -// RunMigrationBeginBlock performs begin block functionality for upgrade module. +// PreBlock performs begin block functionality for upgrade module. // It takes the current context as a parameter and returns a boolean value -// indicating whether the migration was executed or not and an error if fails. -func (m *Manager) RunMigrationBeginBlock(ctx sdk.Context) (bool, error) { - for _, moduleName := range m.OrderBeginBlockers { - if mod, ok := m.Modules[moduleName].(appmodule.HasBeginBlocker); ok { - if _, ok := mod.(appmodule.UpgradeModule); ok { - err := mod.BeginBlock(ctx) - return err == nil, err +// indicating whether the migration was successfully executed or not. +func (m *Manager) PreBlock(ctx sdk.Context) (sdk.ResponsePreBlock, error) { + ctx = ctx.WithEventManager(sdk.NewEventManager()) + paramsChanged := false + for _, moduleName := range m.OrderPreBlockers { + if module, ok := m.Modules[moduleName].(appmodule.HasPreBlocker); ok { + rsp, err := module.PreBlock(ctx) + if err != nil { + return sdk.ResponsePreBlock{}, err + } + if rsp.IsConsensusParamsChanged() { + paramsChanged = true } } } - return false, nil + return sdk.ResponsePreBlock{ + ConsensusParamsChanged: paramsChanged, + }, nil } -// BeginBlock performs begin block functionality for non-upgrade modules. It creates a -// child context with an event manager to aggregate events emitted from non-upgrade +// BeginBlock performs begin block functionality for all modules. It creates a +// child context with an event manager to aggregate events emitted from all // modules. func (m *Manager) BeginBlock(ctx sdk.Context) (sdk.BeginBlock, error) { ctx = ctx.WithEventManager(sdk.NewEventManager()) for _, moduleName := range m.OrderBeginBlockers { if module, ok := m.Modules[moduleName].(appmodule.HasBeginBlocker); ok { - if _, ok := module.(appmodule.UpgradeModule); !ok { - if err := module.BeginBlock(ctx); err != nil { - return sdk.BeginBlock{}, err - } + if err := module.BeginBlock(ctx); err != nil { + return sdk.BeginBlock{}, err } } } diff --git a/types/module/module_test.go b/types/module/module_test.go index 1be647719764..bd5111a6692b 100644 --- a/types/module/module_test.go +++ b/types/module/module_test.go @@ -143,6 +143,10 @@ func TestManagerOrderSetters(t *testing.T) { mm.SetOrderExportGenesis("module2", "module1", "module3") require.Equal(t, []string{"module2", "module1", "module3"}, mm.OrderExportGenesis) + require.Equal(t, []string{}, mm.OrderPreBlockers) + mm.SetOrderPreBlockers("module2", "module1", "module3") + require.Equal(t, []string{"module2", "module1", "module3"}, mm.OrderPreBlockers) + require.Equal(t, []string{"module1", "module2", "module3"}, mm.OrderBeginBlockers) mm.SetOrderBeginBlockers("module2", "module1", "module3") require.Equal(t, []string{"module2", "module1", "module3"}, mm.OrderBeginBlockers) @@ -444,6 +448,10 @@ func TestCoreAPIManagerOrderSetters(t *testing.T) { mm.SetOrderExportGenesis("module2", "module1", "module3") require.Equal(t, []string{"module2", "module1", "module3"}, mm.OrderExportGenesis) + require.Equal(t, []string{}, mm.OrderPreBlockers) + mm.SetOrderPreBlockers("module2", "module1", "module3") + require.Equal(t, []string{"module2", "module1", "module3"}, mm.OrderPreBlockers) + require.Equal(t, []string{"module1", "module2", "module3"}, mm.OrderBeginBlockers) mm.SetOrderBeginBlockers("module2", "module1", "module3") require.Equal(t, []string{"module2", "module1", "module3"}, mm.OrderBeginBlockers) @@ -461,35 +469,38 @@ func TestCoreAPIManagerOrderSetters(t *testing.T) { require.Equal(t, []string{"module3", "module2", "module1"}, mm.OrderPrecommiters) } -func TestCoreAPIManager_RunMigrationBeginBlock(t *testing.T) { +func TestCoreAPIManager_PreBlock(t *testing.T) { mockCtrl := gomock.NewController(t) t.Cleanup(mockCtrl.Finish) - mockAppModule1 := mock.NewMockCoreAppModule(mockCtrl) - mockAppModule2 := mock.NewMockCoreUpgradeAppModule(mockCtrl) + mockAppModule1 := mock.NewMockCoreModuleWithPreBlock(mockCtrl) mm := module.NewManagerFromMap(map[string]appmodule.AppModule{ "module1": mockAppModule1, - "module2": mockAppModule2, + "module2": mock.NewMockCoreAppModule(mockCtrl), }) require.NotNil(t, mm) require.Equal(t, 2, len(mm.Modules)) + require.Equal(t, 1, len(mm.OrderPreBlockers)) - mockAppModule1.EXPECT().BeginBlock(gomock.Any()).Times(0) - mockAppModule2.EXPECT().BeginBlock(gomock.Any()).Times(1).Return(nil) - success, err := mm.RunMigrationBeginBlock(sdk.Context{}) - require.Equal(t, true, success) + mockAppModule1.EXPECT().PreBlock(gomock.Any()).Times(1).Return(sdk.ResponsePreBlock{ + ConsensusParamsChanged: true, + }, nil) + res, err := mm.PreBlock(sdk.Context{}) require.NoError(t, err) + require.True(t, res.ConsensusParamsChanged) // test false - success, err = module.NewManager().RunMigrationBeginBlock(sdk.Context{}) - require.Equal(t, false, success) + mockAppModule1.EXPECT().PreBlock(gomock.Any()).Times(1).Return(sdk.ResponsePreBlock{ + ConsensusParamsChanged: false, + }, nil) + res, err = mm.PreBlock(sdk.Context{}) require.NoError(t, err) + require.False(t, res.ConsensusParamsChanged) - // test panic - mockAppModule2.EXPECT().BeginBlock(gomock.Any()).Times(1).Return(errors.New("some error")) - success, err = mm.RunMigrationBeginBlock(sdk.Context{}) - require.Equal(t, false, success) - require.Error(t, err) + // test error + mockAppModule1.EXPECT().PreBlock(gomock.Any()).Times(1).Return(sdk.ResponsePreBlock{}, errors.New("some error")) + _, err = mm.PreBlock(sdk.Context{}) + require.EqualError(t, err, "some error") } func TestCoreAPIManager_BeginBlock(t *testing.T) { diff --git a/x/circuit/go.mod b/x/circuit/go.mod index 0922afda0f3d..338b4548d237 100644 --- a/x/circuit/go.mod +++ b/x/circuit/go.mod @@ -3,7 +3,7 @@ module cosmossdk.io/x/circuit go 1.21 require ( - cosmossdk.io/api v0.7.0 + cosmossdk.io/api v0.7.1-0.20230820170544-1bd37053e0c0 cosmossdk.io/collections v0.4.0 cosmossdk.io/core v0.11.0 cosmossdk.io/depinject v1.0.0-alpha.4 diff --git a/x/circuit/go.sum b/x/circuit/go.sum index 84239a1b44a6..c5ed7f000e82 100644 --- a/x/circuit/go.sum +++ b/x/circuit/go.sum @@ -35,8 +35,8 @@ cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohl cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs= cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo= -cosmossdk.io/api v0.7.0 h1:QsEMIWuv9xWDbF2HZnW4Lpu1/SejCztPu0LQx7t6MN4= -cosmossdk.io/api v0.7.0/go.mod h1:kJFAEMLN57y0viszHDPLMmieF0471o5QAwwApa+270M= +cosmossdk.io/api v0.7.1-0.20230820170544-1bd37053e0c0 h1:z1aCAqEXi5fzC5tjanWnkP/zhhuWTX17IiNKxLvXFcw= +cosmossdk.io/api v0.7.1-0.20230820170544-1bd37053e0c0/go.mod h1:h4YT2OHIBT/YIwWrc5L+4dY05ZIqvo89zs6m7j4/RSk= cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= cosmossdk.io/core v0.11.0 h1:vtIafqUi+1ZNAE/oxLOQQ7Oek2n4S48SWLG8h/+wdbo= diff --git a/x/evidence/go.mod b/x/evidence/go.mod index 3b77240fc4cb..ee3f479898dd 100644 --- a/x/evidence/go.mod +++ b/x/evidence/go.mod @@ -3,7 +3,7 @@ module cosmossdk.io/x/evidence go 1.21 require ( - cosmossdk.io/api v0.7.0 + cosmossdk.io/api v0.7.1-0.20230820170544-1bd37053e0c0 cosmossdk.io/collections v0.4.0 cosmossdk.io/core v0.11.0 cosmossdk.io/depinject v1.0.0-alpha.4 diff --git a/x/evidence/go.sum b/x/evidence/go.sum index 84239a1b44a6..c5ed7f000e82 100644 --- a/x/evidence/go.sum +++ b/x/evidence/go.sum @@ -35,8 +35,8 @@ cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohl cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs= cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo= -cosmossdk.io/api v0.7.0 h1:QsEMIWuv9xWDbF2HZnW4Lpu1/SejCztPu0LQx7t6MN4= -cosmossdk.io/api v0.7.0/go.mod h1:kJFAEMLN57y0viszHDPLMmieF0471o5QAwwApa+270M= +cosmossdk.io/api v0.7.1-0.20230820170544-1bd37053e0c0 h1:z1aCAqEXi5fzC5tjanWnkP/zhhuWTX17IiNKxLvXFcw= +cosmossdk.io/api v0.7.1-0.20230820170544-1bd37053e0c0/go.mod h1:h4YT2OHIBT/YIwWrc5L+4dY05ZIqvo89zs6m7j4/RSk= cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= cosmossdk.io/core v0.11.0 h1:vtIafqUi+1ZNAE/oxLOQQ7Oek2n4S48SWLG8h/+wdbo= diff --git a/x/feegrant/go.mod b/x/feegrant/go.mod index ff9daba4678a..ff8c2263fdef 100644 --- a/x/feegrant/go.mod +++ b/x/feegrant/go.mod @@ -3,7 +3,7 @@ module cosmossdk.io/x/feegrant go 1.21 require ( - cosmossdk.io/api v0.7.0 + cosmossdk.io/api v0.7.1-0.20230820170544-1bd37053e0c0 cosmossdk.io/collections v0.4.0 cosmossdk.io/core v0.11.0 cosmossdk.io/depinject v1.0.0-alpha.4 diff --git a/x/feegrant/go.sum b/x/feegrant/go.sum index a4470ae361f2..2b051170b6ac 100644 --- a/x/feegrant/go.sum +++ b/x/feegrant/go.sum @@ -35,8 +35,8 @@ cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohl cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs= cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo= -cosmossdk.io/api v0.7.0 h1:QsEMIWuv9xWDbF2HZnW4Lpu1/SejCztPu0LQx7t6MN4= -cosmossdk.io/api v0.7.0/go.mod h1:kJFAEMLN57y0viszHDPLMmieF0471o5QAwwApa+270M= +cosmossdk.io/api v0.7.1-0.20230820170544-1bd37053e0c0 h1:z1aCAqEXi5fzC5tjanWnkP/zhhuWTX17IiNKxLvXFcw= +cosmossdk.io/api v0.7.1-0.20230820170544-1bd37053e0c0/go.mod h1:h4YT2OHIBT/YIwWrc5L+4dY05ZIqvo89zs6m7j4/RSk= cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= cosmossdk.io/core v0.11.0 h1:vtIafqUi+1ZNAE/oxLOQQ7Oek2n4S48SWLG8h/+wdbo= diff --git a/x/nft/go.mod b/x/nft/go.mod index b11ec8b5487e..4de0f1ecf54a 100644 --- a/x/nft/go.mod +++ b/x/nft/go.mod @@ -3,7 +3,7 @@ module cosmossdk.io/x/nft go 1.21 require ( - cosmossdk.io/api v0.7.0 + cosmossdk.io/api v0.7.1-0.20230820170544-1bd37053e0c0 cosmossdk.io/core v0.11.0 cosmossdk.io/depinject v1.0.0-alpha.4 cosmossdk.io/errors v1.0.0 diff --git a/x/nft/go.sum b/x/nft/go.sum index 84239a1b44a6..c5ed7f000e82 100644 --- a/x/nft/go.sum +++ b/x/nft/go.sum @@ -35,8 +35,8 @@ cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohl cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs= cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo= -cosmossdk.io/api v0.7.0 h1:QsEMIWuv9xWDbF2HZnW4Lpu1/SejCztPu0LQx7t6MN4= -cosmossdk.io/api v0.7.0/go.mod h1:kJFAEMLN57y0viszHDPLMmieF0471o5QAwwApa+270M= +cosmossdk.io/api v0.7.1-0.20230820170544-1bd37053e0c0 h1:z1aCAqEXi5fzC5tjanWnkP/zhhuWTX17IiNKxLvXFcw= +cosmossdk.io/api v0.7.1-0.20230820170544-1bd37053e0c0/go.mod h1:h4YT2OHIBT/YIwWrc5L+4dY05ZIqvo89zs6m7j4/RSk= cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= cosmossdk.io/core v0.11.0 h1:vtIafqUi+1ZNAE/oxLOQQ7Oek2n4S48SWLG8h/+wdbo= diff --git a/x/upgrade/abci.go b/x/upgrade/abci.go index e10824646183..58064868c8a9 100644 --- a/x/upgrade/abci.go +++ b/x/upgrade/abci.go @@ -14,7 +14,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ) -// BeginBlock will check if there is a scheduled plan and if it is ready to be executed. +// PreBlocker will check if there is a scheduled plan and if it is ready to be executed. // If the current height is in the provided set of heights to skip, it will skip and clear the upgrade plan. // If it is ready, it will execute it if the handler is installed, and panic/abort otherwise. // If the plan is not ready, it will ensure the handler is not registered too early (and abort otherwise). @@ -22,14 +22,17 @@ import ( // The purpose is to ensure the binary is switched EXACTLY at the desired block, and to allow // a migration to be executed if needed upon this switch (migration defined in the new binary) // skipUpgradeHeightArray is a set of block heights for which the upgrade must be skipped -func BeginBlocker(ctx context.Context, k *keeper.Keeper) error { +func PreBlocker(ctx context.Context, k *keeper.Keeper) (sdk.ResponsePreBlock, error) { + rsp := sdk.ResponsePreBlock{ + ConsensusParamsChanged: false, + } defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker) sdkCtx := sdk.UnwrapSDKContext(ctx) blockHeight := sdkCtx.HeaderInfo().Height plan, err := k.GetUpgradePlan(ctx) if err != nil && !errors.Is(err, types.ErrNoUpgradePlanFound) { - return err + return rsp, err } found := err == nil @@ -43,7 +46,7 @@ func BeginBlocker(ctx context.Context, k *keeper.Keeper) error { if !found || !plan.ShouldExecute(blockHeight) || (plan.ShouldExecute(blockHeight) && k.IsSkipHeight(blockHeight)) { lastAppliedPlan, _, err := k.GetLastCompletedUpgrade(ctx) if err != nil { - return err + return rsp, err } if lastAppliedPlan != "" && !k.HasHandler(lastAppliedPlan) { @@ -54,13 +57,13 @@ func BeginBlocker(ctx context.Context, k *keeper.Keeper) error { appVersion = cp.Version.App } - return fmt.Errorf("wrong app version %d, upgrade handler is missing for %s upgrade plan", appVersion, lastAppliedPlan) + return rsp, fmt.Errorf("wrong app version %d, upgrade handler is missing for %s upgrade plan", appVersion, lastAppliedPlan) } } } if !found { - return nil + return rsp, nil } logger := k.Logger(ctx) @@ -73,7 +76,7 @@ func BeginBlocker(ctx context.Context, k *keeper.Keeper) error { logger.Info(skipUpgradeMsg) // Clear the upgrade plan at current height - return k.ClearUpgradePlan(ctx) + return rsp, k.ClearUpgradePlan(ctx) } // Prepare shutdown if we don't have an upgrade handler for this upgrade name (meaning this software is out of date) @@ -82,20 +85,25 @@ func BeginBlocker(ctx context.Context, k *keeper.Keeper) error { // store migrations. err := k.DumpUpgradeInfoToDisk(blockHeight, plan) if err != nil { - return fmt.Errorf("unable to write upgrade info to filesystem: %w", err) + return rsp, fmt.Errorf("unable to write upgrade info to filesystem: %w", err) } upgradeMsg := BuildUpgradeNeededMsg(plan) logger.Error(upgradeMsg) // Returning an error will end up in a panic - return errors.New(upgradeMsg) + return rsp, errors.New(upgradeMsg) } // We have an upgrade handler for this upgrade name, so apply the upgrade logger.Info(fmt.Sprintf("applying upgrade \"%s\" at %s", plan.Name, plan.DueAt())) sdkCtx = sdkCtx.WithBlockGasMeter(storetypes.NewInfiniteGasMeter()) - return k.ApplyUpgrade(sdkCtx, plan) + err = k.ApplyUpgrade(sdkCtx, plan) + return sdk.ResponsePreBlock{ + // the consensus parameters might be modified in the migration, + // refresh the consensus parameters in context. + ConsensusParamsChanged: true, + }, err } // if we have a pending upgrade, but it is not yet time, make sure we did not @@ -105,10 +113,9 @@ func BeginBlocker(ctx context.Context, k *keeper.Keeper) error { logger.Error(downgradeMsg) // Returning an error will end up in a panic - return errors.New(downgradeMsg) + return rsp, errors.New(downgradeMsg) } - - return nil + return rsp, nil } // BuildUpgradeNeededMsg prints the message that notifies that an upgrade is needed. diff --git a/x/upgrade/abci_test.go b/x/upgrade/abci_test.go index 3dc134d96b98..62e91f22f2f4 100644 --- a/x/upgrade/abci_test.go +++ b/x/upgrade/abci_test.go @@ -31,11 +31,11 @@ import ( ) type TestSuite struct { - module appmodule.HasBeginBlocker - keeper *keeper.Keeper - ctx sdk.Context - baseApp *baseapp.BaseApp - encCfg moduletestutil.TestEncodingConfig + preModule appmodule.HasPreBlocker + keeper *keeper.Keeper + ctx sdk.Context + baseApp *baseapp.BaseApp + encCfg moduletestutil.TestEncodingConfig } func (s *TestSuite) VerifyDoUpgrade(t *testing.T) { @@ -43,7 +43,7 @@ func (s *TestSuite) VerifyDoUpgrade(t *testing.T) { t.Log("Verify that a panic happens at the upgrade height") newCtx := s.ctx.WithHeaderInfo(header.Info{Height: s.ctx.HeaderInfo().Height + 1, Time: time.Now()}) - err := s.module.BeginBlock(newCtx) + _, err := s.preModule.PreBlock(newCtx) require.ErrorContains(t, err, "UPGRADE \"test\" NEEDED at height: 11: ") t.Log("Verify that the upgrade can be successfully applied with a handler") @@ -51,7 +51,7 @@ func (s *TestSuite) VerifyDoUpgrade(t *testing.T) { return vm, nil }) - err = s.module.BeginBlock(newCtx) + _, err = s.preModule.PreBlock(newCtx) require.NoError(t, err) s.VerifyCleared(t, newCtx) @@ -61,7 +61,7 @@ func (s *TestSuite) VerifyDoUpgradeWithCtx(t *testing.T, newCtx sdk.Context, pro t.Helper() t.Log("Verify that a panic happens at the upgrade height") - err := s.module.BeginBlock(newCtx) + _, err := s.preModule.PreBlock(newCtx) require.ErrorContains(t, err, "UPGRADE \""+proposalName+"\" NEEDED at height: ") t.Log("Verify that the upgrade can be successfully applied with a handler") @@ -69,7 +69,7 @@ func (s *TestSuite) VerifyDoUpgradeWithCtx(t *testing.T, newCtx sdk.Context, pro return vm, nil }) - err = s.module.BeginBlock(newCtx) + _, err = s.preModule.PreBlock(newCtx) require.NoError(t, err) s.VerifyCleared(t, newCtx) @@ -128,7 +128,7 @@ func setupTest(t *testing.T, height int64, skip map[int64]bool) *TestSuite { s.ctx = testCtx.Ctx.WithHeaderInfo(header.Info{Time: time.Now(), Height: height}) - s.module = upgrade.NewAppModule(s.keeper, addresscodec.NewBech32Codec("cosmos")) + s.preModule = upgrade.NewAppModule(s.keeper, addresscodec.NewBech32Codec("cosmos")) return &s } @@ -169,21 +169,21 @@ func TestHaltIfTooNew(t *testing.T) { }) newCtx := s.ctx.WithHeaderInfo(header.Info{Height: s.ctx.HeaderInfo().Height + 1, Time: time.Now()}) - err := s.module.BeginBlock(newCtx) + _, err := s.preModule.PreBlock(newCtx) require.NoError(t, err) require.Equal(t, 0, called) t.Log("Verify we error if we have a registered handler ahead of time") err = s.keeper.ScheduleUpgrade(s.ctx, types.Plan{Name: "future", Height: s.ctx.HeaderInfo().Height + 3}) require.NoError(t, err) - err = s.module.BeginBlock(newCtx) + _, err = s.preModule.PreBlock(newCtx) require.EqualError(t, err, "BINARY UPDATED BEFORE TRIGGER! UPGRADE \"future\" - in binary but not executed on chain. Downgrade your binary") require.Equal(t, 0, called) t.Log("Verify we no longer panic if the plan is on time") futCtx := s.ctx.WithHeaderInfo(header.Info{Height: s.ctx.HeaderInfo().Height + 3, Time: time.Now()}) - err = s.module.BeginBlock(futCtx) + _, err = s.preModule.PreBlock(futCtx) require.NoError(t, err) require.Equal(t, 1, called) @@ -217,7 +217,7 @@ func TestCantApplySameUpgradeTwice(t *testing.T) { func TestNoSpuriousUpgrades(t *testing.T) { s := setupTest(t, 10, map[int64]bool{}) t.Log("Verify that no upgrade panic is triggered in the BeginBlocker when we haven't scheduled an upgrade") - err := s.module.BeginBlock(s.ctx) + _, err := s.preModule.PreBlock(s.ctx) require.NoError(t, err) } @@ -254,7 +254,7 @@ func TestSkipUpgradeSkippingAll(t *testing.T) { s.VerifySet(t, map[int64]bool{skipOne: true, skipTwo: true}) newCtx = newCtx.WithHeaderInfo(header.Info{Height: skipOne}) - err = s.module.BeginBlock(newCtx) + _, err = s.preModule.PreBlock(newCtx) require.NoError(t, err) t.Log("Verify a second proposal also is being cleared") @@ -262,7 +262,7 @@ func TestSkipUpgradeSkippingAll(t *testing.T) { require.NoError(t, err) newCtx = newCtx.WithHeaderInfo(header.Info{Height: skipTwo}) - err = s.module.BeginBlock(newCtx) + _, err = s.preModule.PreBlock(newCtx) require.NoError(t, err) // To ensure verification is being done only after both upgrades are cleared @@ -289,7 +289,7 @@ func TestUpgradeSkippingOne(t *testing.T) { // Setting block height of proposal test newCtx = newCtx.WithHeaderInfo(header.Info{Height: skipOne}) - err = s.module.BeginBlock(newCtx) + _, err = s.preModule.PreBlock(newCtx) require.NoError(t, err) t.Log("Verify the second proposal is not skipped") @@ -322,7 +322,7 @@ func TestUpgradeSkippingOnlyTwo(t *testing.T) { // Setting block height of proposal test newCtx = newCtx.WithHeaderInfo(header.Info{Height: skipOne}) - err = s.module.BeginBlock(newCtx) + _, err = s.preModule.PreBlock(newCtx) require.NoError(t, err) // A new proposal with height in skipUpgradeHeights @@ -330,7 +330,7 @@ func TestUpgradeSkippingOnlyTwo(t *testing.T) { require.NoError(t, err) // Setting block height of proposal test2 newCtx = newCtx.WithHeaderInfo(header.Info{Height: skipTwo}) - err = s.module.BeginBlock(newCtx) + _, err = s.preModule.PreBlock(newCtx) require.NoError(t, err) t.Log("Verify a new proposal is not skipped") @@ -351,7 +351,7 @@ func TestUpgradeWithoutSkip(t *testing.T) { err := s.keeper.ScheduleUpgrade(s.ctx, types.Plan{Name: "test", Height: s.ctx.HeaderInfo().Height + 1}) require.NoError(t, err) t.Log("Verify if upgrade happens without skip upgrade") - err = s.module.BeginBlock(newCtx) + _, err = s.preModule.PreBlock(newCtx) require.ErrorContains(t, err, "UPGRADE \"test\" NEEDED at height:") s.VerifyDoUpgrade(t) @@ -441,7 +441,7 @@ func TestBinaryVersion(t *testing.T) { for _, tc := range testCases { ctx := tc.preRun() - err := s.module.BeginBlock(ctx) + _, err := s.preModule.PreBlock(ctx) if tc.expectError { require.Error(t, err) } else { @@ -475,7 +475,8 @@ func TestDowngradeVerification(t *testing.T) { }) // successful upgrade. - require.NoError(t, m.BeginBlock(ctx)) + _, err = m.PreBlock(ctx) + require.NoError(t, err) ctx = ctx.WithHeaderInfo(header.Info{Height: ctx.HeaderInfo().Height + 1}) testCases := map[string]struct { @@ -521,7 +522,7 @@ func TestDowngradeVerification(t *testing.T) { tc.preRun(k, ctx, name) } - err = m.BeginBlock(ctx) + _, err = m.PreBlock(ctx) if tc.expectError { require.Error(t, err, name) } else { diff --git a/x/upgrade/go.mod b/x/upgrade/go.mod index cbb846526298..ddc872afb964 100644 --- a/x/upgrade/go.mod +++ b/x/upgrade/go.mod @@ -3,7 +3,7 @@ module cosmossdk.io/x/upgrade go 1.21 require ( - cosmossdk.io/api v0.7.0 + cosmossdk.io/api v0.7.1-0.20230820170544-1bd37053e0c0 cosmossdk.io/core v0.11.0 cosmossdk.io/depinject v1.0.0-alpha.4 cosmossdk.io/errors v1.0.0 @@ -178,4 +178,10 @@ require ( sigs.k8s.io/yaml v1.3.0 // indirect ) -replace github.com/cosmos/cosmos-sdk => ../../. +// Fix upstream GHSA-h395-qcrw-5vmq and GHSA-3vp4-m3rf-835h vulnerabilities. +// TODO Remove it: https://github.com/cosmos/cosmos-sdk/issues/10409 + +replace ( + github.com/cosmos/cosmos-sdk => ../../. + github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.9.1 +) diff --git a/x/upgrade/go.sum b/x/upgrade/go.sum index 42e15952fc45..2e8bb4595af4 100644 --- a/x/upgrade/go.sum +++ b/x/upgrade/go.sum @@ -187,8 +187,8 @@ cloud.google.com/go/webrisk v1.4.0/go.mod h1:Hn8X6Zr+ziE2aNd8SliSDWpEnSS1u4R9+xX cloud.google.com/go/webrisk v1.5.0/go.mod h1:iPG6fr52Tv7sGk0H6qUFzmL3HHZev1htXuWDEEsqMTg= cloud.google.com/go/workflows v1.6.0/go.mod h1:6t9F5h/unJz41YqfBmqSASJSXccBLtD1Vwf+KmJENM0= cloud.google.com/go/workflows v1.7.0/go.mod h1:JhSrZuVZWuiDfKEFxU0/F1PQjmpnpcoISEXH2bcHC3M= -cosmossdk.io/api v0.7.0 h1:QsEMIWuv9xWDbF2HZnW4Lpu1/SejCztPu0LQx7t6MN4= -cosmossdk.io/api v0.7.0/go.mod h1:kJFAEMLN57y0viszHDPLMmieF0471o5QAwwApa+270M= +cosmossdk.io/api v0.7.1-0.20230820170544-1bd37053e0c0 h1:z1aCAqEXi5fzC5tjanWnkP/zhhuWTX17IiNKxLvXFcw= +cosmossdk.io/api v0.7.1-0.20230820170544-1bd37053e0c0/go.mod h1:h4YT2OHIBT/YIwWrc5L+4dY05ZIqvo89zs6m7j4/RSk= cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= cosmossdk.io/core v0.11.0 h1:vtIafqUi+1ZNAE/oxLOQQ7Oek2n4S48SWLG8h/+wdbo= @@ -272,6 +272,9 @@ github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 h1:q0rUy8C/TYNBQS1+CGKw68tLOF github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc= github.com/bufbuild/protocompile v0.6.0 h1:Uu7WiSQ6Yj9DbkdnOe7U4mNKp58y9WDMKDn28/ZlunY= github.com/bufbuild/protocompile v0.6.0/go.mod h1:YNP35qEYoYGme7QMtz5SBCoN4kL4g12jTtjuzRNdjpE= +github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= +github.com/bytedance/sonic v1.9.1 h1:6iJ6NqdoxCDr6mbY8h18oSO+cShGSMRGCEo7F2h0x8s= +github.com/bytedance/sonic v1.9.1/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U= github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ= github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4= github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM= @@ -285,6 +288,9 @@ github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XL github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cheggaaa/pb v1.0.27/go.mod h1:pQciLPpbU0oxA0h+VJYYLxO+XeDQb5pZijXscXHm81s= +github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY= +github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 h1:qSGYFH7+jGhDF8vLC+iwCD4WpbV1EBDSzWkJODFLams= +github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= github.com/chzyer/logex v1.2.1 h1:XHDu3E6q+gdHgsdTPH6ImJMIp436vR6MPtH8gP05QzM= github.com/chzyer/logex v1.2.1/go.mod h1:JLbx6lG2kDbNRFnfkgvh4eRJRPX1QCoOIWomwysCBrQ= @@ -424,14 +430,15 @@ github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4 github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU= github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw= +github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU= +github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA= github.com/getsentry/sentry-go v0.23.0 h1:dn+QRCeJv4pPt9OjVXiMcGIBIefaTJPw/h0bZWO05nE= github.com/getsentry/sentry-go v0.23.0/go.mod h1:lc76E2QywIyW8WuBnwl8Lc4bkmQH4+w1gwTf25trprY= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= -github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M= -github.com/gin-gonic/gin v1.8.1 h1:4+fr/el88TOO3ewCmQr8cx/CtZ/umlIRIs5M4NTNjf8= -github.com/gin-gonic/gin v1.8.1/go.mod h1:ji8BvRH1azfM+SYow9zQ6SZMvR8qOMZHmsCuWR9tTTk= +github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg= +github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SUcPTeU= github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA= github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og= github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= @@ -450,16 +457,13 @@ github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A= github.com/go-logfmt/logfmt v0.6.0 h1:wGYYu3uicYdqXVgoYbvnkrPVXkuLM1p1ifugDMEdRi4= github.com/go-logfmt/logfmt v0.6.0/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs= -github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= -github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= -github.com/go-playground/locales v0.14.0 h1:u50s323jtVGugKlcYeyzC0etD1HifMjqmJqb8WugfUU= -github.com/go-playground/locales v0.14.0/go.mod h1:sawfccIbzZTqEDETgFXqTho0QybSa7l++s0DH+LDiLs= -github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA= -github.com/go-playground/universal-translator v0.18.0 h1:82dyy6p4OuJq4/CByFNOn/jYrnRPArHwAcmLoJZxyho= -github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl+lu/H90nyDXpg0fqeB/AQUGNTVA= -github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI= -github.com/go-playground/validator/v10 v10.11.1 h1:prmOlTVv+YjZjmRmNSF3VmspqJIxJWXmqUsHwfTRRkQ= -github.com/go-playground/validator/v10 v10.11.1/go.mod h1:i+3WkQ1FvaUjjxh1kSvIA4dMGDBiPU55YFDl0WbKdWU= +github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= +github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= +github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= +github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= +github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= +github.com/go-playground/validator/v10 v10.14.0 h1:vgvQWe3XCz3gIeFDm/HnTIbj6UGmg/+t63MyGU2n5js= +github.com/go-playground/validator/v10 v10.14.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU= github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= @@ -469,8 +473,8 @@ github.com/gobwas/pool v0.2.0 h1:QEmUOlnSjWtnpRGHF3SauEiOsy82Cup83Vf2LcMlnc8= github.com/gobwas/pool v0.2.0/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw= github.com/gobwas/ws v1.0.2 h1:CoAavW/wd/kulfZmSIBt6p24n4j7tHgNVCjsfHVNUbo= github.com/gobwas/ws v1.0.2/go.mod h1:szmBTxLgaFppYjEmNtny/v3w89xOydFnnZMcgRRu/EM= -github.com/goccy/go-json v0.9.11 h1:/pAaQDLHEoCq/5FFmSKBswWmK6H0e8g4159Kc/X/nqk= -github.com/goccy/go-json v0.9.11/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= +github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= +github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 h1:ZpnhV/YsD2/4cESfV5+Hoeu/iUR3ruzNvZ+yQfO03a0= github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2/go.mod h1:bBOAhwG1umN6/6ZUMtDFBMQR8jRg9O75tm9K00oMsK4= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= @@ -719,6 +723,9 @@ github.com/klauspost/compress v1.12.3/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8 github.com/klauspost/compress v1.15.11/go.mod h1:QPwzmACJjUTFsnSHH934V6woptycfrDDJnH7hvFVbGM= github.com/klauspost/compress v1.16.7 h1:2mk3MPGNzKyxErAw8YaohYh69+pa4sIQSC0fPGCFR9I= github.com/klauspost/compress v1.16.7/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= +github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= +github.com/klauspost/cpuid/v2 v2.2.4 h1:acbojRNwl3o09bUq+yDCtZFc1aiwaAAxtcn8YkZXnvk= +github.com/klauspost/cpuid/v2 v2.2.4/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= @@ -730,9 +737,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= -github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w= -github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY= +github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q= +github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4= github.com/lib/pq v1.10.7 h1:p7ZhMD+KsSRozJr34udlUrhboJwWAgCg34+/ZZNvZZw= github.com/lib/pq v1.10.7/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/libp2p/go-buffer-pool v0.1.0 h1:oK4mSFcQz7cTQIfqbe4MIj9gLW+mnanjyFtc6cdF0Y8= @@ -848,6 +854,7 @@ github.com/pascaldekloe/goe v0.1.0 h1:cBOtyMzM9HTpWjXfbbunk26uA6nG3a8n06Wieeh0Mw github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= +github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNcZljzZR9VXg+4= github.com/pelletier/go-toml/v2 v2.0.9 h1:uH2qQXheeefCCkuBBSLi7jCiSmj3VRh2+Goq2N7Xxu0= github.com/pelletier/go-toml/v2 v2.0.9/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc= github.com/performancecopilot/speed v3.0.0+incompatible/go.mod h1:/CLtqpZ5gBg1M9iaPbIdPPGyKcA8hKdoy6hAWba7Yac= @@ -975,6 +982,8 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/subosito/gotenv v1.4.2 h1:X1TuBLAMDFbaTAChgCBLu3DU3UPyELpnF2jjJ2cz/S8= @@ -987,12 +996,11 @@ github.com/tidwall/btree v1.7.0 h1:L1fkJH/AuEh5zBnnBbmTwQ5Lt+bRJ5A8EWecslvo9iI= github.com/tidwall/btree v1.7.0/go.mod h1:twD9XRA5jj9VUQGELzDO4HPQTNJsoWWfYEL+EUQ2cKY= github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM= -github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo= -github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= +github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= +github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= -github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= -github.com/ugorji/go/codec v1.2.7 h1:YPXUKf7fYbp/y8xloBqZOw2qaVggbfwMlI8WM3wZUJ0= -github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY= +github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU= +github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= github.com/ulikunitz/xz v0.5.10/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14= github.com/ulikunitz/xz v0.5.11 h1:kpFauv27b6ynzBNT/Xy+1k+fK4WswhN/6PN5WhFAGw8= github.com/ulikunitz/xz v0.5.11/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14= @@ -1038,6 +1046,9 @@ go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9E go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM= go.uber.org/zap v1.18.1/go.mod h1:xg/QME4nWcxGxrpdeYfq7UvYrLh66cuVKdrbD1XF/NI= +golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= +golang.org/x/arch v0.3.0 h1:02VY4/ZcO/gBOH6PUaoiptASxtXU10jazRCP865E97k= +golang.org/x/arch v0.3.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= @@ -1052,6 +1063,8 @@ golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20220314234659-1baeb1ce4c0b/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= +golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0= golang.org/x/crypto v0.13.0 h1:mvySKfSWJ+UKUii46M40LOvyWfN0s2U+46/jDd0e6Ck= golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -1093,6 +1106,7 @@ golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc= golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -1156,6 +1170,9 @@ golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug golang.org/x/net v0.0.0-20220909164309-bea034e7d591/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= golang.org/x/net v0.0.0-20221014081412-f15817d10f9b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco= +golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= +golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= golang.org/x/net v0.15.0 h1:ugBLEUaxABaB5AJqW9enI0ACdci2RUd4eP51NTBvuJ8= golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -1199,6 +1216,7 @@ golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220929204114-8fcdb60fdcc0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -1292,18 +1310,24 @@ golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220610221304-9f5ed59c137d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220615213510-4f61da869c0c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220624220833-87e55d714810/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20221010170243-090e33056c14/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= +golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= +golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= golang.org/x/term v0.12.0 h1:/ZfYdc3zq+q02Rv9vGqTeSItdzZTSNDmfTi0mBAuidU= golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -1317,6 +1341,9 @@ golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -1387,6 +1414,7 @@ golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/tools v0.12.1-0.20230815132531-74c255bcf846 h1:Vve/L0v7CXXuxUmaMGIEK/dEeq7uiqb5qBgQrZzIE7E= golang.org/x/tools v0.12.1-0.20230815132531-74c255bcf846/go.mod h1:Sc0INKfu04TlqNoRA1hgpFZbhYXHPr4V5DzpSBTPqQM= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -1631,6 +1659,7 @@ google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= @@ -1680,6 +1709,7 @@ nhooyr.io/websocket v1.8.6/go.mod h1:B70DZP8IakI65RVQ51MsWP/8jndNma26DVA/nFSCgW0 pgregory.net/rapid v1.1.0 h1:CMa0sjHSru3puNx+J0MIAuiiEV4N0qj8/cMWGBBCsjw= pgregory.net/rapid v1.1.0/go.mod h1:PY5XlDGj0+V1FCq0o192FdRhpKHGTRIWBgqjDBTrq04= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= +rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o= diff --git a/x/upgrade/module.go b/x/upgrade/module.go index 524c78a1d368..7d73cfc2e80e 100644 --- a/x/upgrade/module.go +++ b/x/upgrade/module.go @@ -87,9 +87,9 @@ func NewAppModule(keeper *keeper.Keeper, ac address.Codec) AppModule { } var ( - _ appmodule.AppModule = AppModule{} - _ appmodule.HasBeginBlocker = AppModule{} - _ module.HasGenesis = AppModule{} + _ appmodule.AppModule = AppModule{} + _ appmodule.HasPreBlocker = AppModule{} + _ module.HasGenesis = AppModule{} ) // IsOnePerModuleType implements the depinject.OnePerModuleType interface. @@ -156,11 +156,11 @@ func (am AppModule) ExportGenesis(_ sdk.Context, cdc codec.JSONCodec) json.RawMe // ConsensusVersion implements AppModule/ConsensusVersion. func (AppModule) ConsensusVersion() uint64 { return ConsensusVersion } -// BeginBlock calls the upgrade module hooks +// PreBlock calls the upgrade module hooks // -// CONTRACT: this is registered in BeginBlocker *before* all other modules' BeginBlock functions -func (am AppModule) BeginBlock(ctx context.Context) error { - return BeginBlocker(ctx, am.keeper) +// CONTRACT: this is called *before* all other modules' BeginBlock functions +func (am AppModule) PreBlock(ctx context.Context) (appmodule.ResponsePreBlock, error) { + return PreBlocker(ctx, am.keeper) } // From 713bce4fef32120160aadc6d518a794d2c63ef00 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Tue, 22 Aug 2023 09:02:59 +0800 Subject: [PATCH 02/10] reimplement PreFinalizeBlockHook as PreBlocker --- baseapp/abci.go | 8 +------- baseapp/abci_test.go | 18 +++++++++++------- baseapp/baseapp.go | 25 ++++++++++++------------- baseapp/options.go | 8 -------- runtime/app.go | 2 +- simapp/app.go | 2 +- types/abci.go | 10 +--------- 7 files changed, 27 insertions(+), 46 deletions(-) diff --git a/baseapp/abci.go b/baseapp/abci.go index dd1ceb5a1f41..3e4801a8a0b0 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -730,13 +730,7 @@ func (app *BaseApp) FinalizeBlock(req *abci.RequestFinalizeBlock) (*abci.Respons WithHeaderHash(req.Hash) } - if app.preFinalizeBlockHook != nil { - if err := app.preFinalizeBlockHook(app.finalizeBlockState.ctx, req); err != nil { - return nil, err - } - } - - if err := app.preBlock(); err != nil { + if err := app.preBlock(req); err != nil { return nil, err } diff --git a/baseapp/abci_test.go b/baseapp/abci_test.go index a86e2ec3880c..8ffdf10ed77a 100644 --- a/baseapp/abci_test.go +++ b/baseapp/abci_test.go @@ -2035,7 +2035,7 @@ func TestABCI_HaltChain(t *testing.T) { } } -func TestBaseApp_PreFinalizeBlockHook(t *testing.T) { +func TestBaseApp_PreBlocker(t *testing.T) { db := dbm.NewMemDB() name := t.Name() logger := log.NewTestLogger(t) @@ -2045,9 +2045,11 @@ func TestBaseApp_PreFinalizeBlockHook(t *testing.T) { require.NoError(t, err) wasHookCalled := false - app.SetPreFinalizeBlockHook(func(ctx sdk.Context, req *abci.RequestFinalizeBlock) error { + app.SetPreBlocker(func(ctx sdk.Context, req *abci.RequestFinalizeBlock) (sdk.ResponsePreBlock, error) { wasHookCalled = true - return nil + return sdk.ResponsePreBlock{ + ConsensusParamsChanged: true, + }, nil }) app.Seal() @@ -2060,8 +2062,8 @@ func TestBaseApp_PreFinalizeBlockHook(t *testing.T) { _, err = app.InitChain(&abci.RequestInitChain{}) require.NoError(t, err) - app.SetPreFinalizeBlockHook(func(ctx sdk.Context, req *abci.RequestFinalizeBlock) error { - return errors.New("some error") + app.SetPreBlocker(func(ctx sdk.Context, req *abci.RequestFinalizeBlock) (sdk.ResponsePreBlock, error) { + return sdk.ResponsePreBlock{}, errors.New("some error") }) app.Seal() @@ -2122,7 +2124,7 @@ func TestBaseApp_VoteExtensions(t *testing.T) { return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_ACCEPT}, nil }) - app.SetPreFinalizeBlockHook(func(ctx sdk.Context, req *abci.RequestFinalizeBlock) error { + app.SetPreBlocker(func(ctx sdk.Context, req *abci.RequestFinalizeBlock) (sdk.ResponsePreBlock, error) { count := uint64(0) pricesSum := uint64(0) for _, v := range req.Txs { @@ -2141,7 +2143,9 @@ func TestBaseApp_VoteExtensions(t *testing.T) { ctx.KVStore(capKey1).Set([]byte("avgPrice"), buf) } - return nil + return sdk.ResponsePreBlock{ + ConsensusParamsChanged: true, + }, nil }) } diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index f59ee0d582b4..9b11f21a770b 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -74,17 +74,16 @@ type BaseApp struct { anteHandler sdk.AnteHandler // ante handler for fee and auth postHandler sdk.PostHandler // post handler, optional, e.g. for tips - initChainer sdk.InitChainer // ABCI InitChain handler - preBlocker sdk.PreBlocker // logic to run before BeginBlocker - beginBlocker sdk.BeginBlocker // (legacy ABCI) BeginBlock handler - endBlocker sdk.EndBlocker // (legacy ABCI) EndBlock handler - processProposal sdk.ProcessProposalHandler // ABCI ProcessProposal handler - prepareProposal sdk.PrepareProposalHandler // ABCI PrepareProposal - extendVote sdk.ExtendVoteHandler // ABCI ExtendVote handler - verifyVoteExt sdk.VerifyVoteExtensionHandler // ABCI VerifyVoteExtension handler - prepareCheckStater sdk.PrepareCheckStater // logic to run during commit using the checkState - precommiter sdk.Precommiter // logic to run during commit using the deliverState - preFinalizeBlockHook sdk.PreFinalizeBlockHook // logic to run before FinalizeBlock + initChainer sdk.InitChainer // ABCI InitChain handler + preBlocker sdk.PreBlocker // logic to run before BeginBlocker + beginBlocker sdk.BeginBlocker // (legacy ABCI) BeginBlock handler + endBlocker sdk.EndBlocker // (legacy ABCI) EndBlock handler + processProposal sdk.ProcessProposalHandler // ABCI ProcessProposal handler + prepareProposal sdk.PrepareProposalHandler // ABCI PrepareProposal + extendVote sdk.ExtendVoteHandler // ABCI ExtendVote handler + verifyVoteExt sdk.VerifyVoteExtensionHandler // ABCI VerifyVoteExtension handler + prepareCheckStater sdk.PrepareCheckStater // logic to run during commit using the checkState + precommiter sdk.Precommiter // logic to run during commit using the deliverState addrPeerFilter sdk.PeerFilter // filter peers by address and port idPeerFilter sdk.PeerFilter // filter peers by node ID @@ -669,10 +668,10 @@ func (app *BaseApp) cacheTxContext(ctx sdk.Context, txBytes []byte) (sdk.Context return ctx.WithMultiStore(msCache), msCache } -func (app *BaseApp) preBlock() error { +func (app *BaseApp) preBlock(req *abci.RequestFinalizeBlock) error { if app.preBlocker != nil { ctx := app.finalizeBlockState.ctx - rsp, err := app.preBlocker(ctx) + rsp, err := app.preBlocker(ctx, req) if err != nil { return err } diff --git a/baseapp/options.go b/baseapp/options.go index 29e517899316..1046ad3a42f3 100644 --- a/baseapp/options.go +++ b/baseapp/options.go @@ -216,14 +216,6 @@ func (app *BaseApp) SetPrecommiter(precommiter sdk.Precommiter) { app.precommiter = precommiter } -func (app *BaseApp) SetPreFinalizeBlockHook(hook sdk.PreFinalizeBlockHook) { - if app.sealed { - panic("SetPreFinalizeBlockHook() on sealed BaseApp") - } - - app.preFinalizeBlockHook = hook -} - func (app *BaseApp) SetAnteHandler(ah sdk.AnteHandler) { if app.sealed { panic("SetAnteHandler() on sealed BaseApp") diff --git a/runtime/app.go b/runtime/app.go index ed6de6adb9da..ab4630e4828c 100644 --- a/runtime/app.go +++ b/runtime/app.go @@ -153,7 +153,7 @@ func (a *App) Load(loadLatest bool) error { } // PreBlocker application updates every pre block -func (a *App) PreBlocker(ctx sdk.Context) (sdk.ResponsePreBlock, error) { +func (a *App) PreBlocker(ctx sdk.Context, _ *abci.RequestFinalizeBlock) (sdk.ResponsePreBlock, error) { return a.ModuleManager.PreBlock(ctx) } diff --git a/simapp/app.go b/simapp/app.go index 1d7ed0776fb8..859a722fcadb 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -583,7 +583,7 @@ func (app *SimApp) setPostHandler() { func (app *SimApp) Name() string { return app.BaseApp.Name() } // PreBlocker application updates every pre block -func (app *SimApp) PreBlocker(ctx sdk.Context) (sdk.ResponsePreBlock, error) { +func (app *SimApp) PreBlocker(ctx sdk.Context, _ *abci.RequestFinalizeBlock) (sdk.ResponsePreBlock, error) { return app.ModuleManager.PreBlock(ctx) } diff --git a/types/abci.go b/types/abci.go index ff40d1109a27..3417b64f4255 100644 --- a/types/abci.go +++ b/types/abci.go @@ -31,7 +31,7 @@ type ExtendVoteHandler func(Context, *abci.RequestExtendVote) (*abci.ResponseExt type VerifyVoteExtensionHandler func(Context, *abci.RequestVerifyVoteExtension) (*abci.ResponseVerifyVoteExtension, error) // PreBlocker runs code before the `BeginBlocker`. -type PreBlocker func(Context) (ResponsePreBlock, error) +type PreBlocker func(Context, *abci.RequestFinalizeBlock) (ResponsePreBlock, error) // BeginBlocker defines a function type alias for executing application // business logic before transactions are executed. @@ -51,14 +51,6 @@ type BeginBlocker func(Context) (BeginBlock, error) // and allows for existing EndBlock functionality within applications. type EndBlocker func(Context) (EndBlock, error) -// PreFinalizeBlockHook defines a function type alias for executing logic right -// before FinalizeBlock is called (but after its context has been set up). It is -// intended to allow applications to perform computation on vote extensions and -// persist their results in state. -// -// Note: returning an error will make FinalizeBlock fail. -type PreFinalizeBlockHook func(Context, *abci.RequestFinalizeBlock) error - // EndBlock defines a type which contains endblock events and validator set updates type EndBlock struct { ValidatorUpdates []abci.ValidatorUpdate From 744311846bc0d2618efd5a2731c1704da80af73a Mon Sep 17 00:00:00 2001 From: mmsqe Date: Sat, 26 Aug 2023 21:16:32 +0800 Subject: [PATCH 03/10] update doc --- CHANGELOG.md | 2 +- docs/architecture/adr-064-abci-2.0.md | 18 +++++++++++------- docs/architecture/adr-068-preblock.md | 1 + .../build/building-apps/04-vote-extensions.md | 2 +- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 05945b0f3004..c2f1052e6d9e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -57,7 +57,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Bug Fixes -* (types) [#16583](https://github.com/cosmos/cosmos-sdk/pull/16583), [#17372](https://github.com/cosmos/cosmos-sdk/pull/17372), [#17421](https://github.com/cosmos/cosmos-sdk/pull/17421) Introduce `PreBlock`, which runs before begin blocker other modules, and allows to modify consensus parameters, and the changes are visible to the following state machine logics. +* (types) [#16583](https://github.com/cosmos/cosmos-sdk/pull/16583), [#17372](https://github.com/cosmos/cosmos-sdk/pull/17372), [#17421](https://github.com/cosmos/cosmos-sdk/pull/17421), [#17713](https://github.com/cosmos/cosmos-sdk/pull/17713) Introduce `PreBlock`, which runs before begin blocker other modules, and allows to modify consensus parameters, and the changes are visible to the following state machine logics and reimplement `PreFinalizeBlockHook` as `PreBlocker`. * (baseapp) [#17518](https://github.com/cosmos/cosmos-sdk/pull/17518) Utilizing voting power from vote extensions (CometBFT) instead of the current bonded tokens (x/staking) to determine if a set of vote extensions are valid. * (config) [#17649](https://github.com/cosmos/cosmos-sdk/pull/17649) Fix `mempool.max-txs` configuration is invalid in `app.config`. * (mempool) [#17668](https://github.com/cosmos/cosmos-sdk/pull/17668) Fix: `PriorityNonceIterator.Next()` nil pointer ref for min priority at the end of iteration. diff --git a/docs/architecture/adr-064-abci-2.0.md b/docs/architecture/adr-064-abci-2.0.md index cdbd88024d88..c0dc7f746e81 100644 --- a/docs/architecture/adr-064-abci-2.0.md +++ b/docs/architecture/adr-064-abci-2.0.md @@ -293,7 +293,7 @@ decision based on the vote extensions. In certain contexts, it may be useful or necessary for applications to persist data derived from vote extensions. In order to facilitate this use case, we propose -to allow app developers to define a pre-FinalizeBlock hook which will be called +to allow app developers to define a pre-Blocker hook which will be called at the very beginning of `FinalizeBlock`, i.e. before `BeginBlock` (see below). Note, we cannot allow applications to directly write to the application state @@ -301,7 +301,7 @@ during `ProcessProposal` because during replay, CometBFT will NOT call `ProcessP which would result in an incomplete state view. ```go -func (a MyApp) PreFinalizeBlockHook(ctx sdk.Context, req.RequestFinalizeBlock) error { +func (a MyApp) PreBlocker(ctx sdk.Context, req *abci.RequestFinalizeBlock) error { voteExts := GetVoteExtensions(ctx, req.Txs) // Process and perform some compute on vote extensions, storing any resulting @@ -353,13 +353,17 @@ we can come up with new types and names altogether. func (app *BaseApp) FinalizeBlock(req abci.RequestFinalizeBlock) (*abci.ResponseFinalizeBlock, error) { ctx := ... - if app.preFinalizeBlockHook != nil { - if err := app.preFinalizeBlockHook(ctx, req); err != nil { + if app.preBlocker != nil { + ctx := app.finalizeBlockState.ctx + rsp, err := app.preBlocker(ctx, req) + if err != nil { return nil, err } + if rsp.ConsensusParamsChanged { + app.finalizeBlockState.ctx = ctx.WithConsensusParams(app.GetConsensusParams(ctx)) + } } - - beginBlockResp := app.beginBlock(ctx, req) + beginBlockResp, err := app.beginBlock(req) appendBlockEventAttr(beginBlockResp.Events, "begin_block") txExecResults := make([]abci.ExecTxResult, 0, len(req.Txs)) @@ -368,7 +372,7 @@ func (app *BaseApp) FinalizeBlock(req abci.RequestFinalizeBlock) (*abci.Response txExecResults = append(txExecResults, result) } - endBlockResp := app.endBlock(ctx, req) + endBlockResp, err := app.endBlock(app.finalizeBlockState.ctx) appendBlockEventAttr(beginBlockResp.Events, "end_block") return abci.ResponseFinalizeBlock{ diff --git a/docs/architecture/adr-068-preblock.md b/docs/architecture/adr-068-preblock.md index dc0cd2a24564..86692c412c4d 100644 --- a/docs/architecture/adr-068-preblock.md +++ b/docs/architecture/adr-068-preblock.md @@ -58,3 +58,4 @@ The new ctx must be passed to all the other lifecycle methods. * [1] https://github.com/cosmos/cosmos-sdk/issues/16494 * [2] https://github.com/cosmos/cosmos-sdk/pull/16583 * [3] https://github.com/cosmos/cosmos-sdk/pull/17421 +* [4] https://github.com/cosmos/cosmos-sdk/pull/17713 diff --git a/docs/docs/build/building-apps/04-vote-extensions.md b/docs/docs/build/building-apps/04-vote-extensions.md index 8b9fb5943f20..f78f4c677ffe 100644 --- a/docs/docs/build/building-apps/04-vote-extensions.md +++ b/docs/docs/build/building-apps/04-vote-extensions.md @@ -77,7 +77,7 @@ will be available to the application during the subsequent `FinalizeBlock` call. An example of how a pre-FinalizeBlock hook could look like is shown below: ```go -app.SetPreFinalizeBlockHook(func(ctx sdk.Context, req *abci.RequestFinalizeBlock) error { +app.SetPreBlocker(func(ctx sdk.Context, req *abci.RequestFinalizeBlock) error { allVEs := []VE{} // store all parsed vote extensions here for _, tx := range req.Txs { // define a custom function that tries to parse the tx as a vote extension From 2f4e1094d460e1ce7882302fb9189a8743c87fc0 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Wed, 13 Sep 2023 15:15:57 +0200 Subject: [PATCH 04/10] feat(client/v2): stringify bytes `cosmos.Dec` (#16985) --- client/v2/autocli/flag/builder.go | 5 +++- client/v2/autocli/query.go | 47 +++++++++++++++++++++++++------ client/v2/go.mod | 2 +- client/v2/go.sum | 4 +-- simapp/go.mod | 2 +- simapp/go.sum | 4 +-- simapp/gomod2nix.toml | 4 +-- tests/go.mod | 2 +- tests/go.sum | 4 +-- tests/starship/tests/go.mod | 2 +- tests/starship/tests/go.sum | 4 +-- 11 files changed, 56 insertions(+), 24 deletions(-) diff --git a/client/v2/autocli/flag/builder.go b/client/v2/autocli/flag/builder.go index c595f5590802..bb2b7a0b530e 100644 --- a/client/v2/autocli/flag/builder.go +++ b/client/v2/autocli/flag/builder.go @@ -30,7 +30,10 @@ type Builder struct { // FileResolver specifies how protobuf file descriptors will be resolved. If it is // nil protoregistry.GlobalFiles will be used. - FileResolver protodesc.Resolver + FileResolver interface { + protodesc.Resolver + RangeFiles(func(protoreflect.FileDescriptor) bool) + } messageFlagTypes map[protoreflect.FullName]Type scalarFlagTypes map[string]Type diff --git a/client/v2/autocli/query.go b/client/v2/autocli/query.go index acad36e9ff40..da88d5b0d25a 100644 --- a/client/v2/autocli/query.go +++ b/client/v2/autocli/query.go @@ -2,11 +2,13 @@ package autocli import ( "fmt" + "io" + "time" autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" + "cosmossdk.io/x/tx/signing/aminojson" "github.com/cockroachdb/errors" "github.com/spf13/cobra" - "google.golang.org/protobuf/encoding/protojson" "google.golang.org/protobuf/reflect/protoreflect" "cosmossdk.io/client/v2/internal/util" @@ -101,17 +103,16 @@ func (b *Builder) BuildQueryMethodCommand(descriptor protoreflect.MethodDescript serviceDescriptor := descriptor.Parent().(protoreflect.ServiceDescriptor) methodName := fmt.Sprintf("/%s/%s", serviceDescriptor.FullName(), descriptor.Name()) outputType := util.ResolveMessageType(b.TypeResolver, descriptor.Output()) - jsonMarshalOptions := protojson.MarshalOptions{ + encoderOptions := aminojson.EncoderOptions{ Indent: " ", - UseProtoNames: true, - UseEnumNumbers: false, - EmitUnpopulated: true, - Resolver: b.TypeResolver, + DoNotSortFields: true, + TypeResolver: b.TypeResolver, + FileResolver: b.FileResolver, } cmd, err := b.buildMethodCommandCommon(descriptor, options, func(cmd *cobra.Command, input protoreflect.Message) error { - if noIdent, _ := cmd.Flags().GetBool(flagNoIndent); noIdent { - jsonMarshalOptions.Indent = "" + if noIndent, _ := cmd.Flags().GetBool(flagNoIndent); noIndent { + encoderOptions.Indent = "" } clientConn, err := getClientConn(cmd) @@ -124,7 +125,8 @@ func (b *Builder) BuildQueryMethodCommand(descriptor protoreflect.MethodDescript return err } - bz, err := jsonMarshalOptions.Marshal(output.Interface()) + enc := encoder(aminojson.NewEncoder(encoderOptions)) + bz, err := enc.Marshal(output.Interface()) if err != nil { return fmt.Errorf("cannot marshal response %v: %w", output.Interface(), err) } @@ -143,3 +145,30 @@ func (b *Builder) BuildQueryMethodCommand(descriptor protoreflect.MethodDescript return cmd, nil } + +func encoder(encoder aminojson.Encoder) aminojson.Encoder { + return encoder.DefineTypeEncoding("google.protobuf.Duration", func(_ *aminojson.Encoder, msg protoreflect.Message, w io.Writer) error { + var ( + secondsName protoreflect.Name = "seconds" + nanosName protoreflect.Name = "nanos" + ) + + fields := msg.Descriptor().Fields() + secondsField := fields.ByName(secondsName) + if secondsField == nil { + return fmt.Errorf("expected seconds field") + } + + seconds := msg.Get(secondsField).Int() + + nanosField := fields.ByName(nanosName) + if nanosField == nil { + return fmt.Errorf("expected nanos field") + } + + nanos := msg.Get(nanosField).Int() + + _, err := fmt.Fprintf(w, `"%s"`, (time.Duration(seconds)*time.Second + (time.Duration(nanos) * time.Nanosecond)).String()) + return err + }) +} diff --git a/client/v2/go.mod b/client/v2/go.mod index 12986377093a..0fd978cec0a5 100644 --- a/client/v2/go.mod +++ b/client/v2/go.mod @@ -7,6 +7,7 @@ require ( cosmossdk.io/core v0.11.0 cosmossdk.io/depinject v1.0.0-alpha.4 cosmossdk.io/log v1.2.1 + cosmossdk.io/x/tx v0.9.2-0.20230913111958-e394604f8382 github.com/cockroachdb/errors v1.11.1 github.com/cosmos/cosmos-proto v1.0.0-beta.3 github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230718211500-1d74652f6021 @@ -24,7 +25,6 @@ require ( cosmossdk.io/errors v1.0.0 // indirect cosmossdk.io/math v1.1.2 // indirect cosmossdk.io/store v1.0.0-rc.0 // indirect - cosmossdk.io/x/tx v0.9.1 // indirect filippo.io/edwards25519 v1.0.0 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect github.com/99designs/keyring v1.2.1 // indirect diff --git a/client/v2/go.sum b/client/v2/go.sum index 5f5e4a82ea3f..5e930c04cc0d 100644 --- a/client/v2/go.sum +++ b/client/v2/go.sum @@ -51,8 +51,8 @@ cosmossdk.io/math v1.1.2 h1:ORZetZCTyWkI5GlZ6CZS28fMHi83ZYf+A2vVnHNzZBM= cosmossdk.io/math v1.1.2/go.mod h1:l2Gnda87F0su8a/7FEKJfFdJrM0JZRXQaohlgJeyQh0= cosmossdk.io/store v1.0.0-rc.0 h1:9DwOjuUYxDtYxn/REkTxGQAmxlIGfRroB35MQ8TrxF4= cosmossdk.io/store v1.0.0-rc.0/go.mod h1:FtBDOJmwtOZfmKKF65bKZbTYgS3bDNjjo3nP76dAegk= -cosmossdk.io/x/tx v0.9.1 h1:9pmmXA9Vs4qdouOFnzhsdsff2mif0f0kylMq5xTGhRI= -cosmossdk.io/x/tx v0.9.1/go.mod h1:/YFGTXG6+kyihd8YbfuJiXHV4R/mIMm2uvVzo80CIhA= +cosmossdk.io/x/tx v0.9.2-0.20230913111958-e394604f8382 h1:p/wyc5pVTMtx2/RsKP0fUpOKGbDfy6q6WswJtmARdbg= +cosmossdk.io/x/tx v0.9.2-0.20230913111958-e394604f8382/go.mod h1:MKo9/b5wsoL8dd9y9pvD2yOP1CMvzHIWYxi1l2oLPFo= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= diff --git a/simapp/go.mod b/simapp/go.mod index acc69f981fec..386f0872c1ab 100644 --- a/simapp/go.mod +++ b/simapp/go.mod @@ -16,7 +16,7 @@ require ( cosmossdk.io/x/evidence v0.0.0-20230613133644-0a778132a60f cosmossdk.io/x/feegrant v0.0.0-20230613133644-0a778132a60f cosmossdk.io/x/nft v0.0.0-20230613133644-0a778132a60f - cosmossdk.io/x/tx v0.9.1 + cosmossdk.io/x/tx v0.9.2-0.20230913111958-e394604f8382 cosmossdk.io/x/upgrade v0.0.0-20230613133644-0a778132a60f github.com/cometbft/cometbft v0.38.0 github.com/cosmos/cosmos-db v1.0.0 diff --git a/simapp/go.sum b/simapp/go.sum index 4d85d7fa798f..1800eee822c8 100644 --- a/simapp/go.sum +++ b/simapp/go.sum @@ -203,8 +203,8 @@ cosmossdk.io/math v1.1.2 h1:ORZetZCTyWkI5GlZ6CZS28fMHi83ZYf+A2vVnHNzZBM= cosmossdk.io/math v1.1.2/go.mod h1:l2Gnda87F0su8a/7FEKJfFdJrM0JZRXQaohlgJeyQh0= cosmossdk.io/store v1.0.0-rc.0 h1:9DwOjuUYxDtYxn/REkTxGQAmxlIGfRroB35MQ8TrxF4= cosmossdk.io/store v1.0.0-rc.0/go.mod h1:FtBDOJmwtOZfmKKF65bKZbTYgS3bDNjjo3nP76dAegk= -cosmossdk.io/x/tx v0.9.1 h1:9pmmXA9Vs4qdouOFnzhsdsff2mif0f0kylMq5xTGhRI= -cosmossdk.io/x/tx v0.9.1/go.mod h1:/YFGTXG6+kyihd8YbfuJiXHV4R/mIMm2uvVzo80CIhA= +cosmossdk.io/x/tx v0.9.2-0.20230913111958-e394604f8382 h1:p/wyc5pVTMtx2/RsKP0fUpOKGbDfy6q6WswJtmARdbg= +cosmossdk.io/x/tx v0.9.2-0.20230913111958-e394604f8382/go.mod h1:MKo9/b5wsoL8dd9y9pvD2yOP1CMvzHIWYxi1l2oLPFo= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= diff --git a/simapp/gomod2nix.toml b/simapp/gomod2nix.toml index ca5798fc2be5..5942be698d1c 100644 --- a/simapp/gomod2nix.toml +++ b/simapp/gomod2nix.toml @@ -41,8 +41,8 @@ schema = 3 version = "v1.0.0-rc.0" hash = "sha256-DgW4ZrDwmgsPtEXajPyAsrQuPjXekw5PfsYFvA5yuiE=" [mod."cosmossdk.io/x/tx"] - version = "v0.9.1" - hash = "sha256-/fopDRDbfIUr8Ub0qqu3k0y6FsLKTAwf51PJaCL18Bk=" + version = "v0.9.2-0.20230913111958-e394604f8382" + hash = "sha256-am/+/mfQR+xqjQSTFh2X/AiC6EQZvZ7te6d8MIwd/EA=" [mod."filippo.io/edwards25519"] version = "v1.0.0" hash = "sha256-APnPAcmItvtJ5Zsy863lzR2TjEBF9Y66TY1e4M1ap98=" diff --git a/tests/go.mod b/tests/go.mod index f7d9c9203eeb..829677832aba 100644 --- a/tests/go.mod +++ b/tests/go.mod @@ -15,7 +15,7 @@ require ( cosmossdk.io/x/evidence v0.0.0-20230613133644-0a778132a60f cosmossdk.io/x/feegrant v0.0.0-20230613133644-0a778132a60f cosmossdk.io/x/nft v0.0.0-20230613133644-0a778132a60f // indirect - cosmossdk.io/x/tx v0.9.1 + cosmossdk.io/x/tx v0.9.2-0.20230913111958-e394604f8382 cosmossdk.io/x/upgrade v0.0.0-20230613133644-0a778132a60f github.com/cometbft/cometbft v0.38.0 github.com/cosmos/cosmos-db v1.0.0 diff --git a/tests/go.sum b/tests/go.sum index 01af9fa03d78..e0b700b510dd 100644 --- a/tests/go.sum +++ b/tests/go.sum @@ -203,8 +203,8 @@ cosmossdk.io/math v1.1.2 h1:ORZetZCTyWkI5GlZ6CZS28fMHi83ZYf+A2vVnHNzZBM= cosmossdk.io/math v1.1.2/go.mod h1:l2Gnda87F0su8a/7FEKJfFdJrM0JZRXQaohlgJeyQh0= cosmossdk.io/store v1.0.0-rc.0 h1:9DwOjuUYxDtYxn/REkTxGQAmxlIGfRroB35MQ8TrxF4= cosmossdk.io/store v1.0.0-rc.0/go.mod h1:FtBDOJmwtOZfmKKF65bKZbTYgS3bDNjjo3nP76dAegk= -cosmossdk.io/x/tx v0.9.1 h1:9pmmXA9Vs4qdouOFnzhsdsff2mif0f0kylMq5xTGhRI= -cosmossdk.io/x/tx v0.9.1/go.mod h1:/YFGTXG6+kyihd8YbfuJiXHV4R/mIMm2uvVzo80CIhA= +cosmossdk.io/x/tx v0.9.2-0.20230913111958-e394604f8382 h1:p/wyc5pVTMtx2/RsKP0fUpOKGbDfy6q6WswJtmARdbg= +cosmossdk.io/x/tx v0.9.2-0.20230913111958-e394604f8382/go.mod h1:MKo9/b5wsoL8dd9y9pvD2yOP1CMvzHIWYxi1l2oLPFo= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= diff --git a/tests/starship/tests/go.mod b/tests/starship/tests/go.mod index b2ef9ae282db..76a5fe5eb18e 100644 --- a/tests/starship/tests/go.mod +++ b/tests/starship/tests/go.mod @@ -49,7 +49,7 @@ require ( cosmossdk.io/x/evidence v0.0.0-20230613133644-0a778132a60f // indirect cosmossdk.io/x/feegrant v0.0.0-20230613133644-0a778132a60f // indirect cosmossdk.io/x/nft v0.0.0-20230613133644-0a778132a60f // indirect - cosmossdk.io/x/tx v0.9.1 // indirect + cosmossdk.io/x/tx v0.9.2-0.20230913111958-e394604f8382 // indirect cosmossdk.io/x/upgrade v0.0.0-20230613133644-0a778132a60f // indirect filippo.io/edwards25519 v1.0.0 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect diff --git a/tests/starship/tests/go.sum b/tests/starship/tests/go.sum index cbd25ba22cc1..f60e57ef40b8 100644 --- a/tests/starship/tests/go.sum +++ b/tests/starship/tests/go.sum @@ -203,8 +203,8 @@ cosmossdk.io/math v1.1.2 h1:ORZetZCTyWkI5GlZ6CZS28fMHi83ZYf+A2vVnHNzZBM= cosmossdk.io/math v1.1.2/go.mod h1:l2Gnda87F0su8a/7FEKJfFdJrM0JZRXQaohlgJeyQh0= cosmossdk.io/store v1.0.0-rc.0 h1:9DwOjuUYxDtYxn/REkTxGQAmxlIGfRroB35MQ8TrxF4= cosmossdk.io/store v1.0.0-rc.0/go.mod h1:FtBDOJmwtOZfmKKF65bKZbTYgS3bDNjjo3nP76dAegk= -cosmossdk.io/x/tx v0.9.1 h1:9pmmXA9Vs4qdouOFnzhsdsff2mif0f0kylMq5xTGhRI= -cosmossdk.io/x/tx v0.9.1/go.mod h1:/YFGTXG6+kyihd8YbfuJiXHV4R/mIMm2uvVzo80CIhA= +cosmossdk.io/x/tx v0.9.2-0.20230913111958-e394604f8382 h1:p/wyc5pVTMtx2/RsKP0fUpOKGbDfy6q6WswJtmARdbg= +cosmossdk.io/x/tx v0.9.2-0.20230913111958-e394604f8382/go.mod h1:MKo9/b5wsoL8dd9y9pvD2yOP1CMvzHIWYxi1l2oLPFo= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= From 43a9d5f7942ea235cc248bb3e0fd70ad95725ab4 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Wed, 13 Sep 2023 21:42:04 +0800 Subject: [PATCH 05/10] Apply suggestions from code review --- types/abci.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/types/abci.go b/types/abci.go index 3417b64f4255..6c5a9a4f43e9 100644 --- a/types/abci.go +++ b/types/abci.go @@ -30,7 +30,12 @@ type ExtendVoteHandler func(Context, *abci.RequestExtendVote) (*abci.ResponseExt // pre-commit vote extension. type VerifyVoteExtensionHandler func(Context, *abci.RequestVerifyVoteExtension) (*abci.ResponseVerifyVoteExtension, error) -// PreBlocker runs code before the `BeginBlocker`. +// PreBlocker runs code before the `BeginBlocker` and defines a function type alias for executing logic right +// before FinalizeBlock is called (but after its context has been set up). It is +// intended to allow applications to perform computation on vote extensions and +// persist their results in state. +// +// Note: returning an error will make FinalizeBlock fail. type PreBlocker func(Context, *abci.RequestFinalizeBlock) (ResponsePreBlock, error) // BeginBlocker defines a function type alias for executing application From 93aa126659c2d0113cf7f754d2e2ff230b40ba2f Mon Sep 17 00:00:00 2001 From: Marko Date: Wed, 13 Sep 2023 16:51:34 +0200 Subject: [PATCH 06/10] chore: Remove legacy code (#17720) --- x/distribution/types/proposal.go | 62 ------------------ x/upgrade/types/proposal.go | 74 ---------------------- x/upgrade/types/proposal_test.go | 105 ------------------------------- 3 files changed, 241 deletions(-) delete mode 100644 x/distribution/types/proposal.go delete mode 100644 x/upgrade/types/proposal.go delete mode 100644 x/upgrade/types/proposal_test.go diff --git a/x/distribution/types/proposal.go b/x/distribution/types/proposal.go deleted file mode 100644 index b522020feb40..000000000000 --- a/x/distribution/types/proposal.go +++ /dev/null @@ -1,62 +0,0 @@ -package types - -import ( - "strings" - - errorsmod "cosmossdk.io/errors" -) - -// GetTitle returns the title of a community pool spend proposal. -func (csp *CommunityPoolSpendProposal) GetTitle() string { return csp.Title } - -// GetDescription returns the description of a community pool spend proposal. -func (csp *CommunityPoolSpendProposal) GetDescription() string { return csp.Description } - -// GetDescription returns the routing key of a community pool spend proposal. -func (csp *CommunityPoolSpendProposal) ProposalRoute() string { return RouterKey } - -// ProposalType returns the type of a community pool spend proposal. -func (csp *CommunityPoolSpendProposal) ProposalType() string { return "CommunityPoolSpend" } - -// ValidateBasic runs basic stateless validity checks -func (csp *CommunityPoolSpendProposal) ValidateBasic() error { - err := validateAbstract(csp) - if err != nil { - return err - } - if !csp.Amount.IsValid() { - return ErrInvalidProposalAmount - } - if csp.Recipient == "" { - return ErrEmptyProposalRecipient - } - - return nil -} - -// validateAbstract is semantically duplicated from x/gov/types/v1beta1/proposal.go to avoid a cyclic dependency -// between these two modules (x/distribution and x/gov). -// See: https://github.com/cosmos/cosmos-sdk/blob/4a6a1e3cb8de459891cb0495052589673d14ef51/x/gov/types/v1beta1/proposal.go#L196-L214 -func validateAbstract(c *CommunityPoolSpendProposal) error { - const ( - MaxTitleLength = 140 - MaxDescriptionLength = 10000 - ) - title := c.GetTitle() - if len(strings.TrimSpace(title)) == 0 { - return errorsmod.Wrap(ErrInvalidProposalContent, "proposal title cannot be blank") - } - if len(title) > MaxTitleLength { - return errorsmod.Wrapf(ErrInvalidProposalContent, "proposal title is longer than max length of %d", MaxTitleLength) - } - - description := c.GetDescription() - if len(description) == 0 { - return errorsmod.Wrap(ErrInvalidProposalContent, "proposal description cannot be blank") - } - if len(description) > MaxDescriptionLength { - return errorsmod.Wrapf(ErrInvalidProposalContent, "proposal description is longer than max length of %d", MaxDescriptionLength) - } - - return nil -} diff --git a/x/upgrade/types/proposal.go b/x/upgrade/types/proposal.go deleted file mode 100644 index ebac9a18eb29..000000000000 --- a/x/upgrade/types/proposal.go +++ /dev/null @@ -1,74 +0,0 @@ -package types - -import ( - gov "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" -) - -const ( - ProposalTypeSoftwareUpgrade string = "SoftwareUpgrade" - ProposalTypeCancelSoftwareUpgrade string = "CancelSoftwareUpgrade" -) - -// NewSoftwareUpgradeProposal creates a new SoftwareUpgradeProposal instance. -// Deprecated: this proposal is considered legacy and is deprecated in favor of -// Msg-based gov proposals. See MsgSoftwareUpgrade. -func NewSoftwareUpgradeProposal(title, description string, plan Plan) gov.Content { - return &SoftwareUpgradeProposal{title, description, plan} -} - -// Implements Proposal Interface -var _ gov.Content = &SoftwareUpgradeProposal{} - -func init() { - gov.RegisterProposalType(ProposalTypeSoftwareUpgrade) - gov.RegisterProposalType(ProposalTypeCancelSoftwareUpgrade) -} - -// GetTitle gets the proposal's title -func (sup *SoftwareUpgradeProposal) GetTitle() string { return sup.Title } - -// GetDescription gets the proposal's description -func (sup *SoftwareUpgradeProposal) GetDescription() string { return sup.Description } - -// ProposalRoute gets the proposal's router key -func (sup *SoftwareUpgradeProposal) ProposalRoute() string { return RouterKey } - -// ProposalType is "SoftwareUpgrade" -func (sup *SoftwareUpgradeProposal) ProposalType() string { return ProposalTypeSoftwareUpgrade } - -// ValidateBasic validates the proposal -func (sup *SoftwareUpgradeProposal) ValidateBasic() error { - if err := sup.Plan.ValidateBasic(); err != nil { - return err - } - return gov.ValidateAbstract(sup) -} - -// NewCancelSoftwareUpgradeProposal creates a new CancelSoftwareUpgradeProposal -// instance. Deprecated: this proposal is considered legacy and is deprecated in -// favor of Msg-based gov proposals. See MsgCancelUpgrade. -func NewCancelSoftwareUpgradeProposal(title, description string) gov.Content { - return &CancelSoftwareUpgradeProposal{title, description} -} - -// Implements Proposal Interface -var _ gov.Content = &CancelSoftwareUpgradeProposal{} - -// GetTitle gets the proposal's title -func (csup *CancelSoftwareUpgradeProposal) GetTitle() string { return csup.Title } - -// GetDescription gets the proposal's description -func (csup *CancelSoftwareUpgradeProposal) GetDescription() string { return csup.Description } - -// ProposalRoute gets the proposal's router key -func (csup *CancelSoftwareUpgradeProposal) ProposalRoute() string { return RouterKey } - -// ProposalType is "CancelSoftwareUpgrade" -func (csup *CancelSoftwareUpgradeProposal) ProposalType() string { - return ProposalTypeCancelSoftwareUpgrade -} - -// ValidateBasic validates the proposal -func (csup *CancelSoftwareUpgradeProposal) ValidateBasic() error { - return gov.ValidateAbstract(csup) -} diff --git a/x/upgrade/types/proposal_test.go b/x/upgrade/types/proposal_test.go deleted file mode 100644 index 0f54bbdeefa9..000000000000 --- a/x/upgrade/types/proposal_test.go +++ /dev/null @@ -1,105 +0,0 @@ -package types_test - -import ( - "testing" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - - "cosmossdk.io/x/upgrade/types" - - "github.com/cosmos/cosmos-sdk/codec" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" - gov "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" -) - -type ProposalWrapper struct { - Prop gov.Content -} - -func TestContentAccessors(t *testing.T) { - cases := map[string]struct { - p gov.Content - title string - desc string - typ string - str string - }{ - "upgrade": { - p: types.NewSoftwareUpgradeProposal("Title", "desc", types.Plan{ - Name: "due_height", - Info: "https://foo.bar", - Height: 99999999999, - }), - title: "Title", - desc: "desc", - typ: "SoftwareUpgrade", - str: "title:\"Title\" description:\"desc\" plan: height:99999999999 info:\"https://foo.bar\" > ", - }, - "cancel": { - p: types.NewCancelSoftwareUpgradeProposal("Cancel", "bad idea"), - title: "Cancel", - desc: "bad idea", - typ: "CancelSoftwareUpgrade", - str: "title:\"Cancel\" description:\"bad idea\" ", - }, - } - - cdc := codec.NewLegacyAmino() - gov.RegisterLegacyAminoCodec(cdc) - types.RegisterLegacyAminoCodec(cdc) - - for name, tc := range cases { - tc := tc // copy to local variable for scopelint - t.Run(name, func(t *testing.T) { - assert.Equal(t, tc.title, tc.p.GetTitle()) - assert.Equal(t, tc.desc, tc.p.GetDescription()) - assert.Equal(t, tc.typ, tc.p.ProposalType()) - assert.Equal(t, "upgrade", tc.p.ProposalRoute()) - assert.Equal(t, tc.str, tc.p.String()) - - // try to encode and decode type to ensure codec works - wrap := ProposalWrapper{tc.p} - bz, err := cdc.Marshal(&wrap) - require.NoError(t, err) - unwrap := ProposalWrapper{} - err = cdc.Unmarshal(bz, &unwrap) - require.NoError(t, err) - - // all methods should look the same - assert.Equal(t, tc.title, unwrap.Prop.GetTitle()) - assert.Equal(t, tc.desc, unwrap.Prop.GetDescription()) - assert.Equal(t, tc.typ, unwrap.Prop.ProposalType()) - assert.Equal(t, "upgrade", unwrap.Prop.ProposalRoute()) - assert.Equal(t, tc.str, unwrap.Prop.String()) - }) - - } -} - -// tests a software update proposal can be marshaled and unmarshaled -func TestMarshalSoftwareUpdateProposal(t *testing.T) { - // create proposal - plan := types.Plan{ - Name: "upgrade", - Height: 1000, - } - content := types.NewSoftwareUpgradeProposal("title", "description", plan) - sup, ok := content.(*types.SoftwareUpgradeProposal) - require.True(t, ok) - - // create codec - ir := codectypes.NewInterfaceRegistry() - types.RegisterInterfaces(ir) - gov.RegisterInterfaces(ir) - cdc := codec.NewProtoCodec(ir) - - // marshal message - bz, err := cdc.MarshalJSON(sup) - require.NoError(t, err) - - // unmarshal proposal - newSup := &types.SoftwareUpgradeProposal{} - err = cdc.UnmarshalJSON(bz, newSup) - require.NoError(t, err) -} From a4042a2c5b3a8a04b4c26b0352d7e4436e57f654 Mon Sep 17 00:00:00 2001 From: samricotta <37125168+samricotta@users.noreply.github.com> Date: Wed, 13 Sep 2023 18:17:51 +0300 Subject: [PATCH 07/10] docs: update documentation order for `build` tab (#17722) --- docs/architecture/_category_.json | 2 +- docs/docs/build/building-apps/_category_.json | 2 +- docs/docs/build/building-modules/_category_.json | 2 +- docs/docs/build/migrations/_category_.json | 2 +- docs/docs/build/modules/_category_.json | 2 +- docs/docs/build/packages/_category_.json | 2 +- docs/docs/build/tooling/_category_.json | 2 +- docs/docs/develop/advanced/_category_.json | 2 +- docs/docs/develop/beginner/_category_.json | 2 +- docs/docs/user/run-node/_category_.json | 2 +- docs/rfc/_category_.json | 5 +++++ docs/spec/_category_.json | 2 +- 12 files changed, 16 insertions(+), 11 deletions(-) create mode 100644 docs/rfc/_category_.json diff --git a/docs/architecture/_category_.json b/docs/architecture/_category_.json index 87ceb9374844..e0b1907a9bb4 100644 --- a/docs/architecture/_category_.json +++ b/docs/architecture/_category_.json @@ -1,5 +1,5 @@ { "label": "ADRs", - "position": 11, + "position": 6, "link": null } \ No newline at end of file diff --git a/docs/docs/build/building-apps/_category_.json b/docs/docs/build/building-apps/_category_.json index de6617ddc10b..342732cce36e 100644 --- a/docs/docs/build/building-apps/_category_.json +++ b/docs/docs/build/building-apps/_category_.json @@ -1,5 +1,5 @@ { "label": "Building Apps", - "position": 4, + "position": 0, "link": null } \ No newline at end of file diff --git a/docs/docs/build/building-modules/_category_.json b/docs/docs/build/building-modules/_category_.json index 8dc3f9a9411b..2d50f8b3ec57 100644 --- a/docs/docs/build/building-modules/_category_.json +++ b/docs/docs/build/building-modules/_category_.json @@ -1,5 +1,5 @@ { "label": "Building Modules", - "position": 3, + "position": 1, "link": null } \ No newline at end of file diff --git a/docs/docs/build/migrations/_category_.json b/docs/docs/build/migrations/_category_.json index 95d1d4717ee2..5a06c3ebba6c 100644 --- a/docs/docs/build/migrations/_category_.json +++ b/docs/docs/build/migrations/_category_.json @@ -1,5 +1,5 @@ { "label": "Migrations", - "position": 6, + "position": 3, "link": null } diff --git a/docs/docs/build/modules/_category_.json b/docs/docs/build/modules/_category_.json index 7202a9479d8c..72d229c0b058 100644 --- a/docs/docs/build/modules/_category_.json +++ b/docs/docs/build/modules/_category_.json @@ -1,5 +1,5 @@ { "label": "Modules", - "position": 7, + "position": 2, "link": null } diff --git a/docs/docs/build/packages/_category_.json b/docs/docs/build/packages/_category_.json index e91118d38435..5ed885eb2836 100644 --- a/docs/docs/build/packages/_category_.json +++ b/docs/docs/build/packages/_category_.json @@ -1,5 +1,5 @@ { "label": "Packages", - "position": 9, + "position": 4, "link": null } \ No newline at end of file diff --git a/docs/docs/build/tooling/_category_.json b/docs/docs/build/tooling/_category_.json index a01a4fcc48f6..eb57cb8a5a5e 100644 --- a/docs/docs/build/tooling/_category_.json +++ b/docs/docs/build/tooling/_category_.json @@ -1,5 +1,5 @@ { "label": "Tooling", - "position": 10, + "position": 5, "link": null } \ No newline at end of file diff --git a/docs/docs/develop/advanced/_category_.json b/docs/docs/develop/advanced/_category_.json index 2a5703c287b9..6677a95ae7e5 100644 --- a/docs/docs/develop/advanced/_category_.json +++ b/docs/docs/develop/advanced/_category_.json @@ -1,5 +1,5 @@ { - "label": "Core Concepts", + "label": "Advanced", "position": 2, "link": null } \ No newline at end of file diff --git a/docs/docs/develop/beginner/_category_.json b/docs/docs/develop/beginner/_category_.json index 1f2b57293f6d..558d052b8b5f 100644 --- a/docs/docs/develop/beginner/_category_.json +++ b/docs/docs/develop/beginner/_category_.json @@ -1,5 +1,5 @@ { - "label": "Basics", + "label": "Beginner", "position": 1, "link": null } \ No newline at end of file diff --git a/docs/docs/user/run-node/_category_.json b/docs/docs/user/run-node/_category_.json index 375a7c423023..65e64b945f56 100644 --- a/docs/docs/user/run-node/_category_.json +++ b/docs/docs/user/run-node/_category_.json @@ -1,5 +1,5 @@ { "label": "Running a Node, API and CLI", - "position": 5, + "position": 0, "link": null } \ No newline at end of file diff --git a/docs/rfc/_category_.json b/docs/rfc/_category_.json new file mode 100644 index 000000000000..a5712bdaeec1 --- /dev/null +++ b/docs/rfc/_category_.json @@ -0,0 +1,5 @@ +{ + "label": "RFC", + "position": 7, + "link": null +} \ No newline at end of file diff --git a/docs/spec/_category_.json b/docs/spec/_category_.json index 1143a00a1d4a..5c2ccf7d4f56 100644 --- a/docs/spec/_category_.json +++ b/docs/spec/_category_.json @@ -1,5 +1,5 @@ { "label": "Specifications", - "position": 13, + "position": 8, "link": null } \ No newline at end of file From 7537d3258a5fd548c2a52f0917aac46fcab1ed4c Mon Sep 17 00:00:00 2001 From: mmsqe Date: Wed, 13 Sep 2023 23:19:32 +0800 Subject: [PATCH 08/10] Apply suggestions from code review --- x/upgrade/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/x/upgrade/CHANGELOG.md b/x/upgrade/CHANGELOG.md index 46980cc8560c..0785d93371ff 100644 --- a/x/upgrade/CHANGELOG.md +++ b/x/upgrade/CHANGELOG.md @@ -41,3 +41,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * [#16511](https://github.com/cosmos/cosmos-sdk/pull/16511) `plan.DownloadURLWithChecksum` has been renamed to `plan.DownloadURL` and does not validate the URL anymore. Call `plan.ValidateURL` before calling `plan.DownloadURL` to validate the URL. * [#16511](https://github.com/cosmos/cosmos-sdk/pull/16511) `plan.DownloadUpgrade` does not validate URL anymore. Call `plan.ValidateURL` before calling `plan.DownloadUpgrade` to validate the URL. * [#16227](https://github.com/cosmos/cosmos-sdk/issues/16227) `NewKeeper` now takes a `KVStoreService` instead of a `StoreKey`, methods in the `Keeper` now take a `context.Context` instead of a `sdk.Context` and return an `error`. `UpgradeHandler` now receives a `context.Context`. `GetUpgradedClient`, `GetUpgradedConsensusState`, `GetUpgradePlan` now return a specific error for "not found". + +### Bug Fixes + +* (types) [#16583](https://github.com/cosmos/cosmos-sdk/pull/16583), [#17372](https://github.com/cosmos/cosmos-sdk/pull/17372), [#17421](https://github.com/cosmos/cosmos-sdk/pull/17421), [#17713](https://github.com/cosmos/cosmos-sdk/pull/17713) Introduce `PreBlock`, which runs before begin blocker other modules, and allows to modify consensus parameters, and the changes are visible to the following state machine logics and reimplement `PreFinalizeBlockHook` as `PreBlocker`. From b1ae0293d702a053400df88df1800805d21cfe30 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Wed, 13 Sep 2023 23:35:08 +0800 Subject: [PATCH 09/10] Update x/upgrade/CHANGELOG.md Co-authored-by: Julien Robert --- x/upgrade/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/upgrade/CHANGELOG.md b/x/upgrade/CHANGELOG.md index 0785d93371ff..bfd682d31993 100644 --- a/x/upgrade/CHANGELOG.md +++ b/x/upgrade/CHANGELOG.md @@ -44,4 +44,4 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Bug Fixes -* (types) [#16583](https://github.com/cosmos/cosmos-sdk/pull/16583), [#17372](https://github.com/cosmos/cosmos-sdk/pull/17372), [#17421](https://github.com/cosmos/cosmos-sdk/pull/17421), [#17713](https://github.com/cosmos/cosmos-sdk/pull/17713) Introduce `PreBlock`, which runs before begin blocker other modules, and allows to modify consensus parameters, and the changes are visible to the following state machine logics and reimplement `PreFinalizeBlockHook` as `PreBlocker`. +* [#17421](https://github.com/cosmos/cosmos-sdk/pull/17421) Replace ` BeginBlock` by `PreBlock`. Read [ADR-68](https://github.com/cosmos/cosmos-sdk/blob/main/docs/architecture/adr-068-preblock.md) for more information. From 2154ce0bbe518744439bd4506e7afba3319ed459 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Wed, 13 Sep 2023 18:15:53 +0200 Subject: [PATCH 10/10] refactor: precise compiler assertions and cleanup module.go (#17718) --- UPGRADING.md | 28 ++- .../building-modules/01-module-manager.md | 10 +- .../06-beginblock-endblock.md | 2 +- testutil/mock/types_mock_appmodule.go | 170 ++++++++++++++++-- testutil/mock/types_module_module.go | 52 +++--- types/module/mock_appmodule_test.go | 9 +- types/module/module.go | 12 +- types/module/module_test.go | 8 +- x/auth/module.go | 18 +- x/auth/vesting/module.go | 11 +- x/authz/module/module.go | 19 +- x/bank/module.go | 12 +- x/circuit/module.go | 7 +- x/consensus/module.go | 14 +- x/crisis/module.go | 20 +-- x/distribution/module.go | 19 +- x/evidence/module.go | 19 +- x/feegrant/module/module.go | 19 +- x/genutil/module.go | 6 +- x/gov/module.go | 15 +- x/group/module/module.go | 19 +- x/mint/module.go | 20 +-- x/nft/module/module.go | 18 +- x/params/module.go | 8 +- x/slashing/module.go | 20 +-- x/staking/module.go | 22 +-- x/upgrade/module.go | 15 +- 27 files changed, 336 insertions(+), 256 deletions(-) diff --git a/UPGRADING.md b/UPGRADING.md index fcd949e96e6b..3b4c55587b74 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -343,7 +343,7 @@ The return type of the interface method `TxConfig.SignModeHandler()` has been ch * `x/slashing` * `x/upgrade` -* BeginBlock and EndBlock have changed their signature, so it is important that any module implementing them are updated accordingly. +* `BeginBlock` and `EndBlock` have changed their signature, so it is important that any module implementing them are updated accordingly. ```diff - BeginBlock(sdk.Context, abci.RequestBeginBlock) @@ -355,18 +355,38 @@ The return type of the interface method `TxConfig.SignModeHandler()` has been ch + EndBlock(context.Context) error ``` -In case a module requires to return `abci.ValidatorUpdate` from `EndBlock`, it can use the `HasABCIEndblock` interface instead. +In case a module requires to return `abci.ValidatorUpdate` from `EndBlock`, it can use the `HasABCIEndBlock` interface instead. ```diff - EndBlock(sdk.Context, abci.RequestEndBlock) []abci.ValidatorUpdate + EndBlock(context.Context) ([]abci.ValidatorUpdate, error) ``` -`GetSigners()` is no longer required to be implemented on `Msg` types. The SDK will automatically infer the signers from the `Signer` field on the message. The signer field is required on all messages unless using a custom signer function. +:::tip +It is possible to ensure that a module implements the correct interfaces by using compiler assertions in your `x/{moduleName}/module.go`: + +```go +var ( + _ module.AppModuleBasic = (*AppModule)(nil) + _ module.AppModuleSimulation = (*AppModule)(nil) + _ module.HasGenesis = (*AppModule)(nil) + + _ appmodule.AppModule = (*AppModule)(nil) + _ appmodule.HasBeginBlocker = (*AppModule)(nil) + _ appmodule.HasEndBlocker = (*AppModule)(nil) + ... +) +``` + +Read more on those interfaces [here](https://docs.cosmos.network/v0.50/building-modules/module-manager#application-module-interfaces). +::: -To find out more please read the [signer field](./05-protobuf-annotations.md#signer) & [here](https://github.com/cosmos/cosmos-sdk/blob/7352d0bce8e72121e824297df453eb1059c28da8/docs/docs/build/building-modules/02-messages-and-queries.md#L40)documentation. +* `GetSigners()` is no longer required to be implemented on `Msg` types. The SDK will automatically infer the signers from the `Signer` field on the message. The signer field is required on all messages unless using a custom signer function. + +To find out more please read the [signer field](./05-protobuf-annotations.md#signer) & [here](https://github.com/cosmos/cosmos-sdk/blob/7352d0bce8e72121e824297df453eb1059c28da8/docs/docs/build/building-modules/02-messages-and-queries.md#L40) documentation. + #### `x/auth` For ante handler construction via `ante.NewAnteHandler`, the field `ante.HandlerOptions.SignModeHandler` has been updated to `x/tx/signing/HandlerMap` from `x/auth/signing/SignModeHandler`. Callers typically fetch this value from `client.TxConfig.SignModeHandler()` (which is also changed) so this change should be transparent to most users. diff --git a/docs/docs/build/building-modules/01-module-manager.md b/docs/docs/build/building-modules/01-module-manager.md index 7b0cc9974441..570a60c0b41e 100644 --- a/docs/docs/build/building-modules/01-module-manager.md +++ b/docs/docs/build/building-modules/01-module-manager.md @@ -42,7 +42,7 @@ The above interfaces are mostly embedding smaller interfaces (extension interfac * [`appmodule.HasPrecommit`](#hasprecommit): The extension interface that contains information about the `AppModule` and `Precommit`. * [`appmodule.HasPrepareCheckState`](#haspreparecheckstate): The extension interface that contains information about the `AppModule` and `PrepareCheckState`. * [`appmodule.HasService` / `module.HasServices`](#hasservices): The extension interface for modules to register services. -* [`module.HasABCIEndblock`](#hasabciendblock): The extension interface that contains information about the `AppModule`, `EndBlock` and returns an updated validator set. +* [`module.HasABCIEndBlock`](#hasabciendblock): The extension interface that contains information about the `AppModule`, `EndBlock` and returns an updated validator set. * (legacy) [`module.HasInvariants`](#hasinvariants): The extension interface for registering invariants. * (legacy) [`module.HasConsensusVersion`](#hasconsensusversion): The extension interface for declaring a module consensus version. @@ -198,7 +198,7 @@ https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/core/appmodule/module. ### `HasEndBlocker` -The `HasEndBlocker` is an extension interface from `appmodule.AppModule`. All modules that have an `EndBlock` method implement this interface. If a module need to return validator set updates (staking), they can use `HasABCIEndblock` +The `HasEndBlocker` is an extension interface from `appmodule.AppModule`. All modules that have an `EndBlock` method implement this interface. If a module need to return validator set updates (staking), they can use `HasABCIEndBlock` ```go reference https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/core/appmodule/module.go#L66-L72 @@ -206,9 +206,9 @@ https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/core/appmodule/module. * `EndBlock(context.Context) error`: This method gives module developers the option to implement logic that is automatically triggered at the end of each block. -### `HasABCIEndblock` +### `HasABCIEndBlock` -The `HasABCIEndblock` is an extension interface from `module.AppModule`. All modules that have an `EndBlock` which return validator set updates implement this interface. +The `HasABCIEndBlock` is an extension interface from `module.AppModule`. All modules that have an `EndBlock` which return validator set updates implement this interface. ```go reference https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/types/module/module.go#L222-L225 @@ -309,7 +309,7 @@ The module manager is used throughout the application whenever an action on a co * `ExportGenesisForModules(ctx context.Context, cdc codec.JSONCodec, modulesToExport []string)`: Behaves the same as `ExportGenesis`, except takes a list of modules to export. * `BeginBlock(ctx context.Context) error`: At the beginning of each block, this function is called from [`BaseApp`](../../develop/advanced/00-baseapp.md#beginblock) and, in turn, calls the [`BeginBlock`](./05-beginblock-endblock.md) function of each modules implementing the `appmodule.HasBeginBlocker` interface, in the order defined in `OrderBeginBlockers`. It creates a child [context](../../develop/advanced/02-context.md) with an event manager to aggregate [events](../../develop/advanced/08-events.md) emitted from each modules. * `EndBlock(ctx context.Context) error`: At the end of each block, this function is called from [`BaseApp`](../../develop/advanced/00-baseapp.md#endblock) and, in turn, calls the [`EndBlock`](./05-beginblock-endblock.md) function of each modules implementing the `appmodule.HasEndBlocker` interface, in the order defined in `OrderEndBlockers`. It creates a child [context](../../develop/advanced/02-context.md) with an event manager to aggregate [events](../../develop/advanced/08-events.md) emitted from all modules. The function returns an `abci` which contains the aforementioned events, as well as validator set updates (if any). -* `EndBlock(context.Context) ([]abci.ValidatorUpdate, error)`: At the end of each block, this function is called from [`BaseApp`](../../develop/advanced/00-baseapp.md#endblock) and, in turn, calls the [`EndBlock`](./05-beginblock-endblock.md) function of each modules implementing the `module.HasABCIEndblock` interface, in the order defined in `OrderEndBlockers`. It creates a child [context](../../develop/advanced/02-context.md) with an event manager to aggregate [events](../../develop/advanced/08-events.md) emitted from all modules. The function returns an `abci` which contains the aforementioned events, as well as validator set updates (if any). +* `EndBlock(context.Context) ([]abci.ValidatorUpdate, error)`: At the end of each block, this function is called from [`BaseApp`](../../develop/advanced/00-baseapp.md#endblock) and, in turn, calls the [`EndBlock`](./05-beginblock-endblock.md) function of each modules implementing the `module.HasABCIEndBlock` interface, in the order defined in `OrderEndBlockers`. It creates a child [context](../../develop/advanced/02-context.md) with an event manager to aggregate [events](../../develop/advanced/08-events.md) emitted from all modules. The function returns an `abci` which contains the aforementioned events, as well as validator set updates (if any). * `Precommit(ctx context.Context)`: During [`Commit`](../../develop/advanced/00-baseapp.md#commit), this function is called from `BaseApp` immediately before the [`deliverState`](../../develop/advanced/00-baseapp.md#state-updates) is written to the underlying [`rootMultiStore`](../../develop/advanced/04-store.md#commitmultistore) and, in turn calls the `Precommit` function of each modules implementing the `HasPrecommit` interface, in the order defined in `OrderPrecommiters`. It creates a child [context](../../develop/advanced/02-context.md) where the underlying `CacheMultiStore` is that of the newly committed block's [`finalizeblockstate`](../../develop/advanced/00-baseapp.md#state-updates). * `PrepareCheckState(ctx context.Context)`: During [`Commit`](../../develop/advanced/00-baseapp.md#commit), this function is called from `BaseApp` immediately after the [`deliverState`](../../develop/advanced/00-baseapp.md#state-updates) is written to the underlying [`rootMultiStore`](../../develop/advanced/04-store.md#commitmultistore) and, in turn calls the `PrepareCheckState` function of each module implementing the `HasPrepareCheckState` interface, in the order defined in `OrderPrepareCheckStaters`. It creates a child [context](../../develop/advanced/02-context.md) where the underlying `CacheMultiStore` is that of the next block's [`checkState`](../../develop/advanced/00-baseapp.md#state-updates). Writes to this state will be present in the [`checkState`](../../develop/advanced/00-baseapp.md#state-updates) of the next block, and therefore this method can be used to prepare the `checkState` for the next block. diff --git a/docs/docs/build/building-modules/06-beginblock-endblock.md b/docs/docs/build/building-modules/06-beginblock-endblock.md index 9472b0b759eb..35b5bb350b2e 100644 --- a/docs/docs/build/building-modules/06-beginblock-endblock.md +++ b/docs/docs/build/building-modules/06-beginblock-endblock.md @@ -20,7 +20,7 @@ sidebar_position: 1 In 0.47.0, Prepare and Process Proposal were added that allow app developers to do arbitrary work at those phases, but they do not influence the work that will be done in BeginBlock. If an application required `BeginBlock` to execute prior to any sort of work is done then this is not possible today (0.50.0). -When needed, `BeginBlocker` and `EndBlocker` are implemented as part of the [`HasBeginBlocker`, `HasABCIEndblocker` and `EndBlocker` interfaces](./01-module-manager.md#appmodule). This means either can be left-out if not required. The `BeginBlock` and `EndBlock` methods of the interface implemented in `module.go` generally defer to `BeginBlocker` and `EndBlocker` methods respectively, which are usually implemented in `abci.go`. +When needed, `BeginBlocker` and `EndBlocker` are implemented as part of the [`HasBeginBlocker`, `HasABCIEndBlocker` and `EndBlocker` interfaces](./01-module-manager.md#appmodule). This means either can be left-out if not required. The `BeginBlock` and `EndBlock` methods of the interface implemented in `module.go` generally defer to `BeginBlocker` and `EndBlocker` methods respectively, which are usually implemented in `abci.go`. The actual implementation of `BeginBlocker` and `EndBlocker` in `abci.go` are very similar to that of a [`Msg` service](./03-msg-services.md): diff --git a/testutil/mock/types_mock_appmodule.go b/testutil/mock/types_mock_appmodule.go index c1d22f377963..48cc6f49a35a 100644 --- a/testutil/mock/types_mock_appmodule.go +++ b/testutil/mock/types_mock_appmodule.go @@ -541,35 +541,125 @@ func (mr *MockCoreAppModuleMockRecorder) ValidateGenesis(arg0 interface{}) *gomo return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidateGenesis", reflect.TypeOf((*MockCoreAppModule)(nil).ValidateGenesis), arg0) } -// MockCoreModuleWithPreBlock is a mock of CoreModuleWithPreBlock interface. -type MockCoreModuleWithPreBlock struct { - MockCoreAppModule - recorder *MockCoreModuleWithPreBlockMockRecorder +// MockCoreAppModuleWithPreBlock is a mock of CoreAppModuleWithPreBlock interface. +type MockCoreAppModuleWithPreBlock struct { + ctrl *gomock.Controller + recorder *MockCoreAppModuleWithPreBlockMockRecorder } -// MockCoreModuleWithPreBlockMockRecorder is the mock recorder for MockCoreModuleWithPreBlock. -type MockCoreModuleWithPreBlockMockRecorder struct { - mock *MockCoreModuleWithPreBlock +// MockCoreAppModuleWithPreBlockMockRecorder is the mock recorder for MockCoreAppModuleWithPreBlock. +type MockCoreAppModuleWithPreBlockMockRecorder struct { + mock *MockCoreAppModuleWithPreBlock } -// NewMockCoreModuleWithPreBlock creates a new mock instance. -func NewMockCoreModuleWithPreBlock(ctrl *gomock.Controller) *MockCoreModuleWithPreBlock { - mock := &MockCoreModuleWithPreBlock{ - MockCoreAppModule: MockCoreAppModule{ - ctrl: ctrl, - }, - } - mock.recorder = &MockCoreModuleWithPreBlockMockRecorder{mock} +// NewMockCoreAppModuleWithPreBlock creates a new mock instance. +func NewMockCoreAppModuleWithPreBlock(ctrl *gomock.Controller) *MockCoreAppModuleWithPreBlock { + mock := &MockCoreAppModuleWithPreBlock{ctrl: ctrl} + mock.recorder = &MockCoreAppModuleWithPreBlockMockRecorder{mock} return mock } // EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockCoreModuleWithPreBlock) EXPECT() *MockCoreModuleWithPreBlockMockRecorder { +func (m *MockCoreAppModuleWithPreBlock) EXPECT() *MockCoreAppModuleWithPreBlockMockRecorder { return m.recorder } +// BeginBlock mocks base method. +func (m *MockCoreAppModuleWithPreBlock) BeginBlock(arg0 context.Context) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "BeginBlock", arg0) + ret0, _ := ret[0].(error) + return ret0 +} + +// BeginBlock indicates an expected call of BeginBlock. +func (mr *MockCoreAppModuleWithPreBlockMockRecorder) BeginBlock(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BeginBlock", reflect.TypeOf((*MockCoreAppModuleWithPreBlock)(nil).BeginBlock), arg0) +} + +// DefaultGenesis mocks base method. +func (m *MockCoreAppModuleWithPreBlock) DefaultGenesis(arg0 appmodule.GenesisTarget) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DefaultGenesis", arg0) + ret0, _ := ret[0].(error) + return ret0 +} + +// DefaultGenesis indicates an expected call of DefaultGenesis. +func (mr *MockCoreAppModuleWithPreBlockMockRecorder) DefaultGenesis(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DefaultGenesis", reflect.TypeOf((*MockCoreAppModuleWithPreBlock)(nil).DefaultGenesis), arg0) +} + +// EndBlock mocks base method. +func (m *MockCoreAppModuleWithPreBlock) EndBlock(arg0 context.Context) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "EndBlock", arg0) + ret0, _ := ret[0].(error) + return ret0 +} + +// EndBlock indicates an expected call of EndBlock. +func (mr *MockCoreAppModuleWithPreBlockMockRecorder) EndBlock(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EndBlock", reflect.TypeOf((*MockCoreAppModuleWithPreBlock)(nil).EndBlock), arg0) +} + +// ExportGenesis mocks base method. +func (m *MockCoreAppModuleWithPreBlock) ExportGenesis(arg0 context.Context, arg1 appmodule.GenesisTarget) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ExportGenesis", arg0, arg1) + ret0, _ := ret[0].(error) + return ret0 +} + +// ExportGenesis indicates an expected call of ExportGenesis. +func (mr *MockCoreAppModuleWithPreBlockMockRecorder) ExportGenesis(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ExportGenesis", reflect.TypeOf((*MockCoreAppModuleWithPreBlock)(nil).ExportGenesis), arg0, arg1) +} + +// InitGenesis mocks base method. +func (m *MockCoreAppModuleWithPreBlock) InitGenesis(arg0 context.Context, arg1 appmodule.GenesisSource) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "InitGenesis", arg0, arg1) + ret0, _ := ret[0].(error) + return ret0 +} + +// InitGenesis indicates an expected call of InitGenesis. +func (mr *MockCoreAppModuleWithPreBlockMockRecorder) InitGenesis(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InitGenesis", reflect.TypeOf((*MockCoreAppModuleWithPreBlock)(nil).InitGenesis), arg0, arg1) +} + +// IsAppModule mocks base method. +func (m *MockCoreAppModuleWithPreBlock) IsAppModule() { + m.ctrl.T.Helper() + m.ctrl.Call(m, "IsAppModule") +} + +// IsAppModule indicates an expected call of IsAppModule. +func (mr *MockCoreAppModuleWithPreBlockMockRecorder) IsAppModule() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsAppModule", reflect.TypeOf((*MockCoreAppModuleWithPreBlock)(nil).IsAppModule)) +} + +// IsOnePerModuleType mocks base method. +func (m *MockCoreAppModuleWithPreBlock) IsOnePerModuleType() { + m.ctrl.T.Helper() + m.ctrl.Call(m, "IsOnePerModuleType") +} + +// IsOnePerModuleType indicates an expected call of IsOnePerModuleType. +func (mr *MockCoreAppModuleWithPreBlockMockRecorder) IsOnePerModuleType() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsOnePerModuleType", reflect.TypeOf((*MockCoreAppModuleWithPreBlock)(nil).IsOnePerModuleType)) +} + // PreBlock mocks base method. -func (m *MockCoreModuleWithPreBlock) PreBlock(arg0 context.Context) (appmodule.ResponsePreBlock, error) { +func (m *MockCoreAppModuleWithPreBlock) PreBlock(arg0 context.Context) (appmodule.ResponsePreBlock, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "PreBlock", arg0) ret0, _ := ret[0].(appmodule.ResponsePreBlock) @@ -578,7 +668,49 @@ func (m *MockCoreModuleWithPreBlock) PreBlock(arg0 context.Context) (appmodule.R } // PreBlock indicates an expected call of PreBlock. -func (mr *MockCoreModuleWithPreBlockMockRecorder) PreBlock(arg0 interface{}) *gomock.Call { +func (mr *MockCoreAppModuleWithPreBlockMockRecorder) PreBlock(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PreBlock", reflect.TypeOf((*MockCoreAppModuleWithPreBlock)(nil).PreBlock), arg0) +} + +// Precommit mocks base method. +func (m *MockCoreAppModuleWithPreBlock) Precommit(arg0 context.Context) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Precommit", arg0) + ret0, _ := ret[0].(error) + return ret0 +} + +// Precommit indicates an expected call of Precommit. +func (mr *MockCoreAppModuleWithPreBlockMockRecorder) Precommit(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Precommit", reflect.TypeOf((*MockCoreAppModuleWithPreBlock)(nil).Precommit), arg0) +} + +// PrepareCheckState mocks base method. +func (m *MockCoreAppModuleWithPreBlock) PrepareCheckState(arg0 context.Context) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "PrepareCheckState", arg0) + ret0, _ := ret[0].(error) + return ret0 +} + +// PrepareCheckState indicates an expected call of PrepareCheckState. +func (mr *MockCoreAppModuleWithPreBlockMockRecorder) PrepareCheckState(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PrepareCheckState", reflect.TypeOf((*MockCoreAppModuleWithPreBlock)(nil).PrepareCheckState), arg0) +} + +// ValidateGenesis mocks base method. +func (m *MockCoreAppModuleWithPreBlock) ValidateGenesis(arg0 appmodule.GenesisSource) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ValidateGenesis", arg0) + ret0, _ := ret[0].(error) + return ret0 +} + +// ValidateGenesis indicates an expected call of ValidateGenesis. +func (mr *MockCoreAppModuleWithPreBlockMockRecorder) ValidateGenesis(arg0 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PreBlock", reflect.TypeOf((*MockCoreModuleWithPreBlock)(nil).PreBlock), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidateGenesis", reflect.TypeOf((*MockCoreAppModuleWithPreBlock)(nil).ValidateGenesis), arg0) } diff --git a/testutil/mock/types_module_module.go b/testutil/mock/types_module_module.go index 9859d1212b32..186cd4d7ca7f 100644 --- a/testutil/mock/types_module_module.go +++ b/testutil/mock/types_module_module.go @@ -516,31 +516,31 @@ func (mr *MockHasConsensusVersionMockRecorder) ConsensusVersion() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ConsensusVersion", reflect.TypeOf((*MockHasConsensusVersion)(nil).ConsensusVersion)) } -// MockHasABCIEndblock is a mock of HasABCIEndblock interface. -type MockHasABCIEndblock struct { +// MockHasABCIEndBlock is a mock of HasABCIEndBlock interface. +type MockHasABCIEndBlock struct { ctrl *gomock.Controller - recorder *MockHasABCIEndblockMockRecorder + recorder *MockHasABCIEndBlockMockRecorder } -// MockHasABCIEndblockMockRecorder is the mock recorder for MockHasABCIEndblock. -type MockHasABCIEndblockMockRecorder struct { - mock *MockHasABCIEndblock +// MockHasABCIEndBlockMockRecorder is the mock recorder for MockHasABCIEndBlock. +type MockHasABCIEndBlockMockRecorder struct { + mock *MockHasABCIEndBlock } -// NewMockHasABCIEndblock creates a new mock instance. -func NewMockHasABCIEndblock(ctrl *gomock.Controller) *MockHasABCIEndblock { - mock := &MockHasABCIEndblock{ctrl: ctrl} - mock.recorder = &MockHasABCIEndblockMockRecorder{mock} +// NewMockHasABCIEndBlock creates a new mock instance. +func NewMockHasABCIEndBlock(ctrl *gomock.Controller) *MockHasABCIEndBlock { + mock := &MockHasABCIEndBlock{ctrl: ctrl} + mock.recorder = &MockHasABCIEndBlockMockRecorder{mock} return mock } // EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockHasABCIEndblock) EXPECT() *MockHasABCIEndblockMockRecorder { +func (m *MockHasABCIEndBlock) EXPECT() *MockHasABCIEndBlockMockRecorder { return m.recorder } // EndBlock mocks base method. -func (m *MockHasABCIEndblock) EndBlock(arg0 context.Context) ([]types.ValidatorUpdate, error) { +func (m *MockHasABCIEndBlock) EndBlock(arg0 context.Context) ([]types.ValidatorUpdate, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "EndBlock", arg0) ret0, _ := ret[0].([]types.ValidatorUpdate) @@ -549,13 +549,13 @@ func (m *MockHasABCIEndblock) EndBlock(arg0 context.Context) ([]types.ValidatorU } // EndBlock indicates an expected call of EndBlock. -func (mr *MockHasABCIEndblockMockRecorder) EndBlock(arg0 interface{}) *gomock.Call { +func (mr *MockHasABCIEndBlockMockRecorder) EndBlock(arg0 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EndBlock", reflect.TypeOf((*MockHasABCIEndblock)(nil).EndBlock), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EndBlock", reflect.TypeOf((*MockHasABCIEndBlock)(nil).EndBlock), arg0) } // Name mocks base method. -func (m *MockHasABCIEndblock) Name() string { +func (m *MockHasABCIEndBlock) Name() string { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Name") ret0, _ := ret[0].(string) @@ -563,45 +563,45 @@ func (m *MockHasABCIEndblock) Name() string { } // Name indicates an expected call of Name. -func (mr *MockHasABCIEndblockMockRecorder) Name() *gomock.Call { +func (mr *MockHasABCIEndBlockMockRecorder) Name() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Name", reflect.TypeOf((*MockHasABCIEndblock)(nil).Name)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Name", reflect.TypeOf((*MockHasABCIEndBlock)(nil).Name)) } // RegisterGRPCGatewayRoutes mocks base method. -func (m *MockHasABCIEndblock) RegisterGRPCGatewayRoutes(arg0 client.Context, arg1 *runtime.ServeMux) { +func (m *MockHasABCIEndBlock) RegisterGRPCGatewayRoutes(arg0 client.Context, arg1 *runtime.ServeMux) { m.ctrl.T.Helper() m.ctrl.Call(m, "RegisterGRPCGatewayRoutes", arg0, arg1) } // RegisterGRPCGatewayRoutes indicates an expected call of RegisterGRPCGatewayRoutes. -func (mr *MockHasABCIEndblockMockRecorder) RegisterGRPCGatewayRoutes(arg0, arg1 interface{}) *gomock.Call { +func (mr *MockHasABCIEndBlockMockRecorder) RegisterGRPCGatewayRoutes(arg0, arg1 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterGRPCGatewayRoutes", reflect.TypeOf((*MockHasABCIEndblock)(nil).RegisterGRPCGatewayRoutes), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterGRPCGatewayRoutes", reflect.TypeOf((*MockHasABCIEndBlock)(nil).RegisterGRPCGatewayRoutes), arg0, arg1) } // RegisterInterfaces mocks base method. -func (m *MockHasABCIEndblock) RegisterInterfaces(arg0 types0.InterfaceRegistry) { +func (m *MockHasABCIEndBlock) RegisterInterfaces(arg0 types0.InterfaceRegistry) { m.ctrl.T.Helper() m.ctrl.Call(m, "RegisterInterfaces", arg0) } // RegisterInterfaces indicates an expected call of RegisterInterfaces. -func (mr *MockHasABCIEndblockMockRecorder) RegisterInterfaces(arg0 interface{}) *gomock.Call { +func (mr *MockHasABCIEndBlockMockRecorder) RegisterInterfaces(arg0 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterInterfaces", reflect.TypeOf((*MockHasABCIEndblock)(nil).RegisterInterfaces), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterInterfaces", reflect.TypeOf((*MockHasABCIEndBlock)(nil).RegisterInterfaces), arg0) } // RegisterLegacyAminoCodec mocks base method. -func (m *MockHasABCIEndblock) RegisterLegacyAminoCodec(arg0 *codec.LegacyAmino) { +func (m *MockHasABCIEndBlock) RegisterLegacyAminoCodec(arg0 *codec.LegacyAmino) { m.ctrl.T.Helper() m.ctrl.Call(m, "RegisterLegacyAminoCodec", arg0) } // RegisterLegacyAminoCodec indicates an expected call of RegisterLegacyAminoCodec. -func (mr *MockHasABCIEndblockMockRecorder) RegisterLegacyAminoCodec(arg0 interface{}) *gomock.Call { +func (mr *MockHasABCIEndBlockMockRecorder) RegisterLegacyAminoCodec(arg0 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterLegacyAminoCodec", reflect.TypeOf((*MockHasABCIEndblock)(nil).RegisterLegacyAminoCodec), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterLegacyAminoCodec", reflect.TypeOf((*MockHasABCIEndBlock)(nil).RegisterLegacyAminoCodec), arg0) } // MockgenesisOnlyModule is a mock of genesisOnlyModule interface. diff --git a/types/module/mock_appmodule_test.go b/types/module/mock_appmodule_test.go index 27049cf54000..07c9c6389f51 100644 --- a/types/module/mock_appmodule_test.go +++ b/types/module/mock_appmodule_test.go @@ -14,7 +14,7 @@ type AppModuleWithAllExtensions interface { module.HasGenesis module.HasInvariants module.HasConsensusVersion - module.HasABCIEndblock + module.HasABCIEndBlock module.HasName } @@ -25,7 +25,7 @@ type AppModuleWithAllExtensionsABCI interface { module.HasABCIGenesis module.HasInvariants module.HasConsensusVersion - module.HasABCIEndblock + module.HasABCIEndBlock module.HasName } @@ -39,3 +39,8 @@ type CoreAppModule interface { appmodule.HasPrecommit appmodule.HasPrepareCheckState } + +type CoreAppModuleWithPreBlock interface { + CoreAppModule + appmodule.HasPreBlocker +} diff --git a/types/module/module.go b/types/module/module.go index 086e281a7cf6..a3c7b2ed62f0 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -197,6 +197,7 @@ type HasABCIGenesis interface { // AppModule is the form for an application module. Most of // its functionality has been moved to extension interfaces. +// Deprecated: use appmodule.AppModule with a combination of extension interfaes interfaces instead. type AppModule interface { AppModuleBasic } @@ -222,7 +223,12 @@ type HasConsensusVersion interface { ConsensusVersion() uint64 } -type HasABCIEndblock interface { +// HasABCIEndblock is a released typo of HasABCIEndBlock. +// Deprecated: use HasABCIEndBlock instead. +type HasABCIEndblock HasABCIEndBlock + +// HasABCIEndBlock is the interface for modules that need to run code at the end of the block. +type HasABCIEndBlock interface { AppModule EndBlock(context.Context) ([]abci.ValidatorUpdate, error) } @@ -397,7 +403,7 @@ func (m *Manager) SetOrderEndBlockers(moduleNames ...string) { return !hasEndBlock } - _, hasABCIEndBlock := module.(HasABCIEndblock) + _, hasABCIEndBlock := module.(HasABCIEndBlock) return !hasABCIEndBlock }) m.OrderEndBlockers = moduleNames @@ -788,7 +794,7 @@ func (m *Manager) EndBlock(ctx sdk.Context) (sdk.EndBlock, error) { if err != nil { return sdk.EndBlock{}, err } - } else if module, ok := m.Modules[moduleName].(HasABCIEndblock); ok { + } else if module, ok := m.Modules[moduleName].(HasABCIEndBlock); ok { moduleValUpdates, err := module.EndBlock(ctx) if err != nil { return sdk.EndBlock{}, err diff --git a/types/module/module_test.go b/types/module/module_test.go index bd5111a6692b..2a348667eb3a 100644 --- a/types/module/module_test.go +++ b/types/module/module_test.go @@ -95,7 +95,7 @@ func TestBasicManager(t *testing.T) { func TestAssertNoForgottenModules(t *testing.T) { mockCtrl := gomock.NewController(t) t.Cleanup(mockCtrl.Finish) - mockAppModule1 := mock.NewMockHasABCIEndblock(mockCtrl) + mockAppModule1 := mock.NewMockHasABCIEndBlock(mockCtrl) mockAppModule3 := mock.NewMockCoreAppModule(mockCtrl) mockAppModule1.EXPECT().Name().Times(2).Return("module1") @@ -320,8 +320,8 @@ func TestManager_EndBlock(t *testing.T) { mockCtrl := gomock.NewController(t) t.Cleanup(mockCtrl.Finish) - mockAppModule1 := mock.NewMockHasABCIEndblock(mockCtrl) - mockAppModule2 := mock.NewMockHasABCIEndblock(mockCtrl) + mockAppModule1 := mock.NewMockHasABCIEndBlock(mockCtrl) + mockAppModule2 := mock.NewMockHasABCIEndBlock(mockCtrl) mockAppModule3 := mock.NewMockAppModule(mockCtrl) mockAppModule1.EXPECT().Name().Times(2).Return("module1") mockAppModule2.EXPECT().Name().Times(2).Return("module2") @@ -473,7 +473,7 @@ func TestCoreAPIManager_PreBlock(t *testing.T) { mockCtrl := gomock.NewController(t) t.Cleanup(mockCtrl.Finish) - mockAppModule1 := mock.NewMockCoreModuleWithPreBlock(mockCtrl) + mockAppModule1 := mock.NewMockCoreAppModuleWithPreBlock(mockCtrl) mm := module.NewManagerFromMap(map[string]appmodule.AppModule{ "module1": mockAppModule1, "module2": mock.NewMockCoreAppModule(mockCtrl), diff --git a/x/auth/module.go b/x/auth/module.go index ae942a774e5c..52e9b93cac85 100644 --- a/x/auth/module.go +++ b/x/auth/module.go @@ -5,7 +5,6 @@ import ( "encoding/json" "fmt" - abci "github.com/cometbft/cometbft/abci/types" gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" modulev1 "cosmossdk.io/api/cosmos/auth/module/v1" @@ -33,9 +32,12 @@ const ( ) var ( - _ module.AppModule = AppModule{} - _ module.AppModuleBasic = AppModuleBasic{} + _ module.AppModuleBasic = AppModule{} _ module.AppModuleSimulation = AppModule{} + _ module.HasGenesis = AppModule{} + _ module.HasServices = AppModule{} + + _ appmodule.AppModule = AppModule{} ) // AppModuleBasic defines the basic application module used by the auth module. @@ -92,8 +94,6 @@ type AppModule struct { legacySubspace exported.Subspace } -var _ appmodule.AppModule = AppModule{} - // IsOnePerModuleType implements the depinject.OnePerModuleType interface. func (am AppModule) IsOnePerModuleType() {} @@ -110,11 +110,6 @@ func NewAppModule(cdc codec.Codec, accountKeeper keeper.AccountKeeper, randGenAc } } -// Name returns the auth module's name. -func (AppModule) Name() string { - return types.ModuleName -} - // RegisterServices registers a GRPC query service to respond to the // module-specific GRPC queries. func (am AppModule) RegisterServices(cfg module.Configurator) { @@ -141,11 +136,10 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { // InitGenesis performs genesis initialization for the auth module. It returns // no validator updates. -func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate { +func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) { var genesisState types.GenesisState cdc.MustUnmarshalJSON(data, &genesisState) am.accountKeeper.InitGenesis(ctx, genesisState) - return []abci.ValidatorUpdate{} } // ExportGenesis returns the exported genesis state as raw bytes for the auth diff --git a/x/auth/vesting/module.go b/x/auth/vesting/module.go index 98a411c01105..139efb1af0de 100644 --- a/x/auth/vesting/module.go +++ b/x/auth/vesting/module.go @@ -24,8 +24,10 @@ import ( ) var ( - _ module.AppModule = AppModule{} - _ module.AppModuleBasic = AppModuleBasic{} + _ module.AppModuleBasic = AppModule{} + + _ appmodule.AppModule = AppModule{} + _ appmodule.HasServices = AppModule{} ) // AppModuleBasic defines the basic application module used by the sub-vesting @@ -87,11 +89,6 @@ func NewAppModule(ak keeper.AccountKeeper, bk types.BankKeeper) AppModule { } } -var ( - _ appmodule.AppModule = AppModule{} - _ appmodule.HasServices = AppModule{} -) - // IsOnePerModuleType implements the depinject.OnePerModuleType interface. func (am AppModule) IsOnePerModuleType() {} diff --git a/x/authz/module/module.go b/x/authz/module/module.go index a933d4fa7d91..248a75b8584b 100644 --- a/x/authz/module/module.go +++ b/x/authz/module/module.go @@ -29,8 +29,13 @@ import ( ) var ( - _ module.AppModuleBasic = AppModuleBasic{} + _ module.AppModuleBasic = AppModule{} _ module.AppModuleSimulation = AppModule{} + _ module.HasGenesis = AppModule{} + _ module.HasServices = AppModule{} + + _ appmodule.AppModule = AppModule{} + _ appmodule.HasBeginBlocker = AppModule{} ) // AppModuleBasic defines the basic application module used by the authz module. @@ -97,6 +102,7 @@ func (ab AppModuleBasic) GetTxCmd() *cobra.Command { // AppModule implements the sdk.AppModule interface type AppModule struct { AppModuleBasic + keeper keeper.Keeper accountKeeper authz.AccountKeeper bankKeeper authz.BankKeeper @@ -114,23 +120,12 @@ func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, ak authz.AccountKeeper, } } -var ( - _ appmodule.AppModule = AppModule{} - _ appmodule.HasBeginBlocker = AppModule{} - _ module.HasGenesis = AppModule{} -) - // IsOnePerModuleType implements the depinject.OnePerModuleType interface. func (am AppModule) IsOnePerModuleType() {} // IsAppModule implements the appmodule.AppModule interface. func (am AppModule) IsAppModule() {} -// Name returns the authz module's name. -func (AppModule) Name() string { - return authz.ModuleName -} - // InitGenesis performs genesis initialization for the authz module. It returns // no validator updates. func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) { diff --git a/x/bank/module.go b/x/bank/module.go index 2a1fc8105321..4de21846524b 100644 --- a/x/bank/module.go +++ b/x/bank/module.go @@ -36,10 +36,13 @@ import ( const ConsensusVersion = 4 var ( - _ module.AppModule = AppModule{} - _ module.AppModuleBasic = AppModuleBasic{} + _ module.AppModuleBasic = AppModule{} _ module.AppModuleSimulation = AppModule{} _ module.HasGenesis = AppModule{} + _ module.HasServices = AppModule{} + _ module.HasInvariants = AppModule{} + + _ appmodule.AppModule = AppModule{} ) // AppModuleBasic defines the basic application module used by the bank module. @@ -103,8 +106,6 @@ type AppModule struct { legacySubspace exported.Subspace } -var _ appmodule.AppModule = AppModule{} - // IsOnePerModuleType implements the depinject.OnePerModuleType interface. func (am AppModule) IsOnePerModuleType() {} @@ -140,9 +141,6 @@ func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, accountKeeper types.Acc } } -// Name returns the bank module's name. -func (AppModule) Name() string { return types.ModuleName } - // RegisterInvariants registers the bank module invariants. func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) { keeper.RegisterInvariants(ir, am.keeper) diff --git a/x/circuit/module.go b/x/circuit/module.go index 182e81737692..dd49a874e7ce 100644 --- a/x/circuit/module.go +++ b/x/circuit/module.go @@ -33,8 +33,11 @@ import ( const ConsensusVersion = 1 var ( - _ module.AppModuleBasic = AppModuleBasic{} + _ module.AppModuleBasic = AppModule{} _ module.HasGenesis = AppModule{} + _ module.HasServices = AppModule{} + + _ appmodule.AppModule = AppModule{} ) // AppModuleBasic defines the basic application module used by the circuit module. @@ -90,8 +93,6 @@ type AppModule struct { keeper keeper.Keeper } -var _ appmodule.AppModule = AppModule{} - // IsOnePerModuleType implements the depinject.OnePerModuleType interface. func (am AppModule) IsOnePerModuleType() {} diff --git a/x/consensus/module.go b/x/consensus/module.go index 3a962b5b12b3..4df4c60ba3d2 100644 --- a/x/consensus/module.go +++ b/x/consensus/module.go @@ -27,8 +27,10 @@ import ( const ConsensusVersion = 1 var ( - _ module.AppModule = AppModule{} - _ module.AppModuleBasic = AppModuleBasic{} + _ module.AppModuleBasic = AppModule{} + + _ appmodule.AppModule = AppModule{} + _ appmodule.HasServices = AppModule{} ) // AppModuleBasic defines the basic application module used by the consensus module. @@ -63,11 +65,6 @@ type AppModule struct { keeper keeper.Keeper } -var ( - _ appmodule.AppModule = AppModule{} - _ appmodule.HasServices = AppModule{} -) - // IsOnePerModuleType implements the depinject.OnePerModuleType interface. func (am AppModule) IsOnePerModuleType() {} @@ -89,9 +86,6 @@ func NewAppModule(cdc codec.Codec, keeper keeper.Keeper) AppModule { } } -// Name returns the consensus module's name. -func (AppModule) Name() string { return types.ModuleName } - // ConsensusVersion implements AppModule/ConsensusVersion. func (AppModule) ConsensusVersion() uint64 { return ConsensusVersion } diff --git a/x/crisis/module.go b/x/crisis/module.go index a40698d8a6cb..87bb60efa273 100644 --- a/x/crisis/module.go +++ b/x/crisis/module.go @@ -35,7 +35,14 @@ import ( // ConsensusVersion defines the current x/crisis module consensus version. const ConsensusVersion = 2 -var _ module.AppModuleBasic = AppModuleBasic{} +var ( + _ module.AppModuleBasic = AppModule{} + _ module.HasGenesis = AppModule{} + _ module.HasServices = AppModule{} + + _ appmodule.AppModule = AppModule{} + _ appmodule.HasEndBlocker = AppModule{} +) // Module init related flags const ( @@ -114,12 +121,6 @@ func NewAppModule(keeper *keeper.Keeper, skipGenesisInvariants bool, ss exported } } -var ( - _ appmodule.AppModule = AppModule{} - _ appmodule.HasEndBlocker = AppModule{} - _ module.HasGenesis = AppModule{} -) - // IsOnePerModuleType implements the depinject.OnePerModuleType interface. func (am AppModule) IsOnePerModuleType() {} @@ -131,11 +132,6 @@ func AddModuleInitFlags(startCmd *cobra.Command) { startCmd.Flags().Bool(FlagSkipGenesisInvariants, false, "Skip x/crisis invariants check on startup") } -// Name returns the crisis module's name. -func (AppModule) Name() string { - return types.ModuleName -} - // RegisterServices registers module services. func (am AppModule) RegisterServices(cfg module.Configurator) { types.RegisterMsgServer(cfg.MsgServer(), am.keeper) diff --git a/x/distribution/module.go b/x/distribution/module.go index 4fb70658a94a..533a54fbbe4c 100644 --- a/x/distribution/module.go +++ b/x/distribution/module.go @@ -33,8 +33,14 @@ import ( const ConsensusVersion = 4 var ( - _ module.AppModuleBasic = AppModuleBasic{} + _ module.AppModuleBasic = AppModule{} _ module.AppModuleSimulation = AppModule{} + _ module.HasGenesis = AppModule{} + _ module.HasServices = AppModule{} + _ module.HasInvariants = AppModule{} + + _ appmodule.AppModule = AppModule{} + _ appmodule.HasBeginBlocker = AppModule{} ) // AppModuleBasic defines the basic application module used by the distribution module. @@ -114,23 +120,12 @@ func NewAppModule( } } -var ( - _ appmodule.AppModule = AppModule{} - _ appmodule.HasBeginBlocker = AppModule{} - _ module.HasGenesis = AppModule{} -) - // IsOnePerModuleType implements the depinject.OnePerModuleType interface. func (am AppModule) IsOnePerModuleType() {} // IsAppModule implements the appmodule.AppModule interface. func (am AppModule) IsAppModule() {} -// Name returns the distribution module's name. -func (AppModule) Name() string { - return types.ModuleName -} - // RegisterInvariants registers the distribution module invariants. func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) { keeper.RegisterInvariants(ir, am.keeper) diff --git a/x/evidence/module.go b/x/evidence/module.go index 12a24b75cb02..d9bb011ba57c 100644 --- a/x/evidence/module.go +++ b/x/evidence/module.go @@ -30,8 +30,13 @@ import ( ) var ( - _ module.AppModuleBasic = AppModuleBasic{} + _ module.AppModuleBasic = AppModule{} _ module.AppModuleSimulation = AppModule{} + _ module.HasGenesis = AppModule{} + + _ appmodule.AppModule = AppModule{} + _ appmodule.HasServices = AppModule{} + _ appmodule.HasBeginBlocker = AppModule{} ) // ---------------------------------------------------------------------------- @@ -117,24 +122,12 @@ func NewAppModule(keeper keeper.Keeper) AppModule { } } -var ( - _ appmodule.AppModule = AppModule{} - _ appmodule.HasServices = AppModule{} - _ appmodule.HasBeginBlocker = AppModule{} - _ module.HasGenesis = AppModule{} -) - // IsOnePerModuleType implements the depinject.OnePerModuleType interface. func (am AppModule) IsOnePerModuleType() {} // IsAppModule implements the appmodule.AppModule interface. func (am AppModule) IsAppModule() {} -// Name returns the evidence module's name. -func (am AppModule) Name() string { - return am.AppModuleBasic.Name() -} - // RegisterServices registers module services. func (am AppModule) RegisterServices(registrar grpc.ServiceRegistrar) error { types.RegisterMsgServer(registrar, keeper.NewMsgServerImpl(am.keeper)) diff --git a/x/feegrant/module/module.go b/x/feegrant/module/module.go index 287daa903f60..82103c7a81cd 100644 --- a/x/feegrant/module/module.go +++ b/x/feegrant/module/module.go @@ -28,8 +28,13 @@ import ( ) var ( - _ module.AppModuleBasic = AppModuleBasic{} + _ module.AppModuleBasic = AppModule{} _ module.AppModuleSimulation = AppModule{} + _ module.HasServices = AppModule{} + _ module.HasGenesis = AppModule{} + + _ appmodule.AppModule = AppModule{} + _ appmodule.HasEndBlocker = AppModule{} ) // ---------------------------------------------------------------------------- @@ -104,6 +109,7 @@ func (ab AppModuleBasic) GetTxCmd() *cobra.Command { // AppModule implements an application module for the feegrant module. type AppModule struct { AppModuleBasic + keeper keeper.Keeper accountKeeper feegrant.AccountKeeper bankKeeper feegrant.BankKeeper @@ -121,23 +127,12 @@ func NewAppModule(cdc codec.Codec, ak feegrant.AccountKeeper, bk feegrant.BankKe } } -var ( - _ appmodule.AppModule = AppModule{} - _ appmodule.HasEndBlocker = AppModule{} - _ module.HasGenesis = AppModule{} -) - // IsOnePerModuleType implements the depinject.OnePerModuleType interface. func (am AppModule) IsOnePerModuleType() {} // IsAppModule implements the appmodule.AppModule interface. func (am AppModule) IsAppModule() {} -// Name returns the feegrant module's name. -func (AppModule) Name() string { - return feegrant.ModuleName -} - // InitGenesis performs genesis initialization for the feegrant module. It returns // no validator updates. func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, bz json.RawMessage) { diff --git a/x/genutil/module.go b/x/genutil/module.go index 11d613d3c7c3..5d3337ba24ab 100644 --- a/x/genutil/module.go +++ b/x/genutil/module.go @@ -21,8 +21,10 @@ import ( ) var ( + _ module.AppModuleBasic = AppModule{} _ module.HasABCIGenesis = AppModule{} - _ module.AppModuleBasic = AppModuleBasic{} + + _ appmodule.AppModule = AppModule{} ) // AppModuleBasic defines the basic application module used by the genutil module. @@ -91,8 +93,6 @@ func NewAppModule(accountKeeper types.AccountKeeper, }) } -var _ appmodule.AppModule = AppModule{} - // IsOnePerModuleType implements the depinject.OnePerModuleType interface. func (AppModule) IsOnePerModuleType() {} diff --git a/x/gov/module.go b/x/gov/module.go index 0309564f466a..a30b718ca1e2 100644 --- a/x/gov/module.go +++ b/x/gov/module.go @@ -42,6 +42,11 @@ var ( _ module.AppModuleBasic = AppModuleBasic{} _ module.AppModuleSimulation = AppModule{} _ module.HasGenesis = AppModule{} + _ module.HasServices = AppModule{} + _ module.HasInvariants = AppModule{} + + _ appmodule.AppModule = AppModule{} + _ appmodule.HasEndBlocker = AppModule{} ) // AppModuleBasic defines the basic application module used by the gov module. @@ -148,11 +153,6 @@ func NewAppModule( } } -var ( - _ appmodule.AppModule = AppModule{} - _ appmodule.HasEndBlocker = AppModule{} -) - // IsOnePerModuleType implements the depinject.OnePerModuleType interface. func (am AppModule) IsOnePerModuleType() {} @@ -267,11 +267,6 @@ func InvokeSetHooks(keeper *keeper.Keeper, govHooks map[string]govtypes.GovHooks return nil } -// Name returns the gov module's name. -func (AppModule) Name() string { - return govtypes.ModuleName -} - // RegisterInvariants registers module invariants func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) { keeper.RegisterInvariants(ir, am.keeper, am.bankKeeper) diff --git a/x/group/module/module.go b/x/group/module/module.go index 46bfa2a583c0..889d22ab1787 100644 --- a/x/group/module/module.go +++ b/x/group/module/module.go @@ -31,8 +31,14 @@ import ( const ConsensusVersion = 2 var ( - _ module.AppModuleBasic = AppModuleBasic{} + _ module.AppModuleBasic = AppModule{} _ module.AppModuleSimulation = AppModule{} + _ module.HasGenesis = AppModule{} + _ module.HasServices = AppModule{} + _ module.HasInvariants = AppModule{} + + _ appmodule.AppModule = AppModule{} + _ appmodule.HasEndBlocker = AppModule{} ) type AppModule struct { @@ -54,12 +60,6 @@ func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, ak group.AccountKeeper, } } -var ( - _ appmodule.AppModule = AppModule{} - _ appmodule.HasEndBlocker = AppModule{} - _ module.HasGenesis = AppModule{} -) - // IsOnePerModuleType implements the depinject.OnePerModuleType interface. func (am AppModule) IsOnePerModuleType() {} @@ -113,11 +113,6 @@ func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { group.RegisterLegacyAminoCodec(cdc) } -// Name returns the group module's name. -func (AppModule) Name() string { - return group.ModuleName -} - // RegisterInvariants does nothing, there are no invariants to enforce func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) { keeper.RegisterInvariants(ir, am.keeper) diff --git a/x/mint/module.go b/x/mint/module.go index 6eeb04e9e387..5a90a517b1c3 100644 --- a/x/mint/module.go +++ b/x/mint/module.go @@ -29,8 +29,13 @@ import ( const ConsensusVersion = 2 var ( - _ module.AppModuleBasic = AppModuleBasic{} + _ module.AppModuleBasic = AppModule{} _ module.AppModuleSimulation = AppModule{} + _ module.HasGenesis = AppModule{} + _ module.HasServices = AppModule{} + + _ appmodule.AppModule = AppModule{} + _ appmodule.HasBeginBlocker = AppModule{} ) // AppModuleBasic defines the basic application module used by the mint module. @@ -38,8 +43,6 @@ type AppModuleBasic struct { cdc codec.Codec } -var _ module.AppModuleBasic = AppModuleBasic{} - // Name returns the mint module's name. func (AppModuleBasic) Name() string { return types.ModuleName @@ -115,23 +118,12 @@ func NewAppModule( } } -var ( - _ appmodule.AppModule = AppModule{} - _ appmodule.HasBeginBlocker = AppModule{} - _ module.HasGenesis = AppModule{} -) - // IsOnePerModuleType implements the depinject.OnePerModuleType interface. func (am AppModule) IsOnePerModuleType() {} // IsAppModule implements the appmodule.AppModule interface. func (am AppModule) IsAppModule() {} -// Name returns the mint module's name. -func (AppModule) Name() string { - return types.ModuleName -} - // RegisterServices registers a gRPC query service to respond to the // module-specific gRPC queries. func (am AppModule) RegisterServices(cfg module.Configurator) { diff --git a/x/nft/module/module.go b/x/nft/module/module.go index 5f75d0ff08fd..9338870b0dbd 100644 --- a/x/nft/module/module.go +++ b/x/nft/module/module.go @@ -28,9 +28,12 @@ import ( ) var ( - _ module.AppModule = AppModule{} - _ module.AppModuleBasic = AppModuleBasic{} + _ module.AppModuleBasic = AppModule{} _ module.AppModuleSimulation = AppModule{} + _ module.HasGenesis = AppModule{} + + _ appmodule.AppModule = AppModule{} + _ appmodule.HasServices = AppModule{} ) // AppModuleBasic defines the basic application module used by the nft module. @@ -109,23 +112,12 @@ func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, ak nft.AccountKeeper, b } } -var ( - _ appmodule.AppModule = AppModule{} - _ appmodule.HasServices = AppModule{} - _ module.HasGenesis = AppModule{} -) - // IsOnePerModuleType implements the depinject.OnePerModuleType interface. func (am AppModule) IsOnePerModuleType() {} // IsAppModule implements the appmodule.AppModule interface. func (am AppModule) IsAppModule() {} -// Name returns the nft module's name. -func (AppModule) Name() string { - return nft.ModuleName -} - // InitGenesis performs genesis initialization for the nft module. It returns // no validator updates. func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) { diff --git a/x/params/module.go b/x/params/module.go index ada51ae1e7dd..8dfe121bea9b 100644 --- a/x/params/module.go +++ b/x/params/module.go @@ -22,9 +22,11 @@ import ( ) var ( - _ module.AppModule = AppModule{} - _ module.AppModuleBasic = AppModuleBasic{} + _ module.AppModuleBasic = AppModule{} _ module.AppModuleSimulation = AppModule{} + _ module.HasServices = AppModule{} + + _ appmodule.AppModule = AppModule{} ) // ConsensusVersion defines the current x/params module consensus version. @@ -69,8 +71,6 @@ func NewAppModule(k keeper.Keeper) AppModule { } } -var _ appmodule.AppModule = AppModule{} - // IsOnePerModuleType implements the depinject.OnePerModuleType interface. func (am AppModule) IsOnePerModuleType() {} diff --git a/x/slashing/module.go b/x/slashing/module.go index 8d8af2e505bb..93a954835c7f 100644 --- a/x/slashing/module.go +++ b/x/slashing/module.go @@ -33,8 +33,13 @@ import ( const ConsensusVersion = 4 var ( - _ module.AppModuleBasic = AppModuleBasic{} + _ module.AppModuleBasic = AppModule{} _ module.AppModuleSimulation = AppModule{} + _ module.HasGenesis = AppModule{} + _ module.HasServices = AppModule{} + + _ appmodule.AppModule = AppModule{} + _ appmodule.HasBeginBlocker = AppModule{} ) // AppModuleBasic defines the basic application module used by the slashing module. @@ -42,8 +47,6 @@ type AppModuleBasic struct { cdc codec.Codec } -var _ module.AppModuleBasic = AppModuleBasic{} - // Name returns the slashing module's name. func (AppModuleBasic) Name() string { return types.ModuleName @@ -122,23 +125,12 @@ func NewAppModule( } } -var ( - _ appmodule.AppModule = AppModule{} - _ appmodule.HasBeginBlocker = AppModule{} - _ module.HasGenesis = AppModule{} -) - // IsOnePerModuleType implements the depinject.OnePerModuleType interface. func (am AppModule) IsOnePerModuleType() {} // IsAppModule implements the appmodule.AppModule interface. func (am AppModule) IsAppModule() {} -// Name returns the slashing module's name. -func (AppModule) Name() string { - return types.ModuleName -} - // RegisterServices registers module services. func (am AppModule) RegisterServices(cfg module.Configurator) { types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper)) diff --git a/x/staking/module.go b/x/staking/module.go index 1e0809cf1d3e..196114037ca7 100644 --- a/x/staking/module.go +++ b/x/staking/module.go @@ -36,11 +36,15 @@ const ( ) var ( - _ appmodule.AppModule = AppModule{} - _ appmodule.HasBeginBlocker = AppModule{} - _ module.HasABCIEndblock = AppModule{} _ module.AppModuleBasic = AppModuleBasic{} _ module.AppModuleSimulation = AppModule{} + _ module.HasServices = AppModule{} + _ module.HasInvariants = AppModule{} + _ module.HasABCIGenesis = AppModule{} + _ module.HasABCIEndBlock = AppModule{} + + _ appmodule.AppModule = AppModule{} + _ appmodule.HasBeginBlocker = AppModule{} ) // AppModuleBasic defines the basic application module used by the staking module. @@ -49,8 +53,6 @@ type AppModuleBasic struct { ak types.AccountKeeper } -var _ module.AppModuleBasic = AppModuleBasic{} - // Name returns the staking module's name. func (AppModuleBasic) Name() string { return types.ModuleName @@ -123,22 +125,12 @@ func NewAppModule( } } -var ( - _ appmodule.AppModule = AppModule{} - _ appmodule.HasBeginBlocker = AppModule{} -) - // IsOnePerModuleType implements the depinject.OnePerModuleType interface. func (am AppModule) IsOnePerModuleType() {} // IsAppModule implements the appmodule.AppModule interface. func (am AppModule) IsAppModule() {} -// Name returns the staking module's name. -func (AppModule) Name() string { - return types.ModuleName -} - // RegisterInvariants registers the staking module invariants. func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) { keeper.RegisterInvariants(ir, am.keeper) diff --git a/x/upgrade/module.go b/x/upgrade/module.go index 7d73cfc2e80e..d96566f3d242 100644 --- a/x/upgrade/module.go +++ b/x/upgrade/module.go @@ -38,7 +38,14 @@ func init() { // ConsensusVersion defines the current x/upgrade module consensus version. const ConsensusVersion uint64 = 3 -var _ module.AppModuleBasic = AppModuleBasic{} +var ( + _ module.AppModuleBasic = AppModule{} + _ module.HasGenesis = AppModule{} + _ module.HasServices = AppModule{} + + _ appmodule.AppModule = AppModule{} + _ appmodule.HasPreBlocker = AppModule{} +) // AppModuleBasic implements the sdk.AppModuleBasic interface type AppModuleBasic struct { @@ -86,12 +93,6 @@ func NewAppModule(keeper *keeper.Keeper, ac address.Codec) AppModule { } } -var ( - _ appmodule.AppModule = AppModule{} - _ appmodule.HasPreBlocker = AppModule{} - _ module.HasGenesis = AppModule{} -) - // IsOnePerModuleType implements the depinject.OnePerModuleType interface. func (am AppModule) IsOnePerModuleType() {}