BOLT 7: clarify how to decode empty arrays#729
Conversation
Channel queries use arrays (of short channel ids, timestamps, ...) encoded with a single byte for the encoding type followed by encoded data. If the encoded data is empty, it always decodes to an empty array, no matter what the encoding type is set to.
|
Actually there's already a pending PR with the same clarification: #560 |
|
Good point! Here I'm mostly focused on how to specifically deal with empty arrays, which goes a bit further than #560 (it's not explicit on that point), the biggest issue being: are empty arrays sent wit a |
|
I don't think #560 touches this at all, and no an empty byte string is not a valid zlib compressed value: >>> import zlib
>>> zlib.compress(b'')
'x\x9c\x03\x00\x00\x00\x00\x01'
>>> zlib.decompress(b'')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
zlib.error: Error -5 while decompressing data: incomplete or truncated streamAs such I think it is invalid to specify an encoding and then providing an invalid value for that encoding, since it might mask other issues internally. We could special-case the empty byte string, but what good would that be? I think the correct way to handle this is ACINQ/eclair#1280, i.e., omitting the fields altogether or specifying the uncompressed encoding if the intention is to communicate an empty byte string. |
|
Ok, I still like the idea of "nothing in means nothing out" but it seems that every zlib encoder out there disagree with me except for the one we use :) so I'll agree that it was rather a bug in our code than a uncertainty in the specs |
Channel queries use arrays (of short channel ids, timestamps, ...) encoded with a single byte for the encoding type followed by encoded data.
If the encoded data is empty, it always decodes to an empty array, no matter what the encoding type is set to.