func StartNode(stack *node.Node) { if err := stack.Start(); err != nil { Fatalf("Error starting protocol stack: %v", err) } go func() { sigc := make(chan os.Signal, 1) signal.Notify(sigc, os.Interrupt) defer signal.Stop(sigc) <-sigc glog.V(logger.Info).Infoln("Got interrupt, shutting down...") go stack.Stop() for i := 10; i > 0; i-- { <-sigc if i > 1 { glog.V(logger.Info).Infof("Already shutting down, interrupt %d more times for panic.", i-1) } } debug.Exit() // ensure trace and CPU profile data is flushed. debug.LoudPanic("boom") }() }
func init() { // Construct the textual version string from the individual components verString = fmt.Sprintf("%d.%d.%d", versionMajor, versionMinor, versionPatch) if versionMeta != "" { verString += "-" + versionMeta } if gitCommit != "" { verString += "-" + gitCommit[:8] } // Construct the version release oracle configuration relConfig.Oracle = common.HexToAddress(versionOracle) relConfig.Major = uint32(versionMajor) relConfig.Minor = uint32(versionMinor) relConfig.Patch = uint32(versionPatch) commit, _ := hex.DecodeString(gitCommit) copy(relConfig.Commit[:], commit) // Initialize the CLI app and start Gexp app = utils.NewApp(verString, "the go-expanse command line interface") app.Action = gexp app.HideVersion = true // we have a command to print the version app.Commands = []cli.Command{ importCommand, exportCommand, upgradedbCommand, removedbCommand, dumpCommand, monitorCommand, accountCommand, walletCommand, consoleCommand, attachCommand, javascriptCommand, { Action: makedag, Name: "makedag", Usage: "generate ethash dag (for testing)", Description: ` The makedag command generates an ethash DAG in /tmp/dag. This command exists to support the system testing project. Regular users do not need to execute it. `, }, { Action: gpuinfo, Name: "gpuinfo", Usage: "gpuinfo", Description: ` Prints OpenCL device info for all found GPUs. `, }, { Action: gpubench, Name: "gpubench", Usage: "benchmark GPU", Description: ` Runs quick benchmark on first GPU found. `, }, { Action: version, Name: "version", Usage: "print expanse version numbers", Description: ` The output of this command is supposed to be machine-readable. `, }, { Action: initGenesis, Name: "init", Usage: "bootstraps and initialises a new genesis block (JSON)", Description: ` The init command initialises a new genesis block and definition for the network. This is a destructive action and changes the network in which you will be participating. `, }, } app.Flags = []cli.Flag{ utils.IdentityFlag, utils.UnlockedAccountFlag, utils.PasswordFileFlag, utils.BootnodesFlag, utils.DataDirFlag, utils.KeyStoreDirFlag, utils.BlockchainVersionFlag, utils.OlympicFlag, utils.FastSyncFlag, utils.CacheFlag, utils.LightKDFFlag, utils.JSpathFlag, utils.ListenPortFlag, utils.MaxPeersFlag, utils.MaxPendingPeersFlag, utils.EtherbaseFlag, utils.GasPriceFlag, utils.SupportDAOFork, utils.OpposeDAOFork, utils.MinerThreadsFlag, utils.MiningEnabledFlag, utils.MiningGPUFlag, utils.AutoDAGFlag, utils.TargetGasLimitFlag, utils.NATFlag, utils.NatspecEnabledFlag, utils.NoDiscoverFlag, utils.NodeKeyFileFlag, utils.NodeKeyHexFlag, utils.RPCEnabledFlag, utils.RPCListenAddrFlag, utils.RPCPortFlag, utils.RPCApiFlag, utils.WSEnabledFlag, utils.WSListenAddrFlag, utils.WSPortFlag, utils.WSApiFlag, utils.WSAllowedOriginsFlag, utils.IPCDisabledFlag, utils.IPCApiFlag, utils.IPCPathFlag, utils.ExecFlag, utils.PreloadJSFlag, utils.WhisperEnabledFlag, utils.DevModeFlag, utils.TestNetFlag, utils.VMForceJitFlag, utils.VMJitCacheFlag, utils.VMEnableJitFlag, utils.NetworkIdFlag, utils.RPCCORSDomainFlag, utils.MetricsEnabledFlag, utils.FakePoWFlag, utils.SolcPathFlag, utils.GpoMinGasPriceFlag, utils.GpoMaxGasPriceFlag, utils.GpoFullBlockRatioFlag, utils.GpobaseStepDownFlag, utils.GpobaseStepUpFlag, utils.GpobaseCorrectionFactorFlag, utils.ExtraDataFlag, } app.Flags = append(app.Flags, debug.Flags...) app.Before = func(ctx *cli.Context) error { runtime.GOMAXPROCS(runtime.NumCPU()) if err := debug.Setup(ctx); err != nil { return err } // Start system runtime metrics collection go metrics.CollectProcessMetrics(3 * time.Second) // This should be the only place where reporting is enabled // because it is not intended to run while testing. // In addition to this check, bad block reports are sent only // for chains with the main network genesis block and network id 1. exp.EnableBadBlockReporting = true utils.SetupNetwork(ctx) return nil } app.After = func(ctx *cli.Context) error { logger.Flush() debug.Exit() console.Stdin.Close() // Resets terminal mode. return nil } }