discovery: perform initial historical sync for pinned peers

This commit is contained in:
Conner Fromknecht 2021-01-29 00:13:50 -08:00
parent 2f0d56d539
commit 340414356d
No known key found for this signature in database
GPG Key ID: E7D737B67FA592C7
3 changed files with 23 additions and 2 deletions

View File

@ -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.

View File

@ -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)
}

View File

@ -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)