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

[Relay] E2E Relay Gaps #177

Merged
merged 129 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from 122 commits
Commits
Show all changes
129 commits
Select commit Hold shift + click to select a range
29b9bdf
refactor: `MapFn`s receive context arg
bryanchriswhite Nov 9, 2023
b6c9c71
chore: add `ForEach` map shorthand operator
bryanchriswhite Nov 9, 2023
f257b46
chore: add `/pkg/observable/filter`
bryanchriswhite Nov 9, 2023
194cee5
chore: add `/pkg/observable/logging`
bryanchriswhite Nov 9, 2023
cca55c2
chore: add `/pkg/relayer/protocol`
bryanchriswhite Nov 9, 2023
c666542
chore: add `Miner` interface
bryanchriswhite Nov 9, 2023
ea8d848
feat: add `Miner` implementation
bryanchriswhite Nov 9, 2023
38329bb
test: `Miner` implementation
bryanchriswhite Nov 9, 2023
d2f9cb4
chore: fix comment
bryanchriswhite Nov 9, 2023
d502b75
chore: add godoc comments
bryanchriswhite Nov 9, 2023
48cef80
feat: Add Relayer struct
red-0ne Nov 9, 2023
f85a381
Merge remote-tracking branch 'pokt/main' into issues/13/feat/miner
bryanchriswhite Nov 9, 2023
cba145e
chore: Rename to RelayMiner
red-0ne Nov 9, 2023
c81c274
chore: Rename relay miner file
red-0ne Nov 9, 2023
0e38e7d
chore: Remove unused
red-0ne Nov 9, 2023
f9e1cbc
[Test] First step for automated E2E Relay test (#167)
Olshansk Nov 9, 2023
0e72490
[Relayer] refactor: simplify `RelayerSessionsManager` (#169)
bryanchriswhite Nov 9, 2023
107f6dd
chore: review feedback improvements
bryanchriswhite Nov 9, 2023
ccad087
chore: review feedback improvements
bryanchriswhite Nov 9, 2023
8737024
Merge remote-tracking branch 'pokt/main' into issues/13/feat/miner
bryanchriswhite Nov 9, 2023
e041472
chore: update start mining comment
red-0ne Nov 9, 2023
8cf0784
fix: Update Miner interface
red-0ne Nov 9, 2023
85a49b7
fix: import cycle & goimports
bryanchriswhite Nov 9, 2023
0788e1d
chore: review feedback improvements
bryanchriswhite Nov 9, 2023
e6a558b
chore: cleanup TODO_THIS_COMMIT comments
bryanchriswhite Nov 9, 2023
d04ea2a
Merge branch 'main' into issues/13/feat/miner
bryanchriswhite Nov 9, 2023
9c75b2c
chore: improve var & func names for clarity and consistency
bryanchriswhite Nov 10, 2023
286e1b2
Merge remote-tracking branch 'pokt/main' into issues/13/feat/miner
bryanchriswhite Nov 10, 2023
a0ffe9d
refactor: move claim/proof lifecycle concerns to `relayerSessionsMana…
bryanchriswhite Nov 10, 2023
2019637
chore: review feedback improvements
bryanchriswhite Nov 10, 2023
709f661
chore: review feedback improvements
bryanchriswhite Nov 10, 2023
394575b
refactor: `miner#hash()` method
bryanchriswhite Nov 10, 2023
1eae9d2
chore: tidy up
bryanchriswhite Nov 10, 2023
efb8a4e
chore: simplify
bryanchriswhite Nov 10, 2023
b38aa81
wip: relayer CLI
bryanchriswhite Nov 10, 2023
c1be2b5
chore: finish first pass
bryanchriswhite Nov 10, 2023
3b2022a
chore: review feedback improvements
bryanchriswhite Nov 10, 2023
967dddc
chore: review feedback improvements
bryanchriswhite Nov 10, 2023
f9a6fb2
chore: review feedback improvements
bryanchriswhite Nov 10, 2023
7d23bd4
chore: review feedback improvements
bryanchriswhite Nov 10, 2023
916c0dd
chore: review feedback improvements
bryanchriswhite Nov 10, 2023
04a79b2
chore: tidy up cmd creation
h5law Nov 10, 2023
55c8118
fix: incomplete refactor
bryanchriswhite Nov 10, 2023
c1784f5
chore: simplify
bryanchriswhite Nov 10, 2023
92925eb
Merge branch 'issues/13/feat/miner' into relayer/cli
bryanchriswhite Nov 10, 2023
0bfdc80
chore: add log lines
h5law Nov 10, 2023
c49394e
Merge remote-tracking branch 'pokt/relayer/cli' into relayer/cli
bryanchriswhite Nov 10, 2023
9efde4f
wip: react to miner, refactor, construct miner, refactor
bryanchriswhite Nov 10, 2023
3de8b3e
chore: cleanup
bryanchriswhite Nov 10, 2023
323b074
Merge remote-tracking branch 'origin/issues/13/feat/miner' into feat/…
red-0ne Nov 10, 2023
059b7df
chore: Reflect responsibility changes of session manager
red-0ne Nov 10, 2023
6460fa9
Merge remote-tracking branch 'origin/main' into feat/relayer
red-0ne Nov 10, 2023
9dfe585
Merge branch 'feat/relayer' into relayer/cli
red-0ne Nov 10, 2023
5f9bd5f
feat: Use relay miner to start
red-0ne Nov 10, 2023
1dcdbbe
chore: Improve comment about startig relayer proxy
red-0ne Nov 10, 2023
da46de7
wip: debugging
bryanchriswhite Nov 10, 2023
6835ce9
Merge remote-tracking branch 'origin/main' into relayer/cli
red-0ne Nov 10, 2023
51bccfe
Merge remote-tracking branch 'origin/main' into relayer/cli
red-0ne Nov 10, 2023
47d8685
wip: debugging
bryanchriswhite Nov 11, 2023
a69b5f3
Merge remote-tracking branch 'pokt/relayer/cli' into relayer/cli
bryanchriswhite Nov 11, 2023
beb0757
wip: debugging
bryanchriswhite Nov 11, 2023
ec1910f
chore: Rename falg variables
red-0ne Nov 11, 2023
ded793f
wip: debugging
bryanchriswhite Nov 11, 2023
9ba2dc1
Merge remote-tracking branch 'origin/relayer/cli' into relayer/cli
red-0ne Nov 11, 2023
bf936e6
revertme: disable tilt relayer service
bryanchriswhite Nov 11, 2023
c96e5c5
Merge remote-tracking branch 'origin/relayer/cli' into relayer/cli
red-0ne Nov 11, 2023
0d9edb9
chore: use arg not flag
h5law Nov 11, 2023
5c5eace
chore: rename command
red-0ne Nov 11, 2023
a3a3635
wip: debugging - improvments
bryanchriswhite Nov 11, 2023
641d60a
Merge remote-tracking branch 'pokt/relayer/cli' into relayer/cli
bryanchriswhite Nov 11, 2023
71052b7
wip: debugging
bryanchriswhite Nov 11, 2023
fa8c2eb
wip: debugging
bryanchriswhite Nov 11, 2023
0638e8d
wip: debugging
bryanchriswhite Nov 11, 2023
bb87722
revert-or-fixme: add error log lines
bryanchriswhite Nov 12, 2023
bcfbef1
revert-or-fixme: add debug log lines
bryanchriswhite Nov 12, 2023
4019a17
fix: set relay server handle function
bryanchriswhite Nov 12, 2023
9c3cfb5
revert-or-fixme: add debug log lines
bryanchriswhite Nov 12, 2023
2c130ce
chore: rename some chan vars
bryanchriswhite Nov 12, 2023
8493b2c
feat: fix all bugs, e2e relay works
h5law Nov 12, 2023
c85f75b
Merge branch 'refactor_appgate' into relayer/cli
h5law Nov 12, 2023
dfd28f8
chore: add some todo comments
h5law Nov 12, 2023
5ab0e4c
wip: debugging
bryanchriswhite Nov 12, 2023
ff4997a
fix: use remote helm charts again
bryanchriswhite Nov 13, 2023
ac54c24
fix: put adequate proxied services endpoitns, prevent session republi…
red-0ne Nov 13, 2023
efc2ab5
chore: Refactor JSONRPCServer and server builder
red-0ne Nov 13, 2023
9c32675
Upate a couple small comments in the maketfile
Olshansk Nov 14, 2023
17597c4
revert: comment relayers out of tiltfile
bryanchriswhite Nov 14, 2023
23ac551
chore: fix subcmd name `relayerminer` -> `relayminer`
bryanchriswhite Nov 14, 2023
e13211e
chore: improve logging
bryanchriswhite Nov 14, 2023
cf5910f
chore: cleanup error messaging & logging in appgate server
bryanchriswhite Nov 14, 2023
eb56997
refactor: rename misnamed `jsonRPCServer` receiver var
bryanchriswhite Nov 14, 2023
5e60381
chore: remove appgate server debug log
bryanchriswhite Nov 14, 2023
0bd05ae
chore: unexport `relayMiner` struct
bryanchriswhite Nov 14, 2023
a031b92
refactor: interrupt signal handling
bryanchriswhite Nov 14, 2023
c05ba2b
chore: improve comments
bryanchriswhite Nov 14, 2023
aeb4ee8
chore: improve comments
bryanchriswhite Nov 14, 2023
6648a38
revert: tiltfile hot-reload dirs
bryanchriswhite Nov 14, 2023
e5a4d73
refactor: re-consolidate client contexts
bryanchriswhite Nov 14, 2023
95fc559
fix: typo
bryanchriswhite Nov 14, 2023
c3898e0
chore: remove todo
bryanchriswhite Nov 14, 2023
c61abaf
chore: add todo comment
bryanchriswhite Nov 14, 2023
839a3dc
revert: comment change
bryanchriswhite Nov 14, 2023
ff8fc6a
fix: error format strings
bryanchriswhite Nov 14, 2023
66bfba5
chore: remove comment
bryanchriswhite Nov 14, 2023
15948a8
Merge branch 'main' into relayer/cli
bryanchriswhite Nov 14, 2023
95a6dc9
fix: error format strings
bryanchriswhite Nov 14, 2023
5bfe151
chore: update anvil service port in make targets
bryanchriswhite Nov 15, 2023
86255b3
chore: review feedback improvements
bryanchriswhite Nov 15, 2023
0aaddc8
refactor: relayminer depinject helpers & godoc comments on all constr…
bryanchriswhite Nov 15, 2023
6ad6abe
refactor: separate tx and query client contexts 🙄
bryanchriswhite Nov 15, 2023
88e046d
fix: sessiontree store path check
bryanchriswhite Nov 15, 2023
9b83691
fix: sessiontree store path check
bryanchriswhite Nov 15, 2023
c865eb0
chore: review feedback improvements
bryanchriswhite Nov 15, 2023
fe9db58
chore: review feedback improvements
bryanchriswhite Nov 15, 2023
8d7e577
chore: add long command description
bryanchriswhite Nov 15, 2023
f945513
fix: supplier client test
bryanchriswhite Nov 15, 2023
0a53626
Merge branch 'main' into relayer/cli
bryanchriswhite Nov 15, 2023
4ce831b
chore: cleanup flags and dependencies for appgateserver cmd
h5law Nov 15, 2023
d83c1e7
chore: move shared dependency setup logic to shared pkg
h5law Nov 15, 2023
e58c848
chore: update comment
h5law Nov 15, 2023
75343bb
Update .gitignore
Olshansk Nov 15, 2023
1cc7085
Update OpenAPI spec
Olshansk Nov 15, 2023
a04ebfc
Updated comments for post 177+179 work for okdas
Olshansk Nov 15, 2023
59f863c
Update pkg/relayer/cmd/cmd.go
Olshansk Nov 15, 2023
753c27a
Update the names and references to queryNode/sequencerNode/fullNode etc
Olshansk Nov 15, 2023
966b874
Update some comments and TODOs
Olshansk Nov 15, 2023
c726dfc
Added a couple more comments
Olshansk Nov 15, 2023
b9c0d62
Merge with main
Olshansk Nov 15, 2023
c36db92
More tiny comment updates
Olshansk Nov 15, 2023
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
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,12 @@ localnet_config.yaml
# Relase artifacts produced by `ignite chain build --release`
release

# SMT KVStore files
Olshansk marked this conversation as resolved.
Show resolved Hide resolved
# TODO_TECHDEBT(#126, @red-0ne): Rename `smt` to `smt_stores` and make it configurable so it can be stored anywhere on this
smt

# Do not allow a multi-moduled projected
go.work.sum

# TODO_IN_THIS_COMMIT: Why did we start generating .dot files?
Copy link
Contributor Author

@bryanchriswhite bryanchriswhite Nov 14, 2023

Choose a reason for hiding this comment

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

@Olshansk I don't see any .dot files in my working tree. Is it possible that something other than running the E2E relay locally produced them on your workstation?

Can you share the output of find . -type f -iname '*.dot'?

Copy link
Contributor

Choose a reason for hiding this comment

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

I started getting them at one point o-o

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@h5law

Can you share the output of find . -type f -iname '*.dot'?

Copy link
Member

Choose a reason for hiding this comment

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

For me it was these two: rm pkg/client/tx/debug_container.dot pkg/client/supplier/debug_container.dot

However, I can't repro it now... Ran unit tests, e2e test and localnet.

# **/*.dot
17 changes: 12 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ app_stake: ## Stake tokens for the application specified (must specify the APP a
poktrolld --home=$(POKTROLLD_HOME) tx application stake-application 1000upokt $(SERVICES) --keyring-backend test --from $(APP) --node $(POCKET_NODE)

.PHONY: app1_stake
app1_stake: ## Stake app1
app1_stake: ## Stake app1 (also staked in genesis)
APP=app1 SERVICES=anvil,svc1,svc2 make app_stake

.PHONY: app2_stake
Expand Down Expand Up @@ -361,16 +361,23 @@ supplier_stake: ## Stake tokens for the supplier specified (must specify the APP
poktrolld --home=$(POKTROLLD_HOME) tx supplier stake-supplier 1000upokt "$(SERVICES)" --keyring-backend test --from $(SUPPLIER) --node $(POCKET_NODE)

.PHONY: supplier1_stake
supplier1_stake: ## Stake supplier1
SUPPLIER=supplier1 SERVICES="anvil;http://anvil:8547,svc1;http://localhost:8081" make supplier_stake
supplier1_stake: ## Stake supplier1 (also staked in genesis)
# TODO_TECHDEBT(#179): once `relayminer` service is added to tilt, this hostname should point to that service.
# I.e.: replace `localhost` with `relayminer` (or whatever the service's hostname is).
# TODO_IMPROVE(#180): Make sure genesis-staked actors are available via AccountKeeper
SUPPLIER=supplier1 SERVICES="anvil;http://localhost:8545,svc1;http://localhost:8081" make supplier_stake

.PHONY: supplier2_stake
supplier2_stake: ## Stake supplier2
SUPPLIER=supplier2 SERVICES="anvil;http://anvil:8547,svc2;http://localhost:8082" make supplier_stake
# TODO_TECHDEBT(#179): once `relayminer` service is added to tilt, this hostname should point to that service.
# I.e.: replace `localhost` with `relayminer` (or whatever the service's hostname is).
SUPPLIER=supplier2 SERVICES="anvil;http://localhost:8545,svc2;http://localhost:8082" make supplier_stake

.PHONY: supplier3_stake
supplier3_stake: ## Stake supplier3
SUPPLIER=supplier3 SERVICES="anvil;http://anvil:8547,svc3;http://localhost:8083" make supplier_stake
# TODO_TECHDEBT(#179): once `relayminer` service is added to tilt, this hostname should point to that service.
# I.e.: replace `localhost` with `relayminer` (or whatever the service's hostname is).
SUPPLIER=supplier3 SERVICES="anvil;http://localhost:8545,svc3;http://localhost:8083" make supplier_stake

.PHONY: supplier_unstake
supplier_unstake: ## Unstake an supplier (must specify the SUPPLIER env var)
Expand Down
6 changes: 6 additions & 0 deletions cmd/pocketd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import (
"github.com/pokt-network/poktroll/app"
appparams "github.com/pokt-network/poktroll/app/params"
appgateservercmd "github.com/pokt-network/poktroll/pkg/appgateserver/cmd"
relayercmd "github.com/pokt-network/poktroll/pkg/relayer/cmd"
)

// NewRootCmd creates a new root command for a Cosmos SDK application
Expand Down Expand Up @@ -142,6 +143,11 @@ func initRootCmd(
addModuleInitFlags,
)

// add relayer command
rootCmd.AddCommand(
Olshansk marked this conversation as resolved.
Show resolved Hide resolved
relayercmd.RelayerCmd(),
)

// add keybase, auxiliary RPC, query, and tx child commands
rootCmd.AddCommand(
rpc.StatusCommand(),
Expand Down
23 changes: 23 additions & 0 deletions cmd/signals/on_exit.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package signals

import (
"os"
"os/signal"
)

// GoOnExitSignal calls the given callback when the process receives an interrupt
// or kill signal.
func GoOnExitSignal(onInterrupt func()) {
Olshansk marked this conversation as resolved.
Show resolved Hide resolved
go func() {
// Set up sigCh to receive when this process receives an interrupt or
// kill signal.
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, os.Interrupt, os.Kill)

// Block until we receive an interrupt or kill signal (OS-agnostic)
<-sigCh

// Call the onInterrupt callback.
onInterrupt()
}()
}
3 changes: 2 additions & 1 deletion config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ genesis:
- endpoints:
- configs: []
rpc_type: JSON_RPC
url: http://anvil:8547
# TODO_TECHDEBT(#179): once `relayminer` service is added to tilt, this hostname should point to it instead of `localhost`.
url: http://localhost:8548
bryanchriswhite marked this conversation as resolved.
Show resolved Hide resolved
service:
id: anvil
name: ""
Expand Down
30 changes: 16 additions & 14 deletions docs/static/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46480,7 +46480,7 @@ paths:
service:
title: >-
The Service for which the application is
configured
configured for
type: object
properties:
id:
Expand Down Expand Up @@ -46660,7 +46660,9 @@ paths:
type: object
properties:
service:
title: The Service for which the application is configured
title: >-
The Service for which the application is configured
for
type: object
properties:
id:
Expand Down Expand Up @@ -47176,7 +47178,7 @@ paths:
service:
title: >-
The Service for which the application is
configured
configured for
type: object
properties:
id:
Expand Down Expand Up @@ -47243,7 +47245,7 @@ paths:
service:
title: >-
The Service for which the supplier is
configured
configured for
type: object
properties:
id:
Expand Down Expand Up @@ -76787,7 +76789,7 @@ definitions:
type: object
properties:
service:
title: The Service for which the application is configured
title: The Service for which the application is configured for
type: object
properties:
id:
Expand Down Expand Up @@ -76871,7 +76873,7 @@ definitions:
type: object
properties:
service:
title: The Service for which the application is configured
title: The Service for which the application is configured for
type: object
properties:
id:
Expand Down Expand Up @@ -76965,7 +76967,7 @@ definitions:
type: object
properties:
service:
title: The Service for which the application is configured
title: The Service for which the application is configured for
type: object
properties:
id:
Expand Down Expand Up @@ -77016,7 +77018,7 @@ definitions:
type: object
properties:
service:
title: The Service for which the application is configured
title: The Service for which the application is configured for
type: object
properties:
id:
Expand Down Expand Up @@ -77284,7 +77286,7 @@ definitions:
type: object
properties:
service:
title: The Service for which the application is configured
title: The Service for which the application is configured for
type: object
properties:
id:
Expand Down Expand Up @@ -77348,7 +77350,7 @@ definitions:
type: object
properties:
service:
title: The Service for which the supplier is configured
title: The Service for which the supplier is configured for
type: object
properties:
id:
Expand Down Expand Up @@ -77538,7 +77540,7 @@ definitions:
type: object
properties:
service:
title: The Service for which the application is configured
title: The Service for which the application is configured for
type: object
properties:
id:
Expand Down Expand Up @@ -77600,7 +77602,7 @@ definitions:
type: object
properties:
service:
title: The Service for which the supplier is configured
title: The Service for which the supplier is configured for
type: object
properties:
id:
Expand Down Expand Up @@ -77814,7 +77816,7 @@ definitions:
type: object
properties:
service:
title: The Service for which the supplier is configured
title: The Service for which the supplier is configured for
type: object
properties:
id:
Expand Down Expand Up @@ -77943,7 +77945,7 @@ definitions:
type: object
properties:
service:
title: The Service for which the supplier is configured
title: The Service for which the supplier is configured for
type: object
properties:
id:
Expand Down
99 changes: 65 additions & 34 deletions pkg/appgateserver/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@ import (
"log"
"net/http"
"net/url"
"os"
"os/signal"

"cosmossdk.io/depinject"
cosmosclient "github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
cosmosflags "github.com/cosmos/cosmos-sdk/client/flags"
"github.com/spf13/cobra"

"github.com/pokt-network/poktroll/cmd/signals"
"github.com/pokt-network/poktroll/pkg/appgateserver"
blockclient "github.com/pokt-network/poktroll/pkg/client/block"
eventsquery "github.com/pokt-network/poktroll/pkg/client/events_query"
"github.com/pokt-network/poktroll/pkg/deps/config"
)

const omittedDefaultFlagValue = "explicitly omitting default"

var (
flagSigningKey string
flagSelfSigning bool
flagListeningEndpoint string
flagCometWebsocketUrl string
flagQueryNodeUrl string
)

func AppGateServerCmd() *cobra.Command {
Expand Down Expand Up @@ -58,11 +58,11 @@ relays to the AppGate server and function as an Application, provided that:

cmd.Flags().StringVar(&flagSigningKey, "signing-key", "", "The name of the key that will be used to sign relays")
cmd.Flags().StringVar(&flagListeningEndpoint, "listening-endpoint", "http://localhost:42069", "The host and port that the appgate server will listen on")
cmd.Flags().StringVar(&flagCometWebsocketUrl, "comet-websocket-url", "ws://localhost:36657/websocket", "The URL of the comet websocket endpoint to communicate with the pocket blockchain")
cmd.Flags().BoolVar(&flagSelfSigning, "self-signing", false, "Whether the server should sign all incoming requests with its own ring (for applications)")
cmd.Flags().StringVar(&flagQueryNodeUrl, "query-node", omittedDefaultFlagValue, "The URL of the pocket node to query for on-chain data")

cmd.Flags().String(flags.FlagKeyringBackend, "", "Select keyring's backend (os|file|kwallet|pass|test)")
cmd.Flags().String(flags.FlagNode, "tcp://localhost:36657", "The URL of the comet tcp endpoint to communicate with the pocket blockchain")
cmd.Flags().String(cosmosflags.FlagKeyringBackend, "", "Select keyring's backend (os|file|kwallet|pass|test)")
cmd.Flags().String(cosmosflags.FlagNode, omittedDefaultFlagValue, "The URL of the comet tcp endpoint to communicate with the pocket blockchain")

return cmd
}
Expand All @@ -72,18 +72,8 @@ func runAppGateServer(cmd *cobra.Command, _ []string) error {
ctx, cancelCtx := context.WithCancel(cmd.Context())
defer cancelCtx()

// Handle interrupts in a goroutine.
go func() {
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, os.Interrupt)

// Block until we receive an interrupt or kill signal (OS-agnostic)
<-sigCh
log.Println("INFO: Interrupt signal received, shutting down...")

// Signal goroutines to stop
cancelCtx()
}()
// Handle interrupt and kill signals asynchronously.
signals.GoOnExitSignal(cancelCtx)

// Parse the listening endpoint.
listeningUrl, err := url.Parse(flagListeningEndpoint)
Expand All @@ -92,7 +82,7 @@ func runAppGateServer(cmd *cobra.Command, _ []string) error {
}

// Setup the AppGate server dependencies.
appGateServerDeps, err := setupAppGateServerDependencies(cmd, ctx, flagCometWebsocketUrl)
appGateServerDeps, err := setupAppGateServerDependencies(ctx, cmd)
if err != nil {
return fmt.Errorf("failed to setup AppGate server dependencies: %w", err)
}
Expand Down Expand Up @@ -127,21 +117,62 @@ func runAppGateServer(cmd *cobra.Command, _ []string) error {
return nil
}

func setupAppGateServerDependencies(cmd *cobra.Command, ctx context.Context, cometWebsocketUrl string) (depinject.Config, error) {
// Retrieve the client context for the chain interactions.
clientCtx := cosmosclient.GetClientContextFromCmd(cmd)
func setupAppGateServerDependencies(
ctx context.Context,
cmd *cobra.Command,
) (depinject.Config, error) {
pocketNodeWebsocketUrl, err := getPocketNodeWebsocketUrl()
if err != nil {
return nil, err
}

// Create the events client.
eventsQueryClient := eventsquery.NewEventsQueryClient(flagCometWebsocketUrl)
supplierFuncs := []config.SupplierFn{
config.NewSupplyEventsQueryClientFn(pocketNodeWebsocketUrl),
config.NewSupplyBlockClientFn(pocketNodeWebsocketUrl),
newSupplyQueryClientContextFn(flagQueryNodeUrl),
}

// Create the block client.
log.Printf("INFO: Creating block client, using comet websocket URL: %s...", flagCometWebsocketUrl)
deps := depinject.Supply(eventsQueryClient)
blockClient, err := blockclient.NewBlockClient(ctx, deps, flagCometWebsocketUrl)
return config.SupplyConfig(ctx, cmd, supplierFuncs)
}

// getPocketNodeWebsocketUrl returns the websocket URL of the Pocket Node to
// connect to for subscribing to on-chain events.
func getPocketNodeWebsocketUrl() (string, error) {
if flagQueryNodeUrl == omittedDefaultFlagValue {
return "", errors.New("missing required flag: --query-node")
}

pocketNodeURL, err := url.Parse(flagQueryNodeUrl)
if err != nil {
return nil, fmt.Errorf("failed to create block client: %w", err)
return "", err
}

// Return the dependencie config.
return depinject.Supply(clientCtx, blockClient), nil
return fmt.Sprintf("ws://%s/websocket", pocketNodeURL.Host), nil
}

// newSupplyQueryClientContextFn returns a new depinject.Config which is supplied with
// the given deps and a new cosmos ClientCtx
func newSupplyQueryClientContextFn(pocketQueryClientUrl string) config.SupplierFn {
return func(
_ context.Context,
deps depinject.Config,
cmd *cobra.Command,
) (depinject.Config, error) {
// Set --node flag to the pocketQueryClientUrl for the client context
// This flag is read by cosmosclient.GetClientQueryContext.
err := cmd.Flags().Set(cosmosflags.FlagNode, pocketQueryClientUrl)
if err != nil {
return nil, err
}

// Get the client context from the command.
queryClientCtx, err := cosmosclient.GetClientQueryContext(cmd)
if err != nil {
return nil, err
}
deps = depinject.Configs(deps, depinject.Supply(
queryClientCtx,
))
return deps, nil
}
}
2 changes: 1 addition & 1 deletion pkg/appgateserver/endpoint_selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (app *appGateServer) getRelayerUrl(
if endpoint.RpcType == rpcType {
supplierUrl, err := url.Parse(endpoint.Url)
if err != nil {
log.Printf("error parsing url: %s", err)
log.Printf("ERROR: error parsing url: %s", err)
continue
}
return supplierUrl, supplier.Address, nil
Expand Down
2 changes: 2 additions & 0 deletions pkg/appgateserver/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ var (
ErrAppGateMissingAppAddress = sdkerrors.Register(codespace, 4, "missing application address")
ErrAppGateMissingSigningInformation = sdkerrors.Register(codespace, 5, "missing app client signing information")
ErrAppGateMissingListeningEndpoint = sdkerrors.Register(codespace, 6, "missing app client listening endpoint")
ErrAppGateEmptyRelayResponse = sdkerrors.Register(codespace, 7, "empty relay response")
ErrAppGateHandleRelay = sdkerrors.Register(codespace, 8, "internal error handling relay request")
)
Loading
Loading