lnwire/query_short_chan_ids: short circuit if 0 sids

In this commit, we alter the behavior of the regular
short channel id encoding, such that it returns a nil
slice if the decoded number of elements is 0. This is
done so that it matches the behavior of the zlib
decompression, allowing us to test both in using the
same corpus.
This commit is contained in:
Conner Fromknecht 2018-06-28 19:04:55 -07:00
parent 8cc217b526
commit 61c2493b7d
No known key found for this signature in database
GPG Key ID: 39DE78FBE6ACB0EF

@ -146,10 +146,13 @@ func decodeShortChanIDs(r io.Reader) (ShortChanIDEncoding, []ShortChannelID, err
// compute the number of bytes encoded based on the size of the // compute the number of bytes encoded based on the size of the
// query body. // query body.
numShortChanIDs := len(queryBody) / 8 numShortChanIDs := len(queryBody) / 8
shortChanIDs := make([]ShortChannelID, numShortChanIDs) if numShortChanIDs == 0 {
return encodingType, nil, nil
}
// Finally, we'll read out the exact number of short channel // Finally, we'll read out the exact number of short channel
// ID's to conclude our parsing. // ID's to conclude our parsing.
shortChanIDs := make([]ShortChannelID, numShortChanIDs)
bodyReader := bytes.NewReader(queryBody) bodyReader := bytes.NewReader(queryBody)
for i := 0; i < numShortChanIDs; i++ { for i := 0; i < numShortChanIDs; i++ {
if err := readElements(bodyReader, &shortChanIDs[i]); err != nil { if err := readElements(bodyReader, &shortChanIDs[i]); err != nil {