Skip to content

Commit

Permalink
add GetAllConsumerWithIBCClients
Browse files Browse the repository at this point in the history
  • Loading branch information
mpoke committed Sep 4, 2024
1 parent ad70394 commit 1186fa9
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 7 deletions.
4 changes: 2 additions & 2 deletions x/ccv/provider/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,13 @@ func (k Keeper) InitGenesisValUpdates(ctx sdk.Context) []abci.ValidatorUpdate {

// ExportGenesis returns the CCV provider module's exported genesis
func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState {
launchedConsumerIds := k.GetAllLaunchedConsumerIds(ctx)
launchedConsumerIds := k.GetAllConsumerWithIBCClients(ctx)

// export states for each consumer chains
var consumerStates []types.ConsumerState
for _, consumerId := range launchedConsumerIds {
// no need for the second return value of GetConsumerClientId
// as GetAllLaunchedConsumerIds already iterated through
// as GetAllConsumerWithIBCClients already iterated through
// the entire prefix range
clientId, _ := k.GetConsumerClientId(ctx, consumerId)
gen, found := k.GetConsumerGenesis(ctx, consumerId)
Expand Down
1 change: 0 additions & 1 deletion x/ccv/provider/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,6 @@ func TestQueryConsumerChainsValidatorHasToValidate(t *testing.T) {
ProviderAddress: providerAddr.String(),
}


consumerNum := 4
consumerIds := make([]string, consumerNum)

Expand Down
4 changes: 2 additions & 2 deletions x/ccv/provider/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ func (k Keeper) DeleteConsumerIdToChannelId(ctx sdk.Context, consumerId string)
store.Delete(types.ConsumerIdToChannelIdKey(consumerId))
}

// GetAllLaunchedConsumerIds returns all consumer ids of chains that are currently launched.
func (k Keeper) GetAllLaunchedConsumerIds(ctx sdk.Context) []string {
// GetAllConsumerWithIBCClients returns all ids of consumer chains that with IBC clients created.
func (k Keeper) GetAllConsumerWithIBCClients(ctx sdk.Context) []string {
consumerIds := []string{}

// All launched chains have created an IBC client when they launched (see `LaunchConsumer`), so we traverse over
Expand Down
4 changes: 2 additions & 2 deletions x/ccv/provider/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func TestInitHeight(t *testing.T) {
}
}

func TestGetAllLaunchedConsumerIds(t *testing.T) {
func TestGetAllConsumerWithIBCClients(t *testing.T) {
pk, ctx, ctrl, _ := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t))
defer ctrl.Finish()

Expand All @@ -234,7 +234,7 @@ func TestGetAllLaunchedConsumerIds(t *testing.T) {
pk.SetConsumerPhase(ctx, consumerId, providertypes.ConsumerPhase_CONSUMER_PHASE_LAUNCHED)
}

actualConsumerIds := pk.GetAllLaunchedConsumerIds(ctx)
actualConsumerIds := pk.GetAllConsumerWithIBCClients(ctx)
require.Len(t, actualConsumerIds, len(consumerIds))

// sort the consumer ids before comparing they are equal
Expand Down
4 changes: 4 additions & 0 deletions x/ccv/provider/keeper/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ func (k Keeper) BlocksUntilNextEpoch(ctx sdk.Context) int64 {
// VSC packets to the chains with established CCV channels.
// If the CCV channel is not established for a consumer chain,
// the updates will remain queued until the channel is established
//
// TODO (mpoke): iterate only over consumers with established channel
func (k Keeper) SendVSCPackets(ctx sdk.Context) error {
for _, consumerId := range k.GetAllLaunchedConsumerIds(ctx) {
// check if CCV channel is established and send
Expand Down Expand Up @@ -193,6 +195,8 @@ func (k Keeper) SendVSCPacketsToChain(ctx sdk.Context, consumerId, channelId str
}

// QueueVSCPackets queues latest validator updates for every registered consumer chain
//
// TODO (mpoke): iterate only over consumers with established channel
func (k Keeper) QueueVSCPackets(ctx sdk.Context) error {
valUpdateID := k.GetValidatorSetUpdateId(ctx) // current valset update ID

Expand Down
1 change: 1 addition & 0 deletions x/ccv/provider/migrations/v6/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func MigrateParams(ctx sdk.Context, paramsSubspace paramtypes.Subspace) {
paramsSubspace.Set(ctx, providertypes.KeyNumberOfEpochsToStartReceivingRewards, providertypes.DefaultNumberOfEpochsToStartReceivingRewards)
}

// TODO (PERMISSIONLESS): this migration needs to be fix or removed
func MigrateMinPowerInTopN(ctx sdk.Context, providerKeeper providerkeeper.Keeper) {
// we only get the registered consumer chains and not also the proposed consumer chains because
// the minimal power is first set when the consumer chain addition proposal passes
Expand Down

0 comments on commit 1186fa9

Please sign in to comment.