Skip to content
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

Merged
merged 32 commits into from
Apr 12, 2017
Merged

cmd/geth: add --config file flag #13875

merged 32 commits into from
Apr 12, 2017

Conversation

fjl
Copy link
Contributor

@fjl fjl commented Apr 6, 2017

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.

@@ -1,3 +1,19 @@
// Copyright 2015 The go-ethereum Authors
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"17 ;)

@karalabe karalabe added this to the 1.6.0 milestone Apr 7, 2017
@fjl fjl force-pushed the config-wip branch 2 times, most recently from 1aea7b9 to 38fd8bd Compare April 11, 2017 09:39
Copy link
Member

@karalabe karalabe left a 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.
Copy link
Member

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()
Copy link
Member

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?

Copy link
Contributor Author

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,
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, looks like it.

@karalabe
Copy link
Member

karalabe commented Apr 11, 2017

Did"t you add --genesis to support dumping the genesis file too? That"s really needed for custom networks as we"ve talked.

Also I"d really like to have --syncMode as a flag too, defaulting to fast. Without the flag, I can"t set it to "full" manually. Maybe I missed osmething?

eth/config.go Outdated

// DefaultConfig contains default settings for use on the Ethereum main net.
var DefaultConfig = Config{
SyncMode: downloader.FullSync,
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Member

@bas-vk bas-vk left a 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
Copy link
Member

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?

Copy link
Contributor Author

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)
Copy link
Member

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"

Copy link
Contributor Author

@fjl fjl Apr 11, 2017

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.

P2P: p2p.Config{MaxPeers: 25},
HTTPModules: []string{"eth", "net", "web3"},
WSModules: []string{"eth", "net", "web3"},
}
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

case ctx.GlobalIsSet(IPCPathFlag.Name):
cfg.IPCPath = ctx.GlobalString(IPCPathFlag.Name)
}
}
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if ctx.GlobalIsSet(RPCListenAddrFlag.Name) {
cfg.HTTPHost = ctx.GlobalString(RPCListenAddrFlag.Name)
}
if ctx.GlobalIsSet(RPCPortFlag.Name) {
Copy link
Member

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.

Copy link
Contributor Author

@fjl fjl Apr 11, 2017

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.

Copy link
Member

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) {
Copy link
Member

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.

Copy link
Contributor Author

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) {
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if ctx.GlobalIsSet(WSListenAddrFlag.Name) {
cfg.WSHost = ctx.GlobalString(WSListenAddrFlag.Name)
}
if ctx.GlobalIsSet(WSPortFlag.Name) {
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fjl
Copy link
Contributor Author

fjl commented Apr 12, 2017

Did"t you add --genesis to support dumping the genesis file too? That"s really needed for custom networks as we"ve talked.

It would require adding toml struct tags to params.Config. I"ll do it in a follow-up PR.

@fjl
Copy link
Contributor Author

fjl commented Apr 12, 2017

@karalabe @bas-vk PTAL

comps = append(comps, "JIT")
}
return strings.Join(comps, "/")
cfg.UserIdent = strings.Join(comps, "/")
}
Copy link
Member

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"`
Copy link
Member

@bas-vk bas-vk Apr 12, 2017

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.

Copy link
Member

@karalabe karalabe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@karalabe karalabe merged commit 30d706c into ethereum:master Apr 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants