mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-06-10 17:01:32 +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
|
// 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
|
// grouped by their common block height. We'll use this to to a remote
|
||||||
// peer's QueryChannelRange message.
|
// peer's QueryChannelRange message.
|
||||||
FilterChannelRange(chain chainhash.Hash,
|
FilterChannelRange(chain chainhash.Hash, startHeight, endHeight uint32,
|
||||||
startHeight, endHeight uint32) ([]channeldb.BlockChannelRange, error)
|
withTimestamps bool) ([]channeldb.BlockChannelRange, error)
|
||||||
|
|
||||||
// FetchChanAnns returns a full set of channel announcements as well as
|
// FetchChanAnns returns a full set of channel announcements as well as
|
||||||
// their updates that match the set of specified short channel ID's.
|
// their updates that match the set of specified short channel ID's.
|
||||||
@ -226,10 +226,13 @@ func (c *ChanSeries) FilterKnownChanIDs(chain chainhash.Hash,
|
|||||||
// message.
|
// message.
|
||||||
//
|
//
|
||||||
// NOTE: This is part of the ChannelGraphTimeSeries interface.
|
// NOTE: This is part of the ChannelGraphTimeSeries interface.
|
||||||
func (c *ChanSeries) FilterChannelRange(chain chainhash.Hash,
|
func (c *ChanSeries) FilterChannelRange(_ chainhash.Hash, startHeight,
|
||||||
startHeight, endHeight uint32) ([]channeldb.BlockChannelRange, error) {
|
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
|
// 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,
|
"num_blocks=%v", g.cfg.peerPub[:], query.FirstBlockHeight,
|
||||||
query.NumBlocks)
|
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
|
// Next, we'll consult the time series to obtain the set of known
|
||||||
// channel ID's that match their query.
|
// channel ID's that match their query.
|
||||||
startBlock := query.FirstBlockHeight
|
startBlock := query.FirstBlockHeight
|
||||||
endBlock := query.LastBlockHeight()
|
endBlock := query.LastBlockHeight()
|
||||||
channelRanges, err := g.cfg.channelSeries.FilterChannelRange(
|
channelRanges, err := g.cfg.channelSeries.FilterChannelRange(
|
||||||
query.ChainHash, startBlock, endBlock,
|
query.ChainHash, startBlock, endBlock, withTimestamps,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -1058,9 +1064,26 @@ func (g *GossipSyncer) replyChanRangeQuery(query *lnwire.QueryChannelRange) erro
|
|||||||
complete = 1
|
complete = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var timestamps lnwire.Timestamps
|
||||||
|
if withTimestamps {
|
||||||
|
timestamps = make(lnwire.Timestamps, len(channelChunk))
|
||||||
|
}
|
||||||
|
|
||||||
scids := make([]lnwire.ShortChannelID, len(channelChunk))
|
scids := make([]lnwire.ShortChannelID, len(channelChunk))
|
||||||
for i, info := range channelChunk {
|
for i, info := range channelChunk {
|
||||||
scids[i] = info.ShortChannelID
|
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{
|
return g.cfg.sendToPeerSync(&lnwire.ReplyChannelRange{
|
||||||
@ -1070,6 +1093,7 @@ func (g *GossipSyncer) replyChanRangeQuery(query *lnwire.QueryChannelRange) erro
|
|||||||
Complete: complete,
|
Complete: complete,
|
||||||
EncodingType: g.cfg.encodingType,
|
EncodingType: g.cfg.encodingType,
|
||||||
ShortChanIDs: scids,
|
ShortChanIDs: scids,
|
||||||
|
Timestamps: timestamps,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,7 +98,8 @@ func (m *mockChannelGraphTimeSeries) FilterKnownChanIDs(chain chainhash.Hash,
|
|||||||
return <-m.filterResp, nil
|
return <-m.filterResp, nil
|
||||||
}
|
}
|
||||||
func (m *mockChannelGraphTimeSeries) FilterChannelRange(chain chainhash.Hash,
|
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}
|
m.filterRangeReqs <- filterRangeReq{startHeight, endHeight}
|
||||||
reply := <-m.filterRangeResp
|
reply := <-m.filterRangeResp
|
||||||
|
Loading…
x
Reference in New Issue
Block a user