From c1a6d3ac31ce1212fb5e0b2950e3a64db576cdf5 Mon Sep 17 00:00:00 2001 From: Matt Morehouse Date: Tue, 10 Sep 2024 14:36:30 -0500 Subject: [PATCH 1/2] lnwire: fail decoding on incorrect number of timestamps Currently if an incorrect number of timestamps is given, we fail later on in the GossipSyncer. It makes more sense to fail right away, since we already do that for incorrect SCID formats (e.g., unsorted or duplicate SCIDs). There is already a matching check in Encode for incorrect number of timestamps, so adding this check to Decode makes things symmetric. --- lnwire/reply_channel_range.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lnwire/reply_channel_range.go b/lnwire/reply_channel_range.go index ea45a5843ce..591fc2bd60b 100644 --- a/lnwire/reply_channel_range.go +++ b/lnwire/reply_channel_range.go @@ -104,6 +104,12 @@ func (c *ReplyChannelRange) Decode(r io.Reader, pver uint32) error { // Set the corresponding TLV types if they were included in the stream. if val, ok := typeMap[TimestampsRecordType]; ok && val == nil { c.Timestamps = timeStamps + + // Check that a timestamp was provided for each SCID. + if len(c.Timestamps) != len(c.ShortChanIDs) { + return fmt.Errorf("number of timestamps does not " + + "match number of SCIDs") + } } if len(tlvRecords) != 0 { From 532fe05b637d34e4dcecda3d911dd146ab049b58 Mon Sep 17 00:00:00 2001 From: Matt Morehouse Date: Tue, 10 Sep 2024 14:52:16 -0500 Subject: [PATCH 2/2] discovery: remove check for incorrect number of timestamps The check is no longer required, as it is now done during decoding. --- discovery/syncer.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/discovery/syncer.go b/discovery/syncer.go index b6adb447a6d..cdb041d99bd 100644 --- a/discovery/syncer.go +++ b/discovery/syncer.go @@ -835,12 +835,6 @@ func (g *GossipSyncer) processChanRangeReply(msg *lnwire.ReplyChannelRange) erro } g.prevReplyChannelRange = msg - if len(msg.Timestamps) != 0 && - len(msg.Timestamps) != len(msg.ShortChanIDs) { - - return fmt.Errorf("number of timestamps not equal to " + - "number of SCIDs") - } for i, scid := range msg.ShortChanIDs { info := channeldb.NewChannelUpdateInfo(