Skip to content

Commit

Permalink
Rename PrivateConsumerGenesisState to GenesisState
Browse files Browse the repository at this point in the history
Rename NewRestartConsumerGenesisState to NewRestartGenesisState
  • Loading branch information
bermuell committed Sep 22, 2023
1 parent b61ee07 commit 92d02bd
Show file tree
Hide file tree
Showing 13 changed files with 190 additions and 192 deletions.
2 changes: 1 addition & 1 deletion app/consumer-democracy/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ func New(
return fromVM, fmt.Errorf("failed to unmarshal genesis state: %w", err)
}

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

consumerGenesis.PreCCV = true
Expand Down
26 changes: 12 additions & 14 deletions proto/interchain_security/ccv/consumer/v1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ import "gogoproto/gogo.proto";
import "interchain_security/ccv/v1/wire.proto";
import "google/protobuf/timestamp.proto";



// GenesisState defines the CCV consumer genesis state
//
// Note this type is only used on consumer side and references shared type with
// consumer
// TODO: rename to GenesisState
message PrivateConsumerGenesisState {
// Note: this type is only used on consumer side and references shared types with
// provider
message GenesisState {
reserved 5, 6, 8;
// ConsumerParams is a shared type with provider module
interchain_security.ccv.v1.ConsumerParams params = 1
[ (gogoproto.nullable) = false ];
// Client ID of the provider. Empty for a new chain, filled in on restart.
Expand Down Expand Up @@ -47,27 +49,25 @@ message PrivateConsumerGenesisState {
}

// HeightValsetUpdateID represents a mapping internal to the consumer CCV module
// AND used in shared consumer genesis state, which links a block height to each
// recv valset update id.
// which links a block height to each recv valset update id.
message HeightToValsetUpdateID {
uint64 height = 1;
uint64 valset_update_id = 2;
}

// OutstandingDowntime defines the type used internally to the consumer CCV
// module, AND used in shared consumer genesis state, in order to not send
// multiple slashing requests for the same downtime infraction.
// module and is used in order to not send multiple slashing requests for
// the same downtime infraction.
message OutstandingDowntime { string validator_consensus_address = 1; }

// LastTransmissionBlockHeight is the last time validator holding
// pools were transmitted to the provider chain. This type is used internally
// to the consumer CCV module AND used in shared consumer genesis state.
// to the consumer CCV modul.
message LastTransmissionBlockHeight { int64 height = 1; }

// MaturingVSCPacket represents a vsc packet that is maturing internal to the
// consumer CCV module, where the consumer has not yet relayed a VSCMatured
// packet back to the provider. This type is used internally to the consumer
// CCV module AND used in shared consumer genesis state.
// packet back to the provider.
message MaturingVSCPacket {
uint64 vscId = 1;
google.protobuf.Timestamp maturity_time = 2
Expand All @@ -77,9 +77,7 @@ message MaturingVSCPacket {
// ConsumerPacketDataList is a list of consumer packet data packets.
//
// Note this type is is used internally to the consumer CCV module
// for exporting / importing state in InitGenesis and ExportGenesis,
// AND included in the consumer genesis type (reffed by provider and consumer
// modules), hence this is a shared type.
// for exporting / importing state in InitGenesis and ExportGenesis.
message ConsumerPacketDataList {
repeated interchain_security.ccv.v1.ConsumerPacketData list = 1
[ (gogoproto.nullable) = false ];
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 := consumertypes.PrivateConsumerGenesisState{}
genesisConsumer := consumertypes.GenesisState{}

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) *consumertypes.PrivateConsumerGenesisState {
func (b *Builder) createConsumerGenesis(client *ibctmtypes.ClientState) *consumertypes.GenesisState {
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) *consume
[]string{},
[]string{},
)
return consumertypes.NewPrivateInitialConsumerGenesisState(client, providerConsState, valUpdates, params)
return consumertypes.NewInitialGenesisState(client, providerConsState, valUpdates, params)
}

// The state of the data returned is equivalent to the state of two chains
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,12 @@ func (suite *CCVTestSuite) SetupTest() {
chainID,
)
suite.Require().True(found, "consumer genesis not found")
privateConsumerGenesisState := consumertypes.PrivateConsumerGenesisState{
genesisState := consumertypes.GenesisState{
Params: consumerGenesisState.Params,
Provider: consumerGenesisState.Provider,
NewChain: consumerGenesisState.NewChain,
}
initConsumerChain(suite, chainID, &privateConsumerGenesisState)
initConsumerChain(suite, chainID, &genesisState)
}

// try updating all clients
Expand Down Expand Up @@ -187,7 +187,7 @@ func (s *CCVTestSuite) getSentPacket(chain *ibctesting.TestChain, sequence uint6
func initConsumerChain(
s *CCVTestSuite,
chainID string,
genesisState *consumertypes.PrivateConsumerGenesisState,
genesisState *consumertypes.GenesisState,
) {
providerKeeper := s.providerApp.GetProviderKeeper()
bundle := s.consumerBundles[chainID]
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 *types.PrivateConsumerGenesisState) []abci.ValidatorUpdate {
func (k Keeper) InitGenesis(ctx sdk.Context, state *types.GenesisState) []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 *types.PrivateConsumerGenesis
}

// ExportGenesis returns the CCV consumer module's exported genesis
func (k Keeper) ExportGenesis(ctx sdk.Context) (genesis *types.PrivateConsumerGenesisState) {
func (k Keeper) ExportGenesis(ctx sdk.Context) (genesis *types.GenesisState) {
params := k.GetConsumerParams(ctx)
if !params.Enabled {
return types.DefaultPrivateConsumerGenesisState()
return types.DefaultGenesisState()
}

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

genesis = types.NewRestartConsumerGenesisState(
genesis = types.NewRestartGenesisState(
clientID,
channelID,
k.GetAllPacketMaturityTimes(ctx),
Expand All @@ -153,11 +153,11 @@ func (k Keeper) ExportGenesis(ctx sdk.Context) (genesis *types.PrivateConsumerGe
// 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 types.DefaultPrivateConsumerGenesisState()
return types.DefaultGenesisState()
}

// export client states and pending slashing requests into a new chain genesis
genesis = types.NewRestartConsumerGenesisState(
genesis = types.NewRestartGenesisState(
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 *consumertypes.PrivateConsumerGenesisState
assertStates func(sdk.Context, consumerkeeper.Keeper, *consumertypes.PrivateConsumerGenesisState)
genesis *consumertypes.GenesisState
assertStates func(sdk.Context, consumerkeeper.Keeper, *consumertypes.GenesisState)
}{
{
"start a new chain",
Expand All @@ -112,13 +112,13 @@ func TestInitGenesis(t *testing.T) {
testkeeper.ExpectGetCapabilityMock(ctx, mocks, 1),
)
},
consumertypes.NewPrivateInitialConsumerGenesisState(
consumertypes.NewInitialGenesisState(
provClientState,
provConsState,
valset,
params,
),
func(ctx sdk.Context, ck consumerkeeper.Keeper, gs *consumertypes.PrivateConsumerGenesisState) {
func(ctx sdk.Context, ck consumerkeeper.Keeper, gs *consumertypes.GenesisState) {
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),
)
},
consumertypes.NewRestartConsumerGenesisState(
consumertypes.NewRestartGenesisState(
provClientID,
"",
matPackets,
Expand All @@ -145,7 +145,7 @@ func TestInitGenesis(t *testing.T) {
consumertypes.LastTransmissionBlockHeight{},
params,
),
func(ctx sdk.Context, ck consumerkeeper.Keeper, gs *consumertypes.PrivateConsumerGenesisState) {
func(ctx sdk.Context, ck consumerkeeper.Keeper, gs *consumertypes.GenesisState) {
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
consumertypes.NewRestartConsumerGenesisState(
consumertypes.NewRestartGenesisState(
provClientID,
provChannelID,
matPackets,
Expand All @@ -183,7 +183,7 @@ func TestInitGenesis(t *testing.T) {
consumertypes.LastTransmissionBlockHeight{Height: int64(100)},
params,
),
func(ctx sdk.Context, ck consumerkeeper.Keeper, gs *consumertypes.PrivateConsumerGenesisState) {
func(ctx sdk.Context, ck consumerkeeper.Keeper, gs *consumertypes.GenesisState) {
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 *consumertypes.PrivateConsumerGenesisState
expGenesis *consumertypes.GenesisState
}{
{
"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)
},
consumertypes.NewRestartConsumerGenesisState(
consumertypes.NewRestartGenesisState(
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)
},
consumertypes.NewRestartConsumerGenesisState(
consumertypes.NewRestartGenesisState(
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 := types.PrivateConsumerGenesisState{
initialValSetState := types.GenesisState{
Provider: ccv.ProviderInfo{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 := types.PrivateConsumerGenesisState{}
initialValSet := types.GenesisState{}
bz := store.Get(types.InitialValSetKey())
if bz != nil {
k.cdc.MustUnmarshal(bz, &initialValSet)
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 consumertypes.PrivateConsumerGenesisState
var data consumertypes.GenesisState
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 consumertypes.PrivateConsumerGenesisState
var genesisState consumertypes.GenesisState
cdc.MustUnmarshalJSON(data, &genesisState)
return am.keeper.InitGenesis(ctx, &genesisState)
}
Expand Down
8 changes: 4 additions & 4 deletions x/ccv/consumer/types/consumer.pb.go

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

24 changes: 12 additions & 12 deletions x/ccv/consumer/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
ccv "github.com/cosmos/interchain-security/v3/x/ccv/types"
)

// NewRestartConsumerGenesisState returns a ConsumerGenesisState that has already been established.
func NewRestartConsumerGenesisState(
// NewRestartGenesisState returns a consumer GenesisState that has already been established.
func NewRestartGenesisState(
clientID, channelID string,
maturingPackets []MaturingVSCPacket,
initValSet []abci.ValidatorUpdate,
Expand All @@ -17,8 +17,8 @@ func NewRestartConsumerGenesisState(
outstandingDowntimes []OutstandingDowntime,
lastTransBlockHeight LastTransmissionBlockHeight,
params ccv.ConsumerParams,
) *PrivateConsumerGenesisState {
return &PrivateConsumerGenesisState{
) *GenesisState {
return &GenesisState{
NewChain: false,
Params: params,
Provider: ccv.ProviderInfo{
Expand All @@ -34,19 +34,19 @@ func NewRestartConsumerGenesisState(
}
}

// DefaultConsumerGenesisState returns a default disabled consumer chain genesis state. This allows the module to be hooked up to app without getting use
// DefaultGenesisState returns a default disabled consumer chain genesis state. This allows the module to be hooked up to app without getting use
// unless explicitly specified in genesis.
func DefaultPrivateConsumerGenesisState() *PrivateConsumerGenesisState {
return &PrivateConsumerGenesisState{
func DefaultGenesisState() *GenesisState {
return &GenesisState{
Params: ccv.DefaultParams(),
}
}

// NewPrivateInitialConsumerGenesisState returns a PrivateConsumerGenesisState for a completely new consumer chain.
func NewPrivateInitialConsumerGenesisState(cs *ibctmtypes.ClientState, consState *ibctmtypes.ConsensusState,
// NewInitialGenesisState returns a GenesisState for a completely new consumer chain.
func NewInitialGenesisState(cs *ibctmtypes.ClientState, consState *ibctmtypes.ConsensusState,
initValSet []abci.ValidatorUpdate, params ccv.ConsumerParams,
) *PrivateConsumerGenesisState {
return &PrivateConsumerGenesisState{
) *GenesisState {
return &GenesisState{
NewChain: true,
Params: params,
Provider: ccv.ProviderInfo{
Expand Down Expand Up @@ -74,7 +74,7 @@ func NewPrivateInitialConsumerGenesisState(cs *ibctmtypes.ClientState, consState
// - MaturingVSCPackets, OutstandingDowntime, PendingConsumerPacket, LastTransmissionBlockHeight // optional
//

func (gs PrivateConsumerGenesisState) Validate() error {
func (gs GenesisState) Validate() error {
if !gs.Params.Enabled {
return nil
}
Expand Down
Loading

0 comments on commit 92d02bd

Please sign in to comment.