Skip to content

Commit

Permalink
config: just DeciderURL, not Host/Port
Browse files Browse the repository at this point in the history
  • Loading branch information
feuGeneA committed Jul 24, 2024
1 parent 8e32fb6 commit a13b080
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 42 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,11 +291,9 @@ The relayer is configured via a JSON file, the path to which is passed in via th

- The AWS region in which the KMS key is located. Required if `kms-key-id` is provided.

`"decider-host": string`
`"decider-url": string`

`"decider-port": unsigned integer`

- The network location of a service implementing the gRPC service defined by `proto/decider`, which will be queried for each message to determine whether that message should be relayed. If a port is specified but a host is not, the host is assumed to be `localhost`. If a host is specified then a port is required.
- The URL of a service implementing the gRPC service defined by `proto/decider`, which will be queried for each message to determine whether that message should be relayed.

## Architecture

Expand Down
19 changes: 3 additions & 16 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import (
"errors"
"fmt"
"net/url"
"strconv"
"strings"

"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/utils/constants"
Expand Down Expand Up @@ -61,8 +59,7 @@ type Config struct {
SourceBlockchains []*SourceBlockchain `mapstructure:"source-blockchains" json:"source-blockchains"`
DestinationBlockchains []*DestinationBlockchain `mapstructure:"destination-blockchains" json:"destination-blockchains"`
ProcessMissedBlocks bool `mapstructure:"process-missed-blocks" json:"process-missed-blocks"`
DeciderHost string `mapstructure:"decider-host" json:"decider-host"`
DeciderPort *uint16 `mapstructure:"decider-port" json:"decider-port"`
DeciderURL string `mapstructure:"decider-url" json:"decider-url"`

// convenience field to fetch a blockchain's subnet ID
blockchainIDToSubnetID map[ids.ID]ids.ID
Expand Down Expand Up @@ -124,18 +121,8 @@ func (c *Config) Validate() error {
}
c.blockchainIDToSubnetID = blockchainIDToSubnetID

if c.DeciderPort != nil {
portStr := strconv.FormatUint(uint64(*c.DeciderPort), 10)

host := c.DeciderHost
if len(host) == 0 {
host = "localhost"
}

uri := strings.Join([]string{host, portStr}, ":")

_, err := url.ParseRequestURI(uri)
if err != nil {
if len(c.DeciderURL) != 0 {
if _, err := url.ParseRequestURI(c.DeciderURL); err != nil {
return fmt.Errorf("Invalid decider URI: %w", err)
}
}
Expand Down
24 changes: 6 additions & 18 deletions main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"net/http"
"os"
"runtime"
"strconv"
"strings"

"github.com/ava-labs/avalanchego/api/metrics"
Expand Down Expand Up @@ -178,10 +177,7 @@ func main() {

relayerHealth := createHealthTrackers(&cfg)

deciderClient, err := createDeciderClient(
cfg.DeciderHost,
cfg.DeciderPort,
)
deciderClient, err := createDeciderClient(cfg.DeciderURL)
if err != nil {
logger.Fatal(
"Failed to instantiate decider client",
Expand Down Expand Up @@ -454,23 +450,15 @@ func createApplicationRelayersForSourceChain(
return applicationRelayers, minHeight, nil
}

/* if port is nil, neither a client nor an error will be returned.
* if is non-nil, a client will be constructed
* if host is an empty string, a default value of "localhost" is assumed. */
func createDeciderClient(host string, port *uint16) (*grpc.ClientConn, error) {
if port == nil {
// create a client for the "should send message" decider service.
// if url is unspecified, returns a nil client pointer
func createDeciderClient(url string) (*grpc.ClientConn, error) {
if len(url) == 0 {
return nil, nil
}

if len(host) == 0 {
host = "localhost"
}

client, err := grpc.NewClient(
strings.Join(
[]string{host, strconv.FormatUint(uint64(*port), 10)},
":",
),
url,
grpc.WithTransportCredentials(insecure.NewCredentials()),
)
if err != nil {
Expand Down
5 changes: 1 addition & 4 deletions tests/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,6 @@ func CreateDefaultRelayerConfig(
)
}

var deciderPort uint16 = 50051

return config.Config{
LogLevel: logging.Info.LowerString(),
PChainAPI: &config.APIConfig{
Expand All @@ -208,8 +206,7 @@ func CreateDefaultRelayerConfig(
SourceBlockchains: sources,
DestinationBlockchains: destinations,
APIPort: 8080,
DeciderHost: "localhost",
DeciderPort: &deciderPort,
DeciderURL: "localhost:50051",
}
}

Expand Down

0 comments on commit a13b080

Please sign in to comment.