From 340414356d2f67e0f4fcb66b4ee60ca87c0c9153 Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Fri, 29 Jan 2021 00:13:50 -0800 Subject: [PATCH] discovery: perform initial historical sync for pinned peers --- discovery/sync_manager.go | 6 +++++- discovery/sync_manager_test.go | 2 ++ discovery/syncer.go | 17 ++++++++++++++++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/discovery/sync_manager.go b/discovery/sync_manager.go index 4c636b6b7..ca54e614a 100644 --- a/discovery/sync_manager.go +++ b/discovery/sync_manager.go @@ -266,7 +266,9 @@ func (m *SyncManager) syncerHandler() { // For pinned syncers, we will immediately transition // the peer into an active (pinned) sync state. case isPinnedSyncer: + attemptHistoricalSync = true s.setSyncType(PinnedSync) + s.setSyncState(syncerIdle) m.pinnedActiveSyncers[s.cfg.peerPub] = s // Regardless of whether the initial historical sync @@ -331,7 +333,9 @@ func (m *SyncManager) syncerHandler() { // keep track of the corresponding syncer to properly // handle disconnects. We'll also use a signal to know // when the historical sync completed. - setInitialHistoricalSyncer(s) + if !isPinnedSyncer { + setInitialHistoricalSyncer(s) + } // An existing peer has disconnected, so we'll tear down its // corresponding GossipSyncer. diff --git a/discovery/sync_manager_test.go b/discovery/sync_manager_test.go index 3eb97b4e6..b016bdafd 100644 --- a/discovery/sync_manager_test.go +++ b/discovery/sync_manager_test.go @@ -90,6 +90,8 @@ func TestSyncManagerNumActiveSyncers(t *testing.T) { require.NoError(t, err) s := assertSyncerExistence(t, syncMgr, peer) + assertTransitionToChansSynced(t, s, peer) + assertActiveGossipTimestampRange(t, peer) assertSyncerStatus(t, s, chansSynced, PinnedSync) } diff --git a/discovery/syncer.go b/discovery/syncer.go index 6d137d712..388be6806 100644 --- a/discovery/syncer.go +++ b/discovery/syncer.go @@ -115,6 +115,12 @@ const ( // AuthenticatedGossiper, and decide if we should forward them to our // target peer based on its update horizon. chansSynced + + // syncerIdle is a state in which the gossip syncer can handle external + // requests to transition or perform historical syncs. It is used as the + // initial state for pinned syncers, as well as a fallthrough case for + // chansSynced allowing fully synced peers to facilitate requests. + syncerIdle ) // String returns a human readable string describing the target syncerState. @@ -135,6 +141,9 @@ func (s syncerState) String() string { case chansSynced: return "chansSynced" + case syncerIdle: + return "syncerIdle" + default: return "UNKNOWN STATE" } @@ -592,10 +601,16 @@ func (g *GossipSyncer) channelGraphSyncer() { g.cfg.peerPub, err) } } - // With our horizon set, we'll simply reply to any new // messages or process any state transitions and exit if // needed. + fallthrough + + // Pinned peers will begin in this state, since they will + // immediately receive a request to perform a historical sync. + // Otherwise, we fall through after ending in chansSynced to + // facilitate new requests. + case syncerIdle: select { case req := <-g.syncTransitionReqs: req.errChan <- g.handleSyncTransition(req)