Skip to content

Commit

Permalink
rpc: remove startup error for invalid modules, log it instead (ethere…
Browse files Browse the repository at this point in the history
…um#20684)

This removes the error added in ethereum#20597 in favor of a log message at
error level. Failing to start broke a bunch of people's setups and is
probably not the right thing to do for this check.
  • Loading branch information
fjl authored and enriquefynn committed Feb 15, 2021
1 parent 9e060e5 commit 097ed55
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions rpc/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,33 @@
package rpc

import (
"fmt"
"net"

"github.com/ethereum/go-ethereum/log"
)

// checkModuleAvailability check that all names given in modules are actually
// available API services.
func checkModuleAvailability(modules []string, apis []API) error {
available := make(map[string]struct{})
var availableNames string
for i, api := range apis {
if _, ok := available[api.Namespace]; !ok {
available[api.Namespace] = struct{}{}
if i > 0 {
availableNames += ", "
}
availableNames += api.Namespace
func checkModuleAvailability(modules []string, apis []API) (bad, available []string) {
availableSet := make(map[string]struct{})
for _, api := range apis {
if _, ok := availableSet[api.Namespace]; !ok {
availableSet[api.Namespace] = struct{}{}
available = append(available, api.Namespace)
}
}
for _, name := range modules {
if _, ok := available[name]; !ok {
return fmt.Errorf("invalid API %q in whitelist (available: %s)", name, availableNames)
if _, ok := availableSet[name]; !ok {
bad = append(bad, name)
}
}
return nil
return bad, available
}

// StartHTTPEndpoint starts the HTTP RPC endpoint, configured with cors/vhosts/modules.
func StartHTTPEndpoint(endpoint string, apis []API, modules []string, cors []string, vhosts []string, timeouts HTTPTimeouts) (net.Listener, *Server, error) {
if err := checkModuleAvailability(modules, apis); err != nil {
return nil, nil, err
if bad, available := checkModuleAvailability(modules, apis); len(bad) > 0 {
log.Error("Unavailable modules in HTTP API list", "unavailable", bad, "available", available)
}
// Generate the whitelist based on the allowed modules
whitelist := make(map[string]bool)
Expand Down Expand Up @@ -79,8 +74,8 @@ func StartHTTPEndpoint(endpoint string, apis []API, modules []string, cors []str

// StartWSEndpoint starts a websocket endpoint.
func StartWSEndpoint(endpoint string, apis []API, modules []string, wsOrigins []string, exposeAll bool) (net.Listener, *Server, error) {
if err := checkModuleAvailability(modules, apis); err != nil {
return nil, nil, err
if bad, available := checkModuleAvailability(modules, apis); len(bad) > 0 {
log.Error("Unavailable modules in WS API list", "unavailable", bad, "available", available)
}
// Generate the whitelist based on the allowed modules
whitelist := make(map[string]bool)
Expand Down

0 comments on commit 097ed55

Please sign in to comment.