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
  • Loading branch information
bermuell authored Sep 15, 2023
1 parent d064649 commit df12b7e
Show file tree
Hide file tree
Showing 28 changed files with 460 additions and 466 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 ];
}

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
[ (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
[ (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 @@ -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 All @@ -540,7 +540,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 @@ -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
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 @@ -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
Loading

0 comments on commit df12b7e

Please sign in to comment.