Change Option<T> 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>
Wed, 4 Mar 2020 19:29:06 +0000 (14:29 -0500)
commitb80d3d9d292007e9646aed1a150345a5b7896d26
tree3a3c9f003724d750965fcb093bb76b06beee28d3
parent32ca8ec13e0928cbb4f7067a3fb6d41f39691d1c
Change Option<T> 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