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

[Optimization] On-chain indexing of GetApplicationsDelegatingToGateway #767

Open
7 tasks
Olshansk opened this issue Aug 28, 2024 · 0 comments
Open
7 tasks
Assignees
Labels
community A ticket intended to potentially be picked up by a community member on-chain On-chain business logic

Comments

@Olshansk
Copy link
Member

Objective

Enable a potentially common operations the shannon-sdk will need.

Origin Document

This came up in a conversation with @adshmh and @commodity. The diff at the bottom of

Goals

  • Use on-chain indexing to enable a potentially common operations gateways will need
  • Avoid off-chain tools resolving the same issue

Deliverables

  • A PR that indexes applications based on the gateway they delegate to
  • A PR that updates QueryAllApps with a filter on "gateway_addr_delegated_to`
  • Follow the same patterns as in QueryAllProofs

General deliverables

  • Comments: Add/update TODOs and comments alongside the source code so it is easier to follow.
  • Testing: Add new tests (unit and/or E2E) to the test suite.
  • Makefile: Add new targets to the Makefile to make the new functionality easier to use.
  • Documentation: Update architectural or development READMEs; use mermaid diagrams where appropriate.

Creator: @Olshansk
Co-Owners: @adshmh @commodity

diff --git a/proto/poktroll/application/query.proto b/proto/poktroll/application/query.proto
index 0707ea6f..56e51b00 100644
--- a/proto/poktroll/application/query.proto
+++ b/proto/poktroll/application/query.proto
@@ -52,6 +52,11 @@ message QueryGetApplicationResponse {
 
 message QueryAllApplicationsRequest {
   cosmos.base.query.v1beta1.PageRequest pagination = 1;
+
+  oneof filter {
+    string gateway_address = 2;
+  }
+
 }
 
 message QueryAllApplicationsResponse {
diff --git a/x/application/keeper/application.go b/x/application/keeper/application.go
index e48068f3..028a8c90 100644
--- a/x/application/keeper/application.go
+++ b/x/application/keeper/application.go
@@ -2,10 +2,12 @@ package keeper
 
 import (
 	"context"
+	"fmt"
 
 	"cosmossdk.io/store/prefix"
 	storetypes "cosmossdk.io/store/types"
 	"github.com/cosmos/cosmos-sdk/runtime"
+	"github.com/docker/docker/daemon/logger"
 
 	"github.com/pokt-network/poktroll/x/application/types"
 )
@@ -13,9 +15,18 @@ import (
 // SetApplication set a specific application in the store from its index
 func (k Keeper) SetApplication(ctx context.Context, application types.Application) {
 	storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx))
-	store := prefix.NewStore(storeAdapter, types.KeyPrefix(types.ApplicationKeyPrefix))
+
+	primaryStore := prefix.NewStore(storeAdapter, types.KeyPrefix(types.ApplicationKeyPrefix))
 	appBz := k.cdc.MustMarshal(&application)
-	store.Set(types.ApplicationKey(application.Address), appBz)
+	primaryStore.Set(types.ApplicationKey(application.Address), appBz)
+
+	// Update the address index: supplierOperatorAddress -> [ProofPrimaryKey]
+	gatewayAddrStore := prefix.NewStore(storeAdapter, types.KeyPrefix(types.GatewayApplicationKeyPrefix))
+	// supplierOperatorAddrKey := types.ProofSupplierOperatorAddressKey(proof.GetSupplierOperatorAddress(), primaryKey)
+	// gatewayAddrStore.Set(supplierOperatorAddrKey, primaryKey)
+
+	logger.Info(fmt.Sprintf("indexed Proof for supplier %s with primaryKey %s", proof.GetSupplierOperatorAddress(), primaryKey))
+
 }
 
 // GetApplication returns a application from its index
diff --git a/x/application/keeper/query_application.go b/x/application/keeper/query_application.go
index 446449d2..ab0b8494 100644
--- a/x/application/keeper/query_application.go
+++ b/x/application/keeper/query_application.go
@@ -38,6 +38,8 @@ func (k Keeper) AllApplications(ctx context.Context, req *types.QueryAllApplicat
 		return nil
 	})
 
+	// Look at `query_proof.go`
+
 	if err != nil {
 		return nil, status.Error(codes.Internal, err.Error())
 	}
diff --git a/x/application/types/key_application.go b/x/application/types/key_application.go
index cb11774e..06214902 100644
--- a/x/application/types/key_application.go
+++ b/x/application/types/key_application.go
@@ -6,7 +6,8 @@ var _ binary.ByteOrder
 
 const (
 	// ApplicationKeyPrefix is the prefix to retrieve all Application
-	ApplicationKeyPrefix = "Application/address/"
+	ApplicationKeyPrefix        = "Application/address/"
+	GatewayApplicationKeyPrefix = "Application/gateway_address/"
 )
 
 // ApplicationKey returns the store key to retrieve a Application from the index fields
@Olshansk Olshansk added on-chain On-chain business logic community A ticket intended to potentially be picked up by a community member labels Aug 28, 2024
@Olshansk Olshansk added this to the Shannon Post MainNet Ideas milestone Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community A ticket intended to potentially be picked up by a community member on-chain On-chain business logic
Projects
Status: 👀 In review
Development

No branches or pull requests

2 participants