Skip to content

Commit

Permalink
feat: update crosschain gov v0.47 (bnb-chain#171)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexgao001 authored and yutianwu committed May 3, 2023
1 parent e227539 commit ec555b5
Show file tree
Hide file tree
Showing 32 changed files with 3,232 additions and 327 deletions.
868 changes: 805 additions & 63 deletions api/cosmos/gov/v1/gov.pulsar.go

Large diffs are not rendered by default.

1,152 changes: 1,067 additions & 85 deletions api/cosmos/gov/v1/tx.pulsar.go

Large diffs are not rendered by default.

51 changes: 45 additions & 6 deletions api/cosmos/gov/v1/tx_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions proto/cosmos/gov/v1/gov.proto
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,14 @@ message Params {
// burn deposits if quorum with vote type no_veto is met
bool burn_vote_veto = 15;
}

// CrossChainParamsChange defines the parameter change or contract upgrade
message CrossChainParamsChange {
// parameter to be updated or 'upgrade' for contract upgrade
string key = 1;
// values is a new parameter or slice of new contract addresses in hex format
repeated string values = 2;
// targets defines a slice of addresses string in hex format
repeated string targets = 3;
}

18 changes: 18 additions & 0 deletions proto/cosmos/gov/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ service Msg {
//
// Since: cosmos-sdk 0.47
rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse);

// UpdateCrossChainParams defines a method to send IBC package to update cross-chain params
rpc UpdateCrossChainParams(MsgUpdateCrossChainParams) returns (MsgUpdateCrossChainParamsResponse);
}

// MsgSubmitProposal defines an sdk.Msg type that supports submitting arbitrary
Expand Down Expand Up @@ -170,3 +173,18 @@ message MsgUpdateParams {
//
// Since: cosmos-sdk 0.47
message MsgUpdateParamsResponse {}

// MsgUpdateCrossChainParams for cross chain gov
message MsgUpdateCrossChainParams {
option (cosmos.msg.v1.signer) = "authority";
option (amino.name) = "cosmos-sdk/x/gov/v1/MsgUpdateCrossChainParams";

// authority is the address that controls the module (defaults to x/gov unless overwritten).
string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];

// for cross chain param change or contract upgrade
CrossChainParamsChange params = 2 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true];
}

