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

refactor: Vaguely named consumer structs #1288

Merged
merged 10 commits into from
Sep 15, 2023
Merged
3 changes: 2 additions & 1 deletion app/consumer-democracy/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"

Check failure on line 82 in app/consumer-democracy/app.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default -s blank -s dot -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) -s prefix(github.com/cometbft/cometbft) -s prefix(github.com/cosmos/interchain-security) --custom-order (gci)
// add mint
mint "github.com/cosmos/cosmos-sdk/x/mint"
mintkeeper "github.com/cosmos/cosmos-sdk/x/mint/keeper"
Expand Down Expand Up @@ -713,7 +714,7 @@
return fromVM, fmt.Errorf("failed to unmarshal genesis state: %w", err)
}

consumerGenesis := ccvtypes.GenesisState{}
consumerGenesis := ccvtypes.ConsumerGenesisState{}
appCodec.MustUnmarshalJSON(appState[consumertypes.ModuleName], &consumerGenesis)

consumerGenesis.PreCCV = true
Expand Down
2 changes: 1 addition & 1 deletion proto/interchain_security/ccv/consumer/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
// QueryParamsResponse is response type for the Query/Params RPC method.
message QueryParamsResponse {
// params holds all the parameters of this module.
interchain_security.ccv.v1.Params params = 1 [ (gogoproto.nullable) = false ];
interchain_security.ccv.v1.ConsumerParams params = 1 [ (gogoproto.nullable) = false ];

Check failure on line 58 in proto/interchain_security/ccv/consumer/v1/query.proto

View workflow job for this annotation

GitHub Actions / break-check

Field "1" on message "QueryParamsResponse" changed type from "interchain_security.ccv.v1.Params" to "interchain_security.ccv.v1.ConsumerParams".
}

message QueryProviderInfoRequest {}
Expand Down
2 changes: 1 addition & 1 deletion proto/interchain_security/ccv/provider/v1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
// InitalHeight defines the initial block height for the consumer chain
uint64 initial_height = 4;
// ConsumerGenesis defines the initial consumer chain genesis states
interchain_security.ccv.v1.GenesisState consumer_genesis = 5
interchain_security.ccv.v1.ConsumerGenesisState consumer_genesis = 5

Check failure on line 67 in proto/interchain_security/ccv/provider/v1/genesis.proto

View workflow job for this annotation

GitHub Actions / break-check

Field "5" on message "ConsumerState" changed type from "interchain_security.ccv.v1.GenesisState" to "interchain_security.ccv.v1.ConsumerGenesisState".
[ (gogoproto.nullable) = false ];
// PendingValsetChanges defines the pending validator set changes for the
// consumer chain
Expand Down
2 changes: 1 addition & 1 deletion proto/interchain_security/ccv/provider/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
message QueryConsumerGenesisRequest { string chain_id = 1; }

message QueryConsumerGenesisResponse {
interchain_security.ccv.v1.GenesisState genesis_state = 1
interchain_security.ccv.v1.ConsumerGenesisState genesis_state = 1

Check failure on line 89 in proto/interchain_security/ccv/provider/v1/query.proto

View workflow job for this annotation

GitHub Actions / break-check

Field "1" on message "QueryConsumerGenesisResponse" changed type from "interchain_security.ccv.v1.GenesisState" to "interchain_security.ccv.v1.ConsumerGenesisState".
[ (gogoproto.nullable) = false ];
}

Expand Down
15 changes: 6 additions & 9 deletions proto/interchain_security/ccv/v1/shared_consumer.proto
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
syntax = "proto3";

Check failure on line 1 in proto/interchain_security/ccv/v1/shared_consumer.proto

View workflow job for this annotation

GitHub Actions / break-check

Previously present message "GenesisState" was deleted from file.

Check failure on line 1 in proto/interchain_security/ccv/v1/shared_consumer.proto

View workflow job for this annotation

GitHub Actions / break-check

Previously present message "Params" was deleted from file.

package interchain_security.ccv.v1;

Expand All @@ -17,13 +17,12 @@
// but not sent over the wire. These schemas could change, only with careful consideration of effects!
//

