mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 10:22:23 +00:00
Merge pull request #168 from nguyenbatam/add_some_config_to_toml_file
add some config to toml file
This commit is contained in:
commit
523a9ea504
5 changed files with 58 additions and 24 deletions
|
|
@ -30,11 +30,13 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/cmd/utils"
|
"github.com/ethereum/go-ethereum/cmd/utils"
|
||||||
"github.com/ethereum/go-ethereum/dashboard"
|
"github.com/ethereum/go-ethereum/dashboard"
|
||||||
"github.com/ethereum/go-ethereum/eth"
|
"github.com/ethereum/go-ethereum/eth"
|
||||||
|
"github.com/ethereum/go-ethereum/internal/debug"
|
||||||
"github.com/ethereum/go-ethereum/node"
|
"github.com/ethereum/go-ethereum/node"
|
||||||
"github.com/ethereum/go-ethereum/params"
|
"github.com/ethereum/go-ethereum/params"
|
||||||
whisper "github.com/ethereum/go-ethereum/whisper/whisperv6"
|
whisper "github.com/ethereum/go-ethereum/whisper/whisperv6"
|
||||||
"github.com/naoina/toml"
|
"github.com/naoina/toml"
|
||||||
"strings"
|
"strings"
|
||||||
|
"github.com/ethereum/go-ethereum/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
@ -72,7 +74,7 @@ var tomlSettings = toml.Config{
|
||||||
}
|
}
|
||||||
|
|
||||||
type ethstatsConfig struct {
|
type ethstatsConfig struct {
|
||||||
URL string `toml:",omitempty"`
|
URL string
|
||||||
}
|
}
|
||||||
|
|
||||||
type account struct {
|
type account struct {
|
||||||
|
|
@ -94,6 +96,8 @@ type tomoConfig struct {
|
||||||
Account account
|
Account account
|
||||||
StakeEnable bool
|
StakeEnable bool
|
||||||
Bootnodes Bootnodes
|
Bootnodes Bootnodes
|
||||||
|
Verbosity int
|
||||||
|
NAT string
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadConfig(file string, cfg *tomoConfig) error {
|
func loadConfig(file string, cfg *tomoConfig) error {
|
||||||
|
|
@ -128,6 +132,8 @@ func makeConfigNode(ctx *cli.Context) (*node.Node, tomoConfig) {
|
||||||
Node: defaultNodeConfig(),
|
Node: defaultNodeConfig(),
|
||||||
Dashboard: dashboard.DefaultConfig,
|
Dashboard: dashboard.DefaultConfig,
|
||||||
StakeEnable: true,
|
StakeEnable: true,
|
||||||
|
Verbosity: 3,
|
||||||
|
NAT: "",
|
||||||
}
|
}
|
||||||
// Load config file.
|
// Load config file.
|
||||||
if file := ctx.GlobalString(configFileFlag.Name); file != "" {
|
if file := ctx.GlobalString(configFileFlag.Name); file != "" {
|
||||||
|
|
@ -138,6 +144,14 @@ func makeConfigNode(ctx *cli.Context) (*node.Node, tomoConfig) {
|
||||||
if ctx.GlobalIsSet(utils.StakingEnabledFlag.Name) {
|
if ctx.GlobalIsSet(utils.StakingEnabledFlag.Name) {
|
||||||
cfg.StakeEnable = ctx.GlobalBool(utils.StakingEnabledFlag.Name)
|
cfg.StakeEnable = ctx.GlobalBool(utils.StakingEnabledFlag.Name)
|
||||||
}
|
}
|
||||||
|
if !ctx.GlobalIsSet(debug.VerbosityFlag.Name) {
|
||||||
|
debug.Glogger.Verbosity(log.Lvl(cfg.Verbosity))
|
||||||
|
}
|
||||||
|
|
||||||
|
if !ctx.GlobalIsSet(utils.NATFlag.Name) && cfg.NAT != "" {
|
||||||
|
ctx.Set(utils.NATFlag.Name, cfg.NAT)
|
||||||
|
}
|
||||||
|
|
||||||
// read passwords from enviroment
|
// read passwords from enviroment
|
||||||
passwords := []string{}
|
passwords := []string{}
|
||||||
for _, env := range cfg.Account.Passwords {
|
for _, env := range cfg.Account.Passwords {
|
||||||
|
|
|
||||||
25
cmd/tomo/testdata/config.toml
vendored
25
cmd/tomo/testdata/config.toml
vendored
|
|
@ -1,4 +1,7 @@
|
||||||
StakeEnable = true # flag --miner ( true : enable staker , false : disable )
|
StakeEnable = true # flag --miner ( true : enable staker , false : disable )
|
||||||
|
Verbosity = 0 # flag --verbosity (0=Crit 1=Error 2=Warn 3=Info 4=Debug 5=Trace)
|
||||||
|
NAT = "" # flag --nat
|
||||||
|
|
||||||
[Eth]
|
[Eth]
|
||||||
NetworkId = 89 # flag --networkid
|
NetworkId = 89 # flag --networkid
|
||||||
SyncMode = "full" # flag --syncmode
|
SyncMode = "full" # flag --syncmode
|
||||||
|
|
@ -8,16 +11,32 @@ GasPrice = 1 # flag --gasprice
|
||||||
|
|
||||||
[Node]
|
[Node]
|
||||||
DataDir = "node1/" # flag --datadir
|
DataDir = "node1/" # flag --datadir
|
||||||
HTTPHost = "localhost" # flag --rpcaddr
|
|
||||||
HTTPPort = 8501 # flag --rpcport
|
HTTPPort = 8501 # flag --rpcport
|
||||||
|
HTTPHost = "localhost" # flags --rpcaddr & --rpc
|
||||||
|
# in 3 cases :
|
||||||
|
# HTTPHost is "" == --rpc & --rpcaddr is not set
|
||||||
|
# HTTPHost is "localhost" or "127.0.0.1" == only set --rpc
|
||||||
|
# HTTPHost is other IP (ex : 192.168.1.1) = set 2 flags --rpc & --rpcaddr
|
||||||
|
WSHost = "localhost" # flags --wsaddr & --ws . same option HTTPHost
|
||||||
|
WSPort = 8546 # flag --wsport
|
||||||
|
WSModules = ["eth","ssh"] #flag --wsapi
|
||||||
|
|
||||||
|
|
||||||
HTTPModules = ["personal","db","eth","net","web3","txpool","miner"] # flag --rpcapi
|
HTTPModules = ["personal","db","eth","net","web3","txpool","miner"] # flag --rpcapi
|
||||||
|
KeyStoreDir = "" # flag --keystore
|
||||||
|
UserIdent = "" # flag --identity
|
||||||
|
|
||||||
[Node.P2P]
|
[Node.P2P]
|
||||||
ListenAddr = ":30311" # flag --port
|
ListenAddr = ":30311" # flag --port
|
||||||
BootstrapNodes = ["enode://a890c5762c406fe046fb93fd307577a8454d571b6bf789f7dbfbf3c559be751f5fa400bc10639691245a9b22be1cfce0bbf82b322a24d06c6dcf29bf7eeb930c@127.0.0.1:30310"]
|
|
||||||
# flag --bootnodes
|
|
||||||
|
BootstrapNodes = ["enode://a890c5762c406fe046fb93fd307577a8454d571b6bf789f7dbfbf3c559be751f5fa400bc10639691245a9b22be1cfce0bbf82b322a24d06c6dcf29bf7eeb930c@127.0.0.1:30310"] # flag --bootnodes
|
||||||
|
|
||||||
[Ethstats]
|
[Ethstats]
|
||||||
|
URL = "" # flag --ethstats
|
||||||
|
|
||||||
[Dashboard]
|
[Dashboard]
|
||||||
|
|
||||||
[Account]
|
[Account]
|
||||||
Unlocks = ["0x12f90a417f41bedd4bbcc99d52971803fb4c3f8b"] # list account slipt in flag --unlock
|
Unlocks = ["0x12f90a417f41bedd4bbcc99d52971803fb4c3f8b"] # list account slipt in flag --unlock
|
||||||
Passwords = ["PWD_DEVNET"] # list password in environment variable (split by ',') : ex : export PWD_DEVNET=123456,123456789
|
Passwords = ["PWD_DEVNET"] # list password in environment variable (split by ',') : ex : export PWD_DEVNET=123456,123456789
|
||||||
|
|
|
||||||
|
|
@ -653,6 +653,7 @@ func setListenAddress(ctx *cli.Context, cfg *p2p.Config) {
|
||||||
// setNAT creates a port mapper from command line flags.
|
// setNAT creates a port mapper from command line flags.
|
||||||
func setNAT(ctx *cli.Context, cfg *p2p.Config) {
|
func setNAT(ctx *cli.Context, cfg *p2p.Config) {
|
||||||
if ctx.GlobalIsSet(NATFlag.Name) {
|
if ctx.GlobalIsSet(NATFlag.Name) {
|
||||||
|
log.Info("NAT is setted","value",ctx.GlobalString(NATFlag.Name))
|
||||||
natif, err := nat.Parse(ctx.GlobalString(NATFlag.Name))
|
natif, err := nat.Parse(ctx.GlobalString(NATFlag.Name))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Fatalf("Option %s: %v", NATFlag.Name, err)
|
Fatalf("Option %s: %v", NATFlag.Name, err)
|
||||||
|
|
|
||||||
|
|
@ -53,19 +53,19 @@ type HandlerT struct {
|
||||||
// Verbosity sets the log verbosity ceiling. The verbosity of individual packages
|
// Verbosity sets the log verbosity ceiling. The verbosity of individual packages
|
||||||
// and source files can be raised using Vmodule.
|
// and source files can be raised using Vmodule.
|
||||||
func (*HandlerT) Verbosity(level int) {
|
func (*HandlerT) Verbosity(level int) {
|
||||||
glogger.Verbosity(log.Lvl(level))
|
Glogger.Verbosity(log.Lvl(level))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Vmodule sets the log verbosity pattern. See package log for details on the
|
// Vmodule sets the log verbosity pattern. See package log for details on the
|
||||||
// pattern syntax.
|
// pattern syntax.
|
||||||
func (*HandlerT) Vmodule(pattern string) error {
|
func (*HandlerT) Vmodule(pattern string) error {
|
||||||
return glogger.Vmodule(pattern)
|
return Glogger.Vmodule(pattern)
|
||||||
}
|
}
|
||||||
|
|
||||||
// BacktraceAt sets the log backtrace location. See package log for details on
|
// BacktraceAt sets the log backtrace location. See package log for details on
|
||||||
// the pattern syntax.
|
// the pattern syntax.
|
||||||
func (*HandlerT) BacktraceAt(location string) error {
|
func (*HandlerT) BacktraceAt(location string) error {
|
||||||
return glogger.BacktraceAt(location)
|
return Glogger.BacktraceAt(location)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MemStats returns detailed runtime memory statistics.
|
// MemStats returns detailed runtime memory statistics.
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
verbosityFlag = cli.IntFlag{
|
VerbosityFlag = cli.IntFlag{
|
||||||
Name: "verbosity",
|
Name: "verbosity",
|
||||||
Usage: "Logging verbosity: 0=silent, 1=error, 2=warn, 3=info, 4=debug, 5=detail",
|
Usage: "Logging verbosity: 0=silent, 1=error, 2=warn, 3=info, 4=debug, 5=detail",
|
||||||
Value: 3,
|
Value: 3,
|
||||||
|
|
@ -87,12 +87,12 @@ var (
|
||||||
|
|
||||||
// Flags holds all command-line flags required for debugging.
|
// Flags holds all command-line flags required for debugging.
|
||||||
var Flags = []cli.Flag{
|
var Flags = []cli.Flag{
|
||||||
verbosityFlag, vmoduleFlag, backtraceAtFlag, debugFlag,
|
VerbosityFlag, vmoduleFlag, backtraceAtFlag, debugFlag,
|
||||||
pprofFlag, pprofAddrFlag, pprofPortFlag,
|
pprofFlag, pprofAddrFlag, pprofPortFlag,
|
||||||
memprofilerateFlag, blockprofilerateFlag, cpuprofileFlag, traceFlag,
|
memprofilerateFlag, blockprofilerateFlag, cpuprofileFlag, traceFlag,
|
||||||
}
|
}
|
||||||
|
|
||||||
var glogger *log.GlogHandler
|
var Glogger *log.GlogHandler
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
usecolor := term.IsTty(os.Stderr.Fd()) && os.Getenv("TERM") != "dumb"
|
usecolor := term.IsTty(os.Stderr.Fd()) && os.Getenv("TERM") != "dumb"
|
||||||
|
|
@ -100,7 +100,7 @@ func init() {
|
||||||
if usecolor {
|
if usecolor {
|
||||||
output = colorable.NewColorableStderr()
|
output = colorable.NewColorableStderr()
|
||||||
}
|
}
|
||||||
glogger = log.NewGlogHandler(log.StreamHandler(output, log.TerminalFormat(usecolor)))
|
Glogger = log.NewGlogHandler(log.StreamHandler(output, log.TerminalFormat(usecolor)))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup initializes profiling and logging based on the CLI flags.
|
// Setup initializes profiling and logging based on the CLI flags.
|
||||||
|
|
@ -108,10 +108,10 @@ func init() {
|
||||||
func Setup(ctx *cli.Context) error {
|
func Setup(ctx *cli.Context) error {
|
||||||
// logging
|
// logging
|
||||||
log.PrintOrigins(ctx.GlobalBool(debugFlag.Name))
|
log.PrintOrigins(ctx.GlobalBool(debugFlag.Name))
|
||||||
glogger.Verbosity(log.Lvl(ctx.GlobalInt(verbosityFlag.Name)))
|
Glogger.Verbosity(log.Lvl(ctx.GlobalInt(VerbosityFlag.Name)))
|
||||||
glogger.Vmodule(ctx.GlobalString(vmoduleFlag.Name))
|
Glogger.Vmodule(ctx.GlobalString(vmoduleFlag.Name))
|
||||||
glogger.BacktraceAt(ctx.GlobalString(backtraceAtFlag.Name))
|
Glogger.BacktraceAt(ctx.GlobalString(backtraceAtFlag.Name))
|
||||||
log.Root().SetHandler(glogger)
|
log.Root().SetHandler(Glogger)
|
||||||
|
|
||||||
// profiling, tracing
|
// profiling, tracing
|
||||||
runtime.MemProfileRate = ctx.GlobalInt(memprofilerateFlag.Name)
|
runtime.MemProfileRate = ctx.GlobalInt(memprofilerateFlag.Name)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue