Skip to content

Commit 3630caf

Browse files
authored
node: drop support for static & trusted node list files (ethereum#25610)
This changes the node setup to ignore datadir files static-nodes.json trusted-nodes.json When these files are present, it an error will be printed to the log.
1 parent e257b3a commit 3630caf

File tree

2 files changed

+24
-62
lines changed

2 files changed

+24
-62
lines changed

node/config.go

Lines changed: 23 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,11 @@ import (
2323
"path/filepath"
2424
"runtime"
2525
"strings"
26-
"sync"
2726

2827
"github.com/ethereum/go-ethereum/common"
2928
"github.com/ethereum/go-ethereum/crypto"
3029
"github.com/ethereum/go-ethereum/log"
3130
"github.com/ethereum/go-ethereum/p2p"
32-
"github.com/ethereum/go-ethereum/p2p/enode"
3331
"github.com/ethereum/go-ethereum/rpc"
3432
)
3533

@@ -194,8 +192,6 @@ type Config struct {
194192
// Logger is a custom logger to use with the p2p.Server.
195193
Logger log.Logger `toml:",omitempty"`
196194

197-
staticNodesWarning bool
198-
trustedNodesWarning bool
199195
oldGethResourceWarning bool
200196

201197
// AllowUnprotectedTxs allows non EIP-155 protected transactions to be send over RPC.
@@ -340,8 +336,9 @@ func (c *Config) ResolvePath(path string) string {
340336
oldpath = filepath.Join(c.DataDir, path)
341337
}
342338
if oldpath != "" && common.FileExist(oldpath) {
343-
if warn {
344-
c.warnOnce(&c.oldGethResourceWarning, "Using deprecated resource file %s, please move this file to the 'geth' subdirectory of datadir.", oldpath)
339+
if warn && !c.oldGethResourceWarning {
340+
c.oldGethResourceWarning = true
341+
log.Warn("Using deprecated resource file, please move this file to the 'geth' subdirectory of datadir.", "file", oldpath)
345342
}
346343
return oldpath
347344
}
@@ -394,48 +391,35 @@ func (c *Config) NodeKey() *ecdsa.PrivateKey {
394391
return key
395392
}
396393

397-
// StaticNodes returns a list of node enode URLs configured as static nodes.
398-
func (c *Config) StaticNodes() []*enode.Node {
399-
return c.parsePersistentNodes(&c.staticNodesWarning, c.ResolvePath(datadirStaticNodes))
394+
// CheckLegacyFiles inspects the datadir for signs of legacy static-nodes
395+
// and trusted-nodes files. If they exist it raises an error.
396+
func (c *Config) checkLegacyFiles() {
397+
c.checkLegacyFile(c.ResolvePath(datadirStaticNodes))
398+
c.checkLegacyFile(c.ResolvePath(datadirTrustedNodes))
400399
}
401400

402-
// TrustedNodes returns a list of node enode URLs configured as trusted nodes.
403-
func (c *Config) TrustedNodes() []*enode.Node {
404-
return c.parsePersistentNodes(&c.trustedNodesWarning, c.ResolvePath(datadirTrustedNodes))
405-
}
406-
407-
// parsePersistentNodes parses a list of discovery node URLs loaded from a .json
408-
// file from within the data directory.
409-
func (c *Config) parsePersistentNodes(w *bool, path string) []*enode.Node {
401+
// checkLegacyFile will only raise an error if a file at the given path exists.
402+
func (c *Config) checkLegacyFile(path string) {
410403
// Short circuit if no node config is present
411404
if c.DataDir == "" {
412-
return nil
405+
return
413406
}
414407
if _, err := os.Stat(path); err != nil {
415-
return nil
408+
return
416409
}
417-
c.warnOnce(w, "Found deprecated node list file %s, please use the TOML config file instead.", path)
418-
419-
// Load the nodes from the config file.
420-
var nodelist []string
421-
if err := common.LoadJSON(path, &nodelist); err != nil {
422-
log.Error(fmt.Sprintf("Can't load node list file: %v", err))
423-
return nil
410+
logger := c.Logger
411+
if logger == nil {
412+
logger = log.Root()
424413
}
425-
// Interpret the list as a discovery node array
426-
var nodes []*enode.Node
427-
for _, url := range nodelist {
428-
if url == "" {
429-
continue
430-
}
431-
node, err := enode.Parse(enode.ValidSchemes, url)
432-
if err != nil {
433-
log.Error(fmt.Sprintf("Node URL %s: %v\n", url, err))
434-
continue
435-
}
436-
nodes = append(nodes, node)
414+
switch fname := filepath.Base(path); fname {
415+
case "static-nodes.json":
416+
logger.Error("The static-nodes.json file is deprecated and ignored. Use P2P.StaticNodes in config.toml instead.")
417+
case "trusted-nodes.json":
418+
logger.Error("The trusted-nodes.json file is deprecated and ignored. Use P2P.TrustedNodes in config.toml instead.")
419+
default:
420+
// We shouldn't wind up here, but better print something just in case.
421+
logger.Error("Ignoring deprecated file.", "file", path)
437422
}
438-
return nodes
439423
}
440424

441425
// KeyDirConfig determines the settings for keydirectory
@@ -482,20 +466,3 @@ func getKeyStoreDir(conf *Config) (string, bool, error) {
482466

483467
return keydir, isEphemeral, nil
484468
}
485-
486-
var warnLock sync.Mutex
487-
488-
func (c *Config) warnOnce(w *bool, format string, args ...interface{}) {
489-
warnLock.Lock()
490-
defer warnLock.Unlock()
491-
492-
if *w {
493-
return
494-
}
495-
l := c.Logger
496-
if l == nil {
497-
l = log.Root()
498-
}
499-
l.Warn(fmt.Sprintf(format, args...))
500-
*w = true
501-
}

node/node.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,7 @@ func New(conf *Config) (*Node, error) {
133133
node.server.Config.PrivateKey = node.config.NodeKey()
134134
node.server.Config.Name = node.config.NodeName()
135135
node.server.Config.Logger = node.log
136-
if node.server.Config.StaticNodes == nil {
137-
node.server.Config.StaticNodes = node.config.StaticNodes()
138-
}
139-
if node.server.Config.TrustedNodes == nil {
140-
node.server.Config.TrustedNodes = node.config.TrustedNodes()
141-
}
136+
node.config.checkLegacyFiles()
142137
if node.server.Config.NodeDatabase == "" {
143138
node.server.Config.NodeDatabase = node.config.NodeDB()
144139
}

0 commit comments

Comments
 (0)