Skip to content

Commit

Permalink
Addressed review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
bermuell committed Sep 15, 2023
1 parent 6c14fef commit 47a2087
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 49 deletions.
2 changes: 1 addition & 1 deletion proto/interchain_security/ccv/v1/shared_consumer.proto
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ message ConsumerGenesisState {
string provider_channel_id =
3; // empty for a new chain, filled in on restart.
bool new_chain =
4; // true for new chain ConsumerConsumerGenesisState, 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
2 changes: 1 addition & 1 deletion tests/difference/core/driver/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ func (b *Builder) createConsumerGenesis(client *ibctmtypes.ClientState) *ccv.Con
[]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
8 changes: 4 additions & 4 deletions x/ccv/consumer/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (k Keeper) InitGenesis(ctx sdk.Context, state *ccv.ConsumerGenesisState) []
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.ConsumerGenesisStat
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.ConsumerGenesisStat
// 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
10 changes: 5 additions & 5 deletions x/ccv/consumer/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func TestInitGenesis(t *testing.T) {
testkeeper.ExpectGetCapabilityMock(ctx, mocks, 1),
)
},
ccv.NewInitialGenesisState(
ccv.NewInitialConsumerGenesisState(
provClientState,
provConsState,
valset,
Expand All @@ -134,7 +134,7 @@ func TestInitGenesis(t *testing.T) {
testkeeper.ExpectGetCapabilityMock(ctx, mocks, 2),
)
},
ccv.NewRestartGenesisState(
ccv.NewRestartConsumerGenesisState(
provClientID,
"",
matPackets,
Expand Down Expand Up @@ -170,7 +170,7 @@ func TestInitGenesis(t *testing.T) {
)
},
// create a genesis for a restarted chain
ccv.NewRestartGenesisState(
ccv.NewRestartConsumerGenesisState(
provClientID,
provChannelID,
matPackets,
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion x/ccv/consumer/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ 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.
Expand Down
52 changes: 26 additions & 26 deletions x/ccv/consumer/types/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,28 +57,28 @@ func TestValidateInitialGenesisState(t *testing.T) {
}{
{
"valid new consumer genesis state",
types.NewInitialGenesisState(cs, consensusState, valUpdates, params),
types.NewInitialConsumerGenesisState(cs, consensusState, valUpdates, params),
false,
},
{
"invalid new consumer genesis state: nil client state",
types.NewInitialGenesisState(nil, consensusState, valUpdates, params),
types.NewInitialConsumerGenesisState(nil, consensusState, valUpdates, params),
true,
},
{
"invalid new consumer genesis state: invalid client state",
types.NewInitialGenesisState(&ibctmtypes.ClientState{ChainId: "badClientState"},
types.NewInitialConsumerGenesisState(&ibctmtypes.ClientState{ChainId: "badClientState"},
consensusState, valUpdates, params),
true,
},
{
"invalid new consumer genesis state: nil consensus state",
types.NewInitialGenesisState(cs, nil, valUpdates, params),
types.NewInitialConsumerGenesisState(cs, nil, valUpdates, params),
true,
},
{
"invalid new consumer genesis state: invalid consensus state",
types.NewInitialGenesisState(cs, &ibctmtypes.ConsensusState{Timestamp: time.Now()},
types.NewInitialConsumerGenesisState(cs, &ibctmtypes.ConsensusState{Timestamp: time.Now()},
valUpdates, params),
true,
},
Expand Down Expand Up @@ -179,36 +179,36 @@ func TestValidateInitialGenesisState(t *testing.T) {
},
{
"invalid new consumer genesis state: nil initial validator set",
types.NewInitialGenesisState(cs, consensusState, nil, params),
types.NewInitialConsumerGenesisState(cs, consensusState, nil, params),
true,
},
{
"invalid new consumer genesis state: invalid consensus state validator set hash",
types.NewInitialGenesisState(
types.NewInitialConsumerGenesisState(
cs, ibctmtypes.NewConsensusState(
time.Now(), commitmenttypes.NewMerkleRoot([]byte("apphash")), []byte("wrong_length_hash")),
valUpdates, params),
true,
},
{
"invalid new consumer genesis state: initial validator set does not match validator set hash",
types.NewInitialGenesisState(
types.NewInitialConsumerGenesisState(
cs, ibctmtypes.NewConsensusState(
time.Now(), commitmenttypes.NewMerkleRoot([]byte("apphash")), []byte("9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08")),
valUpdates, params),
true,
},
{
"invalid new consumer genesis state: initial validator set does not match validator set hash",
types.NewInitialGenesisState(
types.NewInitialConsumerGenesisState(
cs, ibctmtypes.NewConsensusState(
time.Now(), commitmenttypes.NewMerkleRoot([]byte("apphash")), []byte("9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08")),
valUpdates, params),
true,
},
{
"invalid new consumer genesis state: invalid params - ccvTimeoutPeriod",
types.NewInitialGenesisState(cs, consensusState, valUpdates,
types.NewInitialConsumerGenesisState(cs, consensusState, valUpdates,
types.NewParams(
true,
types.DefaultBlocksPerDistributionTransmission,
Expand All @@ -227,7 +227,7 @@ func TestValidateInitialGenesisState(t *testing.T) {
},
{
"invalid new consumer genesis state: invalid params - distributionTransmissionChannel",
types.NewInitialGenesisState(cs, consensusState, valUpdates,
types.NewInitialConsumerGenesisState(cs, consensusState, valUpdates,
types.NewParams(
true,
types.DefaultBlocksPerDistributionTransmission,
Expand Down Expand Up @@ -256,9 +256,9 @@ func TestValidateInitialGenesisState(t *testing.T) {
}
}

// TestValidateRestartGenesisState tests a NewRestartGenesisState instantiation,
// TestValidateRestartConsumerGenesisState tests a NewRestartGenesisState instantiation,
// and its Validate() method over different genesis scenarios
func TestValidateRestartGenesisState(t *testing.T) {
func TestValidateRestartConsumerGenesisState(t *testing.T) {
// generate validator private/public key
cId := crypto.NewCryptoIdentityFromIntSeed(234234)
pubKey := cId.TMCryptoPubKey()
Expand Down Expand Up @@ -304,20 +304,20 @@ func TestValidateRestartGenesisState(t *testing.T) {
}{
{
"valid restart consumer genesis state: empty maturing packets",
types.NewRestartGenesisState("ccvclient", "ccvchannel", nil, valUpdates, heightToValsetUpdateID,
types.NewRestartConsumerGenesisState("ccvclient", "ccvchannel", nil, valUpdates, heightToValsetUpdateID,
types.ConsumerPacketDataList{List: []types.ConsumerPacketData{matConsumerPacket, slashConsumerPacket}},
nil, types.LastTransmissionBlockHeight{Height: 100}, params),
false,
},
{
"valid restart consumer genesis state: handshake in progress ",
types.NewRestartGenesisState("ccvclient", "", nil, valUpdates, heightToValsetUpdateID,
types.NewRestartConsumerGenesisState("ccvclient", "", nil, valUpdates, heightToValsetUpdateID,
types.ConsumerPacketDataList{List: []types.ConsumerPacketData{slashConsumerPacket}}, nil, types.LastTransmissionBlockHeight{}, params),
false,
},
{
"valid restart consumer genesis state: maturing packets",
types.NewRestartGenesisState("ccvclient", "ccvchannel", []types.MaturingVSCPacket{
types.NewRestartConsumerGenesisState("ccvclient", "ccvchannel", []types.MaturingVSCPacket{
{VscId: 1, MaturityTime: time.Now().UTC()},
{VscId: 3, MaturityTime: time.Now().UTC()},
{VscId: 5, MaturityTime: time.Now().UTC()},
Expand All @@ -328,19 +328,19 @@ func TestValidateRestartGenesisState(t *testing.T) {
},
{
"invalid restart consumer genesis state: provider id is empty",
types.NewRestartGenesisState("", "ccvchannel", nil, valUpdates, heightToValsetUpdateID, types.ConsumerPacketDataList{}, nil, types.LastTransmissionBlockHeight{}, params),
types.NewRestartConsumerGenesisState("", "ccvchannel", nil, valUpdates, heightToValsetUpdateID, types.ConsumerPacketDataList{}, nil, types.LastTransmissionBlockHeight{}, params),
true,
},
{
"invalid restart consumer genesis state: maturing packet vscId is invalid",
types.NewRestartGenesisState("ccvclient", "ccvchannel", []types.MaturingVSCPacket{
types.NewRestartConsumerGenesisState("ccvclient", "ccvchannel", []types.MaturingVSCPacket{
{VscId: 0, MaturityTime: time.Now().UTC()},
}, valUpdates, nil, types.ConsumerPacketDataList{}, nil, types.LastTransmissionBlockHeight{}, params),
true,
},
{
"invalid restart consumer genesis state: maturing packet time is invalid",
types.NewRestartGenesisState("ccvclient", "ccvchannel", []types.MaturingVSCPacket{
types.NewRestartConsumerGenesisState("ccvclient", "ccvchannel", []types.MaturingVSCPacket{
{VscId: 1, MaturityTime: time.Time{}},
}, valUpdates, nil, types.ConsumerPacketDataList{}, nil, types.LastTransmissionBlockHeight{}, params),
true,
Expand Down Expand Up @@ -385,37 +385,37 @@ func TestValidateRestartGenesisState(t *testing.T) {
},
{
"invalid restart consumer genesis state: nil initial validator set",
types.NewRestartGenesisState("ccvclient", "ccvchannel", nil, nil, nil, types.ConsumerPacketDataList{}, nil, types.LastTransmissionBlockHeight{}, params),
types.NewRestartConsumerGenesisState("ccvclient", "ccvchannel", nil, nil, nil, types.ConsumerPacketDataList{}, nil, types.LastTransmissionBlockHeight{}, params),
true,
},
{
"invalid restart consumer genesis state: nil height to validator set id mapping",
types.NewRestartGenesisState("ccvclient", "",
types.NewRestartConsumerGenesisState("ccvclient", "",
[]types.MaturingVSCPacket{{VscId: 1, MaturityTime: time.Time{}}}, valUpdates, nil, types.ConsumerPacketDataList{}, nil, types.LastTransmissionBlockHeight{}, params),
true,
},
{
"invalid restart consumer genesis state: maturing packet defined when handshake is still in progress",
types.NewRestartGenesisState("ccvclient", "",
types.NewRestartConsumerGenesisState("ccvclient", "",
[]types.MaturingVSCPacket{{VscId: 1, MaturityTime: time.Time{}}}, valUpdates, heightToValsetUpdateID, types.ConsumerPacketDataList{}, nil, types.LastTransmissionBlockHeight{}, params),
true,
},
{
"invalid restart consumer genesis state: outstanding downtime defined when handshake is still in progress",
types.NewRestartGenesisState("ccvclient", "",
types.NewRestartConsumerGenesisState("ccvclient", "",
nil, valUpdates, heightToValsetUpdateID, types.ConsumerPacketDataList{}, []types.OutstandingDowntime{{ValidatorConsensusAddress: "cosmosvalconsxxx"}},
types.LastTransmissionBlockHeight{}, params),
true,
},
{
"invalid restart consumer genesis state: last transmission block height defined when handshake is still in progress",
types.NewRestartGenesisState("ccvclient", "",
types.NewRestartConsumerGenesisState("ccvclient", "",
nil, valUpdates, heightToValsetUpdateID, types.ConsumerPacketDataList{}, nil, types.LastTransmissionBlockHeight{Height: int64(1)}, params),
true,
},
{
"invalid restart consumer genesis state: pending maturing packets defined when handshake is still in progress",
types.NewRestartGenesisState("ccvclient", "",
types.NewRestartConsumerGenesisState("ccvclient", "",
nil, valUpdates, heightToValsetUpdateID, types.ConsumerPacketDataList{
List: []types.ConsumerPacketData{
{
Expand All @@ -428,7 +428,7 @@ func TestValidateRestartGenesisState(t *testing.T) {
},
{
"invalid restart consumer genesis state: invalid params",
types.NewRestartGenesisState("ccvclient", "ccvchannel", nil, valUpdates, nil, types.ConsumerPacketDataList{}, nil, types.LastTransmissionBlockHeight{},
types.NewRestartConsumerGenesisState("ccvclient", "ccvchannel", nil, valUpdates, nil, types.ConsumerPacketDataList{}, nil, types.LastTransmissionBlockHeight{},
types.NewParams(
true,
types.DefaultBlocksPerDistributionTransmission,
Expand Down
6 changes: 3 additions & 3 deletions x/ccv/provider/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func TestInitAndExportGenesis(t *testing.T) {
expClientID,
"channel",
initHeight,
*ccv.DefaultGenesisState(),
*ccv.DefaultConsumerGenesisState(),
[]providertypes.VscUnbondingOps{
{VscId: vscID, UnbondingOpIds: ubdIndex},
},
Expand All @@ -83,7 +83,7 @@ func TestInitAndExportGenesis(t *testing.T) {
expClientID,
"",
0,
*ccv.DefaultGenesisState(),
*ccv.DefaultConsumerGenesisState(),
nil,
[]ccv.ValidatorSetChangePacketData{{ValsetUpdateId: vscID}},
nil,
Expand Down Expand Up @@ -218,7 +218,7 @@ func assertConsumerChainStates(t *testing.T, ctx sdk.Context, pk keeper.Keeper,
chainID := cs.ChainId
gen, found := pk.GetConsumerGenesis(ctx, chainID)
require.True(t, found)
require.Equal(t, *ccv.DefaultGenesisState(), gen)
require.Equal(t, *ccv.DefaultConsumerGenesisState(), gen)

clientID, found := pk.GetConsumerClientId(ctx, chainID)
require.True(t, found)
Expand Down
2 changes: 1 addition & 1 deletion x/ccv/provider/keeper/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ func (k Keeper) MakeConsumerGenesis(
[]string{},
)

gen = *ccv.NewInitialGenesisState(
gen = *ccv.NewInitialConsumerGenesisState(
clientState,
consState.(*ibctmtypes.ConsensusState),
initialUpdatesWithConsumerKeys,
Expand Down
2 changes: 1 addition & 1 deletion x/ccv/provider/types/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -782,5 +782,5 @@ func getInitialConsumerGenesis(t *testing.T, chainID string) ccv.ConsumerGenesis

params := ccv.DefaultParams()
params.Enabled = true
return *ccv.NewInitialGenesisState(cs, consensusState, valUpdates, params)
return *ccv.NewInitialConsumerGenesisState(cs, consensusState, valUpdates, params)
}
12 changes: 6 additions & 6 deletions x/ccv/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
abci "github.com/cometbft/cometbft/abci/types"
)

// NewInitialGenesisState returns a ConsumerGenesisState for a completely new consumer chain.
func NewInitialGenesisState(cs *ibctmtypes.ClientState, consState *ibctmtypes.ConsensusState,
// NewInitialConsumerGenesisState returns a ConsumerGenesisState for a completely new consumer chain.
func NewInitialConsumerGenesisState(cs *ibctmtypes.ClientState, consState *ibctmtypes.ConsensusState,
initValSet []abci.ValidatorUpdate, params ConsumerParams,
) *ConsumerGenesisState {
return &ConsumerGenesisState{
Expand All @@ -21,8 +21,8 @@ func NewInitialGenesisState(cs *ibctmtypes.ClientState, consState *ibctmtypes.Co
}
}

// NewRestartGenesisState returns a ConsumerGenesisState that has already been established.
func NewRestartGenesisState(
// NewRestartConsumerGenesisState returns a ConsumerGenesisState that has already been established.
func NewRestartConsumerGenesisState(
clientID, channelID string,
maturingPackets []MaturingVSCPacket,
initValSet []abci.ValidatorUpdate,
Expand All @@ -46,9 +46,9 @@ func NewRestartGenesisState(
}
}

// DefaultGenesisState returns a default disabled consumer chain genesis state. This allows the module to be hooked up to app without getting use
// DefaultConsumerGenesisState 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 DefaultGenesisState() *ConsumerGenesisState {
func DefaultConsumerGenesisState() *ConsumerGenesisState {
return &ConsumerGenesisState{
Params: DefaultParams(),
}
Expand Down

0 comments on commit 47a2087

Please sign in to comment.