discovery+lnwire: remove embedding within ReplyChannelRange

In order to prep for allowing TLV extensions for the `ReplyChannelRange`
and `QueryChannelRange` messages, we'll need to remove the struct
embedding as is. If we don't remove this, then we'll attempt to decode
TLV extensions from both the embedded and outer struct.

All relevant call sites have been updated to reflect this minor change.
This commit is contained in:
Olaoluwa Osuntokun authored and Johan T. Halseth committed 2021-02-24 17:31:55 +01:00
1 parent 466c079bbe
commit dd6f0ba931
6 files changed
+108 -74

No files matched your search

+4 -2
View File
@@ -629,8 +629,10 @@ func assertTransitionToChansSynced(t *testing.T, s *GossipSyncer, peer *mockPeer
}, time.Second, 500*time.Millisecond)
require.NoError(t, s.ProcessQueryMsg(&lnwire.ReplyChannelRange{
QueryChannelRange: *query,
Complete: 1,
ChainHash: query.ChainHash,
FirstBlockHeight: query.FirstBlockHeight,
NumBlocks: query.NumBlocks,
Complete: 1,
}, nil))
chanSeries := s.cfg.channelSeries.(*mockChannelGraphTimeSeries)
+17 -15
View File
@@ -753,7 +753,9 @@ func (g *GossipSyncer) synchronizeChanIDs() (bool, error) {
func isLegacyReplyChannelRange(query *lnwire.QueryChannelRange,
reply *lnwire.ReplyChannelRange) bool {
return reply.QueryChannelRange == *query
return (reply.ChainHash == query.ChainHash &&
reply.FirstBlockHeight == query.FirstBlockHeight &&
reply.NumBlocks == query.NumBlocks)
}
// processChanRangeReply is called each time the GossipSyncer receives a new
@@ -773,7 +775,7 @@ func (g *GossipSyncer) processChanRangeReply(msg *lnwire.ReplyChannelRange) erro
// The last block should also be. We don't need to check the
// intermediate ones because they should already be in sorted
// order.
replyLastHeight := msg.QueryChannelRange.LastBlockHeight()
replyLastHeight := msg.LastBlockHeight()
queryLastHeight := g.curQueryRangeMsg.LastBlockHeight()
if replyLastHeight > queryLastHeight {
return fmt.Errorf("reply includes channels for height "+
@@ -832,7 +834,7 @@ func (g *GossipSyncer) processChanRangeReply(msg *lnwire.ReplyChannelRange) erro
// Otherwise, we'll look at the reply's height range.
default:
replyLastHeight := msg.QueryChannelRange.LastBlockHeight()
replyLastHeight := msg.LastBlockHeight()
queryLastHeight := g.curQueryRangeMsg.LastBlockHeight()
// TODO(wilmer): This might require some padding if the remote
@@ -997,10 +999,12 @@ func (g *GossipSyncer) replyChanRangeQuery(query *lnwire.QueryChannelRange) erro
g.cfg.chainHash)
return g.cfg.sendToPeerSync(&lnwire.ReplyChannelRange{
QueryChannelRange: *query,
Complete: 0,
EncodingType: g.cfg.encodingType,
ShortChanIDs: nil,
ChainHash: query.ChainHash,
FirstBlockHeight: query.FirstBlockHeight,
NumBlocks: query.NumBlocks,
Complete: 0,
EncodingType: g.cfg.encodingType,
ShortChanIDs: nil,
})
}
@@ -1040,14 +1044,12 @@ func (g *GossipSyncer) replyChanRangeQuery(query *lnwire.QueryChannelRange) erro
}
return g.cfg.sendToPeerSync(&lnwire.ReplyChannelRange{
QueryChannelRange: lnwire.QueryChannelRange{
ChainHash: query.ChainHash,
NumBlocks: numBlocks,
FirstBlockHeight: firstHeight,
},
Complete: complete,
EncodingType: g.cfg.encodingType,
ShortChanIDs: channelChunk,
ChainHash: query.ChainHash,
NumBlocks: numBlocks,
FirstBlockHeight: firstHeight,
Complete: complete,
EncodingType: g.cfg.encodingType,
ShortChanIDs: channelChunk,
})
}
+32 -35
View File
@@ -609,10 +609,9 @@ func TestGossipSyncerQueryChannelRangeWrongChainHash(t *testing.T) {
t.Fatalf("expected lnwire.ReplyChannelRange, got %T", msg)
}
if msg.QueryChannelRange != *query {
t.Fatalf("wrong query channel range in reply: "+
"expected: %v\ngot: %v", spew.Sdump(*query),
spew.Sdump(msg.QueryChannelRange))
if msg.ChainHash != query.ChainHash {
t.Fatalf("wrong chain hash: expected %v got %v",
query.ChainHash, msg.ChainHash)
}
if msg.Complete != 0 {
t.Fatalf("expected complete set to 0, got %v",
@@ -1227,34 +1226,13 @@ func testGossipSyncerProcessChanRangeReply(t *testing.T, legacy bool) {
t.Fatalf("unable to generate channel range query: %v", err)
}
var replyQueries []*lnwire.QueryChannelRange
if legacy {
// Each reply query is the same as the original query in the
// legacy mode.
replyQueries = []*lnwire.QueryChannelRange{query, query, query}
} else {
// When interpreting block ranges, the first reply should start
// from our requested first block, and the last should end at
// our requested last block.
replyQueries = []*lnwire.QueryChannelRange{
{
FirstBlockHeight: 0,
NumBlocks: 11,
},
{
FirstBlockHeight: 11,
NumBlocks: 1,
},
{
FirstBlockHeight: 12,
NumBlocks: query.NumBlocks - 12,
},
}
}
// When interpreting block ranges, the first reply should start from
// our requested first block, and the last should end at our requested
// last block.
replies := []*lnwire.ReplyChannelRange{
{
QueryChannelRange: *replyQueries[0],
FirstBlockHeight: 0,
NumBlocks: 11,
ShortChanIDs: []lnwire.ShortChannelID{
{
BlockHeight: 10,
@@ -1262,7 +1240,8 @@ func testGossipSyncerProcessChanRangeReply(t *testing.T, legacy bool) {
},
},
{
QueryChannelRange: *replyQueries[1],
FirstBlockHeight: 11,
NumBlocks: 1,
ShortChanIDs: []lnwire.ShortChannelID{
{
BlockHeight: 11,
@@ -1270,8 +1249,9 @@ func testGossipSyncerProcessChanRangeReply(t *testing.T, legacy bool) {
},
},
{
QueryChannelRange: *replyQueries[2],
Complete: 1,
FirstBlockHeight: 12,
NumBlocks: query.NumBlocks - 12,
Complete: 1,
ShortChanIDs: []lnwire.ShortChannelID{
{
BlockHeight: 12,
@@ -1280,6 +1260,19 @@ func testGossipSyncerProcessChanRangeReply(t *testing.T, legacy bool) {
},
}
// Each reply query is the same as the original query in the legacy
// mode.
if legacy {
replies[0].FirstBlockHeight = query.FirstBlockHeight
replies[0].NumBlocks = query.NumBlocks
replies[1].FirstBlockHeight = query.FirstBlockHeight
replies[1].NumBlocks = query.NumBlocks
replies[2].FirstBlockHeight = query.FirstBlockHeight
replies[2].NumBlocks = query.NumBlocks
}
// We'll begin by sending the syncer a set of non-complete channel
// range replies.
if err := syncer.processChanRangeReply(replies[0]); err != nil {
@@ -2377,7 +2370,9 @@ func TestGossipSyncerMaxChannelRangeReplies(t *testing.T) {
// order to transition the syncer's state.
for i := uint32(0); i < syncer.cfg.maxQueryChanRangeReplies; i++ {
reply := &lnwire.ReplyChannelRange{
QueryChannelRange: *query,
ChainHash: query.ChainHash,
FirstBlockHeight: query.FirstBlockHeight,
NumBlocks: query.NumBlocks,
ShortChanIDs: []lnwire.ShortChannelID{
{
BlockHeight: query.FirstBlockHeight + i,
@@ -2408,7 +2403,9 @@ func TestGossipSyncerMaxChannelRangeReplies(t *testing.T) {
// Finally, attempting to process another reply for the same query
// should result in an error.
require.Error(t, syncer.ProcessQueryMsg(&lnwire.ReplyChannelRange{
QueryChannelRange: *query,
ChainHash: query.ChainHash,
FirstBlockHeight: query.FirstBlockHeight,
NumBlocks: query.NumBlocks,
ShortChanIDs: []lnwire.ShortChannelID{
{
BlockHeight: query.LastBlockHeight() + 1,