Skip to content

Commit 6d6ffd4

Browse files
committed
Also ignore deser fails for NodeAnnouncementInfo
1 parent ea80ce1 commit 6d6ffd4

File tree

1 file changed

+54
-17
lines changed

1 file changed

+54
-17
lines changed

lightning/src/routing/gossip.rs

+54-17
Original file line numberDiff line numberDiff line change
@@ -643,18 +643,6 @@ impl Writeable for ChannelUpdateInfo {
643643
}
644644
}
645645

646-
struct ChannelUpdateInfoDeserWrap(Option<ChannelUpdateInfo>);
647-
648-
impl MaybeReadable for ChannelUpdateInfoDeserWrap {
649-
fn read<R: io::Read>(reader: &mut R) -> Result<Option<Self>, DecodeError> {
650-
if let Ok(channel_update_option) = ::util::ser::Readable::read(reader) {
651-
Ok(Some(Self(channel_update_option)))
652-
} else {
653-
Ok(None)
654-
}
655-
}
656-
}
657-
658646
impl Readable for ChannelUpdateInfo {
659647
fn read<R: io::Read>(reader: &mut R) -> Result<Self, DecodeError> {
660648
init_tlv_field_var!(last_update, required);
@@ -784,6 +772,18 @@ impl Writeable for ChannelInfo {
784772
}
785773
}
786774

775+
struct ChannelUpdateInfoDeserWrap(Option<ChannelUpdateInfo>);
776+
777+
impl MaybeReadable for ChannelUpdateInfoDeserWrap {
778+
fn read<R: io::Read>(reader: &mut R) -> Result<Option<Self>, DecodeError> {
779+
if let Ok(channel_update_option) = ::util::ser::Readable::read(reader) {
780+
Ok(Some(Self(channel_update_option)))
781+
} else {
782+
Ok(None)
783+
}
784+
}
785+
}
786+
787787
impl Readable for ChannelInfo {
788788
fn read<R: io::Read>(reader: &mut R) -> Result<Self, DecodeError> {
789789
init_tlv_field_var!(features, required);
@@ -1085,11 +1085,48 @@ impl fmt::Display for NodeInfo {
10851085
}
10861086
}
10871087

1088-
impl_writeable_tlv_based!(NodeInfo, {
1089-
(0, lowest_inbound_channel_fees, option),
1090-
(2, announcement_info, option),
1091-
(4, channels, vec_type),
1092-
});
1088+
impl Writeable for NodeInfo {
1089+
fn write<W: ::util::ser::Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
1090+
write_tlv_fields!(writer, {
1091+
(0, self.lowest_inbound_channel_fees, option),
1092+
(2, self.announcement_info, option),
1093+
(4, self.channels, vec_type),
1094+
});
1095+
Ok(())
1096+
}
1097+
}
1098+
1099+
struct NodeAnnouncementInfoDeserWrap(NodeAnnouncementInfo);
1100+
1101+
impl MaybeReadable for NodeAnnouncementInfoDeserWrap {
1102+
fn read<R: io::Read>(reader: &mut R) -> Result<Option<Self>, DecodeError> {
1103+
if let Ok(node_announcement) = ::util::ser::Readable::read(reader) {
1104+
Ok(Some(Self(node_announcement)))
1105+
} else {
1106+
Ok(None)
1107+
}
1108+
}
1109+
}
1110+
1111+
impl Readable for NodeInfo {
1112+
fn read<R: io::Read>(reader: &mut R) -> Result<Self, DecodeError> {
1113+
init_tlv_field_var!(lowest_inbound_channel_fees, option);
1114+
let mut announcement_info_wrap: Option<NodeAnnouncementInfoDeserWrap> = None;
1115+
init_tlv_field_var!(channels, vec_type);
1116+
1117+
read_tlv_fields!(reader, {
1118+
(0, lowest_inbound_channel_fees, option),
1119+
(2, announcement_info_wrap, ignorable),
1120+
(4, channels, vec_type),
1121+
});
1122+
1123+
Ok(NodeInfo {
1124+
lowest_inbound_channel_fees: init_tlv_based_struct_field!(lowest_inbound_channel_fees, option),
1125+
announcement_info: announcement_info_wrap.map(|w| w.0),
1126+
channels: init_tlv_based_struct_field!(channels, vec_type),
1127+
})
1128+
}
1129+
}
10931130

10941131
const SERIALIZATION_VERSION: u8 = 1;
10951132
const MIN_SERIALIZATION_VERSION: u8 = 1;

0 commit comments

Comments
 (0)