From 44f2b43f8df111cdefa27659f849a1fb59bb2ae5 Mon Sep 17 00:00:00 2001 From: Redouane Lakrache Date: Wed, 13 Dec 2023 16:24:34 +0100 Subject: [PATCH] [SDK] feat: Have distinct JSON-RPC and gRPC urls (#261) * feat: Have distinct JSON-RPC and gRPC urls * chore: Trigger e2e tests * chore: Fix import groups --- Tiltfile | 2 +- pkg/client/query/codec.go | 2 ++ pkg/client/query/supplierquerier.go | 9 ++++----- pkg/deps/config/suppliers.go | 5 ++--- pkg/sdk/deps_builder.go | 14 +++++++++++--- pkg/sdk/sdk.go | 7 ++++--- 6 files changed, 24 insertions(+), 15 deletions(-) diff --git a/Tiltfile b/Tiltfile index b7093223a..e7444a901 100644 --- a/Tiltfile +++ b/Tiltfile @@ -152,7 +152,7 @@ k8s_resource( "sequencer", labels=["blockchains"], resource_deps=["celestia-rollkit"], - port_forwards=["36657", "40004"], + port_forwards=["36657", "36658", "40004"], ) k8s_resource( "relayminers", diff --git a/pkg/client/query/codec.go b/pkg/client/query/codec.go index fd9e83125..536df1484 100644 --- a/pkg/client/query/codec.go +++ b/pkg/client/query/codec.go @@ -3,6 +3,7 @@ package query import ( "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" + cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" accounttypes "github.com/cosmos/cosmos-sdk/x/auth/types" ) @@ -14,5 +15,6 @@ var queryCodec *codec.ProtoCodec func init() { reg := codectypes.NewInterfaceRegistry() accounttypes.RegisterInterfaces(reg) + cryptocodec.RegisterInterfaces(reg) queryCodec = codec.NewProtoCodec(reg) } diff --git a/pkg/client/query/supplierquerier.go b/pkg/client/query/supplierquerier.go index 4f8647838..4c4a91b2f 100644 --- a/pkg/client/query/supplierquerier.go +++ b/pkg/client/query/supplierquerier.go @@ -4,10 +4,9 @@ import ( "context" "cosmossdk.io/depinject" - cosmosclient "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/gogoproto/grpc" "github.com/pokt-network/poktroll/pkg/client" - "github.com/pokt-network/poktroll/pkg/client/query/types" sharedtypes "github.com/pokt-network/poktroll/x/shared/types" suppliertypes "github.com/pokt-network/poktroll/x/supplier/types" ) @@ -16,7 +15,7 @@ import ( // querying of on-chain supplier information through a single exposed method // which returns an sharedtypes.Supplier struct type supplierQuerier struct { - clientCtx types.Context + clientConn grpc.ClientConn supplierQuerier suppliertypes.QueryClient } @@ -30,12 +29,12 @@ func NewSupplierQuerier(deps depinject.Config) (client.SupplierQueryClient, erro if err := depinject.Inject( deps, - &supq.clientCtx, + &supq.clientConn, ); err != nil { return nil, err } - supq.supplierQuerier = suppliertypes.NewQueryClient(cosmosclient.Context(supq.clientCtx)) + supq.supplierQuerier = suppliertypes.NewQueryClient(supq.clientConn) return supq, nil } diff --git a/pkg/deps/config/suppliers.go b/pkg/deps/config/suppliers.go index 48283f849..dd6897b22 100644 --- a/pkg/deps/config/suppliers.go +++ b/pkg/deps/config/suppliers.go @@ -309,9 +309,8 @@ func NewSupplyPOKTRollSDKFn( } config := &sdk.POKTRollSDKConfig{ - PrivateKey: privateKey, - PocketNodeUrl: queryNodeURL, - Deps: deps, + PrivateKey: privateKey, + Deps: deps, } poktrollSDK, err := sdk.NewPOKTRollSDK(ctx, config) diff --git a/pkg/sdk/deps_builder.go b/pkg/sdk/deps_builder.go index 73464d821..8433344bb 100644 --- a/pkg/sdk/deps_builder.go +++ b/pkg/sdk/deps_builder.go @@ -3,6 +3,7 @@ package sdk import ( "context" "fmt" + "net/url" "cosmossdk.io/depinject" grpctypes "github.com/cosmos/gogoproto/grpc" @@ -23,7 +24,7 @@ func (sdk *poktrollSDK) buildDeps( ctx context.Context, config *POKTRollSDKConfig, ) (depinject.Config, error) { - pocketNodeWebsocketURL := fmt.Sprintf("ws://%s/websocket", config.PocketNodeUrl.Host) + pocketNodeWebsocketURL := queryNodeToWebsocketURL(config.QueryNodeUrl) // Have a new depinject config deps := depinject.Configs() @@ -43,10 +44,10 @@ func (sdk *poktrollSDK) buildDeps( deps = depinject.Configs(deps, depinject.Supply(blockClient)) // Create and supply the grpc client used by the queriers - // TODO_TECHDEBT: Configure the grpc client options from the config + // TODO_TECHDEBT: Configure the grpc client options from the config. var grpcClient grpctypes.ClientConn grpcClient, err = grpc.Dial( - config.PocketNodeUrl.Host, + config.QueryNodeGRPCUrl.Host, grpc.WithTransportCredentials(insecure.NewCredentials()), ) if err != nil { @@ -84,3 +85,10 @@ func (sdk *poktrollSDK) buildDeps( return deps, nil } + +// hostToWebsocketURL converts the provided host into a websocket URL that can +// be used to subscribe to onchain events and query the chain via a client +// context or send transactions via a tx client context. +func queryNodeToWebsocketURL(queryNode *url.URL) string { + return fmt.Sprintf("ws://%s/websocket", queryNode.Host) +} diff --git a/pkg/sdk/sdk.go b/pkg/sdk/sdk.go index 233807cec..d3c97d867 100644 --- a/pkg/sdk/sdk.go +++ b/pkg/sdk/sdk.go @@ -24,9 +24,10 @@ var _ POKTRollSDK = (*poktrollSDK)(nil) // Deps is an optional field that can be used to provide the needed dependencies // for the SDK. If it is not provided, the SDK will build the dependencies itself. type POKTRollSDKConfig struct { - PocketNodeUrl *url.URL - PrivateKey cryptotypes.PrivKey - Deps depinject.Config + QueryNodeGRPCUrl *url.URL + QueryNodeUrl *url.URL + PrivateKey cryptotypes.PrivKey + Deps depinject.Config } // poktrollSDK is the implementation of the POKTRollSDK.