Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(bank/v2): create module boilerplate #21559

Merged
merged 9 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
/x/auth/ @facundomedica @testinginprod @aaronc @cosmos/sdk-core-dev
/x/authz/ @akhilkumarpilli @raynaudoe @cosmos/sdk-core-dev
/x/bank/ @julienrbrt @sontrinh16 @cosmos/sdk-core-dev
/x/bank/v2 @julienrbrt @hieuvubk @akhilkumarpilli @cosmos/sdk-core-dev
/x/circuit/ @kocubinski @akhilkumarpilli @raynaudoe @cosmos/sdk-core-dev
/x/consensus/ @testinginprod @raynaudoe @cosmos/sdk-core-dev
/x/distribution/ @alpe @JulianToledano @cosmos/sdk-core-dev
Expand Down
9 changes: 9 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,15 @@ updates:
labels:
- "A:automerge"
- dependencies
- package-ecosystem: gomod
directory: "/x/bank"
schedule:
interval: weekly
day: wednesday
time: "03:20"
labels:
- "A:automerge"
- dependencies

# Dependencies should be up to date on release branch
- package-ecosystem: gomod
Expand Down
2 changes: 2 additions & 0 deletions .github/pr_labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
- x/authz/**/*
"C:x/bank":
- x/bank/**/*
"C:x/bank/v2":
- x/bank/v2/**/*
"C:x/circuit":
- x/circuit/**/*
"C:x/consensus":
Expand Down
5 changes: 5 additions & 0 deletions scripts/protocgen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,9 @@ done
cp -r github.com/cosmos/cosmos-sdk/* ./
rm -rf github.com

# UNTIL WE FIGURE OUT ABOUT COSMOSSDK.IO/API, DO NOT GENERATE PULSAR FILES FOR NEW MODULES
# unfortunately, there is no way to do it nicely directly in the buf.gen.pulsar.yaml file (https://github.com/bufbuild/buf/issues/224)
rm -r api/cosmos/bank/v2
rm -r api/cosmos/bank/module/v2

go mod tidy
12 changes: 7 additions & 5 deletions simapp/app_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ import (
_ "cosmossdk.io/x/authz/module" // import for side-effects
_ "cosmossdk.io/x/bank" // import for side-effects
banktypes "cosmossdk.io/x/bank/types"
_ "cosmossdk.io/x/bank/v2" // import for side-effects
bankv2types "cosmossdk.io/x/bank/v2/types"
bankmodulev2 "cosmossdk.io/x/bank/v2/types/module"
_ "cosmossdk.io/x/circuit" // import for side-effects
circuittypes "cosmossdk.io/x/circuit/types"
_ "cosmossdk.io/x/consensus" // import for side-effects
Expand Down Expand Up @@ -66,8 +69,7 @@ import (

"github.com/cosmos/cosmos-sdk/runtime"
_ "github.com/cosmos/cosmos-sdk/testutil/x/counter" // import for side-effects
countertypes "github.com/cosmos/cosmos-sdk/testutil/x/counter/types"
_ "github.com/cosmos/cosmos-sdk/x/auth/tx/config" // import for side-effects
_ "github.com/cosmos/cosmos-sdk/x/auth/tx/config" // import for side-effects
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
_ "github.com/cosmos/cosmos-sdk/x/auth/vesting" // import for side-effects
vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
Expand Down Expand Up @@ -153,6 +155,7 @@ var (
accounts.ModuleName,
authtypes.ModuleName,
banktypes.ModuleName,
bankv2types.ModuleName,
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure correct integration of bank/v2 module in the application configuration.

The configuration for bankv2types.ModuleName and bankmodulev2.Module has been added to the application's module configuration. This is a crucial part of integrating the new module into the application, ensuring it is loaded and configured correctly at runtime.

  • Verify that bankv2types.ModuleName and bankmodulev2.Module are correctly defined and that they integrate seamlessly with the rest of the application.
  • Check for potential conflicts or issues with other modules, especially those that might interact with the bank module.

Given the complexity and importance of this integration, consider adding more detailed unit tests to cover the new configurations and ensure they do not disrupt existing functionalities.

Would you like me to help draft some unit tests for this new module configuration?

Also applies to: 291-292

distrtypes.ModuleName,
stakingtypes.ModuleName,
slashingtypes.ModuleName,
Expand Down Expand Up @@ -284,10 +287,9 @@ var (
Name: epochstypes.ModuleName,
Config: appconfig.WrapAny(&epochsmodulev1.Module{}),
},
// This module is only used for testing the depinject gogo x pulsar module registration.
Copy link
Member Author

Choose a reason for hiding this comment

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

bank/v2 uses gogoproto for app config, so we don't need to test with counter

{
Name: countertypes.ModuleName,
Config: appconfig.WrapAny(&countertypes.Module{}),
Name: bankv2types.ModuleName,
Config: appconfig.WrapAny(&bankmodulev2.Module{}),
},
},
})
Expand Down
3 changes: 3 additions & 0 deletions simapp/app_di.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"cosmossdk.io/x/accounts"
authzkeeper "cosmossdk.io/x/authz/keeper"
bankkeeper "cosmossdk.io/x/bank/keeper"
bankv2keeper "cosmossdk.io/x/bank/v2/keeper"
circuitkeeper "cosmossdk.io/x/circuit/keeper"
consensuskeeper "cosmossdk.io/x/consensus/keeper"
distrkeeper "cosmossdk.io/x/distribution/keeper"
Expand Down Expand Up @@ -74,6 +75,7 @@ type SimApp struct {
AccountsKeeper accounts.Keeper
AuthKeeper authkeeper.AccountKeeper
BankKeeper bankkeeper.Keeper
BankV2Keeper *bankv2keeper.Keeper
StakingKeeper *stakingkeeper.Keeper
SlashingKeeper slashingkeeper.Keeper
MintKeeper mintkeeper.Keeper
Expand Down Expand Up @@ -184,6 +186,7 @@ func NewSimApp(
&app.AuthKeeper,
&app.AccountsKeeper,
&app.BankKeeper,
&app.BankV2Keeper,
&app.StakingKeeper,
&app.SlashingKeeper,
&app.MintKeeper,
Expand Down
4 changes: 2 additions & 2 deletions simapp/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import (
"cosmossdk.io/core/appmodule"
corestore "cosmossdk.io/core/store"
"cosmossdk.io/x/accounts"
bankv2types "cosmossdk.io/x/bank/v2/types"
epochstypes "cosmossdk.io/x/epochs/types"
protocolpooltypes "cosmossdk.io/x/protocolpool/types"
upgradetypes "cosmossdk.io/x/upgrade/types"

countertypes "github.com/cosmos/cosmos-sdk/testutil/x/counter/types"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
)

Expand Down Expand Up @@ -47,7 +47,7 @@ func (app SimApp) RegisterUpgradeHandlers() {
accounts.StoreKey,
protocolpooltypes.StoreKey,
epochstypes.StoreKey,
countertypes.StoreKey, // This module is used for testing purposes only.
bankv2types.ModuleName,
},
Deleted: []string{"crisis"}, // The SDK discontinued the crisis module in v0.52.0
}
Expand Down
8 changes: 8 additions & 0 deletions simapp/v2/app_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ import (
_ "cosmossdk.io/x/authz/module" // import for side-effects
_ "cosmossdk.io/x/bank" // import for side-effects
banktypes "cosmossdk.io/x/bank/types"
_ "cosmossdk.io/x/bank/v2" // import for side-effects
bankv2types "cosmossdk.io/x/bank/v2/types"
bankmodulev2 "cosmossdk.io/x/bank/v2/types/module"
_ "cosmossdk.io/x/circuit" // import for side-effects
circuittypes "cosmossdk.io/x/circuit/types"
_ "cosmossdk.io/x/consensus" // import for side-effects
Expand Down Expand Up @@ -151,6 +154,7 @@ var (
accounts.ModuleName,
authtypes.ModuleName,
banktypes.ModuleName,
bankv2types.ModuleName,
distrtypes.ModuleName,
stakingtypes.ModuleName,
slashingtypes.ModuleName,
Expand Down Expand Up @@ -283,6 +287,10 @@ var (
Name: epochstypes.ModuleName,
Config: appconfig.WrapAny(&epochsmodulev1.Module{}),
},
{
Name: bankv2types.ModuleName,
Config: appconfig.WrapAny(&bankmodulev2.Module{}),
},
},
})
)
3 changes: 3 additions & 0 deletions simapp/v2/app_di.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"cosmossdk.io/x/accounts"
authzkeeper "cosmossdk.io/x/authz/keeper"
bankkeeper "cosmossdk.io/x/bank/keeper"
bankv2keeper "cosmossdk.io/x/bank/v2/keeper"
circuitkeeper "cosmossdk.io/x/circuit/keeper"
consensuskeeper "cosmossdk.io/x/consensus/keeper"
distrkeeper "cosmossdk.io/x/distribution/keeper"
Expand Down Expand Up @@ -56,6 +57,7 @@ type SimApp[T transaction.Tx] struct {
AccountsKeeper accounts.Keeper
AuthKeeper authkeeper.AccountKeeper
BankKeeper bankkeeper.Keeper
BankV2Keeper *bankv2keeper.Keeper
StakingKeeper *stakingkeeper.Keeper
SlashingKeeper slashingkeeper.Keeper
MintKeeper mintkeeper.Keeper
Expand Down Expand Up @@ -165,6 +167,7 @@ func NewSimApp[T transaction.Tx](
&app.interfaceRegistry,
&app.AuthKeeper,
&app.BankKeeper,
&app.BankV2Keeper,
&app.StakingKeeper,
&app.SlashingKeeper,
&app.MintKeeper,
Expand Down
2 changes: 2 additions & 0 deletions simapp/v2/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"cosmossdk.io/core/appmodule"
"cosmossdk.io/core/store"
"cosmossdk.io/x/accounts"
bankv2types "cosmossdk.io/x/bank/v2/types"
protocolpooltypes "cosmossdk.io/x/protocolpool/types"
upgradetypes "cosmossdk.io/x/upgrade/types"
)
Expand Down Expand Up @@ -36,6 +37,7 @@ func (app *SimApp[T]) RegisterUpgradeHandlers() {
Added: []string{
accounts.ModuleName,
protocolpooltypes.ModuleName,
bankv2types.ModuleName,
},
Deleted: []string{"crisis"}, // The SDK discontinued the crisis module in v0.52.0
}
Expand Down
3 changes: 2 additions & 1 deletion x/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Here are some production-grade modules that can be used in Cosmos SDK applicatio
* [Auth](./auth/README.md) - Authentication of accounts and transactions for Cosmos SDK applications.
* [Authz](./authz/README.md) - Authorization for accounts to perform actions on behalf of other accounts.
* [Bank](./bank/README.md) - Token transfer functionalities.
* [Bank v2](./bank/v2/README.md) - Token transfer functionalities, enhanced.
* [Circuit](./circuit/README.md) - Circuit breaker module for pausing messages.
* [Consensus](./consensus/README.md) - Consensus module for modifying CometBFT's ABCI consensus params.
* [Distribution](./distribution/README.md) - Fee distribution, and staking token provision distribution.
Expand All @@ -23,7 +24,7 @@ Here are some production-grade modules that can be used in Cosmos SDK applicatio
* [Protocolpool](./protocolpool/README.md) - Functionalities handling community pool funds.
* [Slashing](./slashing/README.md) - Validator punishment mechanisms.
* [Staking](./staking/README.md) - Proof-of-Stake layer for public blockchains.
* [tx](./tx/README.md) - Tx utilities for the Cosmos SDK.
* [Tx](./tx/README.md) - Tx utilities for the Cosmos SDK.
* [Upgrade](./upgrade/README.md) - Software upgrades handling and coordination.

To learn more about the process of building modules, visit the [building modules reference documentation](https://docs.cosmos.network/main/building-modules/intro).
Expand Down
17 changes: 17 additions & 0 deletions x/bank/proto/cosmos/bank/module/v2/module.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
syntax = "proto3";

package cosmos.bank.module.v2;

import "cosmos/app/v1alpha1/module.proto";

option go_package = "cosmossdk.io/x/bank/v2/types/module";

// Module is the config object of the bank module.
message Module {
option (cosmos.app.v1alpha1.module) = {
go_import: "cosmossdk.io/x/bank/v2"
};

// authority defines the custom module authority. If not set, defaults to the governance module.
string authority = 1;
}
7 changes: 7 additions & 0 deletions x/bank/proto/cosmos/bank/v2/bank.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
syntax = "proto3";
package cosmos.bank.v2;
Copy link
Contributor

Choose a reason for hiding this comment

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

Directory structure does not match package declaration.

According to the static analysis tool, files with the package cosmos.bank.v2 should be within a directory cosmos/bank/v2 relative to the root but were found in x/bank/proto/cosmos/bank/v2. Consider restructuring the directories to align with the package name to avoid potential build and import issues.

Tools
buf

2-2: Files with package "cosmos.bank.v2" must be within a directory "cosmos/bank/v2" relative to root but were in directory "x/bank/proto/cosmos/bank/v2".

(PACKAGE_DIRECTORY_MATCH)


option go_package = "cosmossdk.io/x/bank/v2/types";

// Params defines the parameters for the bank/v2 module.
message Params {}
14 changes: 14 additions & 0 deletions x/bank/proto/cosmos/bank/v2/genesis.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
syntax = "proto3";
package cosmos.bank.v2;

import "gogoproto/gogo.proto";
import "cosmos/bank/v2/bank.proto";
import "amino/amino.proto";

option go_package = "cosmossdk.io/x/bank/v2/types";

// GenesisState defines the bank/v2 module's genesis state.
message GenesisState {
// params defines all the parameters of the module.
Params params = 1 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true];
}
28 changes: 28 additions & 0 deletions x/bank/proto/cosmos/bank/v2/query.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
syntax = "proto3";
package cosmos.bank.v2;

import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "cosmos/query/v1/query.proto";
import "amino/amino.proto";
import "cosmos/bank/v2/bank.proto";

option go_package = "cosmossdk.io/x/bank/v2/types";

// Query defines the gRPC querier service.
service Query {
// Params queries the parameters of x/bank module.
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
option (cosmos.query.v1.module_query_safe) = true;
option (google.api.http).get = "/cosmos/bank/v2/params";
}
}

// QueryParamsRequest defines the request type for querying x/bank/v2 parameters.
message QueryParamsRequest {}

// QueryParamsResponse defines the response type for querying x/bank/v2 parameters.
message QueryParamsResponse {
// params provides the parameters of the bank module.
Params params = 1 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true];
}
34 changes: 34 additions & 0 deletions x/bank/proto/cosmos/bank/v2/tx.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
syntax = "proto3";
package cosmos.bank.v2;

import "gogoproto/gogo.proto";
Copy link
Contributor

Choose a reason for hiding this comment

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

Issue: Missing import file.

The import statement for "gogoproto/gogo.proto" is flagged by static analysis tools as not existing. This could be a configuration issue or a missing file in the project setup.

Please verify the existence of the gogoproto/gogo.proto file or adjust the import paths accordingly.

Tools
buf

4-4: import "gogoproto/gogo.proto": file does not exist

(COMPILE)

import "cosmos/bank/v2/bank.proto";
import "cosmos_proto/cosmos.proto";
import "cosmos/msg/v1/msg.proto";
import "amino/amino.proto";

option go_package = "cosmossdk.io/x/bank/v2/types";

// Msg defines the bank Msg service.
service Msg {
option (cosmos.msg.v1.service) = true;

// UpdateParams defines a governance operation for updating the x/bank/v2 module parameters.
// The authority is defined in the keeper.
rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse) {}
}

// MsgUpdateParams is the Msg/UpdateParams request type.
message MsgUpdateParams {
option (cosmos.msg.v1.signer) = "authority";

julienrbrt marked this conversation as resolved.
Show resolved Hide resolved
// authority is the address that controls the module (defaults to x/gov unless overwritten).
string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];

// params defines the x/bank parameters to update.
// NOTE: All parameters must be supplied.
Params params = 2 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true];
}

// MsgUpdateParamsResponse defines the response structure for executing a MsgUpdateParams message.
message MsgUpdateParamsResponse {}
26 changes: 26 additions & 0 deletions x/bank/v2/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!--
Guiding Principles:
Changelogs are for humans, not machines.
There should be an entry for every single version.
The same types of changes should be grouped.
Versions and sections should be linkable.
The latest version comes first.
The release date of each version is displayed.
Mention whether you follow Semantic Versioning.
Usage:
Change log entries are to be added to the Unreleased section under the
appropriate stanza (see below). Each entry should ideally include a tag and
the Github issue reference in the following format:
* (<tag>) [#<issue-number>] Changelog message.
Types of changes (Stanzas):
"Features" for new features.
"Improvements" for changes in existing functionality.
"Deprecated" for soon-to-be removed features.
"Bug Fixes" for any bug fixes.
"API Breaking" for breaking exported APIs used by developers building on SDK.
Ref: https://keepachangelog.com/en/1.0.0/
-->

# Changelog

## [Unreleased]
5 changes: 5 additions & 0 deletions x/bank/v2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
julienrbrt marked this conversation as resolved.
Show resolved Hide resolved
sidebar_position: 1
---

# `x/bank/v2`
40 changes: 40 additions & 0 deletions x/bank/v2/autocli.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package bankv2

import (
"fmt"

autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
"cosmossdk.io/x/bank/v2/types"

"github.com/cosmos/cosmos-sdk/version"
)

// AutoCLIOptions implements the autocli.HasAutoCLIConfig interface.
func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions {
return &autocliv1.ModuleOptions{
Query: &autocliv1.ServiceCommandDescriptor{
Service: types.Query_serviceDesc.ServiceName,
RpcCommandOptions: []*autocliv1.RpcCommandOptions{
{
RpcMethod: "Params",
Use: "params",
Short: "Query current bank/v2 parameters",
},
},
},
Tx: &autocliv1.ServiceCommandDescriptor{
Service: types.Msg_serviceDesc.ServiceName,
EnhanceCustomCommand: true,
RpcCommandOptions: []*autocliv1.RpcCommandOptions{
{
RpcMethod: "UpdateParams",
Use: "update-params-proposal <params>",
Short: "Submit a proposal to update bank module params. Note: the entire params must be provided.",
Example: fmt.Sprintf(`%s tx bank update-params-proposal '{ }'`, version.AppName),
PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "params"}},
GovProposal: true,
},
},
},
}
}
Loading
Loading