Skip to content

Commit

Permalink
Add DecodeError::DangerousValue for decoding invalid channel managers
Browse files Browse the repository at this point in the history
This would help distinguish different types of errors when deserialzing
a channel manager. InvalidValue was used previously but this could be
because it is an old serialization format, whereas DangerousValue is a
lot more clear on why the deserialization failed.
  • Loading branch information
benthecarman committed Mar 27, 2024
1 parent 5e41425 commit db33ab4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10927,13 +10927,13 @@ where
log_error!(logger, " client applications must ensure that ChannelMonitor data is always available and the latest to avoid funds loss!");
log_error!(logger, " Without the latest ChannelMonitor we cannot continue without risking funds.");
log_error!(logger, " Please ensure the chain::Watch API requirements are met and file a bug report at https://github.com/lightningdevkit/rust-lightning");
return Err(DecodeError::InvalidValue);
return Err(DecodeError::DangerousValue);
}
} else {
// We shouldn't have persisted (or read) any unfunded channel types so none should have been
// created in this `channel_by_id` map.
debug_assert!(false);
return Err(DecodeError::InvalidValue);
return Err(DecodeError::DangerousValue);
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions lightning/src/ln/msgs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ pub enum DecodeError {
Io(io::ErrorKind),
/// The message included zlib-compressed values, which we don't support.
UnsupportedCompression,
/// Value is validly encoded but is dangerous to use.
/// This is used for things like [`crate::ln::channelmanager::ChannelManager`] deserialization
/// where we want to ensure that we don't use a [`crate::ln::channelmanager::ChannelManager`]
/// which is in the past.
DangerousValue,
}

/// An [`init`] message to be sent to or received from a peer.
Expand Down Expand Up @@ -1796,6 +1801,7 @@ impl fmt::Display for DecodeError {
DecodeError::BadLengthDescriptor => f.write_str("A length descriptor in the packet didn't describe the later data correctly"),
DecodeError::Io(ref e) => fmt::Debug::fmt(e, f),
DecodeError::UnsupportedCompression => f.write_str("We don't support receiving messages with zlib-compressed fields"),
DecodeError::DangerousValue => f.write_str("Value would be dangerous to continue execution with"),
}
}
}
Expand Down
1 change: 1 addition & 0 deletions lightning/src/ln/peer_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1551,6 +1551,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
}
(msgs::DecodeError::BadLengthDescriptor, _) => return Err(PeerHandleError { }),
(msgs::DecodeError::Io(_), _) => return Err(PeerHandleError { }),
(msgs::DecodeError::DangerousValue, _) => return Err(PeerHandleError { }),
}
}
};
Expand Down

0 comments on commit db33ab4

Please sign in to comment.