Skip to content

Commit 7b67b7f

Browse files
committed
node: drop support for static & trusted node list files ethereum#25610
1 parent 10c7e1d commit 7b67b7f

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/XinFinOrg/XDPoSChain/common"
2928
"github.com/XinFinOrg/XDPoSChain/crypto"
3029
"github.com/XinFinOrg/XDPoSChain/log"
3130
"github.com/XinFinOrg/XDPoSChain/p2p"
32-
"github.com/XinFinOrg/XDPoSChain/p2p/discover"
3331
"github.com/XinFinOrg/XDPoSChain/rpc"
3432
)
3533

@@ -177,8 +175,6 @@ type Config struct {
177175
// Logger is a custom logger to use with the p2p.Server.
178176
Logger log.Logger `toml:",omitempty"`
179177

180-
staticNodesWarning bool
181-
trustedNodesWarning bool
182178
oldGethResourceWarning bool
183179

184180
AnnounceTxs bool `toml:",omitempty"`
@@ -329,8 +325,9 @@ func (c *Config) ResolvePath(path string) string {
329325
oldpath = filepath.Join(c.DataDir, path)
330326
}
331327
if oldpath != "" && common.FileExist(oldpath) {
332-
if warn {
333-
c.warnOnce(&c.oldGethResourceWarning, "Using deprecated resource file %s, please move this file to the 'geth' subdirectory of datadir.", oldpath)
328+
if warn && !c.oldGethResourceWarning {
329+
c.oldGethResourceWarning = true
330+
log.Warn("Using deprecated resource file, please move this file to the 'geth' subdirectory of datadir.", "file", oldpath)
334331
}
335332
return oldpath
336333
}
@@ -383,48 +380,35 @@ func (c *Config) NodeKey() *ecdsa.PrivateKey {
383380
return key
384381
}
385382

386-
// StaticNodes returns a list of node enode URLs configured as static nodes.
387-
func (c *Config) StaticNodes() []*discover.Node {
388-
return c.parsePersistentNodes(&c.staticNodesWarning, c.ResolvePath(datadirStaticNodes))
383+
// CheckLegacyFiles inspects the datadir for signs of legacy static-nodes
384+
// and trusted-nodes files. If they exist it raises an error.
385+
func (c *Config) checkLegacyFiles() {
386+
c.checkLegacyFile(c.ResolvePath(datadirStaticNodes))
387+
c.checkLegacyFile(c.ResolvePath(datadirTrustedNodes))
389388
}
390389

391-
// TrustedNodes returns a list of node enode URLs configured as trusted nodes.
392-
func (c *Config) TrustedNodes() []*discover.Node {
393-
return c.parsePersistentNodes(&c.trustedNodesWarning, c.ResolvePath(datadirTrustedNodes))
394-
}
395-
396-
// parsePersistentNodes parses a list of discovery node URLs loaded from a .json
397-
// file from within the data directory.
398-
func (c *Config) parsePersistentNodes(w *bool, path string) []*discover.Node {
390+
// checkLegacyFile will only raise an error if a file at the given path exists.
391+
func (c *Config) checkLegacyFile(path string) {
399392
// Short circuit if no node config is present
400393
if c.DataDir == "" {
401-
return nil
394+
return
402395
}
403396
if _, err := os.Stat(path); err != nil {
404-
return nil
397+
return
405398
}
406-
c.warnOnce(w, "Found deprecated node list file %s, please use the TOML config file instead.", path)
407-
408-
// Load the nodes from the config file.
409-
var nodelist []string
410-
if err := common.LoadJSON(path, &nodelist); err != nil {
411-
log.Error(fmt.Sprintf("Can't load node list file: %v", err))
412-
return nil
399+
logger := c.Logger
400+
if logger == nil {
401+
logger = log.Root()
413402
}
414-
// Interpret the list as a discovery node array
415-
var nodes []*discover.Node
416-
for _, url := range nodelist {
417-
if url == "" {
418-
continue
419-
}
420-
node, err := discover.ParseNode(url)
421-
if err != nil {
422-
log.Error(fmt.Sprintf("Node URL %s: %v\n", url, err))
423-
continue
424-
}
425-
nodes = append(nodes, node)
403+
switch fname := filepath.Base(path); fname {
404+
case "static-nodes.json":
405+
logger.Error("The static-nodes.json file is deprecated and ignored. Use P2P.StaticNodes in config.toml instead.")
406+
case "trusted-nodes.json":
407+
logger.Error("The trusted-nodes.json file is deprecated and ignored. Use P2P.TrustedNodes in config.toml instead.")
408+
default:
409+
// We shouldn't wind up here, but better print something just in case.
410+
logger.Error("Ignoring deprecated file.", "file", path)
426411
}
427-
return nodes
428412
}
429413

430414
// KeyDirConfig determines the settings for keydirectory
@@ -471,20 +455,3 @@ func getKeyStoreDir(conf *Config) (string, bool, error) {
471455

472456
return keydir, isEphemeral, nil
473457
}
474-
475-
var warnLock sync.Mutex
476-
477-
func (c *Config) warnOnce(w *bool, format string, args ...interface{}) {
478-
warnLock.Lock()
479-
defer warnLock.Unlock()
480-
481-
if *w {
482-
return
483-
}
484-
l := c.Logger
485-
if l == nil {
486-
l = log.Root()
487-
}
488-
l.Warn(fmt.Sprintf(format, args...))
489-
*w = true
490-
}

node/node.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,7 @@ func New(conf *Config) (*Node, error) {
138138
node.server.Config.PrivateKey = node.config.NodeKey()
139139
node.server.Config.Name = node.config.NodeName()
140140
node.server.Config.Logger = node.log
141-
if node.server.Config.StaticNodes == nil {
142-
node.server.Config.StaticNodes = node.config.StaticNodes()
143-
}
144-
if node.server.Config.TrustedNodes == nil {
145-
node.server.Config.TrustedNodes = node.config.TrustedNodes()
146-
}
141+
node.config.checkLegacyFiles()
147142
if node.server.Config.NodeDatabase == "" {
148143
node.server.Config.NodeDatabase = node.config.NodeDB()
149144
}

0 commit comments

Comments
 (0)