Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
f32790fb
Commit
f32790fb
authored
Dec 07, 2018
by
Felix Lange
Committed by
Péter Szilágyi
Dec 07, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
node: warn when using deprecated config/resource files (#18199)
parent
d2328b60
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
9 deletions
+35
-9
config.go
node/config.go
+35
-9
No files found.
node/config.go
View file @
f32790fb
...
@@ -24,6 +24,7 @@ import (
...
@@ -24,6 +24,7 @@ import (
"path/filepath"
"path/filepath"
"runtime"
"runtime"
"strings"
"strings"
"sync"
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/ethereum/go-ethereum/accounts/keystore"
...
@@ -152,6 +153,10 @@ type Config struct {
...
@@ -152,6 +153,10 @@ 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
}
}
// IPCEndpoint resolves an IPC endpoint based on a configured value, taking into
// IPCEndpoint resolves an IPC endpoint based on a configured value, taking into
...
@@ -263,8 +268,8 @@ var isOldGethResource = map[string]bool{
...
@@ -263,8 +268,8 @@ var isOldGethResource = map[string]bool{
"chaindata"
:
true
,
"chaindata"
:
true
,
"nodes"
:
true
,
"nodes"
:
true
,
"nodekey"
:
true
,
"nodekey"
:
true
,
"static-nodes.json"
:
true
,
"static-nodes.json"
:
false
,
// no warning for these because they have their
"trusted-nodes.json"
:
true
,
"trusted-nodes.json"
:
false
,
// own separate warning.
}
}
// ResolvePath resolves path in the instance directory.
// ResolvePath resolves path in the instance directory.
...
@@ -277,13 +282,15 @@ func (c *Config) ResolvePath(path string) string {
...
@@ -277,13 +282,15 @@ func (c *Config) ResolvePath(path string) string {
}
}
// Backwards-compatibility: ensure that data directory files created
// Backwards-compatibility: ensure that data directory files created
// by geth 1.4 are used if they exist.
// by geth 1.4 are used if they exist.
if
c
.
name
()
==
"geth"
&&
isOldGethResource
[
path
]
{
if
warn
,
isOld
:=
isOldGethResource
[
path
];
isOld
{
oldpath
:=
""
oldpath
:=
""
if
c
.
Name
==
"geth"
{
if
c
.
name
()
==
"geth"
{
oldpath
=
filepath
.
Join
(
c
.
DataDir
,
path
)
oldpath
=
filepath
.
Join
(
c
.
DataDir
,
path
)
}
}
if
oldpath
!=
""
&&
common
.
FileExist
(
oldpath
)
{
if
oldpath
!=
""
&&
common
.
FileExist
(
oldpath
)
{
// TODO: print warning
if
warn
{
c
.
warnOnce
(
&
c
.
oldGethResourceWarning
,
"Using deprecated resource file %s, please move this file to the 'geth' subdirectory of datadir."
,
oldpath
)
}
return
oldpath
return
oldpath
}
}
}
}
...
@@ -337,17 +344,17 @@ func (c *Config) NodeKey() *ecdsa.PrivateKey {
...
@@ -337,17 +344,17 @@ func (c *Config) NodeKey() *ecdsa.PrivateKey {
// StaticNodes returns a list of node enode URLs configured as static nodes.
// StaticNodes returns a list of node enode URLs configured as static nodes.
func
(
c
*
Config
)
StaticNodes
()
[]
*
enode
.
Node
{
func
(
c
*
Config
)
StaticNodes
()
[]
*
enode
.
Node
{
return
c
.
parsePersistentNodes
(
c
.
ResolvePath
(
datadirStaticNodes
))
return
c
.
parsePersistentNodes
(
&
c
.
staticNodesWarning
,
c
.
ResolvePath
(
datadirStaticNodes
))
}
}
// TrustedNodes returns a list of node enode URLs configured as trusted nodes.
// TrustedNodes returns a list of node enode URLs configured as trusted nodes.
func
(
c
*
Config
)
TrustedNodes
()
[]
*
enode
.
Node
{
func
(
c
*
Config
)
TrustedNodes
()
[]
*
enode
.
Node
{
return
c
.
parsePersistentNodes
(
c
.
ResolvePath
(
datadirTrustedNodes
))
return
c
.
parsePersistentNodes
(
&
c
.
trustedNodesWarning
,
c
.
ResolvePath
(
datadirTrustedNodes
))
}
}
// parsePersistentNodes parses a list of discovery node URLs loaded from a .json
// parsePersistentNodes parses a list of discovery node URLs loaded from a .json
// file from within the data directory.
// file from within the data directory.
func
(
c
*
Config
)
parsePersistentNodes
(
path
string
)
[]
*
enode
.
Node
{
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
nil
...
@@ -355,10 +362,12 @@ func (c *Config) parsePersistentNodes(path string) []*enode.Node {
...
@@ -355,10 +362,12 @@ func (c *Config) parsePersistentNodes(path string) []*enode.Node {
if
_
,
err
:=
os
.
Stat
(
path
);
err
!=
nil
{
if
_
,
err
:=
os
.
Stat
(
path
);
err
!=
nil
{
return
nil
return
nil
}
}
c
.
warnOnce
(
w
,
"Found deprecated node list file %s, please use the TOML config file instead."
,
path
)
// Load the nodes from the config file.
// Load the nodes from the config file.
var
nodelist
[]
string
var
nodelist
[]
string
if
err
:=
common
.
LoadJSON
(
path
,
&
nodelist
);
err
!=
nil
{
if
err
:=
common
.
LoadJSON
(
path
,
&
nodelist
);
err
!=
nil
{
log
.
Error
(
fmt
.
Sprintf
(
"Can't load node
file %s: %v"
,
path
,
err
))
log
.
Error
(
fmt
.
Sprintf
(
"Can't load node
list file: %v"
,
err
))
return
nil
return
nil
}
}
// Interpret the list as a discovery node array
// Interpret the list as a discovery node array
...
@@ -440,3 +449,20 @@ func makeAccountManager(conf *Config) (*accounts.Manager, string, error) {
...
@@ -440,3 +449,20 @@ func makeAccountManager(conf *Config) (*accounts.Manager, string, error) {
}
}
return
accounts
.
NewManager
(
backends
...
),
ephemeral
,
nil
return
accounts
.
NewManager
(
backends
...
),
ephemeral
,
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
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment