7 log "github.com/sirupsen/logrus"
8 "github.com/spf13/cobra"
10 "github.com/bytom/vapor/node"
13 const logModule = "cmd"
15 var runNodeCmd = &cobra.Command{
17 Short: "Run the vapord",
22 runNodeCmd.Flags().String("prof_laddr", config.ProfListenAddress, "Use http to profile vapord programs")
23 runNodeCmd.Flags().Bool("mining", config.Mining, "Enable mining")
24 runNodeCmd.Flags().String("cross_chain.asset_whitelist", config.CrossChain.AssetWhitelist, "Cross-chain-allowed asset whitelist")
26 runNodeCmd.Flags().Bool("auth.disable", config.Auth.Disable, "Disable rpc access authenticate")
28 runNodeCmd.Flags().Bool("wallet.disable", config.Wallet.Disable, "Disable wallet")
29 runNodeCmd.Flags().Bool("wallet.rescan", config.Wallet.Rescan, "Rescan wallet")
30 runNodeCmd.Flags().Bool("wallet.txindex", config.Wallet.TxIndex, "Save global tx index")
31 runNodeCmd.Flags().Bool("vault_mode", config.VaultMode, "Run in the offline enviroment")
32 runNodeCmd.Flags().Bool("web.closed", config.Web.Closed, "Lanch web browser or not")
33 runNodeCmd.Flags().String("chain_id", config.ChainID, "Select network type")
36 runNodeCmd.Flags().String("log_level", config.LogLevel, "Select log level(debug, info, warn, error or fatal)")
39 runNodeCmd.Flags().String("p2p.laddr", config.P2P.ListenAddress, "Node listen address. (0.0.0.0:0 means any interface, any port)")
40 runNodeCmd.Flags().String("p2p.seeds", config.P2P.Seeds, "Comma delimited host:port seed nodes")
41 runNodeCmd.Flags().Bool("p2p.skip_upnp", config.P2P.SkipUPNP, "Skip UPNP configuration")
42 runNodeCmd.Flags().Bool("p2p.lan_discoverable", config.P2P.LANDiscover, "Whether the node can be discovered by nodes in the LAN")
43 runNodeCmd.Flags().Int("p2p.max_num_peers", config.P2P.MaxNumPeers, "Set max num peers")
44 runNodeCmd.Flags().Int("p2p.handshake_timeout", config.P2P.HandshakeTimeout, "Set handshake timeout")
45 runNodeCmd.Flags().Int("p2p.dial_timeout", config.P2P.DialTimeout, "Set dial timeout")
46 runNodeCmd.Flags().String("p2p.proxy_address", config.P2P.ProxyAddress, "Connect via SOCKS5 proxy (eg. 127.0.0.1:1086)")
47 runNodeCmd.Flags().String("p2p.proxy_username", config.P2P.ProxyUsername, "Username for proxy server")
48 runNodeCmd.Flags().String("p2p.proxy_password", config.P2P.ProxyPassword, "Password for proxy server")
49 runNodeCmd.Flags().String("p2p.keep_dial", config.P2P.KeepDial, "Peers addresses try keeping connecting to, separated by ',' (for example \"1.1.1.1:46657;2.2.2.2:46658\")")
52 runNodeCmd.Flags().String("log_file", config.LogFile, "Log output file")
55 runNodeCmd.Flags().Int("ws.max_num_websockets", config.Websocket.MaxNumWebsockets, "Max number of websocket connections")
56 runNodeCmd.Flags().Int("ws.max_num_concurrent_reqs", config.Websocket.MaxNumConcurrentReqs, "Max number of concurrent websocket requests that may be processed concurrently")
58 RootCmd.AddCommand(runNodeCmd)
61 func setLogLevel(level string) {
62 switch strings.ToLower(level) {
64 log.SetLevel(log.DebugLevel)
66 log.SetLevel(log.InfoLevel)
68 log.SetLevel(log.WarnLevel)
70 log.SetLevel(log.ErrorLevel)
72 log.SetLevel(log.FatalLevel)
74 log.SetLevel(log.InfoLevel)
78 func runNode(cmd *cobra.Command, args []string) error {
79 startTime := time.Now()
80 setLogLevel(config.LogLevel)
82 // Create & start node
83 n := node.NewNode(config)
84 if _, err := n.Start(); err != nil {
85 log.WithFields(log.Fields{"module": logModule, "err": err}).Fatal("failed to start node")
88 log.WithFields(log.Fields{
90 "duration": time.Since(startTime),
91 }).Info("start node complete")
93 // Trap signal, run forever.