Skip to content

Commit

Permalink
took into account comments
Browse files Browse the repository at this point in the history
  • Loading branch information
insumity committed Sep 4, 2024
1 parent eef6bb8 commit e1adcc5
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
1 change: 0 additions & 1 deletion x/ccv/provider/keeper/consumer_lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,6 @@ func (k Keeper) DeleteConsumerChain(ctx sdk.Context, consumerId string) (err err
k.DeleteConsumerValSet(ctx, consumerId)

k.DeleteConsumerRewardsAllocation(ctx, consumerId)
k.DeleteConsumerOwnerAddress(ctx, consumerId)
k.DeleteConsumerRemovalTime(ctx, consumerId)

// TODO (PERMISSIONLESS) add newly-added state to be deleted
Expand Down
9 changes: 1 addition & 8 deletions x/ccv/provider/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,6 @@ func (k Keeper) DeleteConsumerIdToChannelId(ctx sdk.Context, consumerId string)
}

// GetAllConsumersWithIBCClients returns the ids of all consumer chains that with IBC clients created.
// This is equivalent to getting the ids of all launched consumer chains:
// All launched chains have created an IBC client when they launched (see `LaunchConsumer`).
func (k Keeper) GetAllConsumersWithIBCClients(ctx sdk.Context) []string {
consumerIds := []string{}

Expand All @@ -224,12 +222,7 @@ func (k Keeper) GetAllConsumersWithIBCClients(ctx sdk.Context) []string {
for ; iterator.Valid(); iterator.Next() {
// remove 1 byte prefix from key to retrieve consumerId
consumerId := string(iterator.Key()[1:])

// A chain might have stopped, but we might not yet have its consumer id to client id association deleted.
// To avoid returning stopped chains, we check the phase of the consumer chain and only return launched chains.
if k.GetConsumerPhase(ctx, consumerId) == types.ConsumerPhase_CONSUMER_PHASE_LAUNCHED {
consumerIds = append(consumerIds, consumerId)
}
consumerIds = append(consumerIds, consumerId)
}

return consumerIds
Expand Down
10 changes: 10 additions & 0 deletions x/ccv/provider/keeper/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ func (k Keeper) BlocksUntilNextEpoch(ctx sdk.Context) int64 {
// TODO (mpoke): iterate only over consumers with established channel
func (k Keeper) SendVSCPackets(ctx sdk.Context) error {
for _, consumerId := range k.GetAllConsumersWithIBCClients(ctx) {
if k.GetConsumerPhase(ctx, consumerId) != providertypes.ConsumerPhase_CONSUMER_PHASE_LAUNCHED {
// only send VSCPackets to launched chains
continue
}

// check if CCV channel is established and send
if channelID, found := k.GetConsumerIdToChannelId(ctx, consumerId); found {
if err := k.SendVSCPacketsToChain(ctx, consumerId, channelID); err != nil {
Expand Down Expand Up @@ -214,6 +219,11 @@ func (k Keeper) QueueVSCPackets(ctx sdk.Context) error {
}

for _, consumerId := range k.GetAllConsumersWithIBCClients(ctx) {
if k.GetConsumerPhase(ctx, consumerId) != providertypes.ConsumerPhase_CONSUMER_PHASE_LAUNCHED {
// only queue VSCPackets to launched chains
continue
}

currentValidators, err := k.GetConsumerValSet(ctx, consumerId)
if err != nil {
return fmt.Errorf("getting consumer validators, consumerId(%s): %w", consumerId, err)
Expand Down
1 change: 1 addition & 0 deletions x/ccv/provider/types/legacy_proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ func NewConsumerRemovalProposal(title, description, chainID string, stopTime tim
Title: title,
Description: description,
ChainId: chainID,
StopTime: stopTime,
}
}

Expand Down

0 comments on commit e1adcc5

Please sign in to comment.