-
Notifications
You must be signed in to change notification settings - Fork 20.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd/geth: add --config file flag #13875
Conversation
@@ -1,3 +1,19 @@ | |||
// Copyright 2015 The go-ethereum Authors |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"17 ;)
1aea7b9
to
38fd8bd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looked though the code, seems ok, just a few questions. Still have to try it out though.
p2p/server.go
Outdated
// Discovery specifies whether the peer discovery mechanism should be started | ||
// or not. Disabling is usually useful for protocol debugging (manual topology). | ||
Discovery bool | ||
// NoDiscowery can be used to disable the peer discovery mechanism. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NoDiscoWery
;)
node/node.go
Outdated
n.serverConfig.TrustedNodes = n.config.TrusterNodes() | ||
} | ||
if n.serverConfig.NodeDatabase == "" { | ||
n.serverConfig.NodeDatabase = n.config.NodeDB() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When does it happen that n.serverConfig.Xyz
is not nil? I.e. when the above code should not override?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
n.serverConfig
is set to (a copy of) n.config.P2P
, which is created from defaults + config file + flags. If there is something set through any of these, that value is used.
Version: params.Version, | ||
DataDir: datadir, | ||
KeyStoreDir: filepath.Join(datadir, "keystore"), // Mobile should never use internal keystores! | ||
NoDiscovery: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn"t the NoDiscover get lost accidentally?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, looks like it.
Did"t you add Also I"d really like to have |
eth/config.go
Outdated
|
||
// DefaultConfig contains default settings for use on the Ethereum main net. | ||
var DefaultConfig = Config{ | ||
SyncMode: downloader.FullSync, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We want to default to fast sync, with full sync being opt in. Users new to geth always just freak out and don"t understand why it takes so long. Archive nodes are the rarity nowadays, not the common config.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went through the code but have not tried it. Will do that tomorrow.
EnablePreimageRecording bool | ||
|
||
// Miscellaneous options | ||
SolcPath string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still need the solc path option?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really.
|
||
// dumpConfig is the dumpconfig command. | ||
func dumpConfig(ctx *cli.Context) error { | ||
_, cfg := makeConfigNode(ctx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In some situation this can lead to undesired output.
> geth dumpconfig
WARN [04-11|21:13:43] No etherbase set and no accounts found as default
[Eth]
NetworkId = 1
SyncMode = "full"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The warning goes to stderr though.
cmd/geth/config.go
Outdated
P2P: p2p.Config{MaxPeers: 25}, | ||
HTTPModules: []string{"eth", "net", "web3"}, | ||
WSModules: []string{"eth", "net", "web3"}, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the reason that some fields are given a default value and others not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The zero value is a good default for the other fields.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some values are missing though. They"re added now.
cmd/utils/flags.go
Outdated
case ctx.GlobalIsSet(IPCPathFlag.Name): | ||
cfg.IPCPath = ctx.GlobalString(IPCPathFlag.Name) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the user starts up geth without any ipc path/disable related options geth currently starts the ipc interface on a default endpoint. This method will leave it empty causing the node not to start it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cmd/utils/flags.go
Outdated
if ctx.GlobalIsSet(RPCListenAddrFlag.Name) { | ||
cfg.HTTPHost = ctx.GlobalString(RPCListenAddrFlag.Name) | ||
} | ||
if ctx.GlobalIsSet(RPCPortFlag.Name) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the user doesn"t specify a custom http port cfg.HTTPPort
will be 0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default port and APIs are set in node.DefaultConfig.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commit 098ba171e4b485774879bdb96d74d10e8ebf863e that fixes this was added after I reviewed it.
if ctx.GlobalIsSet(RPCCORSDomainFlag.Name) { | ||
cfg.HTTPCors = ctx.GlobalString(RPCCORSDomainFlag.Name) | ||
} | ||
if ctx.GlobalIsSet(RPCApiFlag.Name) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the user doesn"t specify custom modules cfg.HTTPModules
will be empty.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if ctx.GlobalIsSet(WSAllowedOriginsFlag.Name) { | ||
cfg.WSOrigins = ctx.GlobalString(WSAllowedOriginsFlag.Name) | ||
} | ||
if ctx.GlobalIsSet(WSApiFlag.Name) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the user doesn"t specify custom modules cfg.WSModules
will be empty.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cmd/utils/flags.go
Outdated
if ctx.GlobalIsSet(WSListenAddrFlag.Name) { | ||
cfg.WSHost = ctx.GlobalString(WSListenAddrFlag.Name) | ||
} | ||
if ctx.GlobalIsSet(WSPortFlag.Name) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the user doesn"t specify custom port cfg.WSPort
will be empty.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would require adding toml struct tags to params.Config. I"ll do it in a follow-up PR. |
cmd/utils/flags.go
Outdated
comps = append(comps, "JIT") | ||
} | ||
return strings.Join(comps, "/") | ||
cfg.UserIdent = strings.Join(comps, "/") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If cfg.UserIdent
is empty strings.split
will return an array with a single string of length 0. If the user specified a custom identify this is appended to this array. When later joined with "/" it will lead to /myIdentify
.
geth --identity "myIdentity"
> admin.nodeInfo.name
"Geth//myIdentity/v1.6.0-unstable-3e2ed7e3/linux-amd64/go1.8.1"
|
||
// HTTPCors is the Cross-Origin Resource Sharing header to send to requesting | ||
// clients. Please be aware that CORS is a browser enforced security, it's fully | ||
// useless for custom HTTP clients. | ||
HTTPCors string | ||
HTTPCors string `toml:",omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be a bit nicer if this was an array just like HTTPModules
. Currently the string is a comma separated string that is is splitted when the cors handler is created. I can do this in an follow up PR. Same thing for the WSOrigins
.
This makes the zero Config slightly more useful. It also fixes package node tests because Node detects reuse of the datadir through the NodeDatabase.
This removes the FastSync, LightSync flags in favour of a more general SyncMode flag.
It now reads: Fatal: flags --dev, --testnet can"t be used at the same time
This exposed a couple of places that needed to be updated to use node.DefaultConfig.
Set it in the frontends instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
In this PR, geth gets a new
--config <file>
option. The new option causes it to read configuration options from a file in TOML syntax. The implementation approach and motivation for it is described in https://twurst.com/articles/geth-config-file.html.