discovery: introduce GossipSyncer signal delivery of chansSynced state
In this commit, we introduce another feature to the GossipSyncer in which it can deliver a signal to an external caller once it reaches its terminal chansSynced state. This is yet to be used, but will serve useful with a round-robin sync mechanism, where we wait for to finish syncing with a specific peer before moving on to the next.
This commit is contained in:
2 files changed
+79
No files matched your search
@@ -2140,3 +2140,53 @@ func TestGossipSyncerHistoricalSync(t *testing.T) {
|
||||
t.Fatalf("expected to send a lnwire.QueryChannelRange message")
|
||||
}
|
||||
}
|
||||
|
||||
// TestGossipSyncerSyncedSignal ensures that we receive a signal when a gossip
|
||||
// syncer reaches its terminal chansSynced state.
|
||||
func TestGossipSyncerSyncedSignal(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// We'll create a new gossip syncer and manually override its state to
|
||||
// chansSynced.
|
||||
_, syncer, _ := newTestSyncer(
|
||||
lnwire.NewShortChanIDFromInt(10), defaultEncoding,
|
||||
defaultChunkSize,
|
||||
)
|
||||
syncer.setSyncState(chansSynced)
|
||||
|
||||
// We'll go ahead and request a signal to be notified of when it reaches
|
||||
// this state.
|
||||
signalChan := syncer.ResetSyncedSignal()
|
||||
|
||||
// Starting the gossip syncer should cause the signal to be delivered.
|
||||
syncer.Start()
|
||||
|
||||
select {
|
||||
case <-signalChan:
|
||||
case <-time.After(time.Second):
|
||||
t.Fatal("expected to receive chansSynced signal")
|
||||
}
|
||||
|
||||
syncer.Stop()
|
||||
|
||||
// We'll try this again, but this time we'll request the signal after
|
||||
// the syncer is active and has already reached its chansSynced state.
|
||||
_, syncer, _ = newTestSyncer(
|
||||
lnwire.NewShortChanIDFromInt(10), defaultEncoding,
|
||||
defaultChunkSize,
|
||||
)
|
||||
|
||||
syncer.setSyncState(chansSynced)
|
||||
|
||||
syncer.Start()
|
||||
defer syncer.Stop()
|
||||
|
||||
signalChan = syncer.ResetSyncedSignal()
|
||||
|
||||
// The signal should be delivered immediately.
|
||||
select {
|
||||
case <-signalChan:
|
||||
case <-time.After(time.Second):
|
||||
t.Fatal("expected to receive chansSynced signal")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user