discovery: limit NumBlocks to best known height for outgoing QueryChannelRange

This is done to ensure we don't receive replies for channels in blocks
not currently known to us, which we wouldn't be able to process.
This commit is contained in:
Wilmer Paulino
2020-12-02 15:15:35 -08:00
parent 592a0c5699
commit c5fc7334a4
5 changed files with 54 additions and 23 deletions

View File

@@ -2,7 +2,6 @@ package discovery
import (
"fmt"
"math"
"reflect"
"sync/atomic"
"testing"
@@ -34,6 +33,9 @@ func newTestSyncManager(numActiveSyncers int) *SyncManager {
RotateTicker: ticker.NewForce(DefaultSyncerRotationInterval),
HistoricalSyncTicker: ticker.NewForce(DefaultHistoricalSyncInterval),
NumActiveSyncers: numActiveSyncers,
BestHeight: func() uint32 {
return latestKnownHeight
},
})
}
@@ -202,7 +204,7 @@ func TestSyncManagerInitialHistoricalSync(t *testing.T) {
syncMgr.InitSyncState(peer)
assertMsgSent(t, peer, &lnwire.QueryChannelRange{
FirstBlockHeight: 0,
NumBlocks: math.MaxUint32,
NumBlocks: latestKnownHeight,
})
// The graph should not be considered as synced since the initial
@@ -290,7 +292,7 @@ func TestSyncManagerForceHistoricalSync(t *testing.T) {
syncMgr.InitSyncState(peer)
assertMsgSent(t, peer, &lnwire.QueryChannelRange{
FirstBlockHeight: 0,
NumBlocks: math.MaxUint32,
NumBlocks: latestKnownHeight,
})
// If an additional peer connects, then a historical sync should not be
@@ -305,7 +307,7 @@ func TestSyncManagerForceHistoricalSync(t *testing.T) {
syncMgr.cfg.HistoricalSyncTicker.(*ticker.Force).Force <- time.Time{}
assertMsgSent(t, extraPeer, &lnwire.QueryChannelRange{
FirstBlockHeight: 0,
NumBlocks: math.MaxUint32,
NumBlocks: latestKnownHeight,
})
}
@@ -326,7 +328,7 @@ func TestSyncManagerGraphSyncedAfterHistoricalSyncReplacement(t *testing.T) {
syncMgr.InitSyncState(peer)
assertMsgSent(t, peer, &lnwire.QueryChannelRange{
FirstBlockHeight: 0,
NumBlocks: math.MaxUint32,
NumBlocks: latestKnownHeight,
})
// The graph should not be considered as synced since the initial
@@ -531,7 +533,7 @@ func assertTransitionToChansSynced(t *testing.T, s *GossipSyncer, peer *mockPeer
query := &lnwire.QueryChannelRange{
FirstBlockHeight: 0,
NumBlocks: math.MaxUint32,
NumBlocks: latestKnownHeight,
}
assertMsgSent(t, peer, query)