From 1ad6bbfbc2b2d8e1bb8fa90ec6553839b01e91a7 Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Sat, 29 Jan 2022 22:47:50 +0800 Subject: [PATCH 1/3] multi: add logs when subservers are starting Also unified the log messages. --- chanbackup/pubsub.go | 2 +- chanfitness/chaneventstore.go | 2 ++ channelnotifier/channelnotifier.go | 2 +- contractcourt/breacharbiter.go | 3 +-- contractcourt/chain_arbitrator.go | 2 +- contractcourt/utxonursery.go | 2 +- discovery/gossiper.go | 3 +-- funding/manager.go | 3 +-- htlcswitch/hop/iterator.go | 1 + htlcswitch/htlcnotifier.go | 2 +- htlcswitch/switch.go | 2 +- invoices/invoiceregistry.go | 2 ++ lnwallet/sigpool.go | 1 + netann/chan_status_manager.go | 1 + netann/host_ann.go | 1 + routing/router.go | 2 +- sweep/sweeper.go | 2 +- watchtower/wtclient/client.go | 2 +- 18 files changed, 20 insertions(+), 15 deletions(-) diff --git a/chanbackup/pubsub.go b/chanbackup/pubsub.go index 4eef45e1c9..3e1580ddd2 100644 --- a/chanbackup/pubsub.go +++ b/chanbackup/pubsub.go @@ -137,7 +137,7 @@ func NewSubSwapper(startingChans []Single, chanNotifier ChannelNotifier, func (s *SubSwapper) Start() error { var startErr error s.started.Do(func() { - log.Infof("Starting chanbackup.SubSwapper") + log.Infof("chanbackup.SubSwapper starting") // Before we enter our main loop, we'll update the on-disk // state with the latest Single state, as nodes may have new diff --git a/chanfitness/chaneventstore.go b/chanfitness/chaneventstore.go index d6a6347931..53a699932b 100644 --- a/chanfitness/chaneventstore.go +++ b/chanfitness/chaneventstore.go @@ -142,6 +142,8 @@ func NewChannelEventStore(config *Config) *ChannelEventStore { // information from the store. If this function fails, it cancels its existing // subscriptions and returns an error. func (c *ChannelEventStore) Start() error { + log.Info("ChannelEventStore starting") + // Create a subscription to channel events. channelClient, err := c.cfg.SubscribeChannelEvents() if err != nil { diff --git a/channelnotifier/channelnotifier.go b/channelnotifier/channelnotifier.go index 2cf6015c4d..7c6cc30955 100644 --- a/channelnotifier/channelnotifier.go +++ b/channelnotifier/channelnotifier.go @@ -87,7 +87,7 @@ func New(chanDB *channeldb.ChannelStateDB) *ChannelNotifier { func (c *ChannelNotifier) Start() error { var err error c.started.Do(func() { - log.Trace("ChannelNotifier starting") + log.Info("ChannelNotifier starting") err = c.ntfnServer.Start() }) return err diff --git a/contractcourt/breacharbiter.go b/contractcourt/breacharbiter.go index 6f160141bc..479c0b8ae8 100644 --- a/contractcourt/breacharbiter.go +++ b/contractcourt/breacharbiter.go @@ -206,14 +206,13 @@ func NewBreachArbiter(cfg *BreachConfig) *BreachArbiter { func (b *BreachArbiter) Start() error { var err error b.started.Do(func() { + brarLog.Info("Breach arbiter starting") err = b.start() }) return err } func (b *BreachArbiter) start() error { - brarLog.Tracef("Starting breach arbiter") - // Load all retributions currently persisted in the retribution store. var breachRetInfos map[wire.OutPoint]retributionInfo if err := b.cfg.Store.ForAll(func(ret *retributionInfo) error { diff --git a/contractcourt/chain_arbitrator.go b/contractcourt/chain_arbitrator.go index ba007ea6ba..02a48a6493 100644 --- a/contractcourt/chain_arbitrator.go +++ b/contractcourt/chain_arbitrator.go @@ -487,7 +487,7 @@ func (c *ChainArbitrator) Start() error { return nil } - log.Tracef("Starting ChainArbitrator") + log.Info("ChainArbitrator starting") // First, we'll fetch all the channels that are still open, in order to // collect them within our set of active contracts. diff --git a/contractcourt/utxonursery.go b/contractcourt/utxonursery.go index d5cc31a796..5a964c418c 100644 --- a/contractcourt/utxonursery.go +++ b/contractcourt/utxonursery.go @@ -241,7 +241,7 @@ func (u *UtxoNursery) Start() error { return nil } - utxnLog.Tracef("Starting UTXO nursery") + utxnLog.Info("UTXO nursery starting") // Retrieve the currently best known block. This is needed to have the // state machine catch up with the blocks we missed when we were down. diff --git a/discovery/gossiper.go b/discovery/gossiper.go index b463a0b24f..f5deee56cf 100644 --- a/discovery/gossiper.go +++ b/discovery/gossiper.go @@ -498,14 +498,13 @@ func (d *AuthenticatedGossiper) PropagateChanPolicyUpdate( func (d *AuthenticatedGossiper) Start() error { var err error d.started.Do(func() { + log.Info("Authenticated Gossiper starting") err = d.start() }) return err } func (d *AuthenticatedGossiper) start() error { - log.Info("Authenticated Gossiper is starting") - // First we register for new notifications of newly discovered blocks. // We do this immediately so we'll later be able to consume any/all // blocks which were discovered. diff --git a/funding/manager.go b/funding/manager.go index 6306f7d912..0db0ccd2ca 100644 --- a/funding/manager.go +++ b/funding/manager.go @@ -588,14 +588,13 @@ func NewFundingManager(cfg Config) (*Manager, error) { func (f *Manager) Start() error { var err error f.started.Do(func() { + log.Info("Funding manager starting") err = f.start() }) return err } func (f *Manager) start() error { - log.Tracef("Funding manager running") - // Upon restart, the Funding Manager will check the database to load any // channels that were waiting for their funding transactions to be // confirmed on the blockchain at the time when the daemon last went diff --git a/htlcswitch/hop/iterator.go b/htlcswitch/hop/iterator.go index 20963bd7b9..45a084755c 100644 --- a/htlcswitch/hop/iterator.go +++ b/htlcswitch/hop/iterator.go @@ -132,6 +132,7 @@ func NewOnionProcessor(router *sphinx.Router) *OnionProcessor { // Start spins up the onion processor's sphinx router. func (p *OnionProcessor) Start() error { + log.Info("Onion processor starting") return p.router.Start() } diff --git a/htlcswitch/htlcnotifier.go b/htlcswitch/htlcnotifier.go index fd067e2b48..00bba71132 100644 --- a/htlcswitch/htlcnotifier.go +++ b/htlcswitch/htlcnotifier.go @@ -81,7 +81,7 @@ func NewHtlcNotifier(now func() time.Time) *HtlcNotifier { func (h *HtlcNotifier) Start() error { var err error h.started.Do(func() { - log.Trace("HtlcNotifier starting") + log.Info("HtlcNotifier starting") err = h.ntfnServer.Start() }) return err diff --git a/htlcswitch/switch.go b/htlcswitch/switch.go index 860076d4dd..a501abf403 100644 --- a/htlcswitch/switch.go +++ b/htlcswitch/switch.go @@ -1846,7 +1846,7 @@ func (s *Switch) Start() error { return errors.New("htlc switch already started") } - log.Infof("Starting HTLC Switch") + log.Infof("HTLC Switch starting") blockEpochStream, err := s.cfg.Notifier.RegisterBlockEpochNtfn(nil) if err != nil { diff --git a/invoices/invoiceregistry.go b/invoices/invoiceregistry.go index 6ba3b23861..11eca9dd35 100644 --- a/invoices/invoiceregistry.go +++ b/invoices/invoiceregistry.go @@ -238,6 +238,8 @@ func (i *InvoiceRegistry) Start() error { return err } + log.Info("InvoiceRegistry starting") + i.wg.Add(1) go i.invoiceEventLoop() diff --git a/lnwallet/sigpool.go b/lnwallet/sigpool.go index ec1d4f3462..cf174df143 100644 --- a/lnwallet/sigpool.go +++ b/lnwallet/sigpool.go @@ -155,6 +155,7 @@ func NewSigPool(numWorkers int, signer input.Signer) *SigPool { // carry out its duties. func (s *SigPool) Start() error { s.started.Do(func() { + walletLog.Info("SigPool starting") for i := 0; i < s.numWorkers; i++ { s.wg.Add(1) go s.poolWorker() diff --git a/netann/chan_status_manager.go b/netann/chan_status_manager.go index fc2b94c05a..4e05be7df8 100644 --- a/netann/chan_status_manager.go +++ b/netann/chan_status_manager.go @@ -172,6 +172,7 @@ func NewChanStatusManager(cfg *ChanStatusConfig) (*ChanStatusManager, error) { func (m *ChanStatusManager) Start() error { var err error m.started.Do(func() { + log.Info("Channel Status Manager starting") err = m.start() }) return err diff --git a/netann/host_ann.go b/netann/host_ann.go index c96b1af8ec..bc50289c12 100644 --- a/netann/host_ann.go +++ b/netann/host_ann.go @@ -58,6 +58,7 @@ func NewHostAnnouncer(cfg HostAnnouncerConfig) *HostAnnouncer { // Start starts the HostAnnouncer. func (h *HostAnnouncer) Start() error { h.startOnce.Do(func() { + log.Info("HostAnnouncer starting") h.wg.Add(1) go h.hostWatcher() }) diff --git a/routing/router.go b/routing/router.go index 27ae7bbd64..9b7a1f96de 100644 --- a/routing/router.go +++ b/routing/router.go @@ -490,7 +490,7 @@ func (r *ChannelRouter) Start() error { return nil } - log.Tracef("Channel Router starting") + log.Info("Channel Router starting") bestHash, bestHeight, err := r.cfg.Chain.GetBestBlock() if err != nil { diff --git a/sweep/sweeper.go b/sweep/sweeper.go index af067445ae..fa46a4dc15 100644 --- a/sweep/sweeper.go +++ b/sweep/sweeper.go @@ -338,7 +338,7 @@ func (s *UtxoSweeper) Start() error { return nil } - log.Tracef("Sweeper starting") + log.Info("Sweeper starting") // Retrieve last published tx from database. lastTx, err := s.cfg.Store.GetLastPublishedTx() diff --git a/watchtower/wtclient/client.go b/watchtower/wtclient/client.go index f81284d538..eabf00bea3 100644 --- a/watchtower/wtclient/client.go +++ b/watchtower/wtclient/client.go @@ -439,7 +439,7 @@ func (c *TowerClient) buildHighestCommitHeights() { func (c *TowerClient) Start() error { var err error c.started.Do(func() { - c.log.Infof("Starting watchtower client") + c.log.Infof("Watchtower client starting") // First, restart a session queue for any sessions that have // committed but unacked state updates. This ensures that these From 1aaa1d89bbab7f2ff5b2e2673751d67af7d30a5b Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Sun, 30 Jan 2022 00:01:58 +0800 Subject: [PATCH 2/3] funding: fix make lint --- funding/manager.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/funding/manager.go b/funding/manager.go index 0db0ccd2ca..28acd2f165 100644 --- a/funding/manager.go +++ b/funding/manager.go @@ -1234,7 +1234,7 @@ func (f *Manager) handleFundingOpen(peer lnpeer.Peer, if amt < f.cfg.MinChanSize { f.failFundingFlow( peer, msg.PendingChannelID, - lnwallet.ErrChanTooSmall(amt, btcutil.Amount(f.cfg.MinChanSize)), + lnwallet.ErrChanTooSmall(amt, f.cfg.MinChanSize), ) return } From 72548ea46325830f8a7e48d1f93c92a285d99507 Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Sun, 30 Jan 2022 12:14:37 +0800 Subject: [PATCH 3/3] server: start htlcSwitch before chainArb --- docs/release-notes/release-notes-0.15.0.md | 4 ++++ server.go | 15 +++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/docs/release-notes/release-notes-0.15.0.md b/docs/release-notes/release-notes-0.15.0.md index f2da8ee176..b88b70d9d5 100644 --- a/docs/release-notes/release-notes-0.15.0.md +++ b/docs/release-notes/release-notes-0.15.0.md @@ -36,6 +36,10 @@ could result in an "invoice too large" error when creating invoices. Hints are now properly limited to our maximum of 20. +* [Fixed an edge case where the lnd might be stuck at starting due to channel + arbitrator relying on htlcswitch to be started + first](https://github.com/lightningnetwork/lnd/pull/6214). + ## Misc * [An example systemd service file](https://github.com/lightningnetwork/lnd/pull/6033) diff --git a/server.go b/server.go index b729dc97cd..d36e013eb8 100644 --- a/server.go +++ b/server.go @@ -1777,6 +1777,15 @@ func (s *server) Start() error { } cleanup = cleanup.add(s.fundingMgr.Stop) + // htlcSwitch must be started before chainArb since the latter + // relies on htlcSwitch to deliver resolution message upon + // start. + if err := s.htlcSwitch.Start(); err != nil { + startErr = err + return + } + cleanup = cleanup.add(s.htlcSwitch.Stop) + if err := s.chainArb.Start(); err != nil { startErr = err return @@ -1807,12 +1816,6 @@ func (s *server) Start() error { } cleanup = cleanup.add(s.sphinx.Stop) - if err := s.htlcSwitch.Start(); err != nil { - startErr = err - return - } - cleanup = cleanup.add(s.htlcSwitch.Stop) - if err := s.chanStatusMgr.Start(); err != nil { startErr = err return