wizard_node.go 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. package main
  17. import (
  18. "encoding/json"
  19. "fmt"
  20. "time"
  21. "github.com/ethereum/go-ethereum/accounts/keystore"
  22. "github.com/ethereum/go-ethereum/common"
  23. "github.com/ethereum/go-ethereum/log"
  24. )
  25. // deployNode creates a new node configuration based on some user input.
  26. func (w *wizard) deployNode(boot bool) {
  27. // Do some sanity check before the user wastes time on input
  28. if w.conf.genesis == nil {
  29. log.Error("No genesis block configured")
  30. return
  31. }
  32. if w.conf.ethstats == "" {
  33. log.Error("No ethstats server configured")
  34. return
  35. }
  36. // Select the server to interact with
  37. server := w.selectServer()
  38. if server == "" {
  39. return
  40. }
  41. client := w.servers[server]
  42. // Retrieve any active ethstats configurations from the server
  43. infos, err := checkNode(client, w.network, boot)
  44. if err != nil {
  45. if boot {
  46. infos = &nodeInfos{portFull: 30303, peersTotal: 512, peersLight: 256}
  47. } else {
  48. infos = &nodeInfos{portFull: 30303, peersTotal: 50, peersLight: 0}
  49. }
  50. }
  51. infos.genesis, _ = json.MarshalIndent(w.conf.genesis, "", " ")
  52. infos.network = w.conf.genesis.Config.ChainId.Int64()
  53. // Figure out where the user wants to store the persistent data
  54. fmt.Println()
  55. if infos.datadir == "" {
  56. fmt.Printf("Where should data be stored on the remote machine?\n")
  57. infos.datadir = w.readString()
  58. } else {
  59. fmt.Printf("Where should data be stored on the remote machine? (default = %s)\n", infos.datadir)
  60. infos.datadir = w.readDefaultString(infos.datadir)
  61. }
  62. // Figure out which port to listen on
  63. fmt.Println()
  64. fmt.Printf("Which TCP/UDP port to listen on? (default = %d)\n", infos.portFull)
  65. infos.portFull = w.readDefaultInt(infos.portFull)
  66. // Figure out how many peers to allow (different based on node type)
  67. fmt.Println()
  68. fmt.Printf("How many peers to allow connecting? (default = %d)\n", infos.peersTotal)
  69. infos.peersTotal = w.readDefaultInt(infos.peersTotal)
  70. // Figure out how many light peers to allow (different based on node type)
  71. fmt.Println()
  72. fmt.Printf("How many light peers to allow connecting? (default = %d)\n", infos.peersLight)
  73. infos.peersLight = w.readDefaultInt(infos.peersLight)
  74. // Set a proper name to report on the stats page
  75. fmt.Println()
  76. if infos.ethstats == "" {
  77. fmt.Printf("What should the node be called on the stats page?\n")
  78. infos.ethstats = w.readString() + ":" + w.conf.ethstats
  79. } else {
  80. fmt.Printf("What should the node be called on the stats page? (default = %s)\n", infos.ethstats)
  81. infos.ethstats = w.readDefaultString(infos.ethstats) + ":" + w.conf.ethstats
  82. }
  83. // If the node is a miner/signer, load up needed credentials
  84. if !boot {
  85. if w.conf.genesis.Config.Ethash != nil {
  86. // Ethash based miners only need an etherbase to mine against
  87. fmt.Println()
  88. if infos.etherbase == "" {
  89. fmt.Printf("What address should the miner user?\n")
  90. for {
  91. if address := w.readAddress(); address != nil {
  92. infos.etherbase = address.Hex()
  93. break
  94. }
  95. }
  96. } else {
  97. fmt.Printf("What address should the miner user? (default = %s)\n", infos.etherbase)
  98. infos.etherbase = w.readDefaultAddress(common.HexToAddress(infos.etherbase)).Hex()
  99. }
  100. } else if w.conf.genesis.Config.Clique != nil {
  101. // If a previous signer was already set, offer to reuse it
  102. if infos.keyJSON != "" {
  103. var key keystore.Key
  104. if err := json.Unmarshal([]byte(infos.keyJSON), &key); err != nil {
  105. infos.keyJSON, infos.keyPass = "", ""
  106. } else {
  107. fmt.Println()
  108. fmt.Printf("Reuse previous (%s) signing account (y/n)? (default = yes)\n", key.Address.Hex())
  109. if w.readDefaultString("y") != "y" {
  110. infos.keyJSON, infos.keyPass = "", ""
  111. }
  112. }
  113. }
  114. // Clique based signers need a keyfile and unlock password, ask if unavailable
  115. if infos.keyJSON == "" {
  116. fmt.Println()
  117. fmt.Println("Please paste the signer's key JSON:")
  118. infos.keyJSON = w.readJSON()
  119. fmt.Println()
  120. fmt.Println("What's the unlock password for the account? (won't be echoed)")
  121. infos.keyPass = w.readPassword()
  122. if _, err := keystore.DecryptKey([]byte(infos.keyJSON), infos.keyPass); err != nil {
  123. log.Error("Failed to decrypt key with given passphrase")
  124. return
  125. }
  126. }
  127. }
  128. }
  129. // Try to deploy the full node on the host
  130. if out, err := deployNode(client, w.network, w.conf.bootFull, infos); err != nil {
  131. log.Error("Failed to deploy Ethereum node container", "err", err)
  132. if len(out) > 0 {
  133. fmt.Printf("%s\n", out)
  134. }
  135. return
  136. }
  137. // All ok, run a network scan to pick any changes up
  138. log.Info("Waiting for node to finish booting")
  139. time.Sleep(3 * time.Second)
  140. w.networkStats(false)
  141. }