forked from cerc-io/plugeth
node: drop support for static & trusted node list files (#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.
This commit is contained in:
parent
e257b3add7
commit
3630cafb34
@ -23,13 +23,11 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
"github.com/ethereum/go-ethereum/p2p"
|
"github.com/ethereum/go-ethereum/p2p"
|
||||||
"github.com/ethereum/go-ethereum/p2p/enode"
|
|
||||||
"github.com/ethereum/go-ethereum/rpc"
|
"github.com/ethereum/go-ethereum/rpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -194,8 +192,6 @@ type Config struct {
|
|||||||
// Logger is a custom logger to use with the p2p.Server.
|
// Logger is a custom logger to use with the p2p.Server.
|
||||||
Logger log.Logger `toml:",omitempty"`
|
Logger log.Logger `toml:",omitempty"`
|
||||||
|
|
||||||
staticNodesWarning bool
|
|
||||||
trustedNodesWarning bool
|
|
||||||
oldGethResourceWarning bool
|
oldGethResourceWarning bool
|
||||||
|
|
||||||
// AllowUnprotectedTxs allows non EIP-155 protected transactions to be send over RPC.
|
// AllowUnprotectedTxs allows non EIP-155 protected transactions to be send over RPC.
|
||||||
@ -340,8 +336,9 @@ func (c *Config) ResolvePath(path string) string {
|
|||||||
oldpath = filepath.Join(c.DataDir, path)
|
oldpath = filepath.Join(c.DataDir, path)
|
||||||
}
|
}
|
||||||
if oldpath != "" && common.FileExist(oldpath) {
|
if oldpath != "" && common.FileExist(oldpath) {
|
||||||
if warn {
|
if warn && !c.oldGethResourceWarning {
|
||||||
c.warnOnce(&c.oldGethResourceWarning, "Using deprecated resource file %s, please move this file to the 'geth' subdirectory of datadir.", oldpath)
|
c.oldGethResourceWarning = true
|
||||||
|
log.Warn("Using deprecated resource file, please move this file to the 'geth' subdirectory of datadir.", "file", oldpath)
|
||||||
}
|
}
|
||||||
return oldpath
|
return oldpath
|
||||||
}
|
}
|
||||||
@ -394,48 +391,35 @@ func (c *Config) NodeKey() *ecdsa.PrivateKey {
|
|||||||
return key
|
return key
|
||||||
}
|
}
|
||||||
|
|
||||||
// StaticNodes returns a list of node enode URLs configured as static nodes.
|
// CheckLegacyFiles inspects the datadir for signs of legacy static-nodes
|
||||||
func (c *Config) StaticNodes() []*enode.Node {
|
// and trusted-nodes files. If they exist it raises an error.
|
||||||
return c.parsePersistentNodes(&c.staticNodesWarning, c.ResolvePath(datadirStaticNodes))
|
func (c *Config) checkLegacyFiles() {
|
||||||
|
c.checkLegacyFile(c.ResolvePath(datadirStaticNodes))
|
||||||
|
c.checkLegacyFile(c.ResolvePath(datadirTrustedNodes))
|
||||||
}
|
}
|
||||||
|
|
||||||
// TrustedNodes returns a list of node enode URLs configured as trusted nodes.
|
// checkLegacyFile will only raise an error if a file at the given path exists.
|
||||||
func (c *Config) TrustedNodes() []*enode.Node {
|
func (c *Config) checkLegacyFile(path string) {
|
||||||
return c.parsePersistentNodes(&c.trustedNodesWarning, c.ResolvePath(datadirTrustedNodes))
|
|
||||||
}
|
|
||||||
|
|
||||||
// parsePersistentNodes parses a list of discovery node URLs loaded from a .json
|
|
||||||
// file from within the data directory.
|
|
||||||
func (c *Config) parsePersistentNodes(w *bool, path string) []*enode.Node {
|
|
||||||
// Short circuit if no node config is present
|
// Short circuit if no node config is present
|
||||||
if c.DataDir == "" {
|
if c.DataDir == "" {
|
||||||
return nil
|
return
|
||||||
}
|
}
|
||||||
if _, err := os.Stat(path); err != nil {
|
if _, err := os.Stat(path); err != nil {
|
||||||
return nil
|
return
|
||||||
}
|
}
|
||||||
c.warnOnce(w, "Found deprecated node list file %s, please use the TOML config file instead.", path)
|
logger := c.Logger
|
||||||
|
if logger == nil {
|
||||||
// Load the nodes from the config file.
|
logger = log.Root()
|
||||||
var nodelist []string
|
|
||||||
if err := common.LoadJSON(path, &nodelist); err != nil {
|
|
||||||
log.Error(fmt.Sprintf("Can't load node list file: %v", err))
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
// Interpret the list as a discovery node array
|
switch fname := filepath.Base(path); fname {
|
||||||
var nodes []*enode.Node
|
case "static-nodes.json":
|
||||||
for _, url := range nodelist {
|
logger.Error("The static-nodes.json file is deprecated and ignored. Use P2P.StaticNodes in config.toml instead.")
|
||||||
if url == "" {
|
case "trusted-nodes.json":
|
||||||
continue
|
logger.Error("The trusted-nodes.json file is deprecated and ignored. Use P2P.TrustedNodes in config.toml instead.")
|
||||||
}
|
default:
|
||||||
node, err := enode.Parse(enode.ValidSchemes, url)
|
// We shouldn't wind up here, but better print something just in case.
|
||||||
if err != nil {
|
logger.Error("Ignoring deprecated file.", "file", path)
|
||||||
log.Error(fmt.Sprintf("Node URL %s: %v\n", url, err))
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
nodes = append(nodes, node)
|
|
||||||
}
|
}
|
||||||
return nodes
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// KeyDirConfig determines the settings for keydirectory
|
// KeyDirConfig determines the settings for keydirectory
|
||||||
@ -482,20 +466,3 @@ func getKeyStoreDir(conf *Config) (string, bool, error) {
|
|||||||
|
|
||||||
return keydir, isEphemeral, nil
|
return keydir, isEphemeral, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var warnLock sync.Mutex
|
|
||||||
|
|
||||||
func (c *Config) warnOnce(w *bool, format string, args ...interface{}) {
|
|
||||||
warnLock.Lock()
|
|
||||||
defer warnLock.Unlock()
|
|
||||||
|
|
||||||
if *w {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
l := c.Logger
|
|
||||||
if l == nil {
|
|
||||||
l = log.Root()
|
|
||||||
}
|
|
||||||
l.Warn(fmt.Sprintf(format, args...))
|
|
||||||
*w = true
|
|
||||||
}
|
|
||||||
|
@ -133,12 +133,7 @@ func New(conf *Config) (*Node, error) {
|
|||||||
node.server.Config.PrivateKey = node.config.NodeKey()
|
node.server.Config.PrivateKey = node.config.NodeKey()
|
||||||
node.server.Config.Name = node.config.NodeName()
|
node.server.Config.Name = node.config.NodeName()
|
||||||
node.server.Config.Logger = node.log
|
node.server.Config.Logger = node.log
|
||||||
if node.server.Config.StaticNodes == nil {
|
node.config.checkLegacyFiles()
|
||||||
node.server.Config.StaticNodes = node.config.StaticNodes()
|
|
||||||
}
|
|
||||||
if node.server.Config.TrustedNodes == nil {
|
|
||||||
node.server.Config.TrustedNodes = node.config.TrustedNodes()
|
|
||||||
}
|
|
||||||
if node.server.Config.NodeDatabase == "" {
|
if node.server.Config.NodeDatabase == "" {
|
||||||
node.server.Config.NodeDatabase = node.config.NodeDB()
|
node.server.Config.NodeDatabase = node.config.NodeDB()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user