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

[SDK] feat: Have distinct JSON-RPC and gRPC urls #261

Merged
merged 3 commits into from
Dec 13, 2023
Merged
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
2 changes: 1 addition & 1 deletion Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions pkg/client/query/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -14,5 +15,6 @@ var queryCodec *codec.ProtoCodec
func init() {
reg := codectypes.NewInterfaceRegistry()
accounttypes.RegisterInterfaces(reg)
cryptocodec.RegisterInterfaces(reg)
queryCodec = codec.NewProtoCodec(reg)
}
9 changes: 4 additions & 5 deletions pkg/client/query/supplierquerier.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import (
"context"

"cosmossdk.io/depinject"
cosmosclient "github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/gogoproto/grpc"
red-0ne marked this conversation as resolved.
Show resolved Hide resolved

"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"
)
Expand All @@ -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
}

Expand All @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥


return supq, nil
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/deps/config/suppliers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 11 additions & 3 deletions pkg/sdk/deps_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package sdk
import (
"context"
"fmt"
"net/url"

"cosmossdk.io/depinject"
grpctypes "github.com/cosmos/gogoproto/grpc"
Expand All @@ -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()
Expand All @@ -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 {
Expand Down Expand Up @@ -84,3 +85,10 @@ func (sdk *poktrollSDK) buildDeps(

return deps, nil
}

// hostToWebsocketURL converts the provided host into a websocket URL that can
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Going to update this in my PR. Should be queryNodeToWebsocketUrl

// 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)
}
7 changes: 4 additions & 3 deletions pkg/sdk/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading