discovery: start sending timestamps if requested

This commit is contained in:
Elle Mouton committed 2023-12-11 09:12:05 +02:00
1 parent 0ad4ef373a
commit 67df687f08
3 files changed
+35 -7

No files matched your search

+25 -1
View File
@@ -1027,12 +1027,18 @@ func (g *GossipSyncer) replyChanRangeQuery(query *lnwire.QueryChannelRange) erro
"num_blocks=%v", g.cfg.peerPub[:], query.FirstBlockHeight,
query.NumBlocks)
// Check if the query asked for timestamps. We will only serve
// timestamps if this has not been disabled with
// noTimestampQueryOption.
withTimestamps := query.WithTimestamps() &&
!g.cfg.noTimestampQueryOption
// Next, we'll consult the time series to obtain the set of known
// channel ID's that match their query.
startBlock := query.FirstBlockHeight
endBlock := query.LastBlockHeight()
channelRanges, err := g.cfg.channelSeries.FilterChannelRange(
query.ChainHash, startBlock, endBlock,
query.ChainHash, startBlock, endBlock, withTimestamps,
)
if err != nil {
return err
@@ -1058,9 +1064,26 @@ func (g *GossipSyncer) replyChanRangeQuery(query *lnwire.QueryChannelRange) erro
complete = 1
}
var timestamps lnwire.Timestamps
if withTimestamps {
timestamps = make(lnwire.Timestamps, len(channelChunk))
}
scids := make([]lnwire.ShortChannelID, len(channelChunk))
for i, info := range channelChunk {
scids[i] = info.ShortChannelID
if !withTimestamps {
continue
}
timestamps[i].Timestamp1 = uint32(
info.Node1UpdateTimestamp.Unix(),
)
timestamps[i].Timestamp2 = uint32(
info.Node2UpdateTimestamp.Unix(),
)
}
return g.cfg.sendToPeerSync(&lnwire.ReplyChannelRange{
@@ -1070,6 +1093,7 @@ func (g *GossipSyncer) replyChanRangeQuery(query *lnwire.QueryChannelRange) erro
Complete: complete,
EncodingType: g.cfg.encodingType,
ShortChanIDs: scids,
Timestamps: timestamps,
})
}