Skip to content

Commit 91b2289

Browse files
authored
rpc: remove startup error for invalid modules, log it instead (#20684)
This removes the error added in #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.
1 parent 1b9c5b3 commit 91b2289

File tree

1 file changed

+13
-18
lines changed

1 file changed

+13
-18
lines changed

rpc/endpoints.go

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,38 +17,33 @@
1717
package rpc
1818

1919
import (
20-
"fmt"
2120
"net"
2221

2322
"github.com/ethereum/go-ethereum/log"
2423
)
2524

2625
// checkModuleAvailability check that all names given in modules are actually
2726
// available API services.
28-
func checkModuleAvailability(modules []string, apis []API) error {
29-
available := make(map[string]struct{})
30-
var availableNames string
31-
for i, api := range apis {
32-
if _, ok := available[api.Namespace]; !ok {
33-
available[api.Namespace] = struct{}{}
34-
if i > 0 {
35-
availableNames += ", "
36-
}
37-
availableNames += api.Namespace
27+
func checkModuleAvailability(modules []string, apis []API) (bad, available []string) {
28+
availableSet := make(map[string]struct{})
29+
for _, api := range apis {
30+
if _, ok := availableSet[api.Namespace]; !ok {
31+
availableSet[api.Namespace] = struct{}{}
32+
available = append(available, api.Namespace)
3833
}
3934
}
4035
for _, name := range modules {
41-
if _, ok := available[name]; !ok {
42-
return fmt.Errorf("invalid API %q in whitelist (available: %s)", name, availableNames)
36+
if _, ok := availableSet[name]; !ok {
37+
bad = append(bad, name)
4338
}
4439
}
45-
return nil
40+
return bad, available
4641
}
4742

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

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

0 commit comments

Comments
 (0)