From cb5a55a9042318810a0a10441c0e184e4b57c766 Mon Sep 17 00:00:00 2001 From: parmarrushabh Date: Wed, 31 Oct 2018 10:30:25 +0530 Subject: [PATCH] change config from flag to toml file; fix tag listenaddr --- cmd/XDC/chaincmd.go | 18 +++++++-------- cmd/XDC/config.go | 46 +++++++++++++++++++++++++++----------- cmd/XDC/consolecmd.go | 11 ++++----- cmd/XDC/main.go | 23 ++++++++++--------- cmd/XDC/testdata/XDC.toml | 23 +++++++++++++++++++ consensus/ethash/ethash.go | 14 ++++++------ dashboard/config.go | 8 +++---- eth/config.go | 8 +++---- node/config.go | 18 +++++++-------- p2p/server.go | 8 +++---- 10 files changed, 110 insertions(+), 67 deletions(-) create mode 100644 cmd/XDC/testdata/XDC.toml diff --git a/cmd/XDC/chaincmd.go b/cmd/XDC/chaincmd.go index d3086921b9..8eadf4fe75 100644 --- a/cmd/XDC/chaincmd.go +++ b/cmd/XDC/chaincmd.go @@ -55,7 +55,6 @@ var ( The init command initializes a new genesis block and definition for the network. This is a destructive action and changes the network in which you will be participating. - It expects the genesis file as argument.`, } importCommand = cli.Command{ @@ -75,7 +74,6 @@ It expects the genesis file as argument.`, Description: ` The import command imports blocks from an RLP-encoded form. The form can be one file with several RLP-encoded blocks, or several files can be used. - If only one file is used, import error will result in failure. If several files are used, processing will proceed even if an individual RLP-file import failure occurs.`, } @@ -190,7 +188,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 +207,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 +301,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 +334,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 +350,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 +367,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 +439,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 @@ -470,4 +468,4 @@ func dump(ctx *cli.Context) error { func hashish(x string) bool { _, err := strconv.Atoi(x) return err != nil -} +} \ No newline at end of file diff --git a/cmd/XDC/config.go b/cmd/XDC/config.go index ef90226f90..81c412f7f3 100644 --- a/cmd/XDC/config.go +++ b/cmd/XDC/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 XDCConfig struct { - Eth eth.Config - Shh whisper.Config - Node node.Config - Ethstats ethstatsConfig - Dashboard dashboard.Config +type account struct { + Unlocks []string `toml:"unlocks"` + Passwords []string `toml:"passwords"` +} +type XDC Config struct { + 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 *XDCConfig) error { @@ -88,7 +95,6 @@ func loadConfig(file string, cfg *XDCConfig) 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, XDCConfig) { 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, XDCConfig) { } } + // 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, XDCConfig) { 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. @@ -195,4 +215,4 @@ func dumpConfig(ctx *cli.Context) error { io.WriteString(os.Stdout, comment) os.Stdout.Write(out) return nil -} +} \ No newline at end of file diff --git a/cmd/XDC/consolecmd.go b/cmd/XDC/consolecmd.go index a9f537fbdb..768ce5f5a1 100644 --- a/cmd/XDC/consolecmd.go +++ b/cmd/XDC/consolecmd.go @@ -54,7 +54,7 @@ See https://github.com/ethereum/go-ethereum/wiki/JavaScript-Console.`, Flags: append(consoleFlags, utils.DataDirFlag), Category: "CONSOLE COMMANDS", Description: ` -The Geth console is an interactive shell for the JavaScript runtime environment +The XDC console is an interactive shell for the JavaScript runtime environment which exposes a node admin interface as well as the Ðapp JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/JavaScript-Console. This command allows to open a console on a running XDC node.`, @@ -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/XDC.ipc", path) } + client, err := dialRPC(endpoint) if err != nil { utils.Fatalf("Unable to attach to remote XDC: %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/XDC/main.go b/cmd/XDC/main.go index 57e73d9b2d..9ccc3e7037 100644 --- a/cmd/XDC/main.go +++ b/cmd/XDC/main.go @@ -146,7 +146,7 @@ func init() { // Initialize the CLI app and start XDC app.Action = XDC app.HideVersion = true // we have a command to print the version - app.Copyright = "Copyright (c) 2018 Xinfin" + app.Copyright = "Copyright (c) 2018 XDCchain" app.Commands = []cli.Command{ // See chaincmd.go: initCommand, @@ -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 XDC(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 XDC(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 XDCConfig) { // 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/XDC/testdata/XDC.toml b/cmd/XDC/testdata/XDC.toml new file mode 100644 index 0000000000..e036cb5c2f --- /dev/null +++ b/cmd/XDC/testdata/XDC.toml @@ -0,0 +1,23 @@ +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 \ No newline at end of file diff --git a/consensus/ethash/ethash.go b/consensus/ethash/ethash.go index 1b3dcee302..86aa0e4355 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 } @@ -575,4 +575,4 @@ func (ethash *Ethash) APIs(chain consensus.ChainReader) []rpc.API { // dataset. func SeedHash(block uint64) []byte { return seedHash(block) -} +} \ No newline at end of file diff --git a/dashboard/config.go b/dashboard/config.go index c260ed4f0e..de4dbf4fd5 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 +} \ No newline at end of file diff --git a/eth/config.go b/eth/config.go index dd7f42c7d9..28979d1534 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 @@ -118,4 +118,4 @@ type Config struct { type configMarshaling struct { ExtraData hexutil.Bytes -} +} \ No newline at end of file diff --git a/node/config.go b/node/config.go index dda24583ee..f066f9bd0d 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. @@ -434,4 +434,4 @@ func makeAccountManager(conf *Config) (*accounts.Manager, string, error) { } } return accounts.NewManager(backends...), ephemeral, nil -} +} \ No newline at end of file diff --git a/p2p/server.go b/p2p/server.go index c41d1dc156..472ddee52b 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 @@ -966,4 +966,4 @@ func (srv *Server) PeersInfo() []*PeerInfo { } } return infos -} +} \ No newline at end of file