github.com/waltonchain/waltonchain_gwtc_src@v1.1.4-0.20201225072101-8a298c95a819/cmd/puppeth/wizard_node.go (about) 1 // Copyright 2017 The go-ethereum Authors 2 // This file is part of go-wtc. 3 // 4 // go-wtc is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // go-wtc is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with go-wtc. If not, see <http://www.gnu.org/licenses/>. 16 17 package main 18 19 import ( 20 "encoding/json" 21 "fmt" 22 "time" 23 24 "github.com/wtc/go-wtc/common" 25 "github.com/wtc/go-wtc/log" 26 ) 27 28 // deployNode creates a new node configuration based on some user input. 29 func (w *wizard) deployNode(boot bool) { 30 // Do some sanity check before the user wastes time on input 31 if w.conf.genesis == nil { 32 log.Error("No genesis block configured") 33 return 34 } 35 if w.conf.ethstats == "" { 36 log.Error("No ethstats server configured") 37 return 38 } 39 // Select the server to interact with 40 server := w.selectServer() 41 if server == "" { 42 return 43 } 44 client := w.servers[server] 45 46 // Retrieve any active ethstats configurations from the server 47 infos, err := checkNode(client, w.network, boot) 48 if err != nil { 49 if boot { 50 infos = &nodeInfos{portFull: 10101, peersTotal: 512, peersLight: 256} 51 } else { 52 infos = &nodeInfos{portFull: 10101, peersTotal: 50, peersLight: 0, gasTarget: 4.7, gasPrice: 18} 53 } 54 } 55 infos.genesis, _ = json.MarshalIndent(w.conf.genesis, "", " ") 56 infos.network = w.conf.genesis.Config.ChainId.Int64() 57 58 // Figure out where the user wants to store the persistent data 59 fmt.Println() 60 if infos.datadir == "" { 61 fmt.Printf("Where should data be stored on the remote machine?\n") 62 infos.datadir = w.readString() 63 } else { 64 fmt.Printf("Where should data be stored on the remote machine? (default = %s)\n", infos.datadir) 65 infos.datadir = w.readDefaultString(infos.datadir) 66 } 67 // Figure out which port to listen on 68 fmt.Println() 69 fmt.Printf("Which TCP/UDP port to listen on? (default = %d)\n", infos.portFull) 70 infos.portFull = w.readDefaultInt(infos.portFull) 71 72 // Figure out how many peers to allow (different based on node type) 73 fmt.Println() 74 fmt.Printf("How many peers to allow connecting? (default = %d)\n", infos.peersTotal) 75 infos.peersTotal = w.readDefaultInt(infos.peersTotal) 76 77 // Figure out how many light peers to allow (different based on node type) 78 fmt.Println() 79 fmt.Printf("How many light peers to allow connecting? (default = %d)\n", infos.peersLight) 80 infos.peersLight = w.readDefaultInt(infos.peersLight) 81 82 // Set a proper name to report on the stats page 83 fmt.Println() 84 if infos.ethstats == "" { 85 fmt.Printf("What should the node be called on the stats page?\n") 86 infos.ethstats = w.readString() + ":" + w.conf.ethstats 87 } else { 88 fmt.Printf("What should the node be called on the stats page? (default = %s)\n", infos.ethstats) 89 infos.ethstats = w.readDefaultString(infos.ethstats) + ":" + w.conf.ethstats 90 } 91 // If the node is a miner/signer, load up needed credentials 92 if !boot { 93 if w.conf.genesis.Config.Ethash != nil { 94 // Ethash based miners only need an etherbase to mine against 95 fmt.Println() 96 if infos.etherbase == "" { 97 fmt.Printf("What address should the miner user?\n") 98 for { 99 if address := w.readAddress(); address != nil { 100 infos.etherbase = address.Hex() 101 break 102 } 103 } 104 } else { 105 fmt.Printf("What address should the miner user? (default = %s)\n", infos.etherbase) 106 infos.etherbase = w.readDefaultAddress(common.HexToAddress(infos.etherbase)).Hex() 107 } 108 } 109 // Establish the gas dynamics to be enforced by the signer 110 fmt.Println() 111 fmt.Printf("What gas limit should empty blocks target (MGas)? (default = %0.3f)\n", infos.gasTarget) 112 infos.gasTarget = w.readDefaultFloat(infos.gasTarget) 113 114 fmt.Println() 115 fmt.Printf("What gas price should the signer require (GWei)? (default = %0.3f)\n", infos.gasPrice) 116 infos.gasPrice = w.readDefaultFloat(infos.gasPrice) 117 } 118 // Try to deploy the full node on the host 119 if out, err := deployNode(client, w.network, w.conf.bootFull, w.conf.bootLight, infos); err != nil { 120 log.Error("Failed to deploy Wtc node container", "err", err) 121 if len(out) > 0 { 122 fmt.Printf("%s\n", out) 123 } 124 return 125 } 126 // All ok, run a network scan to pick any changes up 127 log.Info("Waiting for node to finish booting") 128 time.Sleep(3 * time.Second) 129 130 w.networkStats(false) 131 }