Skip to content

Commit

Permalink
[Cleanup] Centralzie websocket url -> endpoint changes (#272)
Browse files Browse the repository at this point in the history
* Refactor all websocket url changes to one location
* Fix import orders
* Remove the hack for session rollover
  • Loading branch information
Olshansk authored Dec 14, 2023
1 parent df73cfa commit d132e1d
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 42 deletions.
23 changes: 10 additions & 13 deletions pkg/deps/config/suppliers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@ package config

import (
"context"
"fmt"
"net/url"

"cosmossdk.io/depinject"
cosmosclient "github.com/cosmos/cosmos-sdk/client"
cosmosflags "github.com/cosmos/cosmos-sdk/client/flags"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
grpc "github.com/cosmos/gogoproto/grpc"
"github.com/spf13/cobra"

"github.com/pokt-network/poktroll/pkg/client/block"
"github.com/pokt-network/poktroll/pkg/client/events"
"github.com/pokt-network/poktroll/pkg/client/query"
Expand All @@ -20,8 +17,16 @@ import (
"github.com/pokt-network/poktroll/pkg/crypto/rings"
"github.com/pokt-network/poktroll/pkg/polylog"
"github.com/pokt-network/poktroll/pkg/sdk"
"github.com/spf13/cobra"
)

// SupplierFn is a function that is used to supply a depinject config.
type SupplierFn func(
context.Context,
depinject.Config,
*cobra.Command,
) (depinject.Config, error)

// SupplyConfig supplies a depinject config by calling each of the supplied
// supplier functions in order and passing the result of each supplier to the
// next supplier, chaining them together.
Expand Down Expand Up @@ -64,7 +69,7 @@ func NewSupplyEventsQueryClientFn(queryHost string) SupplierFn {
_ *cobra.Command,
) (depinject.Config, error) {
// Convert the host to a websocket URL
pocketNodeWebsocketURL := hostToWebsocketURL(queryHost)
pocketNodeWebsocketURL := sdk.HostToWebsocketURL(queryHost)
eventsQueryClient := events.NewEventsQueryClient(pocketNodeWebsocketURL)

return depinject.Configs(deps, depinject.Supply(eventsQueryClient)), nil
Expand All @@ -82,7 +87,7 @@ func NewSupplyBlockClientFn(queryHost string) SupplierFn {
_ *cobra.Command,
) (depinject.Config, error) {
// Convert the host to a websocket URL
pocketNodeWebsocketURL := hostToWebsocketURL(queryHost)
pocketNodeWebsocketURL := sdk.HostToWebsocketURL(queryHost)
blockClient, err := block.NewBlockClient(ctx, deps, pocketNodeWebsocketURL)
if err != nil {
return nil, err
Expand Down Expand Up @@ -322,11 +327,3 @@ func NewSupplyPOKTRollSDKFn(
return depinject.Configs(deps, depinject.Supply(poktrollSDK)), 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 hostToWebsocketURL(host string) string {
websocketURL := fmt.Sprintf("ws://%s/websocket", host)
return websocketURL
}
15 changes: 0 additions & 15 deletions pkg/deps/config/types.go

This file was deleted.

7 changes: 4 additions & 3 deletions pkg/relayer/config/relayminer_configs_reader.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package config

import (
"fmt"
"net/url"

"gopkg.in/yaml.v2"
yaml "gopkg.in/yaml.v2"

"github.com/pokt-network/poktroll/pkg/sdk"
)

// YAMLRelayMinerConfig is the structure used to unmarshal the RelayMiner config file
Expand Down Expand Up @@ -60,7 +61,7 @@ func ParseRelayMinerConfigs(configContent []byte) (*RelayMinerConfig, error) {
}

// Parse the websocket URL of the Pocket Node to connect to for subscribing to on-chain events.
pocketNodeWebsocketUrl := fmt.Sprintf("ws://%s/websocket", queryNodeUrl.Host)
pocketNodeWebsocketUrl := sdk.HostToWebsocketURL(queryNodeUrl.Host)

if yamlRelayMinerConfig.SigningKeyName == "" {
return nil, ErrRelayMinerConfigInvalidSigningKeyName
Expand Down
3 changes: 2 additions & 1 deletion pkg/relayer/proxy/relay_verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

sdkerrors "cosmossdk.io/errors"
ring_secp256k1 "github.com/athanorlabs/go-dleq/secp256k1"
"github.com/noot/ring-go"
ring "github.com/noot/ring-go"

"github.com/pokt-network/poktroll/x/service/types"
sharedtypes "github.com/pokt-network/poktroll/x/shared/types"
Expand Down Expand Up @@ -97,6 +97,7 @@ func (rp *relayerProxy) VerifyRelayRequest(

currentBlock := rp.blockClient.LastNBlocks(ctx, 1)[0]
session, err := rp.sessionQuerier.GetSession(ctx, appAddress, service.Id, currentBlock.Height())

if err != nil {
return err
}
Expand Down
11 changes: 1 addition & 10 deletions pkg/sdk/deps_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package sdk

import (
"context"
"fmt"
"net/url"

"cosmossdk.io/depinject"
grpctypes "github.com/cosmos/gogoproto/grpc"
Expand All @@ -24,7 +22,7 @@ func (sdk *poktrollSDK) buildDeps(
ctx context.Context,
config *POKTRollSDKConfig,
) (depinject.Config, error) {
pocketNodeWebsocketURL := queryNodeToWebsocketURL(config.QueryNodeUrl)
pocketNodeWebsocketURL := HostToWebsocketURL(config.QueryNodeUrl.Host)

// Have a new depinject config
deps := depinject.Configs()
Expand Down Expand Up @@ -85,10 +83,3 @@ 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)
}
10 changes: 10 additions & 0 deletions pkg/sdk/urls.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package sdk

import "fmt"

// 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 HostToWebsocketURL(host string) string {
return fmt.Sprintf("ws://%s/websocket", host)
}

0 comments on commit d132e1d

Please sign in to comment.