Change Option<T>::read serialization format to include length
authorMatt Corallo <git@bluematt.me>
Mon, 24 Feb 2020 04:25:43 +0000 (23:25 -0500)
committerMatt Corallo <git@bluematt.me>
Sun, 1 Mar 2020 04:26:15 +0000 (23:26 -0500)
commit7b6b0cf0c0909bbf77e9483184c77d8e09670fe2
tree606e3247f6cf59d32f42d951d38c87904da49e82
parent69a39aeaac78d483888001f41ee5e896600db8eb
Change Option<T>::read serialization format to include length

This is a cheap way to fix an error in Router serialization
roundtrip due to us calling read_to_end during the read of
channel/node announcement/updates. During normal message reading,
we only have limited bytes to read (specifically the message buffer)
so this is fine, however when we read them inside Router, we have
more data from other fields of the Router available as well. Thus,
we end up reading the entire rest of the Router into one message
field, and failing to deserialize.

Because such fields are always stored in Option<>s, we can simply
use a LengthLimitingStream in the Option<> serialization format and
make only the correct number of bytes available.

By using a variable-length integer for the new field, we avoid
wasting space compared to the existing serialization format.
lightning/src/ln/channel.rs
lightning/src/ln/channelmonitor.rs
lightning/src/util/ser.rs