In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the relevant knowledge of "what is the method of starting and stopping Bytom". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Pre-work compilation and installation
For detailed steps, see the official bytom install.
Set debug log output
Open debug output files, functions, line numbers and other details
Export BYTOM_DEBUG=debug initializes and starts bytomd
Initialization
. / bytomd init-- chain_id testnet
Bytomd currently supports two kinds of networks. Here we use the test network mainnet: main network testnet: test network
Start bytomd
. / bytomd node-mining-prof_laddr= ": 8011"
-- prof_laddr= ": 8080" / / enable pprof output performance metrics access: http://127.0.0.1:8080/debug/pprof/
Bytomd init initialization
Entry function * * cmd/bytomd/main.go * *
Func init () {log.SetFormatter (& log.TextFormatter {FullTimestamp: true, DisableColors: true}) / / If environment variable BYTOM_DEBUG is not empty / / then add the hook to logrus and set the log level to DEBUG if os.Getenv ("BYTOM_DEBUG")! = "{log.AddHook (ContextHook {}) log.SetLevel (log.DebugLevel)}} func main () {cmd: = cli.PrepareBaseCmd (commands.RootCmd," TM ", os.ExpandEnv (config.DefaultDataDir () cmd.Execute ()}
The init function initializes before the main executes. You can see the bytomd load bytom _ DEBUG variable in init to set the debug log output.
Command cli pass parameters initialize cli parsing of bytomd using cobra library
* * cmd/bytomd/commands * *
Cmd/bytomd/commands/root.go initialization-- root passes parameters. Bytomd stores the root directory for configuration, keystore, and data. Under MacOS, the default path is ~ / Library/Bytom/
Cmd/bytomd/commands/init.go initialization-- chain_id passes parameters. Select the network type. When we started bytomd, we chose testnet, that is, to test the network.
Cmd/bytomd/commands/version.go initializes version parameter transfer
Cmd/bytomd/commands/run_node.go initializes the parameters needed by the node node to run
Initializing the default configuration user parameters has only some parameters, and the other parameters required by that node need to be loaded from the default configuration. * * cmd/bytomd/commands/root.go * *
Var (config = cfg.DefaultConfig ())
There is a config global variable in root.go that loads all the default parameters required by node
/ / Default configurable parameters.func DefaultConfig () * Config {return & Config {BaseConfig: DefaultBaseConfig (), / / node basic related configuration P2P: DefaultP2PConfig (), / / P2P network related configuration Wallet: DefaultWalletConfig (), / / wallet related configuration Auth: DefaultRPCAuthConfig () / / verify related configuration Web: DefaultWebConfig (), / / web related configuration}}
Later articles will describe the role of each configuration one by one.
Bytomd daemon starts and exits
* * cmd/bytomd/commands/run_node.go * *
Func runNode (cmd * cobra.Command, args [] string) error {/ / Create & start node n: = node.NewNode (config) if _, err: = n.Start () Err! = nil {return fmt.Errorf ("Failed to start node:% v", err)} else {log.WithField ("nodeInfo", n.SyncManager (). Switch (). NodeInfo ()) .Info ("Started node")} / / Trap signal, run forever. N.RunForever () return nil}
The runNode function has three steps: node.NewNode: initialize the node runtime environment n.Start: start the node n.RunForever: listen for the exit signal, and exit the node when you receive the ctrl+c operation. In linux, the daemon process generally listens for the SIGTERM signal (ctrl+c) as a signal to exit the daemon.
Initialize the node runtime environment
There are five db databases in bytomd stored in the data directory under the-- root parameter
Accesstoken.db / / Storage token related information (wallet access control permissions)
Trusthistory.db / / Storage P2P network synchronization related information
Txdb.db / / stores transaction-related information
Txfeeds.db / /
Wallet.db / / stores wallet-related information
* * node/node.go * *
Func NewNode (config * cfg.Config) * Node {ctx: = context.Background () initActiveNetParams (config) / / Get store initialize txdb database txDB: = dbm.NewDB ("txdb", config.DBBackend, config.DBDir ()) store: = leveldb.NewStore (txDB) / / initialize accesstoken database tokenDB: = dbm.NewDB ("accesstoken", config.DBBackend) Config.DBDir () accessTokens: = accesstoken.NewStore (tokenDB) / / initialize the event event scheduler Also called Task Scheduler. A task can be called / / Make event switch eventSwitch: = types.NewEventSwitch () _, err: = eventSwitch.Start () if err! = nil {cmn.Exit (cmn.Fmt ("Failed to start switch:% v", err))} / / initialize the transaction pool txPool: = protocol.NewTxPool () chain, err: = protocol.NewChain (store) TxPool) if err! = nil {cmn.Exit (cmn.Fmt ("Failed to create chain structure:% v", err))} var accounts * account.Manager = nil var assets * asset.Registry = nil var wallet * w.Wallet = nil var txFeed * txfeed.Tracker = nil / / initialize txfeeds database txFeedDB: = dbm.NewDB ("txfeeds", config.DBBackend) Config.DBDir () txFeed = txfeed.NewTracker (txFeedDB, chain) if err = txFeed.Prepare (ctx) Err! = nil {log.WithField ("error", err) .error ("start txfeed") return nil} / / initialize keystore hsm, err: = pseudohsm.New (config.KeysDir ()) if err! = nil {cmn.Exit ("initialize HSM failed:% v", err))} / / initialize the wallet The default wallet is if! config.Wallet.Disable {walletDB: = dbm.NewDB ("wallet", config.DBBackend, config.DBDir ()) accounts = account.NewManager (walletDB, chain) assets = asset.NewRegistry (walletDB, chain) wallet, err = w.NewWallet (walletDB, accounts, assets, hsm) Chain) if err! = nil {log.WithField ("error", err) .error ("init NewWallet")} / / Clean up expired UTXO reservations periodically. Go accounts.ExpireReservations (ctx, expireReservationsPeriod)} newBlockCh: = make (chan * bc.Hash, maxNewBlockChSize) / / initialize network node synchronization management syncManager, _: = netsync.NewSyncManager (config, chain, txPool, newBlockCh) / / initialize pprof,pprof to output performance metrics. You need to set-prof_laddr parameter to enable it. We have enabled this function / / run the profile server profileHost: = config.ProfListenAddress if profileHost! = "" {/ / Profiling bytomd programs.see (https://blog.golang.org/profiling-go-programs) / / go tool pprof http://profileHose/debug/pprof/heap go func ()) {http.ListenAndServe (profileHost) at the beginning of the article. Nil)} ()} / / initialize the node Environment node: = & Node {config: config, syncManager: syncManager, evsw: eventSwitch, accessTokens: accessTokens, wallet: wallet, chain: chain, txfeed: txFeed MiningEnable: config.Mining,} / / initialize mining node.cpuMiner = cpuminer.NewCPUMiner (chain, accounts, txPool, newBlockCh) node.miningPool = miningpool.NewMiningPool (chain, accounts, txPool, newBlockCh) node.BaseService = * cmn.NewBaseService (nil, "Node", node) return node}
Currently, bytomd only supports cpu mining, so there is only initialization information of cpuminer in the code.
Start node
* * node/node.go * *
/ / Lanch web broser or notfunc lanchWebBroser () {log.Info ("Launching System Browser with:", webAddress) if err: = browser.Open (webAddress) Err! = nil {log.Error (err.Error () return}} func (n * Node) initAndstartApiServer () {n.api = api.NewAPI (n.syncManager, n.wallet, n.txfeed, n.cpuMiner, n.miningPool, n.chain, n.config, n.accessTokens) listenAddr: = env.String ("LISTEN") N.config.ApiAddress) env.Parse () n.api.StartServer (* listenAddr)} func (n * Node) OnStart () error {if n.miningEnable {n.cpuMiner.Start ()} n.syncManager.Start () n.initAndstartApiServer () if! n.config.Web.Closed {lanchWebBroser ()} return nil}
OnStart () starts the node process as follows:
Start the mining function
Start P2P network synchronization
Start the apiserver service for http protocol
Open a browser to access the transaction page of bytond
Stop node
Bytomd executes the n.RunForever () function at startup, which starts the function of listening for signals by the tendermint framework: * * vendor/github.com/tendermint/tmlibs/common/os.go * *
Func TrapSignal (cb func ()) {c: = make (chan os.Signal, 1) signal.Notify (c, os.Interrupt, syscall.SIGTERM) go func () {for sig: = range c {fmt.Printf ("captured% v, exiting...\ n" Sig) if cb! = nil {cb ()} os.Exit (1)} () select {}}
The TrapSignal function listens for SIGTERM signals so that bytomd can become a daemon that does not exit. Only when ctrl+c or kill bytomd_pid is triggered can the bytomd process exit be terminated. When exiting, bytomd performs the following actions: * * node/node.go * *
Func (n * Node) OnStop () {n.BaseService.OnStop () if n.miningEnable {n.cpuMiner.Stop ()} n.syncManager.Stop () log.Info ("Stopping Node") / / TODO: gracefully disconnect from peers.}
Bytomd will stop the mining function, P2P network and other operations.
This is the end of the content of "what is the method of starting and stopping Bytom". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.