github.com/deso-protocol/core@v1.2.9/cmd/run.go (about) 1 package cmd 2 3 import ( 4 "github.com/golang/glog" 5 "github.com/spf13/cobra" 6 "github.com/spf13/pflag" 7 "github.com/spf13/viper" 8 "os" 9 "os/signal" 10 "syscall" 11 ) 12 13 var runCmd = &cobra.Command{ 14 Use: "run", 15 Short: "Run the node", 16 Long: `...`, 17 Run: Run, 18 } 19 20 func init() { 21 SetupRunFlags(runCmd) 22 rootCmd.AddCommand(runCmd) 23 } 24 25 func Run(cmd *cobra.Command, args []string) { 26 // Parse the configuration (can use CLI flags, environment variables, or config file) 27 config := LoadConfig() 28 29 // Start the deso node 30 node := NewNode(config) 31 go node.Start() 32 33 shutdownListener := make(chan os.Signal) 34 signal.Notify(shutdownListener, syscall.SIGINT, syscall.SIGTERM) 35 defer func() { 36 node.Stop() 37 glog.Info("Shutdown complete") 38 }() 39 40 <-shutdownListener 41 } 42 43 func SetupRunFlags(cmd *cobra.Command) { 44 // Core 45 cmd.PersistentFlags().Bool("testnet", false, "Use the DeSo testnet. Mainnet is used by default") 46 cmd.PersistentFlags().String("data-dir", "", 47 "The location where all of the protocol-related data like blocks is stored. "+ 48 "Useful for testing situations where multiple clients need to run on the "+ 49 "same machine without trampling over each other. "+ 50 "When unset, defaults to the system's configuration directory.") 51 cmd.PersistentFlags().String("mempool-dump-dir", "", 52 "When set, the mempool is initialized using a db in the directory specified, and"+ 53 "subsequent dumps are also written to this dir") 54 cmd.PersistentFlags().Bool("txindex", false, 55 "When set to true, the node will generate an index mapping transaction "+ 56 "ids to transaction information. This enables the use of certain API calls "+ 57 "like ones that allow the lookup of particular transactions by their ID. "+ 58 "Defaults to false because the index can be large.") 59 cmd.PersistentFlags().Bool("regtest", false, 60 "Can only be used in conjunction with --testnet. Creates a private testnet node with fast block times"+ 61 "and instantly spendable block rewards.") 62 cmd.PersistentFlags().String("postgres-uri", "", "BETA: Use Postgres as the backing store for chain data."+ 63 "When enabled, most data is stored in postgres although badger is still currently used for some state. Run your "+ 64 "Postgres instance on the same machine as your node for optimal performance.") 65 66 // Peers 67 cmd.PersistentFlags().StringSlice("connect-ips", []string{}, 68 "A comma-separated list of ip:port addresses that we should connect to on startup. "+ 69 "If this argument is specified, we don't connect to any other peers.") 70 cmd.PersistentFlags().StringSlice("add-ips", []string{}, 71 "A comma-separated list of ip:port addresses that we should connect to on startup. "+ 72 "If this argument is specified, we will still fetch addresses from DNS seeds and "+ 73 "potentially connect to them.") 74 cmd.PersistentFlags().StringSlice("add-seeds", []string{}, 75 "A comma-separated list of DNS seeds to be used in addition to the pre-configured seeds.") 76 cmd.PersistentFlags().Uint64("target-outbound-peers", 8, 77 "The target number of outbound peers. The node will continue attempting to connect to "+ 78 "random addresses until it has this many outbound connections. During testing it's "+ 79 "useful to turn this number down and test a small number of nodes in a controlled "+ 80 "environment.") 81 cmd.PersistentFlags().Uint64("stall-timeout-seconds", 900, 82 "How long the node will wait for a peer to reply to certain types of requests. "+ 83 "We make this gratuitous just in case the node we're connecting to is backed up.") 84 85 // Peer Restrictions 86 cmd.PersistentFlags().Bool("private-mode", false, "The node does not look up addresses from DNS seeds.") 87 cmd.PersistentFlags().Bool("read-only-mode", false, "The node ignores all transactions created on this node.") 88 cmd.PersistentFlags().Bool("disable-networking", false, "The node does not make outgoing or accept incoming connections.") 89 cmd.PersistentFlags().Bool("ignore-inbound-invs", false, 90 "When set to true, the node will ignore all INV messages unless they come from an outbound peer. "+ 91 "This is useful when setting up a node that you want to have a direct and 1:1 relationship with "+ 92 "another node, as is common when setting up read sharding.") 93 cmd.PersistentFlags().Uint64("max-inbound-peers", 125, "The maximum number of inbound peers a node can have.") 94 cmd.PersistentFlags().Bool("one-inbound-per-ip", true, 95 "When set, the node will not allow more than one connection to/from a particular "+ 96 "IP. This prevents forms of attack whereby one node tries to monopolize all of "+ 97 "our connections and potentially make onerous requests as well. Useful to "+ 98 "disable this flag when testing locally to allow multiple inbound connections "+ 99 "from test servers") 100 101 // Listeners 102 cmd.PersistentFlags().Uint64("protocol-port", 0, 103 "When set, determines the port on which this node will listen for protocol-related "+ 104 "messages. If unset, the port will default to what is present in the DeSoParams set. "+ 105 "Note also that even though the node will listen on this port, its outbound "+ 106 "connections will not be determined by this flag.") 107 108 // Mining + Admin 109 cmd.PersistentFlags().StringSlice("miner-public-keys", []string{}, 110 "A miner is started if and only if this field is set. Indicates where to send "+ 111 "block rewards from mining blocks. Public keys must be "+ 112 "comma-separated compressed ECDSA public keys formatted as base58 strings.") 113 cmd.PersistentFlags().Uint64("num-mining-threads", 0, 114 "How many threads to run for mining. Only has an effect when --miner-public-keys "+ 115 "is set. If set to zero, which is the default, then the number of "+ 116 "threads available to the system will be used.") 117 118 // Fees 119 cmd.PersistentFlags().Uint64("rate-limit-feerate", 0, 120 "Transactions below this feerate will be rate-limited rather than flat-out "+ 121 "rejected. This is in contrast to min-feerate, which will flat-out reject "+ 122 "transactions with feerates below what is specified. As such, this value will have no "+ 123 "effect if it is set below min-feerate. This, along with min-feerate, should "+ 124 "be the first line of defense against attacks that involve flooding the "+ 125 "network with low-fee transactions in an attempt to overflow the mempool") 126 cmd.PersistentFlags().Uint64("min-feerate", 1000, 127 "The minimum feerate this node will accept when processing transactions "+ 128 "relayed by peers. Increasing this number, along with increasing "+ 129 "rate-limit-feerate, should be the first line of "+ 130 "defense against attacks that involve flooding the network with low-fee "+ 131 "transactions in an attempt to overflow the mempool") 132 133 // BlockProducer 134 cmd.PersistentFlags().Uint64("max-block-templates-cache", 100, 135 "When set to a non-zero value, the node will generate block "+ 136 "templates, and cache the number of templates specified by this flag. When set "+ 137 "to zero, the node will not produce block templates.") 138 cmd.PersistentFlags().Uint64("min-block-update-interval", 10, 139 "When set to a non-zero value, the node will wait at least this many seconds "+ 140 "before producing another block template") 141 cmd.PersistentFlags().String("block-cypher-api-key", "", 142 "When specified, this key is used to power the BitcoinExchange flow "+ 143 "and to check for double-spends in the mempool") 144 cmd.PersistentFlags().String("block-producer-seed", "", 145 "When set, all blocks produced by the block producer will be signed by this "+ 146 "seed.") 147 cmd.PersistentFlags().StringSlice("trusted-block-producer-public-keys", []string{ 148 "BC1YLgS1zDJQqywFpsty4fFheUrZxVQNKEsrttppvUESFZCq6Nfoypm", 149 "BC1YLh768bVj2R3QpSiduxcvn7ipxF3L3XHsabZYtCGtsinUnNrZvNN", 150 "BC1YLgsiUgM1Vr35YwbkSfZB3NC9tyrMXBPuJ2SEBf8naDf6PRpNit9", 151 "BC1YLgW5jWudzSUvrvNkD4GReN3kvGvsTuqLLttKfsCbXb7vLSCjwTk", 152 "BC1YLi8X7U9DZc2UqPE4s5PjrNJJUa6PKygD7VF4u8vy96srm18YvEX", 153 }, 154 "When set, this node will only accept new blocks that are signed by the trusted block "+ 155 "producers. This setting, is pretty novel. It allows a network of full nodes who "+ 156 "trust each other to create their own network that can't be easily taken over by a 51% "+ 157 "attack. In some sense, it uses trust in order to lower the amount of work needed to "+ 158 "protect the network, making it highly eco-friendly. Then, if full nodes ever want to "+ 159 "allow open mining, all they need to do is unset these public keys (or one of the owners "+ 160 "of the public keys can release her key material, pulling a metaphorical 'ripcord'). "+ 161 "Importantly, until this point, the network will be completely protected from a 51% attack, "+ 162 "giving it time to accumulate the necessary hash power.") 163 cmd.PersistentFlags().Uint64("trusted-block-producer-start-height", 37000, 164 "If --trusted-block-producer-public-keys is set, then all blocks after this height must "+ 165 "be signed by one of these keys in order to be considered valid. Setting this value to zero "+ 166 "enforces that all blocks after genesis must be signed by a trusted block producer. The default "+ 167 "value was chosen to be in-line with the default trusted public keys chosen.") 168 169 // Logging 170 cmd.PersistentFlags().String("log-dir", "", "The directory for logs") 171 cmd.PersistentFlags().Uint64("glog-v", 0, "The log level. 0 = INFO, 1 = DEBUG, 2 = TRACE. Defaults to zero") 172 cmd.PersistentFlags().String("glog-vmodule", "", 173 "The syntax of the argument is a comma-separated list of pattern=N, "+ 174 "where pattern is a literal file name (minus the \".go\" suffix) or \"glob\" "+ 175 "pattern and N is a V level. For instance, -vmodule=gopher*=3 sets the V "+ 176 "level to 3 in all Go files whose names begin \"gopher\".") 177 cmd.PersistentFlags().Bool("log-db-summary-snapshots", false, "The node will log a snapshot of all DB keys every 30s.") 178 cmd.PersistentFlags().Bool("datadog-profiler", false, "Enable the DataDog profiler for performance testing") 179 180 cmd.PersistentFlags().VisitAll(func(flag *pflag.Flag) { 181 viper.BindPFlag(flag.Name, flag) 182 }) 183 }