mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-11-10 06:07:16 +01:00
multi: start asking for update timestamps in QueryChannelRange
This commit also adds a new `protocol.no-timestamp-query-option` option to disable the new behaviour.
This commit is contained in:
@@ -261,6 +261,11 @@ type Config struct {
|
||||
// gossip syncers will be passive.
|
||||
NumActiveSyncers int
|
||||
|
||||
// NoTimestampQueries will prevent the GossipSyncer from querying
|
||||
// timestamps of announcement messages from the peer and from replying
|
||||
// to timestamp queries.
|
||||
NoTimestampQueries bool
|
||||
|
||||
// RotateTicker is a ticker responsible for notifying the SyncManager
|
||||
// when it should rotate its active syncers. A single active syncer with
|
||||
// a chansSynced state will be exchanged for a passive syncer in order
|
||||
@@ -510,6 +515,7 @@ func New(cfg Config, selfKeyDesc *keychain.KeyDescriptor) *AuthenticatedGossiper
|
||||
RotateTicker: cfg.RotateTicker,
|
||||
HistoricalSyncTicker: cfg.HistoricalSyncTicker,
|
||||
NumActiveSyncers: cfg.NumActiveSyncers,
|
||||
NoTimestampQueries: cfg.NoTimestampQueries,
|
||||
IgnoreHistoricalFilters: cfg.IgnoreHistoricalFilters,
|
||||
BestHeight: gossiper.latestHeight,
|
||||
PinnedSyncers: cfg.PinnedSyncers,
|
||||
|
||||
@@ -73,6 +73,11 @@ type SyncManagerCfg struct {
|
||||
// gossip syncers will be passive.
|
||||
NumActiveSyncers int
|
||||
|
||||
// NoTimestampQueries will prevent the GossipSyncer from querying
|
||||
// timestamps of announcement messages from the peer and from responding
|
||||
// to timestamp queries
|
||||
NoTimestampQueries bool
|
||||
|
||||
// RotateTicker is a ticker responsible for notifying the SyncManager
|
||||
// when it should rotate its active syncers. A single active syncer with
|
||||
// a chansSynced state will be exchanged for a passive syncer in order
|
||||
@@ -495,6 +500,7 @@ func (m *SyncManager) createGossipSyncer(peer lnpeer.Peer) *GossipSyncer {
|
||||
bestHeight: m.cfg.BestHeight,
|
||||
markGraphSynced: m.markGraphSynced,
|
||||
maxQueryChanRangeReplies: maxQueryChanRangeReplies,
|
||||
noTimestampQueryOption: m.cfg.NoTimestampQueries,
|
||||
})
|
||||
|
||||
// Gossip syncers are initialized by default in a PassiveSync type
|
||||
|
||||
@@ -277,6 +277,7 @@ func TestSyncManagerInitialHistoricalSync(t *testing.T) {
|
||||
assertMsgSent(t, peer, &lnwire.QueryChannelRange{
|
||||
FirstBlockHeight: 0,
|
||||
NumBlocks: latestKnownHeight,
|
||||
QueryOptions: lnwire.NewTimestampQueryOption(),
|
||||
})
|
||||
|
||||
// The graph should not be considered as synced since the initial
|
||||
@@ -379,6 +380,7 @@ func TestSyncManagerForceHistoricalSync(t *testing.T) {
|
||||
assertMsgSent(t, peer, &lnwire.QueryChannelRange{
|
||||
FirstBlockHeight: 0,
|
||||
NumBlocks: latestKnownHeight,
|
||||
QueryOptions: lnwire.NewTimestampQueryOption(),
|
||||
})
|
||||
|
||||
// If an additional peer connects, then a historical sync should not be
|
||||
@@ -394,6 +396,7 @@ func TestSyncManagerForceHistoricalSync(t *testing.T) {
|
||||
assertMsgSent(t, extraPeer, &lnwire.QueryChannelRange{
|
||||
FirstBlockHeight: 0,
|
||||
NumBlocks: latestKnownHeight,
|
||||
QueryOptions: lnwire.NewTimestampQueryOption(),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -415,6 +418,7 @@ func TestSyncManagerGraphSyncedAfterHistoricalSyncReplacement(t *testing.T) {
|
||||
assertMsgSent(t, peer, &lnwire.QueryChannelRange{
|
||||
FirstBlockHeight: 0,
|
||||
NumBlocks: latestKnownHeight,
|
||||
QueryOptions: lnwire.NewTimestampQueryOption(),
|
||||
})
|
||||
|
||||
// The graph should not be considered as synced since the initial
|
||||
@@ -620,6 +624,7 @@ func assertTransitionToChansSynced(t *testing.T, s *GossipSyncer, peer *mockPeer
|
||||
query := &lnwire.QueryChannelRange{
|
||||
FirstBlockHeight: 0,
|
||||
NumBlocks: latestKnownHeight,
|
||||
QueryOptions: lnwire.NewTimestampQueryOption(),
|
||||
}
|
||||
assertMsgSent(t, peer, query)
|
||||
|
||||
|
||||
@@ -271,6 +271,11 @@ type gossipSyncerCfg struct {
|
||||
// peer.
|
||||
noReplyQueries bool
|
||||
|
||||
// noTimestampQueryOption will prevent the GossipSyncer from querying
|
||||
// timestamps of announcement messages from the peer, and it will
|
||||
// prevent it from responding to timestamp queries.
|
||||
noTimestampQueryOption bool
|
||||
|
||||
// ignoreHistoricalFilters will prevent syncers from replying with
|
||||
// historical data when the remote peer sets a gossip_timestamp_range.
|
||||
// This prevents ranges with old start times from causing us to dump the
|
||||
@@ -922,7 +927,7 @@ func (g *GossipSyncer) genChanRangeQuery(
|
||||
case newestChan.BlockHeight <= chanRangeQueryBuffer:
|
||||
startHeight = 0
|
||||
default:
|
||||
startHeight = uint32(newestChan.BlockHeight - chanRangeQueryBuffer)
|
||||
startHeight = newestChan.BlockHeight - chanRangeQueryBuffer
|
||||
}
|
||||
|
||||
// Determine the number of blocks to request based on our best height.
|
||||
@@ -945,6 +950,11 @@ func (g *GossipSyncer) genChanRangeQuery(
|
||||
FirstBlockHeight: startHeight,
|
||||
NumBlocks: numBlocks,
|
||||
}
|
||||
|
||||
if !g.cfg.noTimestampQueryOption {
|
||||
query.QueryOptions = lnwire.NewTimestampQueryOption()
|
||||
}
|
||||
|
||||
g.curQueryRangeMsg = query
|
||||
|
||||
return query, nil
|
||||
|
||||
@@ -160,23 +160,30 @@ func newTestSyncer(hID lnwire.ShortChannelID,
|
||||
flags ...bool) (chan []lnwire.Message,
|
||||
*GossipSyncer, *mockChannelGraphTimeSeries) {
|
||||
|
||||
syncChannels := true
|
||||
replyQueries := true
|
||||
var (
|
||||
syncChannels = true
|
||||
replyQueries = true
|
||||
timestamps = false
|
||||
)
|
||||
if len(flags) > 0 {
|
||||
syncChannels = flags[0]
|
||||
}
|
||||
if len(flags) > 1 {
|
||||
replyQueries = flags[1]
|
||||
}
|
||||
if len(flags) > 2 {
|
||||
timestamps = flags[2]
|
||||
}
|
||||
|
||||
msgChan := make(chan []lnwire.Message, 20)
|
||||
cfg := gossipSyncerCfg{
|
||||
channelSeries: newMockChannelGraphTimeSeries(hID),
|
||||
encodingType: encodingType,
|
||||
chunkSize: chunkSize,
|
||||
batchSize: chunkSize,
|
||||
noSyncChannels: !syncChannels,
|
||||
noReplyQueries: !replyQueries,
|
||||
channelSeries: newMockChannelGraphTimeSeries(hID),
|
||||
encodingType: encodingType,
|
||||
chunkSize: chunkSize,
|
||||
batchSize: chunkSize,
|
||||
noSyncChannels: !syncChannels,
|
||||
noReplyQueries: !replyQueries,
|
||||
noTimestampQueryOption: !timestamps,
|
||||
sendToPeer: func(msgs ...lnwire.Message) error {
|
||||
msgChan <- msgs
|
||||
return nil
|
||||
@@ -2250,7 +2257,7 @@ func TestGossipSyncerHistoricalSync(t *testing.T) {
|
||||
// historical sync requests in this state.
|
||||
msgChan, syncer, _ := newTestSyncer(
|
||||
lnwire.ShortChannelID{BlockHeight: latestKnownHeight},
|
||||
defaultEncoding, defaultChunkSize,
|
||||
defaultEncoding, defaultChunkSize, true, true, true,
|
||||
)
|
||||
syncer.setSyncType(PassiveSync)
|
||||
syncer.setSyncState(chansSynced)
|
||||
@@ -2265,6 +2272,7 @@ func TestGossipSyncerHistoricalSync(t *testing.T) {
|
||||
expectedMsg := &lnwire.QueryChannelRange{
|
||||
FirstBlockHeight: 0,
|
||||
NumBlocks: latestKnownHeight,
|
||||
QueryOptions: lnwire.NewTimestampQueryOption(),
|
||||
}
|
||||
|
||||
select {
|
||||
|
||||
Reference in New Issue
Block a user