discovery: don't historical sync when NumActiveSyncers == 0

Currently when numgraphsyncpeers=0, lnd will still attempt to perform
an initial historical sync. We change this behavior here to forgoe
historical sync entirely when numgraphsyncpeers is zero, since the
routing table isn't being updated anyway while the node is active.

This permits a no-graph lnd mode where no syncing occurs at all.
This commit is contained in:
Conner Fromknecht
2021-01-22 13:01:29 -08:00
parent 5cec468ff4
commit 58e924ad1c
3 changed files with 59 additions and 6 deletions

View File

@@ -279,7 +279,8 @@ func (m *SyncManager) syncerHandler() {
case len(m.activeSyncers) == 0 &&
len(m.inactiveSyncers) == 0:
attemptHistoricalSync = true
attemptHistoricalSync =
m.cfg.NumActiveSyncers > 0
fallthrough
// If we've exceeded our total number of active syncers,
@@ -353,6 +354,8 @@ func (m *SyncManager) syncerHandler() {
case initialHistoricalSyncer == nil:
fallthrough
case staleSyncer.peer != initialHistoricalSyncer.cfg.peerPub:
fallthrough
case m.cfg.NumActiveSyncers == 0:
continue
}
@@ -414,6 +417,16 @@ func (m *SyncManager) syncerHandler() {
// Our HistoricalSyncTicker has ticked, so we'll randomly select
// a peer and force a historical sync with them.
case <-m.cfg.HistoricalSyncTicker.Ticks():
// To be extra cautious, gate the forceHistoricalSync
// call such that it can only execute if we are
// configured to have a non-zero number of sync peers.
// This way even if the historical sync ticker manages
// to tick we can be sure that a historical sync won't
// accidentally begin.
if m.cfg.NumActiveSyncers == 0 {
continue
}
// If we don't have a syncer available we have nothing
// to do.
s := m.forceHistoricalSync()