mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-05-30 01:30:11 +02:00
discovery: start sending timestamps if requested
This commit is contained in:
parent
0ad4ef373a
commit
67df687f08
@ -43,8 +43,8 @@ type ChannelGraphTimeSeries interface {
|
||||
// between the start height and the end height. The channel IDs are
|
||||
// grouped by their common block height. We'll use this to to a remote
|
||||
// peer's QueryChannelRange message.
|
||||
FilterChannelRange(chain chainhash.Hash,
|
||||
startHeight, endHeight uint32) ([]channeldb.BlockChannelRange, error)
|
||||
FilterChannelRange(chain chainhash.Hash, startHeight, endHeight uint32,
|
||||
withTimestamps bool) ([]channeldb.BlockChannelRange, error)
|
||||
|
||||
// FetchChanAnns returns a full set of channel announcements as well as
|
||||
// their updates that match the set of specified short channel ID's.
|
||||
@ -226,10 +226,13 @@ func (c *ChanSeries) FilterKnownChanIDs(chain chainhash.Hash,
|
||||
// message.
|
||||
//
|
||||
// NOTE: This is part of the ChannelGraphTimeSeries interface.
|
||||
func (c *ChanSeries) FilterChannelRange(chain chainhash.Hash,
|
||||
startHeight, endHeight uint32) ([]channeldb.BlockChannelRange, error) {
|
||||
func (c *ChanSeries) FilterChannelRange(_ chainhash.Hash, startHeight,
|
||||
endHeight uint32, withTimestamps bool) ([]channeldb.BlockChannelRange,
|
||||
error) {
|
||||
|
||||
return c.graph.FilterChannelRange(startHeight, endHeight, false)
|
||||
return c.graph.FilterChannelRange(
|
||||
startHeight, endHeight, withTimestamps,
|
||||
)
|
||||
}
|
||||
|
||||
// FetchChanAnns returns a full set of channel announcements as well as their
|
||||
|
@ -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,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -98,7 +98,8 @@ func (m *mockChannelGraphTimeSeries) FilterKnownChanIDs(chain chainhash.Hash,
|
||||
return <-m.filterResp, nil
|
||||
}
|
||||
func (m *mockChannelGraphTimeSeries) FilterChannelRange(chain chainhash.Hash,
|
||||
startHeight, endHeight uint32) ([]channeldb.BlockChannelRange, error) {
|
||||
startHeight, endHeight uint32, withTimestamps bool) (
|
||||
[]channeldb.BlockChannelRange, error) {
|
||||
|
||||
m.filterRangeReqs <- filterRangeReq{startHeight, endHeight}
|
||||
reply := <-m.filterRangeResp
|
||||
|
Loading…
x
Reference in New Issue
Block a user