MCPcopy Create free account
hub / github.com/DeAI-Artist/Linkis / OnStart

Method OnStart

node/node.go:941–1004  ·  view source on GitHub ↗

OnStart starts the Node. It implements service.Service.

()

Source from the content-addressed store, hash-verified

939
940// OnStart starts the Node. It implements service.Service.
941func (n *Node) OnStart() error {
942 now := tmtime.Now()
943 genTime := n.genesisDoc.GenesisTime
944 if genTime.After(now) {
945 n.Logger.Info("Genesis time is in the future. Sleeping until then...", "genTime", genTime)
946 time.Sleep(genTime.Sub(now))
947 }
948
949 // Add private IDs to addrbook to block those peers being added
950 n.addrBook.AddPrivateIDs(splitAndTrimEmpty(n.config.P2P.PrivatePeerIDs, ",", " "))
951
952 // Start the RPC server before the P2P server
953 // so we can eg. receive txs for the first block
954 if n.config.RPC.ListenAddress != "" {
955 listeners, err := n.startRPC()
956 if err != nil {
957 return err
958 }
959 n.rpcListeners = listeners
960 }
961
962 if n.config.Instrumentation.Prometheus &&
963 n.config.Instrumentation.PrometheusListenAddr != "" {
964 n.prometheusSrv = n.startPrometheusServer(n.config.Instrumentation.PrometheusListenAddr)
965 }
966
967 // Start the transport.
968 addr, err := p2p.NewNetAddressString(p2p.IDAddressString(n.nodeKey.ID(), n.config.P2P.ListenAddress))
969 if err != nil {
970 return err
971 }
972 if err := n.transport.Listen(*addr); err != nil {
973 return err
974 }
975
976 n.isListening = true
977
978 // Start the switch (the P2P server).
979 err = n.sw.Start()
980 if err != nil {
981 return err
982 }
983
984 // Always connect to persistent peers
985 err = n.sw.DialPeersAsync(splitAndTrimEmpty(n.config.P2P.PersistentPeers, ",", " "))
986 if err != nil {
987 return fmt.Errorf("could not dial peers from persistent_peers field: %w", err)
988 }
989
990 // Run state sync
991 if n.stateSync {
992 bcR, ok := n.bcReactor.(fastSyncReactor)
993 if !ok {
994 return fmt.Errorf("this blockchain reactor does not support switching from state sync")
995 }
996 err := startStateSync(n.stateSyncReactor, bcR, n.consensusReactor, n.stateSyncProvider,
997 n.config.StateSync, n.config.FastSyncMode, n.stateStore, n.blockStore, n.stateSyncGenesis)
998 if err != nil {

Callers

nothing calls this directly

Calls 13

startRPCMethod · 0.95
startPrometheusServerMethod · 0.95
NewNetAddressStringFunction · 0.92
IDAddressStringFunction · 0.92
SubMethod · 0.80
splitAndTrimEmptyFunction · 0.70
startStateSyncFunction · 0.70
InfoMethod · 0.65
AddPrivateIDsMethod · 0.65
IDMethod · 0.65
ListenMethod · 0.65
StartMethod · 0.65

Tested by

no test coverage detected