Skip to content

Commit

Permalink
apply review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
mpoke committed Jun 7, 2024
1 parent 6bec074 commit 7dc86dc
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 17 deletions.
11 changes: 2 additions & 9 deletions x/ccv/provider/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ func (k Keeper) QueryConsumerChains(goCtx context.Context, req *types.QueryConsu

chains := []*types.Chain{}
for _, chainID := range k.GetAllRegisteredConsumerChainIDs(ctx) {
// prevent implicit memory aliasing
c, err := k.GetConsumerChain(ctx, chainID)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
Expand All @@ -61,41 +60,35 @@ func (k Keeper) QueryConsumerChains(goCtx context.Context, req *types.QueryConsu

// GetConsumerChain returns a Chain data structure with all the necessary fields
func (k Keeper) GetConsumerChain(ctx sdk.Context, chainID string) (types.Chain, error) {
// Get ClientId
clientID, found := k.GetConsumerClientId(ctx, chainID)
if !found {
return types.Chain{}, fmt.Errorf("cannot find clientID for consumer (%s)", chainID)
}

// Get Top_N
topN, found := k.GetTopN(ctx, chainID)

// Get MinPowerInTop_N
var minPowerInTopN int64
if found && topN > 0 {
res, err := k.ComputeMinPowerToOptIn(ctx, k.stakingKeeper.GetLastValidators(ctx), topN)
if err != nil {
return types.Chain{}, fmt.Errorf("failed to compute min power to opt in for chain (%s): %s", chainID, err.Error())
return types.Chain{}, fmt.Errorf("failed to compute min power to opt in for chain (%s): %w", chainID, err)
}
minPowerInTopN = res
} else {
minPowerInTopN = -1
}

// Get ValidatorSetCap
validatorSetCap, _ := k.GetValidatorSetCap(ctx, chainID)

// Get ValidatorsPowerCap
validatorsPowerCap, _ := k.GetValidatorsPowerCap(ctx, chainID)

// Get Allowlist
allowlist := k.GetAllowList(ctx, chainID)
strAllowlist := make([]string, len(allowlist))
for i, addr := range allowlist {
strAllowlist[i] = addr.String()
}

// Get Denylist
denylist := k.GetDenyList(ctx, chainID)
strDenylist := make([]string, len(denylist))
for i, addr := range denylist {
Expand Down Expand Up @@ -376,7 +369,7 @@ func (k Keeper) QueryConsumerChainsValidatorHasToValidate(goCtx context.Context,
}, nil
}

// HasToValidate checks whether a validator needs to validate on a consumer chain
// hasToValidate checks if a validator needs to validate on a consumer chain
func (k Keeper) hasToValidate(
ctx sdk.Context,
provAddr types.ProviderConsAddress,
Expand Down
7 changes: 1 addition & 6 deletions x/ccv/provider/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package keeper_test

import (
"fmt"
"sort"
"testing"
"time"

Expand Down Expand Up @@ -259,7 +258,7 @@ func TestGetConsumerChain(t *testing.T) {
pk, ctx, ctrl, mocks := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t))
defer ctrl.Finish()

chainIDs := []string{"chain-2", "chain-1", "chain-4", "chain-3"}
chainIDs := []string{"chain-1", "chain-2", "chain-3", "chain-4"}

// mock the validator set
vals := []stakingtypes.Validator{
Expand Down Expand Up @@ -336,10 +335,6 @@ func TestGetConsumerChain(t *testing.T) {
Denylist: strDenylist,
})
}
// sorting by chainID
sort.Slice(expectedGetAllOrder, func(i, j int) bool {
return expectedGetAllOrder[i].ChainId < expectedGetAllOrder[j].ChainId
})

for i, chainID := range pk.GetAllRegisteredAndProposedChainIDs(ctx) {
c, err := pk.GetConsumerChain(ctx, chainID)
Expand Down
2 changes: 1 addition & 1 deletion x/ccv/provider/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ func (k Keeper) GetAllPendingConsumerChainIDs(ctx sdk.Context) []string {
return chainIDs
}

// GetAllConsumerChainIDs gets all of the consumer chain ID, for which the provider module
// GetAllRegisteredConsumerChainIDs gets all of the consumer chain IDs, for which the provider module
// created IBC clients. Consumer chains with created clients are also referred to as registered.
//
// Note that the registered consumer chains are stored under keys with the following format:
Expand Down
2 changes: 1 addition & 1 deletion x/ccv/provider/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ func TestGetAllRegisteredConsumerChainIDs(t *testing.T) {

result := pk.GetAllRegisteredConsumerChainIDs(ctx)
require.Len(t, result, len(chainIDs))
require.Equal(t, result, expectedChainIDs)
require.Equal(t, expectedChainIDs, result)
}

// TestGetAllChannelToChains tests GetAllChannelToChains behaviour correctness
Expand Down

0 comments on commit 7dc86dc

Please sign in to comment.