From ef0cd82c1f30cfd85dfa4c027b5d19948ca6fe04 Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Fri, 29 Jan 2021 00:13:16 -0800 Subject: [PATCH] discovery/sync_manager: make setHistoricalSyncer closure --- discovery/sync_manager.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/discovery/sync_manager.go b/discovery/sync_manager.go index 62137fa0..782f5edf 100644 --- a/discovery/sync_manager.go +++ b/discovery/sync_manager.go @@ -214,6 +214,11 @@ func (m *SyncManager) syncerHandler() { initialHistoricalSyncSignal chan struct{} ) + setHistoricalSyncer := func(s *GossipSyncer) { + initialHistoricalSyncer = s + initialHistoricalSyncSignal = s.ResetSyncedSignal() + } + for { select { // A new peer has been connected, so we'll create its @@ -297,8 +302,7 @@ 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. - initialHistoricalSyncer = s - initialHistoricalSyncSignal = s.ResetSyncedSignal() + setHistoricalSyncer(s) // An existing peer has disconnected, so we'll tear down its // corresponding GossipSyncer. @@ -337,8 +341,7 @@ func (m *SyncManager) syncerHandler() { "GossipSyncer(%v) with GossipSyncer(%x)", staleSyncer.peer, s.cfg.peerPub) - initialHistoricalSyncer = s - initialHistoricalSyncSignal = s.ResetSyncedSignal() + setHistoricalSyncer(s) // Our initial historical sync signal has completed, so we'll // nil all of the relevant fields as they're no longer needed. @@ -398,8 +401,7 @@ func (m *SyncManager) syncerHandler() { // where our previous historical sync peer did not // respond to our queries and we haven't ingested as // much of the graph as we should. - initialHistoricalSyncer = s - initialHistoricalSyncSignal = s.ResetSyncedSignal() + setHistoricalSyncer(s) case <-m.quit: return