// Params defines the parameters for CCV consumer module.
// ConsumerParams defines the parameters for CCV consumer module.
//
// Note this type is referenced in both the consumer and provider CCV modules,
// and persisted on the provider, see MakeConsumerGenesis and SetConsumerGenesis.
//
// TODO: Rename to ConsumerParams. See https://github.com/cosmos/interchain-security/issues/1206
message Params {
message ConsumerParams {
// TODO: Remove enabled flag and find a better way to setup integration tests
// See: https://github.com/cosmos/interchain-security/issues/339
bool enabled = 1;
Expand Down Expand Up @@ -79,19 +78,17 @@
repeated string provider_reward_denoms = 12;
}

// GenesisState defines the CCV consumer chain genesis state.
// ConsumerGenesisState defines the CCV consumer chain genesis state.
//
// Note this type is referenced in both the consumer and provider CCV modules,
// and persisted on the provider, see MakeConsumerGenesis and SetConsumerGenesis.
//
// TODO: Rename to ConsumerGenesisState. See https://github.com/cosmos/interchain-security/issues/1206
message GenesisState {
Params params = 1 [ (gogoproto.nullable) = false ];
message ConsumerGenesisState {
ConsumerParams params = 1 [ (gogoproto.nullable) = false ];
string provider_client_id = 2; // empty for a new chain, filled in on restart.
string provider_channel_id =
3; // empty for a new chain, filled in on restart.
bool new_chain =
4; // true for new chain GenesisState, false for chain restart.
4; // true for new chain ConsumerConsumerGenesisState, false for chain restart.
bermuell marked this conversation as resolved.
Show resolved Hide resolved
// ProviderClientState filled in on new chain, nil on restart.
ibc.lightclients.tendermint.v1.ClientState provider_client_state = 5;
// ProviderConsensusState filled in on new chain, nil on restart.
Expand Down
4 changes: 2 additions & 2 deletions tests/difference/core/driver/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func (b *Builder) getAppBytesAndSenders(

bondDenom := sdk.DefaultBondDenom
genesisStaking := stakingtypes.GenesisState{}
genesisConsumer := ccv.GenesisState{}
genesisConsumer := ccv.ConsumerGenesisState{}

if genesis[stakingtypes.ModuleName] != nil {
// If staking module genesis already exists
Expand Down Expand Up @@ -522,7 +522,7 @@ func (b *Builder) createConsumersLocalClientGenesis() *ibctmtypes.ClientState {
)
}

func (b *Builder) createConsumerGenesis(client *ibctmtypes.ClientState) *ccv.GenesisState {
func (b *Builder) createConsumerGenesis(client *ibctmtypes.ClientState) *ccv.ConsumerGenesisState {
providerConsState := b.provider().LastHeader.ConsensusState()

valUpdates := tmtypes.TM2PB.ValidatorUpdates(b.provider().Vals)
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func (s *CCVTestSuite) getSentPacket(chain *ibctesting.TestChain, sequence uint6
func initConsumerChain(
s *CCVTestSuite,
chainID string,
genesisState *ccv.GenesisState,
genesisState *ccv.ConsumerGenesisState,
) {
providerKeeper := s.providerApp.GetProviderKeeper()
bundle := s.consumerBundles[chainID]
Expand Down
4 changes: 2 additions & 2 deletions testutil/ibc_testing/specific_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func ConsumerAppIniter(initValPowers []types.ValidatorUpdate) AppIniter {
},
)
// Feed consumer genesis with provider validators
var consumerGenesis ccvtypes.GenesisState
var consumerGenesis ccvtypes.ConsumerGenesisState
encoding.Codec.MustUnmarshalJSON(genesisState[consumertypes.ModuleName], &consumerGenesis)
consumerGenesis.InitialValSet = initValPowers
consumerGenesis.Params.Enabled = true
Expand All @@ -69,7 +69,7 @@ func DemocracyConsumerAppIniter(initValPowers []types.ValidatorUpdate) AppIniter
genesisState := appConsumerDemocracy.NewDefaultGenesisState(encoding.Codec)
// Feed consumer genesis with provider validators
// TODO See if useful for democracy
var consumerGenesis ccvtypes.GenesisState
var consumerGenesis ccvtypes.ConsumerGenesisState
encoding.Codec.MustUnmarshalJSON(genesisState[consumertypes.ModuleName], &consumerGenesis)
consumerGenesis.InitialValSet = initValPowers
consumerGenesis.Params.Enabled = true
Expand Down
4 changes: 2 additions & 2 deletions x/ccv/consumer/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
// 1. A client to the provider was never created, i.e. a new consumer chain is started for the first time.
// 2. A consumer chain restarts after a client to the provider was created, but the CCV channel handshake is still in progress
// 3. A consumer chain restarts after the CCV channel handshake was completed.
func (k Keeper) InitGenesis(ctx sdk.Context, state *ccv.GenesisState) []abci.ValidatorUpdate {
func (k Keeper) InitGenesis(ctx sdk.Context, state *ccv.ConsumerGenesisState) []abci.ValidatorUpdate {
// PreCCV is true during the process of a standalone to consumer changeover.
// At the PreCCV point in the process, the standalone chain has just been upgraded to include
// the consumer ccv module, but the standalone staking keeper is still managing the validator set.
Expand Down Expand Up @@ -115,7 +115,7 @@ func (k Keeper) InitGenesis(ctx sdk.Context, state *ccv.GenesisState) []abci.Val
}

// ExportGenesis returns the CCV consumer module's exported genesis
func (k Keeper) ExportGenesis(ctx sdk.Context) (genesis *ccv.GenesisState) {
func (k Keeper) ExportGenesis(ctx sdk.Context) (genesis *ccv.ConsumerGenesisState) {
params := k.GetConsumerParams(ctx)
if !params.Enabled {
return ccv.DefaultGenesisState()
Expand Down
12 changes: 6 additions & 6 deletions x/ccv/consumer/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ func TestInitGenesis(t *testing.T) {
testCases := []struct {
name string
malleate func(sdk.Context, testkeeper.MockedKeepers)
genesis *ccv.GenesisState
assertStates func(sdk.Context, consumerkeeper.Keeper, *ccv.GenesisState)
genesis *ccv.ConsumerGenesisState
assertStates func(sdk.Context, consumerkeeper.Keeper, *ccv.ConsumerGenesisState)
}{
{
"start a new chain",
Expand All @@ -118,7 +118,7 @@ func TestInitGenesis(t *testing.T) {
valset,
params,
),
func(ctx sdk.Context, ck consumerkeeper.Keeper, gs *ccv.GenesisState) {
func(ctx sdk.Context, ck consumerkeeper.Keeper, gs *ccv.ConsumerGenesisState) {
assertConsumerPortIsBound(t, ctx, &ck)

assertProviderClientID(t, ctx, &ck, provClientID)
Expand All @@ -145,7 +145,7 @@ func TestInitGenesis(t *testing.T) {
ccv.LastTransmissionBlockHeight{},
params,
),
func(ctx sdk.Context, ck consumerkeeper.Keeper, gs *ccv.GenesisState) {
func(ctx sdk.Context, ck consumerkeeper.Keeper, gs *ccv.ConsumerGenesisState) {
assertConsumerPortIsBound(t, ctx, &ck)

obtainedPendingPackets := ck.GetPendingPackets(ctx)
Expand Down Expand Up @@ -183,7 +183,7 @@ func TestInitGenesis(t *testing.T) {
ccv.LastTransmissionBlockHeight{Height: int64(100)},
params,
),
func(ctx sdk.Context, ck consumerkeeper.Keeper, gs *ccv.GenesisState) {
func(ctx sdk.Context, ck consumerkeeper.Keeper, gs *ccv.ConsumerGenesisState) {
assertConsumerPortIsBound(t, ctx, &ck)

gotChannelID, ok := ck.GetProviderChannel(ctx)
Expand Down Expand Up @@ -289,7 +289,7 @@ func TestExportGenesis(t *testing.T) {
testCases := []struct {
name string
malleate func(sdk.Context, consumerkeeper.Keeper, testkeeper.MockedKeepers)
expGenesis *ccv.GenesisState
expGenesis *ccv.ConsumerGenesisState
}{
{
"export a chain without an established CCV channel",
Expand Down
4 changes: 2 additions & 2 deletions x/ccv/consumer/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ func (k Keeper) DeletePreCCV(ctx sdk.Context) {

func (k Keeper) SetInitialValSet(ctx sdk.Context, initialValSet []tmtypes.ValidatorUpdate) {
store := ctx.KVStore(k.storeKey)
initialValSetState := ccv.GenesisState{
initialValSetState := ccv.ConsumerGenesisState{
InitialValSet: initialValSet,
}
bz := k.cdc.MustMarshal(&initialValSetState)
Expand All @@ -318,7 +318,7 @@ func (k Keeper) SetInitialValSet(ctx sdk.Context, initialValSet []tmtypes.Valida

func (k Keeper) GetInitialValSet(ctx sdk.Context) []tmtypes.ValidatorUpdate {
store := ctx.KVStore(k.storeKey)
initialValSet := ccv.GenesisState{}
initialValSet := ccv.ConsumerGenesisState{}
bz := store.Get(types.InitialValSetKey())
if bz != nil {
k.cdc.MustUnmarshal(bz, &initialValSet)
Expand Down
4 changes: 2 additions & 2 deletions x/ccv/consumer/keeper/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

// GetParams returns the params for the consumer ccv module
// NOTE: it is different from the GetParams method which is required to implement StakingKeeper interface
func (k Keeper) GetConsumerParams(ctx sdk.Context) ccvtypes.Params {
func (k Keeper) GetConsumerParams(ctx sdk.Context) ccvtypes.ConsumerParams {
return ccvtypes.NewParams(
k.GetEnabled(ctx),
k.GetBlocksPerDistributionTransmission(ctx),
Expand All @@ -29,7 +29,7 @@ func (k Keeper) GetConsumerParams(ctx sdk.Context) ccvtypes.Params {
}

// SetParams sets the paramset for the consumer module
func (k Keeper) SetParams(ctx sdk.Context, params ccvtypes.Params) {
func (k Keeper) SetParams(ctx sdk.Context, params ccvtypes.ConsumerParams) {
k.paramStore.SetParamSet(ctx, &params)
}

Expand Down
4 changes: 2 additions & 2 deletions x/ccv/consumer/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {

// ValidateGenesis performs genesis state validation for the ibc consumer module.
func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, bz json.RawMessage) error {
var data ccvtypes.GenesisState
var data ccvtypes.ConsumerGenesisState
if err := cdc.UnmarshalJSON(bz, &data); err != nil {
return fmt.Errorf("failed to unmarshal %s genesis state: %w", consumertypes.ModuleName, err)
}
Expand Down Expand Up @@ -112,7 +112,7 @@ func (am AppModule) RegisterServices(cfg module.Configurator) {
// InitGenesis performs genesis initialization for the consumer module. It returns
// no validator updates.
func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate {
var genesisState ccvtypes.GenesisState
var genesisState ccvtypes.ConsumerGenesisState
cdc.MustUnmarshalJSON(data, &genesisState)
return am.keeper.InitGenesis(ctx, &genesisState)
}
Expand Down
18 changes: 9 additions & 9 deletions x/ccv/consumer/types/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestValidateInitialGenesisState(t *testing.T) {

cases := []struct {
name string
gs *types.GenesisState
gs *types.ConsumerGenesisState
expError bool
}{
{
Expand Down Expand Up @@ -84,7 +84,7 @@ func TestValidateInitialGenesisState(t *testing.T) {
},
{
"invalid new consumer genesis state: client id not empty",
&types.GenesisState{
&types.ConsumerGenesisState{
Params: params,
ProviderClientId: "ccvclient",
ProviderChannelId: "",
Expand All @@ -103,7 +103,7 @@ func TestValidateInitialGenesisState(t *testing.T) {
},
{
"invalid new consumer genesis state: channel id not empty",
&types.GenesisState{
&types.ConsumerGenesisState{
Params: params,
ProviderClientId: "",
ProviderChannelId: "ccvchannel",
Expand All @@ -122,7 +122,7 @@ func TestValidateInitialGenesisState(t *testing.T) {
},
{
"invalid new consumer genesis state: non-empty unbonding sequences",
&types.GenesisState{
&types.ConsumerGenesisState{
Params: params,
ProviderClientId: "",
ProviderChannelId: "",
Expand All @@ -141,7 +141,7 @@ func TestValidateInitialGenesisState(t *testing.T) {
},
{
"invalid new consumer genesis state: non-empty last transmission packet",
&types.GenesisState{
&types.ConsumerGenesisState{
Params: params,
ProviderClientId: "",
ProviderChannelId: "",
Expand All @@ -160,7 +160,7 @@ func TestValidateInitialGenesisState(t *testing.T) {
},
{
"invalid new consumer genesis state: non-empty pending consumer packets",
&types.GenesisState{
&types.ConsumerGenesisState{
Params: params,
ProviderClientId: "",
ProviderChannelId: "",
Expand Down Expand Up @@ -299,7 +299,7 @@ func TestValidateRestartGenesisState(t *testing.T) {

cases := []struct {
name string
gs *types.GenesisState
gs *types.ConsumerGenesisState
expError bool
}{
{
Expand Down Expand Up @@ -347,7 +347,7 @@ func TestValidateRestartGenesisState(t *testing.T) {
},
{
"invalid restart consumer genesis: client state defined",
&types.GenesisState{
&types.ConsumerGenesisState{
Params: params,
ProviderClientId: "ccvclient",
ProviderChannelId: "ccvchannel",
Expand All @@ -366,7 +366,7 @@ func TestValidateRestartGenesisState(t *testing.T) {
},
{
"invalid restart consumer genesis: consensus state defined",
&types.GenesisState{
&types.ConsumerGenesisState{
Params: params,
ProviderClientId: "ccvclient",
ProviderChannelId: "ccvchannel",
Expand Down
2 changes: 1 addition & 1 deletion x/ccv/consumer/types/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
func TestValidateParams(t *testing.T) {
testCases := []struct {
name string
params ccvtypes.Params
params ccvtypes.ConsumerParams
expPass bool
}{
{"default params", ccvtypes.DefaultParams(), true},
Expand Down
Loading
Loading