github.com/Elemental-core/elementalcore@v0.0.0-20191206075037-63891242267a/cmd/puppeth/wizard_node.go (about) 1 // Copyright 2017 The elementalcore Authors 2 // This file is part of elementalcore. 3 // 4 // elementalcore 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 // elementalcore 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 elementalcore. 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/Elemental-core/elementalcore/accounts/keystore" 25 "github.com/Elemental-core/elementalcore/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: 30303, peersTotal: 512, peersLight: 256} 51 } else { 52 infos = &nodeInfos{portFull: 30303, 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.Dpos != nil { 94 // If a previous signer was already set, offer to reuse it 95 if infos.keyJSON != "" { 96 if key, err := keystore.DecryptKey([]byte(infos.keyJSON), infos.keyPass); err != nil { 97 infos.keyJSON, infos.keyPass = "", "" 98 } else { 99 fmt.Println() 100 fmt.Printf("Reuse previous (%s) signing account (y/n)? (default = yes)\n", key.Address.Hex()) 101 if w.readDefaultString("y") != "y" { 102 infos.keyJSON, infos.keyPass = "", "" 103 } 104 } 105 } 106 // Clique based signers need a keyfile and unlock password, ask if unavailable 107 if infos.keyJSON == "" { 108 fmt.Println() 109 fmt.Println("Please paste the signer's key JSON:") 110 infos.keyJSON = w.readJSON() 111 112 fmt.Println() 113 fmt.Println("What's the unlock password for the account? (won't be echoed)") 114 infos.keyPass = w.readPassword() 115 116 if _, err := keystore.DecryptKey([]byte(infos.keyJSON), infos.keyPass); err != nil { 117 log.Error("Failed to decrypt key with given passphrase") 118 return 119 } 120 } 121 } 122 // Establish the gas dynamics to be enforced by the signer 123 fmt.Println() 124 fmt.Printf("What gas limit should empty blocks target (MGas)? (default = %0.3f)\n", infos.gasTarget) 125 infos.gasTarget = w.readDefaultFloat(infos.gasTarget) 126 127 fmt.Println() 128 fmt.Printf("What gas price should the signer require (GWei)? (default = %0.3f)\n", infos.gasPrice) 129 infos.gasPrice = w.readDefaultFloat(infos.gasPrice) 130 } 131 // Try to deploy the full node on the host 132 if out, err := deployNode(client, w.network, w.conf.bootFull, w.conf.bootLight, infos); err != nil { 133 log.Error("Failed to deploy Ethereum node container", "err", err) 134 if len(out) > 0 { 135 fmt.Printf("%s\n", out) 136 } 137 return 138 } 139 // All ok, run a network scan to pick any changes up 140 log.Info("Waiting for node to finish booting") 141 time.Sleep(3 * time.Second) 142 143 w.networkStats(false) 144 }