Skip to content

Commit

Permalink
Merge remote-tracking branch 'pokt/relayer/cli' into relayer/cli
Browse files Browse the repository at this point in the history
* pokt/relayer/cli:
  chore: rename command
  chore: Rename falg variables
  • Loading branch information
bryanchriswhite committed Nov 11, 2023
2 parents a3a3635 + 5c5eace commit 641d60a
Showing 1 changed file with 25 additions and 22 deletions.
47 changes: 25 additions & 22 deletions pkg/relayer/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,37 +26,36 @@ import (
)

var (
signingKeyName string
smtStorePath string
sequencerNode string
pocketNode string
flagSigningKeyName string
flagSmtStorePath string
flagSequencerNode string
flagPocketNode string
)

func RelayerCmd() *cobra.Command {
cmd := &cobra.Command{
// TODO_DISCUSS: do we want to rename this to `relay-miner`?
Use: "relayer",
Short: "Run a relayer",
Long: `Run a relayer`,
Use: "relayerminer",
Short: "Run a relay miner",
Long: `Run a relay miner`,
RunE: runRelayer,
}

cmd.Flags().String(cosmosflags.FlagKeyringBackend, "", "Select keyring's backend (os|file|kwallet|pass|test)")

// TECHDEBT: integrate these cosmosflags with the client context (i.e. cosmosflags, config, viper, etc.)
// TODO_TECHDEBT: integrate these cosmosflags with the client context (i.e. cosmosflags, config, viper, etc.)
// This is simpler to do with server-side configs (see rootCmd#PersistentPreRunE).
// Will require more effort than currently justifiable.
cmd.Flags().StringVar(&signingKeyName, "signing-key", "", "Name of the key to sign transactions")
cmd.Flags().StringVar(&smtStorePath, "smt-store", "smt", "Path to the SMT KV store")
cmd.Flags().StringVar(&flagSigningKeyName, "signing-key", "", "Name of the key to sign transactions")
cmd.Flags().StringVar(&flagSmtStorePath, "smt-store", "smt", "Path to the SMT KV store")
// Communication cosmosflags
// TODO_DISCUSS: We're using `explicitly omitting default` so the relayer crashes if these aren't specified. Figure out
// what the defaults should be post alpha.
cmd.Flags().StringVar(&sequencerNode, "sequencer-node", "explicitly omitting default", "<host>:<port> to sequencer/validator node to submit txs")
cmd.Flags().StringVar(&pocketNode, "pocket-node", "explicitly omitting default", "<host>:<port> to full/light pocket node for reading data and listening for on-chain events")
// TODO_TECHDEBT: We're using `explicitly omitting default` so the relayer crashes if these aren't specified. Figure out
// Figure out what good defaults should be post alpha.
cmd.Flags().StringVar(&flagSequencerNode, "sequencer-node", "explicitly omitting default", "<host>:<port> to sequencer node to submit txs")
cmd.Flags().StringVar(&flagPocketNode, "pocket-node", "explicitly omitting default", "<host>:<port> to full pocket node for reading data and listening for on-chain events")
cmd.Flags().String(cosmosflags.FlagNode, "explicitly omitting default", "registering the default cosmos node flag; needed to initialize the cosmostx and query contexts correctly")

// Set --node flag to the --sequencer-node for the client context
err := cmd.Flags().Set(cosmosflags.FlagNode, fmt.Sprintf("tcp://%s", sequencerNode))
err := cmd.Flags().Set(cosmosflags.FlagNode, fmt.Sprintf("tcp://%s", flagSequencerNode))
if err != nil {
//return nil, err
panic(err)
Expand All @@ -70,6 +69,8 @@ func runRelayer(cmd *cobra.Command, _ []string) error {
// Ensure context cancellation.
defer cancelCtx()

// Sets up the following dependencies:
// Miner, EventsQueryClient, BlockClient, TxClient, SupplierClient, RelayerProxy, RelayMiner dependencies.
deps, err := setupRelayerDependencies(ctx, cmd)
if err != nil {
return err
Expand Down Expand Up @@ -103,6 +104,8 @@ func runRelayer(cmd *cobra.Command, _ []string) error {
return nil
}

// setupRelayerDependencies sets up all the dependencies the relay miner needs to run:
// Miner, EventsQueryClient, BlockClient, TxClient, SupplierClient, RelayerProxy, RelayMiner
func setupRelayerDependencies(
ctx context.Context,
cmd *cobra.Command,
Expand Down Expand Up @@ -251,7 +254,7 @@ func supplyTxClient(
txClient, err := tx.NewTxClient(
ctx,
deps,
tx.WithSigningKeyName(signingKeyName),
tx.WithSigningKeyName(flagSigningKeyName),
// TODO_TECHDEBT: populate this from some config.
tx.WithCommitTimeoutBlocks(tx.DefaultCommitTimeoutHeightOffset),
)
Expand All @@ -265,7 +268,7 @@ func supplyTxClient(
func supplySupplierClient(deps depinject.Config) (depinject.Config, error) {
supplierClient, err := supplier.NewSupplierClient(
deps,
supplier.WithSigningKeyName(signingKeyName),
supplier.WithSigningKeyName(flagSigningKeyName),
)
if err != nil {
return nil, err
Expand All @@ -278,14 +281,14 @@ func supplyRelayerProxy(
deps depinject.Config,
cmd *cobra.Command,
) (depinject.Config, error) {
// TODO_INCOMPLETE: this should be populated from some relayerProxy config.
// TODO_TECHDEBT: this should be populated from some relayerProxy config.
anvilURL, err := url.Parse("ws://anvil:8547/")
if err != nil {
return nil, err
}

proxiedServiceEndpoints := map[string]url.URL{
"svc1": *anvilURL,
"anvil": *anvilURL,
}

clientCtx, err := cosmosclient.GetClientQueryContext(cmd)
Expand All @@ -298,7 +301,7 @@ func supplyRelayerProxy(

relayerProxy, err := proxy.NewRelayerProxy(
deps,
proxy.WithSigningKeyName(signingKeyName),
proxy.WithSigningKeyName(flagSigningKeyName),
proxy.WithProxiedServicesEndpoints(proxiedServiceEndpoints),
)
if err != nil {
Expand All @@ -314,7 +317,7 @@ func supplyRelayerSessionsManager(
) (depinject.Config, error) {
relayerSessionsManager, err := session.NewRelayerSessions(
ctx, deps,
session.WithStoresDirectory(smtStorePath),
session.WithStoresDirectory(flagSmtStorePath),
)
if err != nil {
return nil, err
Expand Down

0 comments on commit 641d60a

Please sign in to comment.