Skip to content

Commit

Permalink
relay makes sub-contexts for different clients (#988)
Browse files Browse the repository at this point in the history
* relay makes sub-contexts for different clients
  • Loading branch information
willscott committed May 7, 2022
1 parent ec23598 commit cf6c1d9
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions cmd/relay/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"encoding/hex"
"flag"
"fmt"
"net"
"net/http"
Expand Down Expand Up @@ -45,7 +46,7 @@ var metricsFlag = &cli.StringFlag{
}

// Relay a GRPC connection to an HTTP server.
// nolint:gocyclo
// nolint:gocyclo,funlen
func Relay(c *cli.Context) error {
version := common.GetAppVersion()

Expand Down Expand Up @@ -80,21 +81,33 @@ func Relay(c *cli.Context) error {
}

for hash := range hashesMap {
fs := flag.NewFlagSet(fmt.Sprintf("sub-client %s", hash), flag.ContinueOnError)
for _, f := range c.App.Flags {
if err := f.Apply(fs); err != nil {
return fmt.Errorf("failed to transfer flag: %w", err)
}
}
subC := cli.NewContext(c.App, fs, c)

if hash != common.DefaultChainHash {
if _, err := hex.DecodeString(hash); err != nil {
return fmt.Errorf("failed to decode chain hash value: %w", err)
}
if err := c.Set(lib.HashFlag.Name, hash); err != nil {
if err := subC.Set(lib.HashFlag.Name, hash); err != nil {
return fmt.Errorf("failed to initiate chain hash handler: %w", err)
}
} else {
if err := subC.Set(lib.HashFlag.Name, ""); err != nil {
return fmt.Errorf("failed to initiate default chain hash handler: %w", err)
}
}

c, err := lib.Create(c, c.IsSet(metricsFlag.Name))
subCli, err := lib.Create(subC, c.IsSet(metricsFlag.Name))
if err != nil {
return err
}

handler.RegisterNewBeaconHandler(c, hash)
handler.RegisterNewBeaconHandler(subCli, hash)
}

if c.IsSet(accessLogFlag.Name) {
Expand Down

0 comments on commit cf6c1d9

Please sign in to comment.