github.com/n1ghtfa1l/go-vnt@v0.6.4-alpha.6/cmd/puppeth/wizard_node.go (about) 1 // Copyright 2017 The go-ethereum Authors 2 // This file is part of go-ethereum. 3 // 4 // go-ethereum 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-ethereum 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-ethereum. 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/vntchain/go-vnt/log" 25 ) 26 27 // deployNode creates a new node configuration based on some user input. 28 func (w *wizard) deployNode(boot bool) { 29 // Do some sanity check before the user wastes time on input 30 if w.conf.Genesis == nil { 31 log.Error("No genesis block configured") 32 return 33 } 34 if w.conf.vntstats == "" { 35 log.Error("No vntstats server configured") 36 return 37 } 38 // Select the server to interact with 39 server := w.selectServer() 40 if server == "" { 41 return 42 } 43 client := w.servers[server] 44 45 // Retrieve any active node configurations from the server 46 infos, err := checkNode(client, w.network, boot) 47 if err != nil { 48 if boot { 49 infos = &nodeInfos{port: 30303, peersTotal: 512, peersLight: 256} 50 } else { 51 infos = &nodeInfos{port: 30303, peersTotal: 50, peersLight: 0, gasTarget: 4.7, gasPrice: 18} 52 } 53 } 54 existed := err == nil 55 56 infos.genesis, _ = json.MarshalIndent(w.conf.Genesis, "", " ") 57 infos.network = w.conf.Genesis.Config.ChainID.Int64() 58 59 // Figure out where the user wants to store the persistent data 60 fmt.Println() 61 if infos.datadir == "" { 62 fmt.Printf("Where should data be stored on the remote machine?\n") 63 infos.datadir = w.readString() 64 } else { 65 fmt.Printf("Where should data be stored on the remote machine? (default = %s)\n", infos.datadir) 66 infos.datadir = w.readDefaultString(infos.datadir) 67 } 68 // Figure out which port to listen on 69 fmt.Println() 70 fmt.Printf("Which TCP/UDP port to listen on? (default = %d)\n", infos.port) 71 infos.port = w.readDefaultInt(infos.port) 72 73 // Figure out how many peers to allow (different based on node type) 74 fmt.Println() 75 fmt.Printf("How many peers to allow connecting? (default = %d)\n", infos.peersTotal) 76 infos.peersTotal = w.readDefaultInt(infos.peersTotal) 77 78 // Figure out how many light peers to allow (different based on node type) 79 fmt.Println() 80 fmt.Printf("How many light peers to allow connecting? (default = %d)\n", infos.peersLight) 81 infos.peersLight = w.readDefaultInt(infos.peersLight) 82 83 // Set a proper name to report on the stats page 84 fmt.Println() 85 if infos.vntstats == "" { 86 fmt.Printf("What should the node be called on the stats page?\n") 87 infos.vntstats = w.readString() + ":" + w.conf.vntstats 88 } else { 89 fmt.Printf("What should the node be called on the stats page? (default = %s)\n", infos.vntstats) 90 infos.vntstats = w.readDefaultString(infos.vntstats) + ":" + w.conf.vntstats 91 } 92 // If the node is a producer/signer, load up needed credentials 93 if !boot { 94 // Establish the gas dynamics to be enforced by the signer 95 fmt.Println() 96 fmt.Printf("What gas limit should empty blocks target (MGas)? (default = %0.3f)\n", infos.gasTarget) 97 infos.gasTarget = w.readDefaultFloat(infos.gasTarget) 98 99 fmt.Println() 100 fmt.Printf("What gas price should the signer require (GWei)? (default = %0.3f)\n", infos.gasPrice) 101 infos.gasPrice = w.readDefaultFloat(infos.gasPrice) 102 } 103 // Try to deploy the full node on the host 104 nocache := false 105 if existed { 106 fmt.Println() 107 fmt.Printf("Should the node be built from scratch (y/n)? (default = no)\n") 108 nocache = w.readDefaultString("n") != "n" 109 } 110 if out, err := deployNode(client, w.network, w.conf.bootnodes, infos, nocache); err != nil { 111 log.Error("Failed to deploy VNT node container", "err", err) 112 if len(out) > 0 { 113 fmt.Printf("%s\n", out) 114 } 115 return 116 } 117 // All ok, run a network scan to pick any changes up 118 log.Info("Waiting for node to finish booting") 119 time.Sleep(3 * time.Second) 120 121 w.networkStats() 122 }