ethereumproject / go-ethereum

Go language implementation of the original/classic design of the Ethereum protocol
GNU Lesser General Public License v3.0
442 stars 166 forks source link

Config file #116

Closed realcodywburns closed 5 years ago

realcodywburns commented 7 years ago

I propose we add a stateful default config file to geth as opposed to using flags by default.

something in '/cmd/utils/flags.go' like:

func GetConfigFile() 
    f, err := os.Open(common.configETC())
       if err != nil {
          fmt.Println(err)
       }
    var (
       for {
         var n int
          n, err = fmt.Fscanln(f)
          if n == 0 || err != nil {
            break
          }
        }
      )
    }

Expected behavior:

pascaldekloe commented 7 years ago

A configuration file makes sense. Few questions though.

realcodywburns commented 7 years ago

When running geth, if you want to customize it for you machine currently you have to include a ton of flags, have your own a bat file, or write a custom .sh. By stateful, i mean having an external file that can be configured with flag settings that will remain on the system or can be moved to others if you like. The code, properly written the above is mostly a placeholder I never went back to repair. would be used around https://github.com/ethereumproject/go-ethereum/blob/3093dcf128340f33a9dfa8ffe6ef376d80383313/cmd/geth/main.go#L148 to check if a config file exists, and if so use it. Parity has this feature and makes it very easy to move between systems and backups. They even made a handy front end to spit out a .toml file.

It is useful because some of the flags are helpful, but if you dont go looking for them many would never know they exist and there is no way to tweak the system once it is launched

mikeyb commented 7 years ago

Another option to consider is just including a sample configuration file with the application (yaml, json, bash vars, etc). Along with startup scripts (startgeth.bat, startgeth[.sh], etc) that parse the config file.

startup.config

VAR1='default1'
VAR2='default2'
VAR3='default3'

rudimentary poc bash

#!/usr/bin/env bash

if [ -f 'startup.config' ]; then
  #  source startup.config file
  source startup.config

  #  parsing logic

  #  startup geth with defined variables sourced from startup.config

else
  #  Start geth with sane defaults
fi

Python may be a better option? or golang? Don't know how friendly golang is to system environments. Distro specific system startup scripts even? Windows would use powershell?

Would require no changes to current code base and also makes for greater portability at the same time.

realcodywburns commented 7 years ago

Yes, the idea would be to avoid having to string together flags each time you run geth. for window my launchgeth.bat looks something like:

 SET nodeName="Dontpanic node 1"
 :how much ram to use for chain cache
 SET cacheValue=1028
 :finds all ETC bootnodes
 SET bootstrapNodes= " a lot of enodes"
 :tweak for better proformance
 SET maxPeers=250
 SET pendPeers=20
 :other stuff
 SET datadir="L:\ethereum"
 :change this to the location of geth
 "C:\Ethereum\geth\geth.exe" --identity %nodeName% --datadir %datadir% --cache %cacheValue% --maxpeers %maxPeers% --maxpendpeers %pendPeers% --fast --rpc --bootnodes %bootstrapNodes%
PAUSE

But it isn't the the best "out of the box" experince.

whilei commented 6 years ago

What if we used a similar structure to git's config, where there'd be

and each more granular level of configuration would override the one above it... like

$HOME/.gethclassicconfig

data-dir: $HOME/Library/EthereumClassic
chain: mainnet
port: 30303
rpc: true
verbosity: 3

$HOME/Library/EthereumClassic/mainnet/config

# chain config overrides global config
rpc: false
verbosity: 2 

command

# flag overrides chain config
geth \
    --verbosity 5 

Would result in a final configuration equivalent to geth --data-dir=$HOME/Library/EthereumClassic --chain=mainnet --port=30303 --rpc=false --verbosity=5.

Each of these configurations will only override defaults for the values present in the files (or the CLI). (So you don't have to use a "complete" file with 79 fields, you can just modify the values you want and keep the defaults otherwise).

Also there could be a flag/option to point geth to a specific flag config file instead of using this defacto order of inheritance, ala --config=path/to/config, where using this flag would override in-code defaults with the one given config file.

I'd also like to prefer YAML and/or TOML over JSON because they allow for comments.