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.
This commit is contained in:
Matt Morehouse 2024-09-10 14:36:30 -05:00
parent 65046561c4
commit c1a6d3ac31
No known key found for this signature in database
GPG Key ID: CC8ECA224831C982

View File

@ -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 {