Skip to content

Commit

Permalink
Also ignore deser fails for NodeAnnouncementInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
tnull committed Jul 14, 2022
1 parent ea80ce1 commit 6d6ffd4
Showing 1 changed file with 54 additions and 17 deletions.
71 changes: 54 additions & 17 deletions lightning/src/routing/gossip.rs
Expand Up @@ -643,18 +643,6 @@ impl Writeable for ChannelUpdateInfo {
}
}

struct ChannelUpdateInfoDeserWrap(Option<ChannelUpdateInfo>);

impl MaybeReadable for ChannelUpdateInfoDeserWrap {
fn read<R: io::Read>(reader: &mut R) -> Result<Option<Self>, DecodeError> {
if let Ok(channel_update_option) = ::util::ser::Readable::read(reader) {
Ok(Some(Self(channel_update_option)))
} else {
Ok(None)
}
}
}

impl Readable for ChannelUpdateInfo {
fn read<R: io::Read>(reader: &mut R) -> Result<Self, DecodeError> {
init_tlv_field_var!(last_update, required);
Expand Down Expand Up @@ -784,6 +772,18 @@ impl Writeable for ChannelInfo {
}
}

struct ChannelUpdateInfoDeserWrap(Option<ChannelUpdateInfo>);

impl MaybeReadable for ChannelUpdateInfoDeserWrap {
fn read<R: io::Read>(reader: &mut R) -> Result<Option<Self>, DecodeError> {
if let Ok(channel_update_option) = ::util::ser::Readable::read(reader) {
Ok(Some(Self(channel_update_option)))
} else {
Ok(None)
}
}
}

impl Readable for ChannelInfo {
fn read<R: io::Read>(reader: &mut R) -> Result<Self, DecodeError> {
init_tlv_field_var!(features, required);
Expand Down Expand Up @@ -1085,11 +1085,48 @@ impl fmt::Display for NodeInfo {
}
}

impl_writeable_tlv_based!(NodeInfo, {
(0, lowest_inbound_channel_fees, option),
(2, announcement_info, option),
(4, channels, vec_type),
});
impl Writeable for NodeInfo {
fn write<W: ::util::ser::Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
write_tlv_fields!(writer, {
(0, self.lowest_inbound_channel_fees, option),
(2, self.announcement_info, option),
(4, self.channels, vec_type),
});
Ok(())
}
}

struct NodeAnnouncementInfoDeserWrap(NodeAnnouncementInfo);

impl MaybeReadable for NodeAnnouncementInfoDeserWrap {
fn read<R: io::Read>(reader: &mut R) -> Result<Option<Self>, DecodeError> {
if let Ok(node_announcement) = ::util::ser::Readable::read(reader) {
Ok(Some(Self(node_announcement)))
} else {
Ok(None)
}
}
}

impl Readable for NodeInfo {
fn read<R: io::Read>(reader: &mut R) -> Result<Self, DecodeError> {
init_tlv_field_var!(lowest_inbound_channel_fees, option);
let mut announcement_info_wrap: Option<NodeAnnouncementInfoDeserWrap> = None;
init_tlv_field_var!(channels, vec_type);

read_tlv_fields!(reader, {
(0, lowest_inbound_channel_fees, option),
(2, announcement_info_wrap, ignorable),
(4, channels, vec_type),
});

Ok(NodeInfo {
lowest_inbound_channel_fees: init_tlv_based_struct_field!(lowest_inbound_channel_fees, option),
announcement_info: announcement_info_wrap.map(|w| w.0),
channels: init_tlv_based_struct_field!(channels, vec_type),
})
}
}

const SERIALIZATION_VERSION: u8 = 1;
const MIN_SERIALIZATION_VERSION: u8 = 1;
Expand Down

0 comments on commit 6d6ffd4

Please sign in to comment.