Skip to content

Commit

Permalink
refactor: Vaguely named consumer structs (#1288)
Browse files Browse the repository at this point in the history
* Rename GenesisState proto
* make proto-gen
* proto rename: Params -> ConsumerParams
* make proto-gen
* App, fix type change for Param renaming
* App, fix type change for GenesisState renaming
* Fix unit-tests for GenesisState renaming
* Fix unit-tests for Params renaming
* Addressed review comments
* Fix linter issues

(cherry picked from commit df12b7e)

# Conflicts:
#	testutil/ibc_testing/specific_setup.go
  • Loading branch information
bermuell authored and mergify[bot] committed Nov 13, 2023
1 parent f06519e commit baffeac
Show file tree
Hide file tree
Showing 28 changed files with 501 additions and 464 deletions.
2 changes: 1 addition & 1 deletion app/consumer-democracy/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ func New(
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 @@ message QueryParamsRequest {}
// 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 @@ message ConsumerState {
// 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 @@ service Query {
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
Expand Up @@ -17,13 +17,12 @@ import "google/protobuf/timestamp.proto";
// 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 @@ message Params {
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, false for chain restart.
// 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
6 changes: 3 additions & 3 deletions tests/difference/core/driver/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,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 @@ -520,7 +520,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 All @@ -538,7 +538,7 @@ func (b *Builder) createConsumerGenesis(client *ibctmtypes.ClientState) *ccv.Gen
[]string{},
[]string{},
)
return ccv.NewInitialGenesisState(client, providerConsState, valUpdates, params)
return ccv.NewInitialConsumerGenesisState(client, providerConsState, valUpdates, params)
}

