Skip to content

Commit

Permalink
lnd: add new method startLowLevelServices
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
yyforyongyu committed Nov 12, 2024
1 parent 93da9d0 commit b8625eb
Showing 1 changed file with 34 additions and 6 deletions.
40 changes: 34 additions & 6 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,17 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
quit: make(chan struct{}),
}

// Start the low-level services once they are initialized.
//
// TODO(yy): break the server startup into four steps,
// 1. init the low-level services.
// 2. start the low-level services.
// 3. init the high-level services.
// 4. start the high-level services.
if err := s.startLowLevelServices(); err != nil {
return nil, err
}

currentHash, currentHeight, err := s.cc.ChainIO.GetBestBlock()
if err != nil {
return nil, err
Expand Down Expand Up @@ -2034,6 +2045,29 @@ func (c cleaner) run() {
}
}

// startLowLevelServices starts the low-level services of the server. These
// services must be started successfully before running the main server. The
// services are,
// 1. the chain notifier.
//
// TODO(yy): identify and add more low-level services here.
func (s *server) startLowLevelServices() error {
var startErr error

cleanup := cleaner{}

cleanup = cleanup.add(s.cc.ChainNotifier.Stop)
if err := s.cc.ChainNotifier.Start(); err != nil {
startErr = err
}

if startErr != nil {
cleanup.run()
}

return startErr
}

// Start starts the main daemon server, all requested listeners, and any helper
// goroutines.
// NOTE: This function is safe for concurrent access.
Expand Down Expand Up @@ -2099,12 +2133,6 @@ func (s *server) Start() error {
return
}

cleanup = cleanup.add(s.cc.ChainNotifier.Stop)
if err := s.cc.ChainNotifier.Start(); err != nil {
startErr = err
return
}

cleanup = cleanup.add(s.cc.BestBlockTracker.Stop)
if err := s.cc.BestBlockTracker.Start(); err != nil {
startErr = err
Expand Down

0 comments on commit b8625eb

Please sign in to comment.