diff --git a/README.md b/README.md index 2d91cc86..801f2820 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,9 @@ The relayer is configured via a JSON file, the path to which is passed in via th `"p-chain-api-url": string` - The URL of the Avalanche P-Chain API node to which the relayer will connect. Defaults to `https://api.avax.network`. +`info-api-url": string` +- The URL of the Avalanche API node to which the relayer will connect to get information about the network. The Info API must be enabled on the node. + `"encrypt-connection": boolean` - Whether or not to encrypt the connection to the P-Chain API node. Defaults to `true`. diff --git a/config/config.go b/config/config.go index d05c1ced..f319fbd3 100644 --- a/config/config.go +++ b/config/config.go @@ -70,6 +70,7 @@ type Config struct { LogLevel string `mapstructure:"log-level" json:"log-level"` NetworkID uint32 `mapstructure:"network-id" json:"network-id"` PChainAPIURL string `mapstructure:"p-chain-api-url" json:"p-chain-api-url"` + InfoAPIURL string `mapstructure:"info-api-url" json:"info-api-url"` EncryptConnection bool `mapstructure:"encrypt-connection" json:"encrypt-connection"` StorageLocation string `mapstructure:"storage-location" json:"storage-location"` SourceSubnets []SourceSubnet `mapstructure:"source-subnets" json:"source-subnets"` @@ -109,6 +110,7 @@ func BuildConfig(v *viper.Viper) (Config, bool, error) { cfg.LogLevel = v.GetString(LogLevelKey) cfg.NetworkID = v.GetUint32(NetworkIDKey) cfg.PChainAPIURL = v.GetString(PChainAPIURLKey) + cfg.InfoAPIURL = v.GetString(InfoAPIURLKey) cfg.EncryptConnection = v.GetBool(EncryptConnectionKey) cfg.StorageLocation = v.GetString(StorageLocationKey) if err := v.UnmarshalKey(DestinationSubnetsKey, &cfg.DestinationSubnets); err != nil { @@ -153,11 +155,17 @@ func BuildConfig(v *viper.Viper) (Config, bool, error) { protocol = "http" } - pChainapiUrl, err := utils.ConvertProtocol(cfg.PChainAPIURL, protocol) + pChainApiUrl, err := utils.ConvertProtocol(cfg.PChainAPIURL, protocol) if err != nil { return Config{}, false, err } - cfg.PChainAPIURL = pChainapiUrl + cfg.PChainAPIURL = pChainApiUrl + + infoApiUrl, err := utils.ConvertProtocol(cfg.InfoAPIURL, protocol) + if err != nil { + return Config{}, false, err + } + cfg.InfoAPIURL = infoApiUrl globalConfig = cfg @@ -174,6 +182,9 @@ func (c *Config) Validate() error { if _, err := url.ParseRequestURI(c.PChainAPIURL); err != nil { return err } + if _, err := url.ParseRequestURI(c.InfoAPIURL); err != nil { + return err + } // Validate the destination chains destinationChains := set.NewSet[string](len(c.DestinationSubnets)) diff --git a/config/config_test.go b/config/config_test.go index b5d64e73..fbc49dcc 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -27,6 +27,7 @@ var ( LogLevel: "info", NetworkID: 1337, PChainAPIURL: "http://test.avax.network", + InfoAPIURL: "http://info.avax.network", EncryptConnection: false, SourceSubnets: []SourceSubnet{ { diff --git a/config/keys.go b/config/keys.go index d872a0e1..3c0dccc8 100644 --- a/config/keys.go +++ b/config/keys.go @@ -9,6 +9,7 @@ const ( LogLevelKey = "log-level" NetworkIDKey = "network-id" PChainAPIURLKey = "p-chain-api-url" + InfoAPIURLKey = "info-api-url" SourceSubnetsKey = "source-subnets" DestinationSubnetsKey = "destination-subnets" EncryptConnectionKey = "encrypt-connection" diff --git a/main/main.go b/main/main.go index 6b505958..550e5353 100644 --- a/main/main.go +++ b/main/main.go @@ -103,7 +103,7 @@ func main() { panic(err) } - network, responseChans, err := peers.NewNetwork(logger, registerer, cfg.NetworkID, sourceSubnetIDs, sourceChainIDs, cfg.PChainAPIURL) + network, responseChans, err := peers.NewNetwork(logger, registerer, cfg.NetworkID, sourceSubnetIDs, sourceChainIDs, cfg.InfoAPIURL) if err != nil { logger.Error( "Failed to create app request network", diff --git a/tests/basic_relay.go b/tests/basic_relay.go index 6d9cda42..02edcbcb 100644 --- a/tests/basic_relay.go +++ b/tests/basic_relay.go @@ -86,6 +86,7 @@ func BasicRelay() { LogLevel: logging.Info.LowerString(), NetworkID: peers.LocalNetworkID, PChainAPIURL: subnetAInfo.ChainNodeURIs[0], + InfoAPIURL: subnetAInfo.ChainNodeURIs[0], EncryptConnection: false, StorageLocation: storageLocation, SourceSubnets: []config.SourceSubnet{