diff --git a/x/ccv/provider/keeper/grpc_query.go b/x/ccv/provider/keeper/grpc_query.go index ff0e7f43cc..ee00556f06 100644 --- a/x/ccv/provider/keeper/grpc_query.go +++ b/x/ccv/provider/keeper/grpc_query.go @@ -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()) @@ -61,13 +60,11 @@ 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 @@ -75,27 +72,23 @@ func (k Keeper) GetConsumerChain(ctx sdk.Context, chainID string) (types.Chain, 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 { @@ -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, diff --git a/x/ccv/provider/keeper/grpc_query_test.go b/x/ccv/provider/keeper/grpc_query_test.go index d0cc03286b..4f3825238f 100644 --- a/x/ccv/provider/keeper/grpc_query_test.go +++ b/x/ccv/provider/keeper/grpc_query_test.go @@ -2,7 +2,6 @@ package keeper_test import ( "fmt" - "sort" "testing" "time" @@ -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{ @@ -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) diff --git a/x/ccv/provider/keeper/keeper.go b/x/ccv/provider/keeper/keeper.go index 60273efb0d..9b95036dda 100644 --- a/x/ccv/provider/keeper/keeper.go +++ b/x/ccv/provider/keeper/keeper.go @@ -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: diff --git a/x/ccv/provider/keeper/keeper_test.go b/x/ccv/provider/keeper/keeper_test.go index cbdd0a6657..f68afc20c2 100644 --- a/x/ccv/provider/keeper/keeper_test.go +++ b/x/ccv/provider/keeper/keeper_test.go @@ -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