Skip to content

Commit

Permalink
feat: Enable gRPC client connection
Browse files Browse the repository at this point in the history
  • Loading branch information
red-0ne committed Dec 11, 2023
1 parent 99f0549 commit 62069d5
Show file tree
Hide file tree
Showing 18 changed files with 378 additions and 172 deletions.
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", "40004", "36658"],
)
k8s_resource(
"relayminers",
Expand Down
3 changes: 2 additions & 1 deletion localnet/kubernetes/values-appgateserver.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
config:
query_node_url: tcp://sequencer-poktroll-sequencer:36657
query_node_grpc_url: tcp://sequencer-poktroll-sequencer:36658
pocket_node_websocket_url: tcp://sequencer-poktroll-sequencer:36657
6 changes: 3 additions & 3 deletions localnet/kubernetes/values-relayminer.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
config:
query_node_url: tcp://sequencer-poktroll-sequencer:36657
network_node_url: tcp://sequencer-poktroll-sequencer:36657

query_node_grpc_url: tcp://sequencer-poktroll-sequencer:36658
network_node_grpc_url: tcp://sequencer-poktroll-sequencer:36658
pocket_node_websocket_url: tcp://sequencer-poktroll-sequencer:36657
8 changes: 6 additions & 2 deletions localnet/poktrolld/config/appgate_server_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,9 @@ self_signing: true
signing_key: app1
# The host and port that the appgate server will listen on
listening_endpoint: http://localhost:42069
# tcp://<host>:<port> to a full pocket node for reading data and listening for on-chain events
query_node_url: tcp://127.0.0.1:36657
# tcp://<host>:<port> to a full pocket node for reading data
query_node_grpc_url: tcp://127.0.0.1:36658
# grpc client insecure flag
grpc_insecure: true
# tcp://<host>:<port> to a full pocket node websocket endpoint for listening for on-chain events
pocket_node_websocket_url: tcp://127.0.0.1:36657
10 changes: 7 additions & 3 deletions localnet/poktrolld/config/relayminer_config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# tcp://<host>:<port> to a full pocket node for reading data and listening for on-chain events
query_node_url: tcp://localhost:36657
# tcp://<host>:<port> to a full pocket node for reading data
query_node_grpc_url: tcp://127.0.0.1:36658
# tcp://<host>:<port> to a pocket node that gossips transactions throughout the network (may or may not be the sequencer)
network_node_url: tcp://127.0.0.1:36657
network_node_grpc_url: tcp://127.0.0.1:36658
# grpc client insecure flag
grpc_insecure: true
# tcp://<host>:<port> to a full pocket node websocket endpoint for listening for on-chain events
pocket_node_websocket_url: tcp://127.0.0.1:36657
# Name of the key (in the keyring) to sign transactions
signing_key_name: supplier1
# TODO_TECHDEBT(#137, #130): Once the `relayer.json` config file is implemented AND a local LLM RPC service
Expand Down
45 changes: 31 additions & 14 deletions pkg/appgateserver/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ import (
const omittedDefaultFlagValue = "explicitly omitting default"

var (
flagAppGateConfig string
flagCosmosNodeURL string
flagAppGateConfig string
flagCosmosNodeURL string
flagCosmosNodeGRPCURL string
)

// AppGateServerCmd returns the Cobra command for running the AppGate server.
Expand Down Expand Up @@ -66,8 +67,9 @@ provided that:

// Cosmos flags
cmd.Flags().String(cosmosflags.FlagKeyringBackend, "", "Select keyring's backend (os|file|kwallet|pass|test)")
cmd.Flags().
StringVar(&flagCosmosNodeURL, cosmosflags.FlagNode, omittedDefaultFlagValue, "Register the default Cosmos node flag, which is needed to initialize the Cosmos query context correctly. It can be used to override the `QueryNodeUrl` field in the config file if specified.")
cmd.Flags().StringVar(&flagCosmosNodeURL, cosmosflags.FlagNode, omittedDefaultFlagValue, "Register the default Cosmos node flag, which is needed to initialise the Cosmos query context correctly. It can be used to override the `QueryNodeUrl` field in the config file if specified.")

Check warning on line 70 in pkg/appgateserver/cmd/cmd.go

View workflow job for this annotation

GitHub Actions / misspell

[misspell] pkg/appgateserver/cmd/cmd.go#L70

"initialise" is a misspelling of "initialize"
Raw output
./pkg/appgateserver/cmd/cmd.go:70:149: "initialise" is a misspelling of "initialize"
cmd.Flags().StringVar(&flagCosmosNodeGRPCURL, cosmosflags.FlagGRPC, omittedDefaultFlagValue, "Register the default Cosmos node grpc flag, which is needed to initialise the Cosmos query context with grpc correctly. It can be used to override the `QueryNodeGRPCUrl` field in the config file if specified.")

Check warning on line 71 in pkg/appgateserver/cmd/cmd.go

View workflow job for this annotation

GitHub Actions / misspell

[misspell] pkg/appgateserver/cmd/cmd.go#L71

"initialise" is a misspelling of "initialize"
Raw output
./pkg/appgateserver/cmd/cmd.go:71:158: "initialise" is a misspelling of "initialize"
cmd.Flags().Bool(cosmosflags.FlagGRPCInsecure, true, "Used to initialise the Cosmos query context with grpc security options. It can be used to override the `QueryNodeGRPCInsecure` field in the config file if specified.")

Check warning on line 72 in pkg/appgateserver/cmd/cmd.go

View workflow job for this annotation

GitHub Actions / misspell

[misspell] pkg/appgateserver/cmd/cmd.go#L72

"initialise" is a misspelling of "initialize"
Raw output
./pkg/appgateserver/cmd/cmd.go:72:63: "initialise" is a misspelling of "initialize"

return cmd
}
Expand Down Expand Up @@ -145,26 +147,41 @@ func setupAppGateServerDependencies(
cmd *cobra.Command,
appGateConfig *appgateconfig.AppGateServerConfig,
) (_ depinject.Config, err error) {
queryNodeURL := appGateConfig.QueryNodeUrl
// Override the config file's `QueryNodeUrl` fields
pocketNodeWebsocketURL := appGateConfig.PocketNodeWebsocketUrl
queryNodeGRPCURL := appGateConfig.QueryNodeGRPCUrl

// Override the config file's `QueryNodeGRPCUrl` fields
// with the `--grpc-addr` flag if it was specified.
if flagCosmosNodeGRPCURL != omittedDefaultFlagValue {
queryNodeGRPCURL, err = url.Parse(flagCosmosNodeGRPCURL)
if err != nil {
return nil, fmt.Errorf("failed to parse Cosmos node URL: %w", err)
}
}

// Override the config file's `PocketNodeWebsocketUrl` fields
// with the `--node` flag if it was specified.
if flagCosmosNodeURL != omittedDefaultFlagValue {
queryNodeURL, err = url.Parse(flagCosmosNodeURL)
pocketNodeWebsocketURL, err = url.Parse(flagCosmosNodeURL)
if err != nil {
return nil, fmt.Errorf("failed to parse Cosmos node URL: %w", err)
}
}

supplierFuncs := []config.SupplierFn{
config.NewSupplyLoggerFromCtx(ctx),
config.NewSupplyEventsQueryClientFn(queryNodeURL.Host), // leaf
config.NewSupplyBlockClientFn(queryNodeURL.Host), // leaf
config.NewSupplyQueryClientContextFn(queryNodeURL.String()), // leaf
config.NewSupplyAccountQuerierFn(), // leaf
config.NewSupplyApplicationQuerierFn(), // leaf
config.NewSupplySessionQuerierFn(), // leaf
config.NewSupplyEventsQueryClientFn(pocketNodeWebsocketURL), // leaf
config.NewSupplyBlockClientFn(pocketNodeWebsocketURL), // leaf
config.NewSupplyQueryClientContextFn(queryNodeGRPCURL, appGateConfig.GRPCInsecure), // leaf
config.NewSupplyAccountQuerierFn(), // leaf
config.NewSupplyApplicationQuerierFn(), // leaf
config.NewSupplySessionQuerierFn(), // leaf
config.NewSupplyRingCacheFn(),
config.NewSupplyPOKTRollSDKFn(queryNodeURL, appGateConfig.SigningKey),
config.NewSupplyPOKTRollSDKFn(
queryNodeGRPCURL,
pocketNodeWebsocketURL,
appGateConfig.SigningKey,
),
}

return config.SupplyConfig(ctx, cmd, supplierFuncs)
Expand Down
47 changes: 31 additions & 16 deletions pkg/appgateserver/config/appgate_configs_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,22 @@ import (
// YAMLAppGateServerConfig is the structure used to unmarshal the AppGateServer config file
// TODO_DOCUMENT(@red-0ne): Add proper README documentation for yaml config files.
type YAMLAppGateServerConfig struct {
SelfSigning bool `yaml:"self_signing"`
SigningKey string `yaml:"signing_key"`
ListeningEndpoint string `yaml:"listening_endpoint"`
QueryNodeUrl string `yaml:"query_node_url"`
SelfSigning bool `yaml:"self_signing"`
SigningKey string `yaml:"signing_key"`
ListeningEndpoint string `yaml:"listening_endpoint"`
QueryNodeGRPCUrl string `yaml:"query_node_grpc_url"`
GRPCInsecure bool `yaml:"grpc_insecure"`
PocketNodeWebsocketUrl string `yaml:"pocket_node_websocket_url"`
}

// AppGateServerConfig is the structure describing the AppGateServer config
type AppGateServerConfig struct {
SelfSigning bool
SigningKey string
ListeningEndpoint *url.URL
QueryNodeUrl *url.URL
SelfSigning bool
SigningKey string
ListeningEndpoint *url.URL
QueryNodeGRPCUrl *url.URL
GRPCInsecure bool
PocketNodeWebsocketUrl *url.URL
}

// ParseAppGateServerConfigs parses the stake config file into a AppGateConfig
Expand All @@ -46,21 +50,32 @@ func ParseAppGateServerConfigs(configContent []byte) (*AppGateServerConfig, erro
return nil, ErrAppGateConfigInvalidListeningEndpoint.Wrapf("%s", err)
}

if yamlAppGateServerConfig.QueryNodeUrl == "" {
return nil, ErrAppGateConfigInvalidQueryNodeUrl
if yamlAppGateServerConfig.QueryNodeGRPCUrl == "" {
return nil, ErrAppGateConfigInvalidQueryNodeGRPCUrl
}

queryNodeUrl, err := url.Parse(yamlAppGateServerConfig.QueryNodeUrl)
queryNodeGRPCUrl, err := url.Parse(yamlAppGateServerConfig.QueryNodeGRPCUrl)
if err != nil {
return nil, ErrAppGateConfigInvalidQueryNodeUrl.Wrapf("%s", err)
return nil, ErrAppGateConfigInvalidQueryNodeGRPCUrl.Wrapf("%s", err)
}

if yamlAppGateServerConfig.PocketNodeWebsocketUrl == "" {
return nil, ErrAppGateConfigInvalidPocketNodeWebsocketUrl
}

pocketNodeWebsocketUrl, err := url.Parse(yamlAppGateServerConfig.PocketNodeWebsocketUrl)
if err != nil {
return nil, ErrAppGateConfigInvalidPocketNodeWebsocketUrl.Wrapf("%s", err)
}

// Populate the appGateServerConfig with the values from the yamlAppGateServerConfig
appGateServerConfig := &AppGateServerConfig{
SelfSigning: yamlAppGateServerConfig.SelfSigning,
SigningKey: yamlAppGateServerConfig.SigningKey,
ListeningEndpoint: listeningEndpoint,
QueryNodeUrl: queryNodeUrl,
SelfSigning: yamlAppGateServerConfig.SelfSigning,
SigningKey: yamlAppGateServerConfig.SigningKey,
ListeningEndpoint: listeningEndpoint,
QueryNodeGRPCUrl: queryNodeGRPCUrl,
GRPCInsecure: yamlAppGateServerConfig.GRPCInsecure,
PocketNodeWebsocketUrl: pocketNodeWebsocketUrl,
}

return appGateServerConfig, nil
Expand Down
95 changes: 79 additions & 16 deletions pkg/appgateserver/config/appgate_configs_reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,19 @@ func Test_ParseAppGateConfigs(t *testing.T) {
self_signing: true
signing_key: app1
listening_endpoint: http://localhost:42069
query_node_url: tcp://127.0.0.1:36657
query_node_grpc_url: tcp://127.0.0.1:36658
grpc_insecure: true
pocket_node_websocket_url: tcp://127.0.0.1:36657
`,

expectedError: nil,
expectedConfig: &config.AppGateServerConfig{
SelfSigning: true,
SigningKey: "app1",
ListeningEndpoint: &url.URL{Scheme: "http", Host: "localhost:42069"},
QueryNodeUrl: &url.URL{Scheme: "tcp", Host: "127.0.0.1:36657"},
SelfSigning: true,
SigningKey: "app1",
ListeningEndpoint: &url.URL{Scheme: "http", Host: "localhost:42069"},
QueryNodeGRPCUrl: &url.URL{Scheme: "tcp", Host: "127.0.0.1:36658"},
GRPCInsecure: true,
PocketNodeWebsocketUrl: &url.URL{Scheme: "tcp", Host: "127.0.0.1:36657", Path: "webcosket"},
},
},
{
Expand All @@ -46,15 +50,40 @@ func Test_ParseAppGateConfigs(t *testing.T) {
inputConfig: `
signing_key: app1
listening_endpoint: http://localhost:42069
query_node_url: tcp://127.0.0.1:36657
query_node_grpc_url: tcp://127.0.0.1:36658
grpc_insecure: true
pocket_node_websocket_url: tcp://127.0.0.1:36657
`,

expectedError: nil,
expectedConfig: &config.AppGateServerConfig{
SelfSigning: false,
SigningKey: "app1",
ListeningEndpoint: &url.URL{Scheme: "http", Host: "localhost:42069"},
QueryNodeUrl: &url.URL{Scheme: "tcp", Host: "127.0.0.1:36657"},
SelfSigning: false,
SigningKey: "app1",
ListeningEndpoint: &url.URL{Scheme: "http", Host: "localhost:42069"},
QueryNodeGRPCUrl: &url.URL{Scheme: "tcp", Host: "127.0.0.1:36658"},
GRPCInsecure: true,
PocketNodeWebsocketUrl: &url.URL{Scheme: "tcp", Host: "127.0.0.1:36657", Path: "webcosket"},
},
},
{
desc: "valid: AppGateServer config with undefined grpc insecure",

inputConfig: `
self_signing: true
signing_key: app1
listening_endpoint: http://localhost:42069
query_node_grpc_url: tcp://127.0.0.1:36658
pocket_node_websocket_url: tcp://127.0.0.1:36657
`,

expectedError: nil,
expectedConfig: &config.AppGateServerConfig{
SelfSigning: true,
SigningKey: "app1",
ListeningEndpoint: &url.URL{Scheme: "http", Host: "localhost:42069"},
QueryNodeGRPCUrl: &url.URL{Scheme: "tcp", Host: "127.0.0.1:36658"},
GRPCInsecure: false,
PocketNodeWebsocketUrl: &url.URL{Scheme: "tcp", Host: "127.0.0.1:36657", Path: "webcosket"},
},
},
// Invalid Configs
Expand All @@ -72,7 +101,9 @@ func Test_ParseAppGateConfigs(t *testing.T) {
self_signing: true
signing_key:
listening_endpoint: http://localhost:42069
query_node_url: tcp://127.0.0.1:36657
query_node_grpc_url: tcp://127.0.0.1:36658
grpc_insecure: true
pocket_node_websocket_url: tcp://127.0.0.1:36657
`,

expectedError: config.ErrAppGateConfigEmptySigningKey,
Expand All @@ -84,22 +115,53 @@ func Test_ParseAppGateConfigs(t *testing.T) {
self_signing: true
signing_key: app1
listening_endpoint: &localhost:42069
query_node_url: tcp://127.0.0.1:36657
query_node_grpc_url: tcp://127.0.0.1:36658
grpc_insecure: true
pocket_node_websocket_url: tcp://127.0.0.1:36657
`,

expectedError: config.ErrAppGateConfigInvalidListeningEndpoint,
},
{
desc: "invalid: invalid query node url",
desc: "invalid: invalid query node grpc url",

inputConfig: `
self_signing: true
signing_key: app1
listening_endpoint: http://localhost:42069
query_node_grpc_url: &127.0.0.1:36658
grpc_insecure: true
pocket_node_websocket_url: tcp://127.0.0.1:36657
`,

expectedError: config.ErrAppGateConfigInvalidQueryNodeGRPCUrl,
},
{
desc: "invalid: invalid pocket node websocket",

inputConfig: `
self_signing: true
signing_key: app1
listening_endpoint: http://localhost:42069
query_node_grpc_url: tcp://127.0.0.1:36658
grpc_insecure: true
pocket_node_websocket_url: &127.0.0.1:36657
`,

expectedError: config.ErrAppGateConfigInvalidPocketNodeWebsocketUrl,
},
{
desc: "invalid: missing pocket node websocket url",

inputConfig: `
self_signing: true
signing_key: app1
listening_endpoint: http://localhost:42069
query_node_url: &127.0.0.1:36657
query_node_grpc_url: tcp://127.0.0.1:36658
grpc_insecure: true
`,

expectedError: config.ErrAppGateConfigInvalidQueryNodeUrl,
expectedError: config.ErrAppGateConfigInvalidPocketNodeWebsocketUrl,
},
}

Expand All @@ -123,7 +185,8 @@ func Test_ParseAppGateConfigs(t *testing.T) {
require.Equal(t, tt.expectedConfig.SelfSigning, config.SelfSigning)
require.Equal(t, tt.expectedConfig.SigningKey, config.SigningKey)
require.Equal(t, tt.expectedConfig.ListeningEndpoint.String(), config.ListeningEndpoint.String())
require.Equal(t, tt.expectedConfig.QueryNodeUrl.String(), config.QueryNodeUrl.String())
require.Equal(t, tt.expectedConfig.QueryNodeGRPCUrl.String(), config.QueryNodeGRPCUrl.String())
require.Equal(t, tt.expectedConfig.QueryNodeGRPCUrl.String(), config.QueryNodeGRPCUrl.String())
})
}
}
11 changes: 6 additions & 5 deletions pkg/appgateserver/config/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package config
import sdkerrors "cosmossdk.io/errors"

var (
codespace = "appgate_config"
ErrAppGateConfigUnmarshalYAML = sdkerrors.Register(codespace, 1, "config reader cannot unmarshal yaml content")
ErrAppGateConfigEmptySigningKey = sdkerrors.Register(codespace, 2, "empty signing key in AppGateServer config")
ErrAppGateConfigInvalidListeningEndpoint = sdkerrors.Register(codespace, 3, "invalid listening endpoint in AppGateServer config")
ErrAppGateConfigInvalidQueryNodeUrl = sdkerrors.Register(codespace, 4, "invalid pocket query node url in AppGateServer config")
codespace = "appgate_config"
ErrAppGateConfigUnmarshalYAML = sdkerrors.Register(codespace, 1, "config reader cannot unmarshal yaml content")
ErrAppGateConfigEmptySigningKey = sdkerrors.Register(codespace, 2, "empty signing key in AppGateServer config")
ErrAppGateConfigInvalidListeningEndpoint = sdkerrors.Register(codespace, 3, "invalid listening endpoint in AppGateServer config")
ErrAppGateConfigInvalidQueryNodeGRPCUrl = sdkerrors.Register(codespace, 5, "invalid pocket query node grpc url in AppGateServer config")
ErrAppGateConfigInvalidPocketNodeWebsocketUrl = sdkerrors.Register(codespace, 6, "invalid pocket node websocket url in AppGateServer config")
)
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)
}
Loading

0 comments on commit 62069d5

Please sign in to comment.