Skip to content

Commit a1449ae

Browse files
committed
Send warning instead of error when we incounter bogus gossip
1 parent eea1447 commit a1449ae

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

lightning/src/ln/peer_handler.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -902,22 +902,27 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, L: Deref, CMH: Deref> P
902902
Ok(x) => x,
903903
Err(e) => {
904904
match e {
905-
msgs::DecodeError::UnknownVersion => return Err(PeerHandleError { no_connection_possible: false }),
906-
msgs::DecodeError::UnknownRequiredFeature => {
905+
(_, Some(ty)) if is_gossip_msg(ty) => {
906+
log_gossip!(self.logger, "Got an invalid value while deserializing a gossip message");
907+
self.enqueue_message(peer, &msgs::WarningMessage { channel_id: [0; 32], data: "Unreadable/bogus gossip message".to_owned() });
908+
continue;
909+
}
910+
(msgs::DecodeError::UnknownVersion, _) => return Err(PeerHandleError { no_connection_possible: false }),
911+
(msgs::DecodeError::UnknownRequiredFeature, _) => {
907912
log_gossip!(self.logger, "Got a channel/node announcement with an unknown required feature flag, you may want to update!");
908913
continue;
909914
}
910-
msgs::DecodeError::InvalidValue => {
915+
(msgs::DecodeError::InvalidValue, _) => {
911916
log_debug!(self.logger, "Got an invalid value while deserializing message");
912917
return Err(PeerHandleError { no_connection_possible: false });
913918
}
914-
msgs::DecodeError::ShortRead => {
919+
(msgs::DecodeError::ShortRead, _) => {
915920
log_debug!(self.logger, "Deserialization failed due to shortness of message");
916921
return Err(PeerHandleError { no_connection_possible: false });
917922
}
918-
msgs::DecodeError::BadLengthDescriptor => return Err(PeerHandleError { no_connection_possible: false }),
919-
msgs::DecodeError::Io(_) => return Err(PeerHandleError { no_connection_possible: false }),
920-
msgs::DecodeError::UnsupportedCompression => {
923+
(msgs::DecodeError::BadLengthDescriptor, _) => return Err(PeerHandleError { no_connection_possible: false }),
924+
(msgs::DecodeError::Io(_), _) => return Err(PeerHandleError { no_connection_possible: false }),
925+
(msgs::DecodeError::UnsupportedCompression, _) => {
921926
log_gossip!(self.logger, "We don't support zlib-compressed message fields, sending a warning and ignoring message");
922927
self.enqueue_message(peer, &msgs::WarningMessage { channel_id: [0; 32], data: "Unsupported message compression: zlib".to_owned() });
923928
continue;

lightning/src/ln/wire.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,15 +119,20 @@ impl<T> Message<T> where T: core::fmt::Debug + Type {
119119
/// # Errors
120120
///
121121
/// Returns an error if the message payload code not be decoded as the specified type.
122-
pub(crate) fn read<R: io::Read, T, H: core::ops::Deref>(
123-
buffer: &mut R,
124-
custom_reader: H,
125-
) -> Result<Message<T>, msgs::DecodeError>
126-
where
122+
pub(crate) fn read<R: io::Read, T, H: core::ops::Deref>(buffer: &mut R, custom_reader: H)
123+
-> Result<Message<T>, (msgs::DecodeError, Option<u16>)> where
124+
T: core::fmt::Debug + Type + Writeable,
125+
H::Target: CustomMessageReader<CustomMessage = T>,
126+
{
127+
let message_type = <u16 as Readable>::read(buffer).map_err(|e| (e, None))?;
128+
do_read(buffer, message_type, custom_reader).map_err(|e| (e, Some(message_type)))
129+
}
130+
131+
fn do_read<R: io::Read, T, H: core::ops::Deref>(buffer: &mut R, message_type: u16, custom_reader: H)
132+
-> Result<Message<T>, msgs::DecodeError> where
127133
T: core::fmt::Debug + Type + Writeable,
128134
H::Target: CustomMessageReader<CustomMessage = T>,
129135
{
130-
let message_type = <u16 as Readable>::read(buffer)?;
131136
match message_type {
132137
msgs::Init::TYPE => {
133138
Ok(Message::Init(Readable::read(buffer)?))

0 commit comments

Comments
 (0)