// MsgUpdateCrossChainParamsResponse defines the response structure for executing a MsgUpdateCrossChainParams message.
message MsgUpdateCrossChainParamsResponse {}
3 changes: 2 additions & 1 deletion simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ func NewSimApp(
// set the governance module account as the authority for conducting upgrades
app.UpgradeKeeper = upgradekeeper.NewKeeper(skipUpgradeHeights, keys[upgradetypes.StoreKey], appCodec, homePath, app.BaseApp, authtypes.NewModuleAddress(govtypes.ModuleName).String())

app.CrossChainKeeper = crosschainkeeper.NewKeeper(appCodec, keys[crosschaintypes.StoreKey], authtypes.NewModuleAddress(govtypes.ModuleName).String())
// Register the proposal types
// Deprecated: Avoid adding new handlers, instead use the new proposal flow
// by granting the governance module the right to execute the message.
Expand All @@ -372,7 +373,7 @@ func NewSimApp(
*/
govKeeper := govkeeper.NewKeeper(
appCodec, keys[govtypes.StoreKey], app.AccountKeeper, app.BankKeeper,
app.StakingKeeper, app.MsgServiceRouter(), govConfig, authtypes.NewModuleAddress(govtypes.ModuleName).String(),
app.StakingKeeper, app.CrossChainKeeper, app.MsgServiceRouter(), govConfig, authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

// Set legacy router for backwards compatibility with gov v1beta1
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/gov/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
_ "github.com/cosmos/cosmos-sdk/x/consensus"
_ "github.com/cosmos/cosmos-sdk/x/crosschain"
_ "github.com/cosmos/cosmos-sdk/x/distribution"
distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper"
distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
Expand Down Expand Up @@ -52,6 +53,7 @@ var appConfig = configurator.NewAppConfig(
configurator.StakingModule(),
configurator.BankModule(),
configurator.GovModule(),
configurator.CrossChainModule(),
configurator.DistributionModule(),
configurator.MintModule(),
configurator.ConsensusModule(),
Expand Down
1 change: 1 addition & 0 deletions tests/integration/gov/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
_ "github.com/cosmos/cosmos-sdk/x/authz/module"
_ "github.com/cosmos/cosmos-sdk/x/crosschain"
_ "github.com/cosmos/cosmos-sdk/x/distribution"
"github.com/cosmos/cosmos-sdk/x/gov/types"
)
Expand Down
58 changes: 58 additions & 0 deletions testutil/configurator/configurator.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ import (
authzmodulev1 "cosmossdk.io/api/cosmos/authz/module/v1"
bankmodulev1 "cosmossdk.io/api/cosmos/bank/module/v1"
consensusmodulev1 "cosmossdk.io/api/cosmos/consensus/module/v1"
crosschainmodulev1 "cosmossdk.io/api/cosmos/crosschain/module/v1"
distrmodulev1 "cosmossdk.io/api/cosmos/distribution/module/v1"
evidencemodulev1 "cosmossdk.io/api/cosmos/evidence/module/v1"
feegrantmodulev1 "cosmossdk.io/api/cosmos/feegrant/module/v1"
genutilmodulev1 "cosmossdk.io/api/cosmos/genutil/module/v1"
govmodulev1 "cosmossdk.io/api/cosmos/gov/module/v1"
groupmodulev1 "cosmossdk.io/api/cosmos/group/module/v1"
mintmodulev1 "cosmossdk.io/api/cosmos/mint/module/v1"
nftmodulev1 "cosmossdk.io/api/cosmos/nft/module/v1"
oraclemodulev1 "cosmossdk.io/api/cosmos/oracle/module/v1"
paramsmodulev1 "cosmossdk.io/api/cosmos/params/module/v1"
slashingmodulev1 "cosmossdk.io/api/cosmos/slashing/module/v1"
stakingmodulev1 "cosmossdk.io/api/cosmos/staking/module/v1"
Expand Down Expand Up @@ -42,6 +47,8 @@ var beginBlockOrder = []string{
"params",
"consensus",
"vesting",
"crosschain",
"oracle",
}

var endBlockersOrder = []string{
Expand All @@ -65,6 +72,8 @@ var endBlockersOrder = []string{
"consensus",
"upgrade",
"vesting",
"crosschain",
"oracle",
}

var initGenesisOrder = []string{
Expand All @@ -88,6 +97,8 @@ var initGenesisOrder = []string{
"consensus",
"upgrade",
"vesting",
"crosschain",
"oracle",
}

type appConfig struct {
Expand Down Expand Up @@ -119,6 +130,8 @@ func AuthModule() ModuleOption {
{Account: "bonded_tokens_pool", Permissions: []string{"burner", "staking"}},
{Account: "not_bonded_tokens_pool", Permissions: []string{"burner", "staking"}},
{Account: "gov", Permissions: []string{"burner"}},
{Account: "nft"},
{Account: "crosschain", Permissions: []string{"minter"}},
},
}),
}
Expand Down Expand Up @@ -239,6 +252,51 @@ func MintModule() ModuleOption {
}
}

func EvidenceModule() ModuleOption {
return func(config *appConfig) {
config.moduleConfigs["evidence"] = &appv1alpha1.ModuleConfig{
Name: "evidence",
Config: appconfig.WrapAny(&evidencemodulev1.Module{}),
}
}
}

func GroupModule() ModuleOption {
return func(config *appConfig) {
config.moduleConfigs["group"] = &appv1alpha1.ModuleConfig{
Name: "group",
Config: appconfig.WrapAny(&groupmodulev1.Module{}),
}
}
}

func NFTModule() ModuleOption {
return func(config *appConfig) {
config.moduleConfigs["nft"] = &appv1alpha1.ModuleConfig{
Name: "nft",
Config: appconfig.WrapAny(&nftmodulev1.Module{}),
}
}
}

func CrossChainModule() ModuleOption {
return func(config *appConfig) {
config.moduleConfigs["crosschain"] = &appv1alpha1.ModuleConfig{
Name: "crosschain",
Config: appconfig.WrapAny(&crosschainmodulev1.Module{}),
}
}
}

func OracleModule() ModuleOption {
return func(config *appConfig) {
config.moduleConfigs["oracle"] = &appv1alpha1.ModuleConfig{
Name: "oracle",
Config: appconfig.WrapAny(&oraclemodulev1.Module{}),
}
}
}

func OmitInitGenesis() ModuleOption {
return func(config *appConfig) {
config.setInitGenesis = false
Expand Down
3 changes: 3 additions & 0 deletions x/bank/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
"github.com/cosmos/cosmos-sdk/x/bank/testutil"
"github.com/cosmos/cosmos-sdk/x/bank/types"
_ "github.com/cosmos/cosmos-sdk/x/consensus"
_ "github.com/cosmos/cosmos-sdk/x/crosschain"
_ "github.com/cosmos/cosmos-sdk/x/distribution"
_ "github.com/cosmos/cosmos-sdk/x/gov"
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
_ "github.com/cosmos/cosmos-sdk/x/params"
Expand Down Expand Up @@ -115,6 +117,7 @@ func createTestSuite(t *testing.T, genesisAccounts []authtypes.GenesisAccount) s
configurator.ConsensusModule(),
configurator.BankModule(),
configurator.GovModule(),
configurator.CrossChainModule(),
),
startupCfg, &res.BankKeeper, &res.AccountKeeper)

Expand Down
3 changes: 3 additions & 0 deletions x/gov/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
_ "github.com/cosmos/cosmos-sdk/x/bank"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
_ "github.com/cosmos/cosmos-sdk/x/consensus"
_ "github.com/cosmos/cosmos-sdk/x/crosschain"
_ "github.com/cosmos/cosmos-sdk/x/distribution"
"github.com/cosmos/cosmos-sdk/x/gov/keeper"
"github.com/cosmos/cosmos-sdk/x/gov/types"
v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
Expand Down Expand Up @@ -120,6 +122,7 @@ func createTestSuite(t *testing.T) suite {
configurator.BankModule(),
configurator.AuthzModule(),
configurator.GovModule(),
configurator.CrossChainModule(),
configurator.ConsensusModule(),
),
simtestutil.DefaultStartUpConfig(),
Expand Down
9 changes: 7 additions & 2 deletions x/gov/keeper/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func setupGovKeeper(t *testing.T) (
*govtestutil.MockAccountKeeper,
*govtestutil.MockBankKeeper,
*govtestutil.MockStakingKeeper,
*govtestutil.MockCrossChainKeeper,
moduletestutil.TestEncodingConfig,
sdk.Context,
) {
Expand All @@ -69,6 +70,8 @@ func setupGovKeeper(t *testing.T) (
acctKeeper := govtestutil.NewMockAccountKeeper(ctrl)
bankKeeper := govtestutil.NewMockBankKeeper(ctrl)
stakingKeeper := govtestutil.NewMockStakingKeeper(ctrl)
crossChainKeeper := govtestutil.NewMockCrossChainKeeper(ctrl)

acctKeeper.EXPECT().GetModuleAddress(types.ModuleName).Return(govAcct).AnyTimes()
acctKeeper.EXPECT().GetModuleAccount(gomock.Any(), types.ModuleName).Return(authtypes.NewEmptyModuleAccount(types.ModuleName)).AnyTimes()
trackMockBalances(bankKeeper)
Expand All @@ -81,19 +84,21 @@ func setupGovKeeper(t *testing.T) (
stakingKeeper.EXPECT().TotalBondedTokens(gomock.Any()).Return(math.NewInt(10000000)).AnyTimes()

// Gov keeper initializations
govKeeper := keeper.NewKeeper(encCfg.Codec, key, acctKeeper, bankKeeper, stakingKeeper, msr, types.DefaultConfig(), govAcct.String())
govKeeper := keeper.NewKeeper(encCfg.Codec, key, acctKeeper, bankKeeper, stakingKeeper, crossChainKeeper, msr, types.DefaultConfig(), govAcct.String())
govKeeper.SetProposalID(ctx, 1)
govRouter := v1beta1.NewRouter() // Also register legacy gov handlers to test them too.
govRouter.AddRoute(types.RouterKey, v1beta1.ProposalHandler)
govKeeper.SetLegacyRouter(govRouter)
govKeeper.SetParams(ctx, v1.DefaultParams())

crossChainKeeper.EXPECT().CreateRawIBCPackageWithFee(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(uint64(0), nil).AnyTimes()

// Register all handlers for the MegServiceRouter.
msr.SetInterfaceRegistry(encCfg.InterfaceRegistry)
v1.RegisterMsgServer(msr, keeper.NewMsgServerImpl(govKeeper))
banktypes.RegisterMsgServer(msr, nil) // Nil is fine here as long as we never execute the proposal's Msgs.

return govKeeper, acctKeeper, bankKeeper, stakingKeeper, encCfg, ctx
return govKeeper, acctKeeper, bankKeeper, stakingKeeper, crossChainKeeper, encCfg, ctx
}

// trackMockBalances sets up expected calls on the Mock BankKeeper, and also
Expand Down
Loading

0 comments on commit ec555b5

Please sign in to comment.