diff --git a/README.md b/README.md index 6e98557e..c10e44a2 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/config/config.go b/config/config.go index c2b6c5a2..c8ea74dc 100644 --- a/config/config.go +++ b/config/config.go @@ -8,8 +8,6 @@ import ( "errors" "fmt" "net/url" - "strconv" - "strings" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/utils/constants" @@ -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 @@ -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) } } diff --git a/main/main.go b/main/main.go index b07e1f25..d3c5b58a 100644 --- a/main/main.go +++ b/main/main.go @@ -10,7 +10,6 @@ import ( "net/http" "os" "runtime" - "strconv" "strings" "github.com/ava-labs/avalanchego/api/metrics" @@ -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", @@ -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 { diff --git a/tests/utils/utils.go b/tests/utils/utils.go index d312b8a3..99bbd41d 100644 --- a/tests/utils/utils.go +++ b/tests/utils/utils.go @@ -191,8 +191,6 @@ func CreateDefaultRelayerConfig( ) } - var deciderPort uint16 = 50051 - return config.Config{ LogLevel: logging.Info.LowerString(), PChainAPI: &config.APIConfig{ @@ -208,8 +206,7 @@ func CreateDefaultRelayerConfig( SourceBlockchains: sources, DestinationBlockchains: destinations, APIPort: 8080, - DeciderHost: "localhost", - DeciderPort: &deciderPort, + DeciderURL: "localhost:50051", } }