github.com/amazechain/amc@v0.1.3/cmd/amc/cmd.go (about) 1 // Copyright 2022 The AmazeChain Authors 2 // This file is part of the AmazeChain library. 3 // 4 // The AmazeChain library is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Lesser 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 // The AmazeChain library 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 Lesser General Public License for more details. 13 // 14 // You should have received a copy of the GNU Lesser General Public License 15 // along with the AmazeChain library. If not, see <http://www.gnu.org/licenses/>. 16 17 package main 18 19 import ( 20 "github.com/amazechain/amc/params/networkname" 21 "github.com/urfave/cli/v2" 22 ) 23 24 var ( 25 privateKey string 26 //engine string 27 miner bool 28 // todo 29 listenAddress = cli.NewStringSlice() 30 bootstraps = cli.NewStringSlice() 31 cfgFile string 32 33 p2pStaticPeers = cli.NewStringSlice() 34 p2pBootstrapNode = cli.NewStringSlice() 35 p2pDenyList = cli.NewStringSlice() 36 ) 37 38 var rootCmd []*cli.Command 39 40 var networkFlags = []cli.Flag{ 41 &cli.StringSliceFlag{ 42 Name: "p2p.listen", 43 Usage: "p2p listen address", 44 Value: cli.NewStringSlice(), 45 Destination: listenAddress, 46 }, 47 48 &cli.StringSliceFlag{ 49 Name: "p2p.bootstrap", 50 Usage: "bootstrap node info", 51 Value: cli.NewStringSlice(), 52 Destination: bootstraps, 53 }, 54 55 &cli.StringFlag{ 56 Name: "p2p.key", 57 Usage: "private key of p2p node", 58 Value: "", 59 Destination: &DefaultConfig.NetworkCfg.LocalPeerKey, 60 }, 61 } 62 63 var nodeFlg = []cli.Flag{ 64 &cli.StringFlag{ 65 Name: "node.key", 66 Usage: "node private", 67 Value: "", 68 Destination: &DefaultConfig.NodeCfg.NodePrivate, 69 }, 70 } 71 72 var rpcFlags = []cli.Flag{ 73 74 &cli.StringFlag{ 75 Name: "ipcpath", 76 Usage: "Filename for IPC socket/pipe within the data dir (explicit paths escape it)", 77 Value: DefaultConfig.NodeCfg.IPCPath, 78 Destination: &DefaultConfig.NodeCfg.IPCPath, 79 }, 80 81 &cli.BoolFlag{ 82 Name: "http", 83 Usage: "Enable the HTTP json-rpc server", 84 Value: false, 85 Destination: &DefaultConfig.NodeCfg.HTTP, 86 }, 87 &cli.StringFlag{ 88 Name: "http.addr", 89 Usage: "HTTP server listening interface", 90 Value: DefaultConfig.NodeCfg.HTTPHost, 91 Destination: &DefaultConfig.NodeCfg.HTTPHost, 92 }, 93 &cli.StringFlag{ 94 Name: "http.port", 95 Usage: "HTTP server listening port", 96 Value: "20012", 97 Destination: &DefaultConfig.NodeCfg.HTTPPort, 98 }, 99 &cli.StringFlag{ 100 Name: "http.api", 101 Usage: "API's offered over the HTTP-RPC interface", 102 Value: "", 103 Destination: &DefaultConfig.NodeCfg.HTTPApi, 104 }, 105 106 &cli.StringFlag{ 107 Name: "http.corsdomain", 108 Usage: "Comma separated list of domains from which to accept cross origin requests (browser enforced)", 109 Value: "", 110 Destination: &DefaultConfig.NodeCfg.HTTPCors, 111 }, 112 113 &cli.BoolFlag{ 114 Name: "ws", 115 Usage: "Enable the WS-RPC server", 116 Value: false, 117 Destination: &DefaultConfig.NodeCfg.WS, 118 }, 119 &cli.StringFlag{ 120 Name: "ws.addr", 121 Usage: "WS-RPC server listening interface", 122 Value: DefaultConfig.NodeCfg.WSHost, 123 Destination: &DefaultConfig.NodeCfg.WSHost, 124 }, 125 &cli.StringFlag{ 126 Name: "ws.port", 127 Usage: "WS-RPC server listening port", 128 Value: "20013", 129 Destination: &DefaultConfig.NodeCfg.WSPort, 130 }, 131 132 &cli.StringFlag{ 133 Name: "ws.api", 134 Usage: "API's offered over the WS-RPC interface", 135 Value: "", 136 Destination: &DefaultConfig.NodeCfg.WSApi, 137 }, 138 139 &cli.StringFlag{ 140 Name: "ws.origins", 141 Usage: "Origins from which to accept websockets requests", 142 Value: "", 143 Destination: &DefaultConfig.NodeCfg.WSOrigins, 144 }, 145 } 146 147 var consensusFlag = []cli.Flag{ 148 //&cli.StringFlag{ 149 // Name: "engine.type", 150 // Usage: "consensus engine", 151 // Value: "APosEngine", //APoaEngine,APosEngine 152 // Destination: &DefaultConfig.ChainCfg.Consensus, 153 //}, 154 &cli.BoolFlag{ 155 Name: "engine.miner", 156 Usage: "miner", 157 Value: false, 158 Destination: &DefaultConfig.NodeCfg.Miner, 159 }, 160 &cli.StringFlag{ 161 Name: "engine.etherbase", 162 Usage: "consensus etherbase", 163 Value: "", 164 Destination: &DefaultConfig.Miner.Etherbase, 165 }, 166 } 167 168 var configFlag = []cli.Flag{ 169 &cli.StringFlag{ 170 Name: "blockchain", 171 Usage: "Loading a Configuration File", 172 Destination: &cfgFile, 173 }, 174 } 175 176 var pprofCfg = []cli.Flag{ 177 &cli.BoolFlag{ 178 Name: "pprof", 179 Usage: "Enable the pprof HTTP server", 180 Value: false, 181 Destination: &DefaultConfig.PprofCfg.Pprof, 182 }, 183 184 &cli.BoolFlag{ 185 Name: "pprof.block", 186 Usage: "Turn on block profiling", 187 Value: false, 188 Destination: &DefaultConfig.PprofCfg.TraceBlock, 189 }, 190 &cli.BoolFlag{ 191 Name: "pprof.mutex", 192 Usage: "Turn on mutex profiling", 193 Value: false, 194 Destination: &DefaultConfig.PprofCfg.TraceMutex, 195 }, 196 &cli.IntFlag{ 197 Name: "pprof.maxcpu", 198 Usage: "setup number of cpu", 199 Value: 0, 200 Destination: &DefaultConfig.PprofCfg.MaxCpu, 201 }, 202 &cli.IntFlag{ 203 Name: "pprof.port", 204 Usage: "pprof HTTP server listening port", 205 Value: 0, 206 Destination: &DefaultConfig.PprofCfg.Port, 207 }, 208 } 209 210 var loggerFlag = []cli.Flag{ 211 &cli.StringFlag{ 212 Name: "log.name", 213 Usage: "logger file name and path", 214 Value: "amc.log", 215 Destination: &DefaultConfig.LoggerCfg.LogFile, 216 }, 217 218 &cli.StringFlag{ 219 Name: "log.level", 220 Usage: "logger output level (value:[debug,info,warn,error,dpanic,panic,fatal])", 221 Value: "debug", 222 Destination: &DefaultConfig.LoggerCfg.Level, 223 }, 224 225 &cli.IntFlag{ 226 Name: "log.maxSize", 227 Usage: "logger file max size M", 228 Value: 10, 229 Destination: &DefaultConfig.LoggerCfg.MaxSize, 230 }, 231 &cli.IntFlag{ 232 Name: "log.maxBackups", 233 Usage: "logger file max backups", 234 Value: 10, 235 Destination: &DefaultConfig.LoggerCfg.MaxBackups, 236 }, 237 &cli.IntFlag{ 238 Name: "log.maxAge", 239 Usage: "logger file max age", 240 Value: 30, 241 Destination: &DefaultConfig.LoggerCfg.MaxAge, 242 }, 243 &cli.BoolFlag{ 244 Name: "log.compress", 245 Usage: "logger file compress", 246 Value: false, 247 Destination: &DefaultConfig.LoggerCfg.Compress, 248 }, 249 } 250 var ( 251 // P2PNoDiscovery specifies whether we are running a local network and have no need for connecting 252 // to the bootstrap nodes in the cloud 253 P2PNoDiscovery = &cli.BoolFlag{ 254 Name: "p2p.no-discovery", 255 Usage: "Enable only local network p2p and do not connect to cloud bootstrap nodes.", 256 Destination: &DefaultConfig.P2PCfg.NoDiscovery, 257 } 258 // P2PStaticPeers specifies a set of peers to connect to explicitly. 259 P2PStaticPeers = &cli.StringSliceFlag{ 260 Name: "p2p.peer", 261 Usage: "Connect with this peer. This flag may be used multiple times.", 262 Destination: p2pStaticPeers, 263 } 264 // P2PBootstrapNode tells the beacon node which bootstrap node to connect to 265 P2PBootstrapNode = &cli.StringSliceFlag{ 266 Name: "p2p.bootstrap-node", 267 Usage: "The address of bootstrap node. Beacon node will connect for peer discovery via DHT. Multiple nodes can be passed by using the flag multiple times but not comma-separated. You can also pass YAML files containing multiple nodes.", 268 Destination: p2pBootstrapNode, 269 } 270 // P2PRelayNode tells the beacon node which relay node to connect to. 271 P2PRelayNode = &cli.StringFlag{ 272 Name: "p2p.relay-node", 273 Usage: "The address of relay node. The beacon node will connect to the " + 274 "relay node and advertise their address via the relay node to other peers", 275 Value: "", 276 Destination: &DefaultConfig.P2PCfg.RelayNodeAddr, 277 } 278 // P2PUDPPort defines the port to be used by discv5. 279 P2PUDPPort = &cli.IntFlag{ 280 Name: "p2p.udp-port", 281 Usage: "The port used by discv5.", 282 Value: 61015, 283 Destination: &DefaultConfig.P2PCfg.UDPPort, 284 } 285 // P2PTCPPort defines the port to be used by libp2p. 286 P2PTCPPort = &cli.IntFlag{ 287 Name: "p2p.tcp-port", 288 Usage: "The port used by libp2p.", 289 Value: 61016, 290 Destination: &DefaultConfig.P2PCfg.TCPPort, 291 } 292 // P2PIP defines the local IP to be used by libp2p. 293 P2PIP = &cli.StringFlag{ 294 Name: "p2p.local-ip", 295 Usage: "The local ip address to listen for incoming data.", 296 Value: "", 297 Destination: &DefaultConfig.P2PCfg.LocalIP, 298 } 299 // P2PHost defines the host IP to be used by libp2p. 300 P2PHost = &cli.StringFlag{ 301 Name: "p2p.host-ip", 302 Usage: "The IP address advertised by libp2p. This may be used to advertise an external IP.", 303 Value: "", 304 Destination: &DefaultConfig.P2PCfg.HostAddress, 305 } 306 // P2PHostDNS defines the host DNS to be used by libp2p. 307 P2PHostDNS = &cli.StringFlag{ 308 Name: "p2p.host-dns", 309 Usage: "The DNS address advertised by libp2p. This may be used to advertise an external DNS.", 310 Value: "", 311 Destination: &DefaultConfig.P2PCfg.HostDNS, 312 } 313 // P2PPrivKey defines a flag to specify the location of the private key file for libp2p. 314 P2PPrivKey = &cli.StringFlag{ 315 Name: "p2p.priv-key", 316 Usage: "The file containing the private key to use in communications with other peers.", 317 Value: "", 318 Destination: &DefaultConfig.P2PCfg.PrivateKey, 319 } 320 P2PStaticID = &cli.BoolFlag{ 321 Name: "p2p.static-id", 322 Usage: "Enables the peer id of the node to be fixed by saving the generated network key to the default key path.", 323 Value: true, 324 Destination: &DefaultConfig.P2PCfg.StaticPeerID, 325 } 326 // P2PMetadata defines a flag to specify the location of the peer metadata file. 327 P2PMetadata = &cli.StringFlag{ 328 Name: "p2p.metadata", 329 Usage: "The file containing the metadata to communicate with other peers.", 330 Value: "", 331 Destination: &DefaultConfig.P2PCfg.MetaDataDir, 332 } 333 // P2PMaxPeers defines a flag to specify the max number of peers in libp2p. 334 P2PMaxPeers = &cli.IntFlag{ 335 Name: "p2p.max-peers", 336 Usage: "The max number of p2p peers to maintain.", 337 Value: 5, 338 Destination: &DefaultConfig.P2PCfg.MaxPeers, 339 } 340 // P2PAllowList defines a CIDR subnet to exclusively allow connections. 341 P2PAllowList = &cli.StringFlag{ 342 Name: "p2p.allowlist", 343 Usage: "The CIDR subnet for allowing only certain peer connections. " + 344 "Using \"public\" would allow only public subnets. Example: " + 345 "192.168.0.0/16 would permit connections to peers on your local network only. The " + 346 "default is to accept all connections.", 347 Destination: &DefaultConfig.P2PCfg.AllowListCIDR, 348 } 349 // P2PDenyList defines a list of CIDR subnets to disallow connections from them. 350 P2PDenyList = &cli.StringSliceFlag{ 351 Name: "p2p.denylist", 352 Usage: "The CIDR subnets for denying certainty peer connections. " + 353 "Using \"private\" would deny all private subnets. Example: " + 354 "192.168.0.0/16 would deny connections from peers on your local network only. The " + 355 "default is to accept all connections.", 356 Destination: p2pDenyList, 357 } 358 359 // P2PMinSyncPeers specifies the required number of successful peer handshakes in order 360 // to start syncing with external peers. 361 P2PMinSyncPeers = &cli.IntFlag{ 362 Name: "p2p.min-sync-peers", 363 Usage: "The required number of valid peers to connect with before syncing.", 364 Value: 1, 365 Destination: &DefaultConfig.P2PCfg.MinSyncPeers, 366 } 367 368 // P2PBlockBatchLimit specifies the requested block batch size. 369 P2PBlockBatchLimit = &cli.IntFlag{ 370 Name: "p2p.limit.block-batch", 371 Usage: "The amount of blocks the local peer is bounded to request and respond to in a batch.", 372 Value: 64, 373 Destination: &DefaultConfig.P2PCfg.P2PLimit.BlockBatchLimit, 374 } 375 // P2PBlockBatchLimitBurstFactor specifies the factor by which block batch size may increase. 376 P2PBlockBatchLimitBurstFactor = &cli.IntFlag{ 377 Name: "p2p.limit.block-burst-factor", 378 Usage: "The factor by which block batch limit may increase on burst.", 379 Value: 2, 380 Destination: &DefaultConfig.P2PCfg.P2PLimit.BlockBatchLimitBurstFactor, 381 } 382 // P2PBlockBatchLimiterPeriod Period to calculate expected limit for a single peer. 383 P2PBlockBatchLimiterPeriod = &cli.IntFlag{ 384 Name: "p2p.limit.block-limiter-period", 385 Usage: "Period to calculate expected limit for a single peer.", 386 Value: 5, 387 Destination: &DefaultConfig.P2PCfg.P2PLimit.BlockBatchLimiterPeriod, 388 } 389 ) 390 391 var ( 392 DataDirFlag = &cli.StringFlag{ 393 Name: "data.dir", 394 Usage: "data save dir", 395 Value: "./amc/", 396 Destination: &DefaultConfig.NodeCfg.DataDir, 397 } 398 399 MinFreeDiskSpaceFlag = &cli.IntFlag{ 400 Name: "data.dir.minfreedisk", 401 Usage: "Minimum free disk space in GB, once reached triggers auto shut down (default = 10GB, 0 = disabled)", 402 Value: 10, 403 Destination: &DefaultConfig.NodeCfg.MinFreeDiskSpace, 404 } 405 406 FromDataDirFlag = &cli.StringFlag{ 407 Name: "chaindata.from", 408 Usage: "source data dir", 409 } 410 ToDataDirFlag = &cli.StringFlag{ 411 Name: "chaindata.to", 412 Usage: "to data dir", 413 } 414 415 ChainFlag = &cli.StringFlag{ 416 Name: "chain", 417 Usage: "Name of the testnet to join (value:[mainnet,testnet,private])", 418 Value: networkname.MainnetChainName, 419 Destination: &DefaultConfig.NodeCfg.Chain, 420 } 421 ) 422 423 var ( 424 AuthRPCFlag = &cli.BoolFlag{ 425 Name: "authrpc", 426 Usage: "Enable the AUTH-RPC server", 427 Value: false, 428 Destination: &DefaultConfig.NodeCfg.AuthRPC, 429 } 430 // Authenticated RPC HTTP settings 431 AuthRPCListenFlag = &cli.StringFlag{ 432 Name: "authrpc.addr", 433 Usage: "Listening address for authenticated APIs", 434 Value: "", 435 Destination: &DefaultConfig.NodeCfg.AuthAddr, 436 } 437 AuthRPCPortFlag = &cli.IntFlag{ 438 Name: "authrpc.port", 439 Usage: "Listening port for authenticated APIs", 440 Destination: &DefaultConfig.NodeCfg.AuthPort, 441 } 442 JWTSecretFlag = &cli.StringFlag{ 443 Name: "authrpc.jwtsecret", 444 Usage: "Path to a JWT secret to use for authenticated RPC endpoints", 445 Value: "", 446 Destination: &DefaultConfig.NodeCfg.JWTSecret, 447 } 448 ) 449 450 var ( 451 // Account settings 452 UnlockedAccountFlag = &cli.StringFlag{ 453 Name: "account.unlock", 454 Usage: "Comma separated list of accounts to unlock", 455 Value: "", 456 } 457 PasswordFileFlag = &cli.PathFlag{ 458 Name: "account.password", 459 Usage: "Password file to use for non-interactive password input", 460 Destination: &DefaultConfig.NodeCfg.PasswordFile, 461 } 462 LightKDFFlag = &cli.BoolFlag{ 463 Name: "account.lightkdf", 464 Usage: "Reduce key-derivation RAM & CPU usage at some expense of KDF strength", 465 } 466 KeyStoreDirFlag = &cli.PathFlag{ 467 Name: "account.keystore", 468 Usage: "Directory for the keystore (default = inside the datadir)", 469 TakesFile: true, 470 Destination: &DefaultConfig.NodeCfg.KeyStoreDir, 471 } 472 InsecureUnlockAllowedFlag = &cli.BoolFlag{ 473 Name: "account.allow.insecure.unlock", 474 Usage: "Allow insecure account unlocking when account-related RPCs are exposed by http", 475 Value: false, 476 Destination: &DefaultConfig.NodeCfg.InsecureUnlockAllowed, 477 } 478 479 // MetricsEnabledFlag Metrics flags 480 MetricsEnabledFlag = &cli.BoolFlag{ 481 Name: "metrics", 482 Usage: "Enable metrics collection and reporting", 483 Value: false, 484 Destination: &DefaultConfig.MetricsCfg.Enable, 485 } 486 487 // MetricsHTTPFlag defines the endpoint for a stand-alone metrics HTTP endpoint. 488 // Since the pprof service enables sensitive/vulnerable behavior, this allows a user 489 // to enable a public-OK metrics endpoint without having to worry about ALSO exposing 490 // other profiling behavior or information. 491 MetricsHTTPFlag = &cli.StringFlag{ 492 Name: "metrics.addr", 493 Usage: `Enable stand-alone metrics HTTP server listening interface.`, 494 //Category: flags.MetricsCategory, 495 Value: "127.0.0.1", 496 Destination: &DefaultConfig.MetricsCfg.HTTP, 497 } 498 MetricsPortFlag = &cli.IntFlag{ 499 Name: "metrics.port", 500 Usage: `Metrics HTTP server listening port. 501 Please note that --` + MetricsHTTPFlag.Name + ` must be set to start the server.`, 502 Value: 6060, 503 // Category: flags.MetricsCategory, 504 Destination: &DefaultConfig.MetricsCfg.Port, 505 } 506 ) 507 508 var ( 509 authRPCFlag = []cli.Flag{ 510 AuthRPCFlag, 511 AuthRPCListenFlag, 512 AuthRPCPortFlag, 513 JWTSecretFlag, 514 } 515 settingFlag = []cli.Flag{ 516 DataDirFlag, 517 ChainFlag, 518 MinFreeDiskSpaceFlag, 519 } 520 accountFlag = []cli.Flag{ 521 PasswordFileFlag, 522 KeyStoreDirFlag, 523 LightKDFFlag, 524 InsecureUnlockAllowedFlag, 525 UnlockedAccountFlag, 526 } 527 528 metricsFlags = []cli.Flag{ 529 MetricsEnabledFlag, 530 MetricsHTTPFlag, 531 MetricsPortFlag, 532 } 533 534 p2pFlags = []cli.Flag{ 535 P2PNoDiscovery, 536 P2PAllowList, 537 P2PBootstrapNode, 538 P2PDenyList, 539 P2PIP, 540 P2PHost, 541 P2PMaxPeers, 542 P2PMetadata, 543 P2PStaticID, 544 P2PPrivKey, 545 P2PHostDNS, 546 P2PRelayNode, 547 P2PStaticPeers, 548 P2PUDPPort, 549 P2PTCPPort, 550 P2PMinSyncPeers, 551 } 552 553 p2pLimitFlags = []cli.Flag{ 554 P2PBlockBatchLimit, 555 P2PBlockBatchLimitBurstFactor, 556 P2PBlockBatchLimiterPeriod, 557 } 558 )