// The state of the data returned is equivalent to the state of two chains
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func (suite *CCVTestSuite) SetupTest() {
func initConsumerChain(
s *CCVTestSuite,
chainID string,
genesisState *ccv.GenesisState,
genesisState *ccv.ConsumerGenesisState,
) {
providerKeeper := s.providerApp.GetProviderKeeper()
bundle := s.consumerBundles[chainID]
Expand Down
43 changes: 43 additions & 0 deletions testutil/ibc_testing/specific_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func ProviderAppIniter() (ibctesting.TestingApp, map[string]json.RawMessage) {
return testApp, appProvider.NewDefaultGenesisState(encoding.Codec)
}

<<<<<<< HEAD
// ConsumerAppIniter implements ibctesting.AppIniter for a consumer app
func ConsumerAppIniter() (ibctesting.TestingApp, map[string]json.RawMessage) {
encoding := appConsumer.MakeTestEncodingConfig()
Expand All @@ -37,4 +38,46 @@ func DemocracyConsumerAppIniter() (ibctesting.TestingApp, map[string]json.RawMes
encoding := appConsumerDemocracy.MakeTestEncodingConfig()
testApp := appConsumerDemocracy.New(log.NewNopLogger(), tmdb.NewMemDB(), nil, true, simtestutil.EmptyAppOptions{})
return testApp, appConsumerDemocracy.NewDefaultGenesisState(encoding.Codec)
=======
// ConsumerAppIniter returns a ibctesting.ValSetAppIniter for a consumer app
func ConsumerAppIniter(initValPowers []types.ValidatorUpdate) AppIniter {
return func() (ibctesting.TestingApp, map[string]json.RawMessage) {
encoding := appConsumer.MakeTestEncodingConfig()
testApp := appConsumer.New(log.NewNopLogger(), tmdb.NewMemDB(), nil, true, simtestutil.EmptyAppOptions{})
genesisState := appConsumer.NewDefaultGenesisState(encoding.Codec)
// NOTE ibc-go/v7/testing.SetupWithGenesisValSet requires a staking module
// genesisState or it panics. Feed a minimum one.
genesisState[stakingtypes.ModuleName] = encoding.Codec.MustMarshalJSON(
&stakingtypes.GenesisState{
Params: stakingtypes.Params{BondDenom: sdk.DefaultBondDenom},
},
)
// Feed consumer genesis with provider validators
var consumerGenesis ccvtypes.ConsumerGenesisState
encoding.Codec.MustUnmarshalJSON(genesisState[consumertypes.ModuleName], &consumerGenesis)
consumerGenesis.InitialValSet = initValPowers
consumerGenesis.Params.Enabled = true
genesisState[consumertypes.ModuleName] = encoding.Codec.MustMarshalJSON(&consumerGenesis)

return testApp, genesisState
}
}

// DemocracyConsumerAppIniter implements ibctesting.ValSetAppIniter for a democracy consumer app
func DemocracyConsumerAppIniter(initValPowers []types.ValidatorUpdate) AppIniter {
return func() (ibctesting.TestingApp, map[string]json.RawMessage) {
encoding := appConsumerDemocracy.MakeTestEncodingConfig()
testApp := appConsumerDemocracy.New(log.NewNopLogger(), tmdb.NewMemDB(), nil, true, simtestutil.EmptyAppOptions{})
genesisState := appConsumerDemocracy.NewDefaultGenesisState(encoding.Codec)
// Feed consumer genesis with provider validators
// TODO See if useful for democracy
var consumerGenesis ccvtypes.ConsumerGenesisState
encoding.Codec.MustUnmarshalJSON(genesisState[consumertypes.ModuleName], &consumerGenesis)
consumerGenesis.InitialValSet = initValPowers
consumerGenesis.Params.Enabled = true
genesisState[consumertypes.ModuleName] = encoding.Codec.MustMarshalJSON(&consumerGenesis)

return testApp, genesisState
}
>>>>>>> df12b7e (refactor: Vaguely named consumer structs (#1288))
}
12 changes: 6 additions & 6 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,10 +115,10 @@ 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()
return ccv.DefaultConsumerGenesisState()
}

// export the current validator set
Expand All @@ -137,7 +137,7 @@ func (k Keeper) ExportGenesis(ctx sdk.Context) (genesis *ccv.GenesisState) {
panic("provider client does not exist although provider channel does exist")
}

genesis = ccv.NewRestartGenesisState(
genesis = ccv.NewRestartConsumerGenesisState(
clientID,
channelID,
k.GetAllPacketMaturityTimes(ctx),
Expand All @@ -153,11 +153,11 @@ func (k Keeper) ExportGenesis(ctx sdk.Context) (genesis *ccv.GenesisState) {
// if provider clientID and channelID don't exist on the consumer chain,
// then CCV protocol is disabled for this chain return a default genesis state
if !ok {
return ccv.DefaultGenesisState()
return ccv.DefaultConsumerGenesisState()
}

// export client states and pending slashing requests into a new chain genesis
genesis = ccv.NewRestartGenesisState(
genesis = ccv.NewRestartConsumerGenesisState(
clientID,
"",
nil,
Expand Down
22 changes: 11 additions & 11 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 @@ -112,13 +112,13 @@ func TestInitGenesis(t *testing.T) {
testkeeper.ExpectGetCapabilityMock(ctx, mocks, 1),
)
},
ccv.NewInitialGenesisState(
ccv.NewInitialConsumerGenesisState(
provClientState,
provConsState,
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 @@ -134,7 +134,7 @@ func TestInitGenesis(t *testing.T) {
testkeeper.ExpectGetCapabilityMock(ctx, mocks, 2),
)
},
ccv.NewRestartGenesisState(
ccv.NewRestartConsumerGenesisState(
provClientID,
"",
matPackets,
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 All @@ -170,7 +170,7 @@ func TestInitGenesis(t *testing.T) {
)
},
// create a genesis for a restarted chain
ccv.NewRestartGenesisState(
ccv.NewRestartConsumerGenesisState(
provClientID,
provChannelID,
matPackets,
Expand All @@ -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 All @@ -307,7 +307,7 @@ func TestExportGenesis(t *testing.T) {

ck.SetHeightValsetUpdateID(ctx, defaultHeightValsetUpdateIDs[0].Height, defaultHeightValsetUpdateIDs[0].ValsetUpdateId)
},
ccv.NewRestartGenesisState(
ccv.NewRestartConsumerGenesisState(
provClientID,
"",
nil,
Expand Down Expand Up @@ -343,7 +343,7 @@ func TestExportGenesis(t *testing.T) {
ck.SetOutstandingDowntime(ctx, sdk.ConsAddress(validator.Address.Bytes()))
ck.SetLastTransmissionBlockHeight(ctx, ltbh)
},
ccv.NewRestartGenesisState(
ccv.NewRestartConsumerGenesisState(
provClientID,
provChannelID,
matPackets,
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
6 changes: 3 additions & 3 deletions x/ccv/consumer/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry)
// DefaultGenesis returns default genesis state as raw bytes for the ibc
// consumer module.
func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
return cdc.MustMarshalJSON(ccvtypes.DefaultGenesisState())
return cdc.MustMarshalJSON(ccvtypes.DefaultConsumerGenesisState())
}

// 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 @@ -117,7 +117,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
Loading

0 comments on commit baffeac

Please sign in to comment.