Skip to content

Commit 16a8b62

Browse files
committed
lnd: add new method startLowLevelServices
In this commit we start to break up the starting process into smaller pieces, which is needed in the following commit to initialize blockbeat consumers.
1 parent 545cea0 commit 16a8b62

File tree

1 file changed

+34
-6
lines changed

1 file changed

+34
-6
lines changed

server.go

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,17 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
666666
quit: make(chan struct{}),
667667
}
668668

669+
// Start the low-level services once they are initialized.
670+
//
671+
// TODO(yy): break the server startup into four steps,
672+
// 1. init the low-level services.
673+
// 2. start the low-level services.
674+
// 3. init the high-level services.
675+
// 4. start the high-level services.
676+
if err := s.startLowLevelServices(); err != nil {
677+
return nil, err
678+
}
679+
669680
currentHash, currentHeight, err := s.cc.ChainIO.GetBestBlock()
670681
if err != nil {
671682
return nil, err
@@ -2068,6 +2079,29 @@ func (c cleaner) run() {
20682079
}
20692080
}
20702081

2082+
// startLowLevelServices starts the low-level services of the server. These
2083+
// services must be started successfully before running the main server. The
2084+
// services are,
2085+
// 1. the chain notifier.
2086+
//
2087+
// TODO(yy): identify and add more low-level services here.
2088+
func (s *server) startLowLevelServices() error {
2089+
var startErr error
2090+
2091+
cleanup := cleaner{}
2092+
2093+
cleanup = cleanup.add(s.cc.ChainNotifier.Stop)
2094+
if err := s.cc.ChainNotifier.Start(); err != nil {
2095+
startErr = err
2096+
}
2097+
2098+
if startErr != nil {
2099+
cleanup.run()
2100+
}
2101+
2102+
return startErr
2103+
}
2104+
20712105
// Start starts the main daemon server, all requested listeners, and any helper
20722106
// goroutines.
20732107
// NOTE: This function is safe for concurrent access.
@@ -2133,12 +2167,6 @@ func (s *server) Start() error {
21332167
return
21342168
}
21352169

2136-
cleanup = cleanup.add(s.cc.ChainNotifier.Stop)
2137-
if err := s.cc.ChainNotifier.Start(); err != nil {
2138-
startErr = err
2139-
return
2140-
}
2141-
21422170
cleanup = cleanup.add(s.cc.BestBlockTracker.Stop)
21432171
if err := s.cc.BestBlockTracker.Start(); err != nil {
21442172
startErr = err

0 commit comments

Comments
 (0)