Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP - Application Filter Flag #1030

Draft
wants to merge 2 commits into
base: filter_suppliers_flag
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
178 changes: 89 additions & 89 deletions api/poktroll/application/query.pulsar.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ module github.com/pokt-network/poktroll

go 1.23.0

// replace (
replace (
// DEVELOPER_TIP: Uncomment to use a local copy of shannon-sdk for development purposes.
// github.com/pokt-network/shannon-sdk => ../shannon-sdk

// DEVELOPER_TIP: Uncomment to use a local copy of smt for development purposes.
// github.com/pokt-network/smt => ../smt
// github.com/pokt-network/smt/kvstore/badger => ../smt/kvstore/badger
// github.com/pokt-network/smt/kvstore/pebble => ../smt/kvstore/pebble
// )
)

// replace broken goleveldb
replace github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
Expand Down
7 changes: 4 additions & 3 deletions proto/poktroll/application/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ message QueryGetApplicationResponse {

message QueryAllApplicationsRequest {
cosmos.base.query.v1beta1.PageRequest pagination = 1;
// TODO_MAINNET(@adshmh): rename this field to `gateway_address_delegated_to`
// delegatee_gateway_address, if specified, filters the application list to only include those with delegation to the specified gateway address.
string delegatee_gateway_address = 2;

oneof filter {
string gateway_address_delegated_to = 2; // filters applications that delegate to the specified gateway address
}
}

message QueryAllApplicationsResponse {
Expand Down
14 changes: 6 additions & 8 deletions x/application/keeper/application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package keeper_test

import (
"context"
"slices"
"strconv"
"testing"

Expand All @@ -12,6 +11,7 @@ import (
"github.com/pokt-network/poktroll/cmd/poktrolld/cmd"
keepertest "github.com/pokt-network/poktroll/testutil/keeper"
"github.com/pokt-network/poktroll/testutil/nullify"
"github.com/pokt-network/poktroll/testutil/sample"
"github.com/pokt-network/poktroll/x/application/keeper"
"github.com/pokt-network/poktroll/x/application/types"
)
Expand All @@ -25,7 +25,7 @@ type testAppModifier func(app *types.Application)
func createNApplications(keeper keeper.Keeper, ctx context.Context, n int, testAppModifiers ...testAppModifier) []types.Application {
apps := make([]types.Application, n)
for i := range apps {
apps[i].Address = strconv.Itoa(i)
apps[i].Address = sample.AccAddress()
// Setting pending undelegations since nullify.Fill() does not seem to do it.
apps[i].PendingUndelegations = make(map[uint64]types.UndelegatingGatewayList)

Expand All @@ -38,13 +38,11 @@ func createNApplications(keeper keeper.Keeper, ctx context.Context, n int, testA
return apps
}

// testAppModifierDelegateeAddr adds the supplied gateway address to the application's delegatee list if the application's address matches
// the supplied address list.
func withAppDelegateeGatewayAddr(delegateeGatewayAddr string, appsWithDelegationAddr []string) testAppModifier {
// withGatewayAddressDelegatedTo updates the list of gateways the application delegates
// to by adding the given gateway address.
func withGatewayAddressDelegatedTo(gatewayDelegatedToAddr string) testAppModifier {
return func(app *types.Application) {
if slices.Contains(appsWithDelegationAddr, app.Address) {
app.DelegateeGatewayAddresses = append(app.DelegateeGatewayAddresses, delegateeGatewayAddr)
}
app.DelegateeGatewayAddresses = append(app.DelegateeGatewayAddresses, gatewayDelegatedToAddr)
}
}

Expand Down
22 changes: 17 additions & 5 deletions x/application/keeper/query_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ import (
"github.com/pokt-network/poktroll/x/application/types"
)

func (k Keeper) AllApplications(ctx context.Context, req *types.QueryAllApplicationsRequest) (*types.QueryAllApplicationsResponse, error) {
// AllApplications returns all applications filtered based on any criteria specified in the request.
func (k Keeper) AllApplications(
ctx context.Context,
req *types.QueryAllApplicationsRequest,
) (*types.QueryAllApplicationsResponse, error) {
logger := k.Logger().With("method", "AllApplications")

if req == nil {
Expand All @@ -27,6 +31,12 @@ func (k Keeper) AllApplications(ctx context.Context, req *types.QueryAllApplicat

var apps []types.Application

// TODO_IMPROVE(#767): Consider adding a custom onchain index (similar to proofs)
// if/when the performance of the flags used to filter the response becomes an issue.
// Specifically, the following onchain indecies can be added:
// - app_addr -> [gateways delegated to]
// - gateway_addr -> [apps that delegate to it]
// - service_id -> [apps that have a service with that id]
store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx))
applicationStore := prefix.NewStore(store, types.KeyPrefix(types.ApplicationKeyPrefix))

Expand All @@ -37,10 +47,12 @@ func (k Keeper) AllApplications(ctx context.Context, req *types.QueryAllApplicat
return status.Error(codes.Internal, err.Error())
}

// Filter out the application if the request specifies a delegatee gateway address as a contraint and the application
// does not delegate to the specifies gateway address.
if req.DelegateeGatewayAddress != "" && !slices.Contains(application.DelegateeGatewayAddresses, req.DelegateeGatewayAddress) {
return nil
// Filter out the application if the request specifies a gateway address delegated to as a constraint
gatewayDelegatedToAddrFilter := req.GetGatewayAddressDelegatedTo()
if gatewayDelegatedToAddrFilter != "" {
if !slices.Contains(application.DelegateeGatewayAddresses, req.GatewayAddressDelegatedTo) {
return nil
}
}

// Ensure that the PendingUndelegations is an empty map and not nil when
Expand Down
25 changes: 16 additions & 9 deletions x/application/keeper/query_application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,25 +125,32 @@ func TestApplicationQueryPaginated(t *testing.T) {
})
}

func TestAllApplicationsQuery_WithDelegateeGatewayAddressConstraint(t *testing.T) {
func TestAllApplicationsQuery_WithGatewayAddressDelegatedTo(t *testing.T) {
keeper, ctx := keepertest.ApplicationKeeper(t)
gatewayAddr1 := sample.AccAddress()
appsWithDelegationAddr := []string{"1", "2"}
apps := createNApplications(keeper, ctx, 5, withAppDelegateeGatewayAddr(gatewayAddr1, appsWithDelegationAddr))
gatewayAddr := sample.AccAddress()

appsWithDelegation := createNApplications(keeper, ctx, 2, withGatewayAddressDelegatedTo(gatewayAddr))
appsWithDelegationAddrs := make([]string, len(appsWithDelegation))
for i, app := range appsWithDelegation {
appsWithDelegationAddrs[i] = app.Address
}

appsWithoutDelegation := createNApplications(keeper, ctx, 3)
apps := append(appsWithDelegation, appsWithoutDelegation...)

requestBuilder := func(gatewayAddr string) *types.QueryAllApplicationsRequest {
return &types.QueryAllApplicationsRequest{
DelegateeGatewayAddress: gatewayAddr,
GatewayAddressDelegatedTo: gatewayAddr,
}
}

t.Run("QueryAppsWithDelegatee", func(t *testing.T) {
resp, err := keeper.AllApplications(ctx, requestBuilder(gatewayAddr1))
t.Run("QueryAppsWithGatewayAddressDelegatedTo", func(t *testing.T) {
resp, err := keeper.AllApplications(ctx, requestBuilder(gatewayAddr))
require.NoError(t, err)

var expectedApps []types.Application
for _, app := range apps {
if slices.Contains(appsWithDelegationAddr, app.Address) {
if slices.Contains(appsWithDelegationAddrs, app.Address) {
expectedApps = append(expectedApps, app)
}
}
Expand All @@ -154,7 +161,7 @@ func TestAllApplicationsQuery_WithDelegateeGatewayAddressConstraint(t *testing.T
)
})

t.Run("QueryAppsWithNoDelegationConstraint", func(t *testing.T) {
t.Run("QueryAppsWithoutGatewayAddressDelegatedTo", func(t *testing.T) {
resp, err := keeper.AllApplications(ctx, &types.QueryAllApplicationsRequest{})
require.NoError(t, err)

Expand Down
79 changes: 50 additions & 29 deletions x/application/module/autocli.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,57 @@ import (
func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions {
return &autocliv1.ModuleOptions{
Query: &autocliv1.ServiceCommandDescriptor{
Service: modulev1.Query_ServiceDesc.ServiceName,
Service: modulev1.Query_ServiceDesc.ServiceName,
EnhanceCustomCommand: true, // Enable custom command enhancement for backwards compatibility
RpcCommandOptions: []*autocliv1.RpcCommandOptions{
// {
// RpcMethod: "Params",
// Use: "params",
// Short: "Shows the parameters of the module",
// Long: `Shows all the parameters related to the application module.
//
// Example:
// $ poktrolld q application params --node $(POCKET_NODE) --home $(POKTROLLD_HOME)`,
// },
// {
// RpcMethod: "AllApplications",
// Use: "list-application",
// Short: "List all application",
// Long: `List all the applications that staked in the network.
//
// Example:
// $ poktrolld q application list-application --node $(POCKET_NODE) --home $(POKTROLLD_HOME)`,
// },
// {
// RpcMethod: "Application",
// Use: "show-application [address]",
// Short: "Shows a application",
// Long: `Finds a staked application given its address.
//
// Example:
// $ poktrolld q application show-application $(APP_ADDRESS) --node $(POCKET_NODE) --home $(POKTROLLD_HOME)`,
// PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "address"}},
// },
{
Alias: []string{"apps", "ls"},
RpcMethod: "AllApplications",
Use: "list-applications",
Short: "List all applications on Pocket Network",
Long: `Retrieves a paginated list of all applications currently registered on Pocket Network, including all their details.

The command supports pagination parameters.
Returns application addresses, staked amounts, and current status.`,

Example: `
poktrolld query application list-applications
poktrolld query application list-applications --page 2 --limit 50
poktrolld query application list-applications --page 1 --limit 100`,
},
{
Alias: []string{"app", "a"},
RpcMethod: "Application",
Use: "show-application [address]",
Short: "Shows detailed information about a specific application",
Long: `Retrieves comprehensive information about an application identified by its address.

Returns details include:
- Application's staked amount and status
- Application metadata and configuration`,

Example: `
poktrolld query application show-application pokt1abc...xyz
poktrolld query application show-application pokt1abc...xyz --output json
poktrolld query application show-application pokt1abc...xyz --height 100`,
PositionalArgs: []*autocliv1.PositionalArgDescriptor{
{
ProtoField: "address",
},
},
},
{
RpcMethod: "Params",
Use: "params",
Short: "Shows the parameters of the application module",
Long: `Shows all the parameters related to the application module.

Returns the current values of all application module parameters.`,

Example: `
poktrolld query application params
poktrolld query application params --output json`,
},
// this line is used by ignite scaffolding # autocli/query
},
},
Expand Down
2 changes: 0 additions & 2 deletions x/application/module/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ func (am AppModule) GetQueryCmd() *cobra.Command {
}

cmd.AddCommand(CmdQueryParams())
cmd.AddCommand(CmdListApplication())
cmd.AddCommand(CmdShowApplication())
// this line is used by starport scaffolding # 1

return cmd
Expand Down
86 changes: 0 additions & 86 deletions x/application/module/query_application.go

This file was deleted.

Loading
Loading