Merge pull request #9643 from yyforyongyu/fix-startup

lnd: make sure startup flow is not aborted
This commit is contained in:
Oliver Gugger authored and GitHub committed 2025-03-26 07:56:46 -06:00
commit f48e5098b1
2 files changed
+28 -6

No files matched your search

@@ -107,6 +107,10 @@
keysend payment would not fail properly and only resolve after restart. Now keysend payment would not fail properly and only resolve after restart. Now
keysend payment validation is stricter. keysend payment validation is stricter.
* [Make sure](https://github.com/lightningnetwork/lnd/pull/9643) the startup
process of the node won't be interrupted if a non-fatal error is returned from
the subsystems.
# New Features # New Features
* Add support for [archiving channel backup](https://github.com/lightningnetwork/lnd/pull/9232) * Add support for [archiving channel backup](https://github.com/lightningnetwork/lnd/pull/9232)
+24 -6
View File
@@ -2195,7 +2195,7 @@ func (c cleaner) add(cleanup func() error) cleaner {
func (c cleaner) run() { func (c cleaner) run() {
for i := len(c) - 1; i >= 0; i-- { for i := len(c) - 1; i >= 0; i-- {
if err := c[i](); err != nil { if err := c[i](); err != nil {
srvrLog.Infof("Cleanup failed: %v", err) srvrLog.Errorf("Cleanup failed: %v", err)
} }
} }
} }
@@ -2498,7 +2498,11 @@ func (s *server) Start() error {
// brontide.NewListener() is called in newServer. This means // brontide.NewListener() is called in newServer. This means
// that we are actually listening and partially accepting // that we are actually listening and partially accepting
// inbound connections even before the connMgr starts. // inbound connections even before the connMgr starts.
//
// TODO(yy): move the log into the connMgr's `Start` method.
srvrLog.Info("connMgr starting...")
s.connMgr.Start() s.connMgr.Start()
srvrLog.Debug("connMgr started")
// If peers are specified as a config option, we'll add those // If peers are specified as a config option, we'll add those
// peers first. // peers first.
@@ -2540,6 +2544,9 @@ func (s *server) Start() error {
// Subscribe to NodeAnnouncements that advertise new addresses // Subscribe to NodeAnnouncements that advertise new addresses
// our persistent peers. // our persistent peers.
if err := s.updatePersistentPeerAddrs(); err != nil { if err := s.updatePersistentPeerAddrs(); err != nil {
srvrLog.Errorf("Failed to update persistent peer "+
"addr: %v", err)
startErr = err startErr = err
return return
} }
@@ -2551,12 +2558,15 @@ func (s *server) Start() error {
// to ensure we don't reconnect to any nodes we no longer have // to ensure we don't reconnect to any nodes we no longer have
// open channels with. // open channels with.
if err := s.chanStateDB.PruneLinkNodes(); err != nil { if err := s.chanStateDB.PruneLinkNodes(); err != nil {
srvrLog.Errorf("Failed to prune link nodes: %v", err)
startErr = err startErr = err
return return
} }
if err := s.establishPersistentConnections(); err != nil { if err := s.establishPersistentConnections(); err != nil {
startErr = err srvrLog.Errorf("Failed to establish persistent "+
return "connections: %v", err)
} }
// setSeedList is a helper function that turns multiple DNS seed // setSeedList is a helper function that turns multiple DNS seed
@@ -3535,8 +3545,9 @@ func (s *server) establishPersistentConnections() error {
// the reconnection port to the default peer port. // the reconnection port to the default peer port.
linkNodes, err := s.chanStateDB.LinkNodeDB().FetchAllLinkNodes() linkNodes, err := s.chanStateDB.LinkNodeDB().FetchAllLinkNodes()
if err != nil && err != channeldb.ErrLinkNodesNotFound { if err != nil && err != channeldb.ErrLinkNodesNotFound {
return err return fmt.Errorf("failed to fetch all link nodes: %w", err)
} }
for _, node := range linkNodes { for _, node := range linkNodes {
pubStr := string(node.IdentityPub.SerializeCompressed()) pubStr := string(node.IdentityPub.SerializeCompressed())
nodeAddrs := &nodeAddresses{ nodeAddrs := &nodeAddresses{
@@ -3551,7 +3562,7 @@ func (s *server) establishPersistentConnections() error {
// that have been added via NodeAnnouncement messages. // that have been added via NodeAnnouncement messages.
sourceNode, err := s.graphDB.SourceNode() sourceNode, err := s.graphDB.SourceNode()
if err != nil { if err != nil {
return err return fmt.Errorf("failed to fetch source node: %w", err)
} }
// TODO(roasbeef): instead iterate over link nodes and query graph for // TODO(roasbeef): instead iterate over link nodes and query graph for
@@ -3637,9 +3648,16 @@ func (s *server) establishPersistentConnections() error {
nodeAddrsMap[pubStr] = n nodeAddrsMap[pubStr] = n
return nil return nil
}) })
if err != nil && !errors.Is(err, graphdb.ErrGraphNoEdgesFound) { if err != nil {
srvrLog.Errorf("Failed to iterate channels for node %x",
sourceNode.PubKeyBytes)
if !errors.Is(err, graphdb.ErrGraphNoEdgesFound) &&
!errors.Is(err, graphdb.ErrEdgeNotFound) {
return err return err
} }
}
srvrLog.Debugf("Establishing %v persistent connections on start", srvrLog.Debugf("Establishing %v persistent connections on start",
len(nodeAddrsMap)) len(nodeAddrsMap))