github.com/yinchengtsinghua/golang-Eos-dpos-Ethereum@v0.0.0-20190121132951-92cc4225ed8e/cmd/puppeth/wizard_node.go (about)

     1  
     2  //此源码被清华学神尹成大魔王专业翻译分析并修改
     3  //尹成QQ77025077
     4  //尹成微信18510341407
     5  //尹成所在QQ群721929980
     6  //尹成邮箱 yinc13@mails.tsinghua.edu.cn
     7  //尹成毕业于清华大学,微软区块链领域全球最有价值专家
     8  //https://mvp.microsoft.com/zh-cn/PublicProfile/4033620
     9  //版权所有2017 Go Ethereum作者
    10  //此文件是Go以太坊的一部分。
    11  //
    12  //Go以太坊是免费软件:您可以重新发布和/或修改它
    13  //根据GNU通用公共许可证的条款
    14  //自由软件基金会,或者许可证的第3版,或者
    15  //(由您选择)任何更高版本。
    16  //
    17  //Go以太坊的分布希望它会有用,
    18  //但没有任何保证;甚至没有
    19  //适销性或特定用途的适用性。见
    20  //GNU通用公共许可证了解更多详细信息。
    21  //
    22  //你应该已经收到一份GNU通用公共许可证的副本
    23  //一起去以太坊吧。如果没有,请参见<http://www.gnu.org/licenses/>。
    24  
    25  package main
    26  
    27  import (
    28  	"encoding/json"
    29  	"fmt"
    30  	"time"
    31  
    32  	"github.com/ethereum/go-ethereum/accounts/keystore"
    33  	"github.com/ethereum/go-ethereum/common"
    34  	"github.com/ethereum/go-ethereum/log"
    35  )
    36  
    37  //
    38  func (w *wizard) deployNode(boot bool) {
    39  //
    40  	if w.conf.Genesis == nil {
    41  		log.Error("No genesis block configured")
    42  		return
    43  	}
    44  	if w.conf.ethstats == "" {
    45  		log.Error("No ethstats server configured")
    46  		return
    47  	}
    48  //
    49  	server := w.selectServer()
    50  	if server == "" {
    51  		return
    52  	}
    53  	client := w.servers[server]
    54  
    55  //
    56  	infos, err := checkNode(client, w.network, boot)
    57  	if err != nil {
    58  		if boot {
    59  			infos = &nodeInfos{port: 30303, peersTotal: 512, peersLight: 256}
    60  		} else {
    61  			infos = &nodeInfos{port: 30303, peersTotal: 50, peersLight: 0, gasTarget: 4.7, gasPrice: 18}
    62  		}
    63  	}
    64  	existed := err == nil
    65  
    66  	infos.genesis, _ = json.MarshalIndent(w.conf.Genesis, "", "  ")
    67  	infos.network = w.conf.Genesis.Config.ChainID.Int64()
    68  
    69  //找出用户希望存储持久数据的位置
    70  	fmt.Println()
    71  	if infos.datadir == "" {
    72  		fmt.Printf("Where should data be stored on the remote machine?\n")
    73  		infos.datadir = w.readString()
    74  	} else {
    75  		fmt.Printf("Where should data be stored on the remote machine? (default = %s)\n", infos.datadir)
    76  		infos.datadir = w.readDefaultString(infos.datadir)
    77  	}
    78  	if w.conf.Genesis.Config.Ethash != nil && !boot {
    79  		fmt.Println()
    80  		if infos.ethashdir == "" {
    81  			fmt.Printf("Where should the ethash mining DAGs be stored on the remote machine?\n")
    82  			infos.ethashdir = w.readString()
    83  		} else {
    84  			fmt.Printf("Where should the ethash mining DAGs be stored on the remote machine? (default = %s)\n", infos.ethashdir)
    85  			infos.ethashdir = w.readDefaultString(infos.ethashdir)
    86  		}
    87  	}
    88  //找出要监听的端口
    89  	fmt.Println()
    90  	fmt.Printf("Which TCP/UDP port to listen on? (default = %d)\n", infos.port)
    91  	infos.port = w.readDefaultInt(infos.port)
    92  
    93  //计算允许多少对等点(根据节点类型不同)
    94  	fmt.Println()
    95  	fmt.Printf("How many peers to allow connecting? (default = %d)\n", infos.peersTotal)
    96  	infos.peersTotal = w.readDefaultInt(infos.peersTotal)
    97  
    98  //计算允许多少光对等(根据节点类型不同)
    99  	fmt.Println()
   100  	fmt.Printf("How many light peers to allow connecting? (default = %d)\n", infos.peersLight)
   101  	infos.peersLight = w.readDefaultInt(infos.peersLight)
   102  
   103  //
   104  	fmt.Println()
   105  	if infos.ethstats == "" {
   106  		fmt.Printf("What should the node be called on the stats page?\n")
   107  		infos.ethstats = w.readString() + ":" + w.conf.ethstats
   108  	} else {
   109  		fmt.Printf("What should the node be called on the stats page? (default = %s)\n", infos.ethstats)
   110  		infos.ethstats = w.readDefaultString(infos.ethstats) + ":" + w.conf.ethstats
   111  	}
   112  //
   113  	if !boot {
   114  		if w.conf.Genesis.Config.Ethash != nil {
   115  //Ethash based miners only need an etherbase to mine against
   116  			fmt.Println()
   117  			if infos.etherbase == "" {
   118  				fmt.Printf("What address should the miner use?\n")
   119  				for {
   120  					if address := w.readAddress(); address != nil {
   121  						infos.etherbase = address.Hex()
   122  						break
   123  					}
   124  				}
   125  			} else {
   126  				fmt.Printf("What address should the miner use? (default = %s)\n", infos.etherbase)
   127  				infos.etherbase = w.readDefaultAddress(common.HexToAddress(infos.etherbase)).Hex()
   128  			}
   129  		} else if w.conf.Genesis.Config.Clique != nil {
   130  //
   131  			if infos.keyJSON != "" {
   132  				if key, err := keystore.DecryptKey([]byte(infos.keyJSON), infos.keyPass); err != nil {
   133  					infos.keyJSON, infos.keyPass = "", ""
   134  				} else {
   135  					fmt.Println()
   136  					fmt.Printf("Reuse previous (%s) signing account (y/n)? (default = yes)\n", key.Address.Hex())
   137  					if w.readDefaultString("y") != "y" {
   138  						infos.keyJSON, infos.keyPass = "", ""
   139  					}
   140  				}
   141  			}
   142  //基于集团的签名者需要一个密钥文件和解锁密码,询问是否不可用
   143  			if infos.keyJSON == "" {
   144  				fmt.Println()
   145  				fmt.Println("Please paste the signer's key JSON:")
   146  				infos.keyJSON = w.readJSON()
   147  
   148  				fmt.Println()
   149  				fmt.Println("What's the unlock password for the account? (won't be echoed)")
   150  				infos.keyPass = w.readPassword()
   151  
   152  				if _, err := keystore.DecryptKey([]byte(infos.keyJSON), infos.keyPass); err != nil {
   153  					log.Error("Failed to decrypt key with given passphrase")
   154  					return
   155  				}
   156  			}
   157  		}
   158  //
   159  		fmt.Println()
   160  		fmt.Printf("What gas limit should empty blocks target (MGas)? (default = %0.3f)\n", infos.gasTarget)
   161  		infos.gasTarget = w.readDefaultFloat(infos.gasTarget)
   162  
   163  		fmt.Println()
   164  		fmt.Printf("What gas price should the signer require (GWei)? (default = %0.3f)\n", infos.gasPrice)
   165  		infos.gasPrice = w.readDefaultFloat(infos.gasPrice)
   166  	}
   167  //
   168  	nocache := false
   169  	if existed {
   170  		fmt.Println()
   171  		fmt.Printf("Should the node be built from scratch (y/n)? (default = no)\n")
   172  		nocache = w.readDefaultString("n") != "n"
   173  	}
   174  	if out, err := deployNode(client, w.network, w.conf.bootnodes, infos, nocache); err != nil {
   175  		log.Error("Failed to deploy Ethereum node container", "err", err)
   176  		if len(out) > 0 {
   177  			fmt.Printf("%s\n", out)
   178  		}
   179  		return
   180  	}
   181  //
   182  	log.Info("Waiting for node to finish booting")
   183  	time.Sleep(3 * time.Second)
   184  
   185  	w.networkStats()
   186  }