diff --git a/cmd/tomo/chaincmd.go b/cmd/tomo/chaincmd.go index d3086921b9..8439f26c26 100644 --- a/cmd/tomo/chaincmd.go +++ b/cmd/tomo/chaincmd.go @@ -190,7 +190,7 @@ func initGenesis(ctx *cli.Context) error { utils.Fatalf("invalid genesis file: %v", err) } // Open an initialise both full and light databases - stack := makeFullNode(ctx) + stack,_ := makeFullNode(ctx) for _, name := range []string{"chaindata", "lightchaindata"} { chaindb, err := stack.OpenDatabase(name, 0, 0) if err != nil { @@ -209,7 +209,7 @@ func importChain(ctx *cli.Context) error { if len(ctx.Args()) < 1 { utils.Fatalf("This command requires an argument.") } - stack := makeFullNode(ctx) + stack,_ := makeFullNode(ctx) chain, chainDb := utils.MakeChain(ctx, stack) defer chainDb.Close() @@ -303,7 +303,7 @@ func exportChain(ctx *cli.Context) error { if len(ctx.Args()) < 1 { utils.Fatalf("This command requires an argument.") } - stack := makeFullNode(ctx) + stack,_ := makeFullNode(ctx) chain, _ := utils.MakeChain(ctx, stack) start := time.Now() @@ -336,7 +336,7 @@ func importPreimages(ctx *cli.Context) error { if len(ctx.Args()) < 1 { utils.Fatalf("This command requires an argument.") } - stack := makeFullNode(ctx) + stack,_ := makeFullNode(ctx) diskdb := utils.MakeChainDatabase(ctx, stack).(*ethdb.LDBDatabase) start := time.Now() @@ -352,7 +352,7 @@ func exportPreimages(ctx *cli.Context) error { if len(ctx.Args()) < 1 { utils.Fatalf("This command requires an argument.") } - stack := makeFullNode(ctx) + stack,_ := makeFullNode(ctx) diskdb := utils.MakeChainDatabase(ctx, stack).(*ethdb.LDBDatabase) start := time.Now() @@ -369,7 +369,7 @@ func copyDb(ctx *cli.Context) error { utils.Fatalf("Source chaindata directory path argument missing") } // Initialize a new chain for the running node to sync into - stack := makeFullNode(ctx) + stack,_ := makeFullNode(ctx) chain, chainDb := utils.MakeChain(ctx, stack) syncmode := *utils.GlobalTextMarshaler(ctx, utils.SyncModeFlag.Name).(*downloader.SyncMode) @@ -441,7 +441,7 @@ func removeDB(ctx *cli.Context) error { } func dump(ctx *cli.Context) error { - stack := makeFullNode(ctx) + stack,_ := makeFullNode(ctx) chain, chainDb := utils.MakeChain(ctx, stack) for _, arg := range ctx.Args() { var block *types.Block diff --git a/cmd/tomo/config.go b/cmd/tomo/config.go index 8856071901..33cb2e060f 100644 --- a/cmd/tomo/config.go +++ b/cmd/tomo/config.go @@ -25,7 +25,7 @@ import ( "reflect" "unicode" - cli "gopkg.in/urfave/cli.v1" + "gopkg.in/urfave/cli.v1" "github.com/ethereum/go-ethereum/cmd/utils" "github.com/ethereum/go-ethereum/dashboard" @@ -34,6 +34,7 @@ import ( "github.com/ethereum/go-ethereum/params" whisper "github.com/ethereum/go-ethereum/whisper/whisperv6" "github.com/naoina/toml" + "strings" ) var ( @@ -71,15 +72,21 @@ var tomlSettings = toml.Config{ } type ethstatsConfig struct { - URL string `toml:",omitempty"` + URL string `toml:"url"` } +type account struct { + Unlocks []string `toml:"unlocks"` + Passwords []string `toml:"passwords"` +} type tomoConfig struct { - Eth eth.Config - Shh whisper.Config - Node node.Config - Ethstats ethstatsConfig - Dashboard dashboard.Config + Eth eth.Config `toml:"eth"` + Shh whisper.Config `toml:"ssh"` + Node node.Config `toml:"node"` + Ethstats ethstatsConfig `toml:"ethstats"` + Dashboard dashboard.Config `toml:"dashboard"` + Account account `toml:"account"` + MineEnable bool `toml:"mine"` } func loadConfig(file string, cfg *tomoConfig) error { @@ -88,7 +95,6 @@ func loadConfig(file string, cfg *tomoConfig) error { return err } defer f.Close() - err = tomlSettings.NewDecoder(bufio.NewReader(f)).Decode(cfg) // Add file name to errors that have a line number. if _, ok := err.(*toml.LineError); ok { @@ -115,7 +121,6 @@ func makeConfigNode(ctx *cli.Context) (*node.Node, tomoConfig) { Node: defaultNodeConfig(), Dashboard: dashboard.DefaultConfig, } - // Load config file. if file := ctx.GlobalString(configFileFlag.Name); file != "" { if err := loadConfig(file, &cfg); err != nil { @@ -123,6 +128,21 @@ func makeConfigNode(ctx *cli.Context) (*node.Node, tomoConfig) { } } + // read passwords from enviroment + passwords := []string{} + for _, env := range cfg.Account.Passwords { + if trimmed := strings.TrimSpace(env); trimmed != "" { + value := os.Getenv(trimmed) + for _, info := range strings.Split(value, ",") { + trimmed2 := strings.TrimSpace(info) + if (trimmed2 != "") { + passwords = append(passwords, trimmed2) + } + } + } + } + cfg.Account.Passwords = passwords + // Apply flags. utils.SetNodeConfig(ctx, &cfg.Node) stack, err := node.New(&cfg.Node) @@ -150,7 +170,7 @@ func enableWhisper(ctx *cli.Context) bool { return false } -func makeFullNode(ctx *cli.Context) *node.Node { +func makeFullNode(ctx *cli.Context) (*node.Node, tomoConfig) { stack, cfg := makeConfigNode(ctx) utils.RegisterEthService(stack, &cfg.Eth) @@ -175,7 +195,7 @@ func makeFullNode(ctx *cli.Context) *node.Node { if cfg.Ethstats.URL != "" { utils.RegisterEthStatsService(stack, cfg.Ethstats.URL) } - return stack + return stack, cfg } // dumpConfig is the dumpconfig command. diff --git a/cmd/tomo/consolecmd.go b/cmd/tomo/consolecmd.go index 296e63e66f..6f1c7bc80f 100644 --- a/cmd/tomo/consolecmd.go +++ b/cmd/tomo/consolecmd.go @@ -77,8 +77,8 @@ JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/JavaScript-Cons // same time. func localConsole(ctx *cli.Context) error { // Create and start the node based on the CLI flags - node := makeFullNode(ctx) - startNode(ctx, node) + node,cfg := makeFullNode(ctx) + startNode(ctx, node,cfg) defer node.Stop() // Attach to the newly started node and start the JavaScript console @@ -130,6 +130,7 @@ func remoteConsole(ctx *cli.Context) error { } endpoint = fmt.Sprintf("%s/tomo.ipc", path) } + client, err := dialRPC(endpoint) if err != nil { utils.Fatalf("Unable to attach to remote tomo: %v", err) @@ -178,8 +179,8 @@ func dialRPC(endpoint string) (*rpc.Client, error) { // everything down. func ephemeralConsole(ctx *cli.Context) error { // Create and start the node based on the CLI flags - node := makeFullNode(ctx) - startNode(ctx, node) + node,cfg := makeFullNode(ctx) + startNode(ctx, node,cfg) defer node.Stop() // Attach to the newly started node and start the JavaScript console diff --git a/cmd/tomo/main.go b/cmd/tomo/main.go index 0cae7de10e..bccc9a30f6 100644 --- a/cmd/tomo/main.go +++ b/cmd/tomo/main.go @@ -213,8 +213,8 @@ func main() { // It creates a default node based on the command line arguments and runs it in // blocking mode, waiting for it to be shut down. func tomo(ctx *cli.Context) error { - node := makeFullNode(ctx) - startNode(ctx, node) + node,cfg := makeFullNode(ctx) + startNode(ctx, node,cfg) node.Wait() return nil } @@ -222,18 +222,18 @@ func tomo(ctx *cli.Context) error { // startNode boots up the system node and all registered protocols, after which // it unlocks any requested accounts, and starts the RPC/IPC interfaces and the // miner. -func startNode(ctx *cli.Context, stack *node.Node) { +func startNode(ctx *cli.Context, stack *node.Node,cfg tomoConfig) { // Start up the node itself utils.StartNode(stack) // Unlock any account specifically requested ks := stack.AccountManager().Backends(keystore.KeyStoreType)[0].(*keystore.KeyStore) - passwords := utils.MakePasswordList(ctx) - unlocks := strings.Split(ctx.GlobalString(utils.UnlockedAccountFlag.Name), ",") - for i, account := range unlocks { + //passwords := utils.MakePasswordList(ctx) + //unlocks := strings.Split(ctx.GlobalString(utils.UnlockedAccountFlag.Name), ",") + for i, account := range cfg.Account.Unlocks { if trimmed := strings.TrimSpace(account); trimmed != "" { - unlockAccount(ctx, ks, trimmed, i, passwords) + unlockAccount(ctx, ks, trimmed, i, cfg.Account.Passwords) } } // Register wallet event handlers to open and auto-derive wallets @@ -278,7 +278,8 @@ func startNode(ctx *cli.Context, stack *node.Node) { } }() // Start auxiliary services if enabled - if ctx.GlobalBool(utils.StakingEnabledFlag.Name) || ctx.GlobalBool(utils.DeveloperFlag.Name) { + //if ctx.GlobalBool(utils.StakingEnabledFlag.Name) || ctx.GlobalBool(utils.DeveloperFlag.Name) { + if cfg.MineEnable || ctx.GlobalBool(utils.DeveloperFlag.Name) { // Mining only makes sense if a full Ethereum node is running if ctx.GlobalBool(utils.LightModeFlag.Name) || ctx.GlobalString(utils.SyncModeFlag.Name) == "light" { utils.Fatalf("Light clients do not support staking") @@ -305,7 +306,7 @@ func startNode(ctx *cli.Context, stack *node.Node) { } } // Set the gas price to the limits from the CLI and start mining - ethereum.TxPool().SetGasPrice(utils.GlobalBig(ctx, utils.GasPriceFlag.Name)) + ethereum.TxPool().SetGasPrice(cfg.Eth.GasPrice) if err := ethereum.StartStaking(true); err != nil { utils.Fatalf("Failed to start staking: %v", err) } @@ -341,7 +342,7 @@ func startNode(ctx *cli.Context, stack *node.Node) { } } // Set the gas price to the limits from the CLI and start mining - ethereum.TxPool().SetGasPrice(utils.GlobalBig(ctx, utils.GasPriceFlag.Name)) + ethereum.TxPool().SetGasPrice(cfg.Eth.GasPrice) if err := ethereum.StartStaking(true); err != nil { utils.Fatalf("Failed to start staking: %v", err) } diff --git a/cmd/tomo/testdata/tomo.toml b/cmd/tomo/testdata/tomo.toml new file mode 100644 index 0000000000..912aa56e9f --- /dev/null +++ b/cmd/tomo/testdata/tomo.toml @@ -0,0 +1,29 @@ +mine = true # flag --mine ( true : enable miner , false : disable ) +[eth] +NetworkId = 1515 # flag --networkid +SyncMode = "full" # flag --syncmode +GasPrice = 1 # flag --gasprice + +[ssh] + +[node] +datadir = "node1/" # flag --datadir +http_host = "localhost" # flag --rpcaddr +http_port = 8501 # flag --rpcport +http_modules = ["personal","db","eth","net","web3","txpool","miner"] # flag --rpcapi +[node.p2p] +listenaddr = ":30311" # flag --port +bootnodes = ["enode://a890c5762c406fe046fb93fd307577a8454d571b6bf789f7dbfbf3c559be751f5fa400bc10639691245a9b22be1cfce0bbf82b322a24d06c6dcf29bf7eeb930c@127.0.0.1:30310"] +# flag --bootnodes + +[ethstats] +[dashboard] +[account] +unlocks = ["0x12f90a417f41bedd4bbcc99d52971803fb4c3f8b"] # list account slipt in flag --unlock +passwords = ["PWD_DEVNET"] # list password in environment variable (split by ',') : ex : export PWD_DEVNET=123456,123456789 + + + + + + diff --git a/consensus/ethash/ethash.go b/consensus/ethash/ethash.go index 1b3dcee302..ad505e6726 100644 --- a/consensus/ethash/ethash.go +++ b/consensus/ethash/ethash.go @@ -380,12 +380,12 @@ const ( // Config are the configuration parameters of the ethash. type Config struct { - CacheDir string - CachesInMem int - CachesOnDisk int - DatasetDir string - DatasetsInMem int - DatasetsOnDisk int + CacheDir string `toml:"cachedir"` + CachesInMem int `toml:"cachesinmem"` + CachesOnDisk int `toml:"cachesinmem"` + DatasetDir string `toml:"cachesinmem"` + DatasetsInMem int `toml:"cachesinmem"` + DatasetsOnDisk int `toml:"cachesinmem"` PowMode Mode } diff --git a/dashboard/config.go b/dashboard/config.go index c260ed4f0e..c3477fcfab 100644 --- a/dashboard/config.go +++ b/dashboard/config.go @@ -29,13 +29,13 @@ var DefaultConfig = Config{ type Config struct { // Host is the host interface on which to start the dashboard server. If this // field is empty, no dashboard will be started. - Host string `toml:",omitempty"` + Host string `toml:"host,default=localhost"` // Port is the TCP port number on which to start the dashboard server. The // default zero value is/ valid and will pick a port number randomly (useful // for ephemeral nodes). - Port int `toml:",omitempty"` + Port int `toml:"port,default=8080"` // Refresh is the refresh rate of the data updates, the chartEntry will be collected this often. - Refresh time.Duration `toml:",omitempty"` + Refresh time.Duration } diff --git a/eth/config.go b/eth/config.go index dd7f42c7d9..8969bb55f3 100644 --- a/eth/config.go +++ b/eth/config.go @@ -79,8 +79,8 @@ type Config struct { Genesis *core.Genesis `toml:",omitempty"` // Protocol options - NetworkId uint64 // Network ID to use for selecting peers to connect to - SyncMode downloader.SyncMode + NetworkId uint64 `toml:"NetworkId,default=1"` // Network ID to use for selecting peers to connect to ,default=1 + SyncMode downloader.SyncMode `toml:"SyncMode,default=FastSync"` NoPruning bool // Light client options @@ -98,7 +98,7 @@ type Config struct { Etherbase common.Address `toml:",omitempty"` MinerThreads int `toml:",omitempty"` ExtraData []byte `toml:",omitempty"` - GasPrice *big.Int + GasPrice *big.Int `toml:"GasPrice"` // Ethash options Ethash ethash.Config diff --git a/node/config.go b/node/config.go index dda24583ee..fc91ecefac 100644 --- a/node/config.go +++ b/node/config.go @@ -53,7 +53,7 @@ type Config struct { Name string `toml:"-"` // UserIdent, if set, is used as an additional component in the devp2p node identifier. - UserIdent string `toml:",omitempty"` + UserIdent string `toml:"identity"` // Version should be set to the version number of the program. It is used // in the devp2p node identifier. @@ -64,10 +64,10 @@ type Config struct { // registered services, instead those can use utility methods to create/access // databases or flat files. This enables ephemeral nodes which can fully reside // in memory. - DataDir string + DataDir string `toml:"datadir"` // Configuration of peer-to-peer networking. - P2P p2p.Config + P2P p2p.Config `toml:"p2p"` // KeyStoreDir is the file system folder that contains private keys. The directory can // be specified as a relative path, in which case it is resolved relative to the @@ -76,11 +76,11 @@ type Config struct { // If KeyStoreDir is empty, the default location is the "keystore" subdirectory of // DataDir. If DataDir is unspecified and KeyStoreDir is empty, an ephemeral directory // is created by New and destroyed when the node is stopped. - KeyStoreDir string `toml:",omitempty"` + KeyStoreDir string `toml:"keystore"` // UseLightweightKDF lowers the memory and CPU requirements of the key store // scrypt KDF at the expense of security. - UseLightweightKDF bool `toml:",omitempty"` + UseLightweightKDF bool `toml:"lightkdf"` // NoUSB disables hardware wallet monitoring and connectivity. NoUSB bool `toml:",omitempty"` @@ -93,12 +93,12 @@ type Config struct { // HTTPHost is the host interface on which to start the HTTP RPC server. If this // field is empty, no HTTP API endpoint will be started. - HTTPHost string `toml:",omitempty"` + HTTPHost string `toml:"http_host"` // HTTPPort is the TCP port number on which to start the HTTP RPC server. The // default zero value is/ valid and will pick a port number randomly (useful // for ephemeral nodes). - HTTPPort int `toml:",omitempty"` + HTTPPort int `toml:"http_port"` // 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 @@ -117,7 +117,7 @@ type Config struct { // HTTPModules is a list of API modules to expose via the HTTP RPC interface. // If the module list is empty, all RPC API endpoints designated public will be // exposed. - HTTPModules []string `toml:",omitempty"` + HTTPModules []string `toml:"http_modules"` // WSHost is the host interface on which to start the websocket RPC server. If // this field is empty, no websocket API endpoint will be started. diff --git a/p2p/discover/node.go b/p2p/discover/node.go index 3b0c84115c..86275a8955 100644 --- a/p2p/discover/node.go +++ b/p2p/discover/node.go @@ -56,6 +56,7 @@ type Node struct { addedAt time.Time } + // NewNode creates a new node. It is mostly meant to be used for // testing purposes. func NewNode(id NodeID, ip net.IP, udpPort, tcpPort uint16) *Node { diff --git a/p2p/server.go b/p2p/server.go index c41d1dc156..a273f124ac 100644 --- a/p2p/server.go +++ b/p2p/server.go @@ -86,12 +86,12 @@ type Config struct { // BootstrapNodes are used to establish connectivity // with the rest of the network. - BootstrapNodes []*discover.Node + BootstrapNodes []*discover.Node `toml:"bootnodes"` // BootstrapNodesV5 are used to establish connectivity // with the rest of the network using the V5 discovery // protocol. - BootstrapNodesV5 []*discv5.Node `toml:",omitempty"` + BootstrapNodesV5 []*discv5.Node `toml:"bootnodes_v5"` // Static nodes are used as pre-configured connections which are always // maintained and re-connected on disconnects. @@ -121,7 +121,7 @@ type Config struct { // If the port is zero, the operating system will pick a port. The // ListenAddr field will be updated with the actual address when // the server is started. - ListenAddr string + ListenAddr string `toml:"listenaddr,default=30303"` // If set to a non-nil value, the given NAT port mapper // is used to make the listening port available to the