Skip to content

Commit

Permalink
validate decider host/port in config, not main
Browse files Browse the repository at this point in the history
addresses review comment ava-labs/awm-relayer#344 (comment)
  • Loading branch information
feuGeneA committed Jul 24, 2024
1 parent bfa6e14 commit d8b6b83
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
19 changes: 19 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import (
"context"
"errors"
"fmt"
"net/url"
"strconv"
"strings"

"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/utils/constants"
Expand Down Expand Up @@ -121,6 +124,22 @@ 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 {
return fmt.Errorf("Invalid decider URI: %w", err)
}
}

return nil
}

Expand Down
16 changes: 4 additions & 12 deletions main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"fmt"
"log"
"net/http"
"net/url"
"os"
"runtime"
"strconv"
Expand Down Expand Up @@ -464,18 +463,11 @@ func createDeciderClient(host string, port *uint16) (*grpc.ClientConn, error) {
host = "localhost"
}

uri := strings.Join(
[]string{host, strconv.FormatUint(uint64(*port), 10)},
":",
)

_, err := url.ParseRequestURI(uri)
if err != nil {
return nil, fmt.Errorf("Invalid URI: %w", err)
}

client, err := grpc.NewClient(
uri,
strings.Join(
[]string{host, strconv.FormatUint(uint64(*port), 10)},
":",
),
grpc.WithTransportCredentials(insecure.NewCredentials()),
)
if err != nil {
Expand Down

0 comments on commit d8b6b83

Please sign in to comment.