Skip to content

Commit 307e4c2

Browse files
committed
Add DecodeError::DangerousValue for decoding invalid channel managers
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.
1 parent 5e41425 commit 307e4c2

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

lightning/src/ln/channelmanager.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10927,13 +10927,13 @@ where
1092710927
log_error!(logger, " client applications must ensure that ChannelMonitor data is always available and the latest to avoid funds loss!");
1092810928
log_error!(logger, " Without the latest ChannelMonitor we cannot continue without risking funds.");
1092910929
log_error!(logger, " Please ensure the chain::Watch API requirements are met and file a bug report at https://github.com/lightningdevkit/rust-lightning");
10930-
return Err(DecodeError::InvalidValue);
10930+
return Err(DecodeError::DangerousValue);
1093110931
}
1093210932
} else {
1093310933
// We shouldn't have persisted (or read) any unfunded channel types so none should have been
1093410934
// created in this `channel_by_id` map.
1093510935
debug_assert!(false);
10936-
return Err(DecodeError::InvalidValue);
10936+
return Err(DecodeError::DangerousValue);
1093710937
}
1093810938
}
1093910939
}

lightning/src/ln/msgs.rs

+9
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,14 @@ pub enum DecodeError {
9191
Io(io::ErrorKind),
9292
/// The message included zlib-compressed values, which we don't support.
9393
UnsupportedCompression,
94+
/// Value is validly encoded but is dangerous to use.
95+
///
96+
/// This is used for things like [`crate::ln::channelmanager::ChannelManager`] deserialization
97+
/// where we want to ensure that we don't use a [`crate::ln::channelmanager::ChannelManager`]
98+
/// which is in out of sync with the [`crate::chain::channelmonitor::ChannelMonitor`]. This
99+
/// indicates that there is a critical implementation flaw in the storage implementation
100+
/// and it's unsafe to continue.
101+
DangerousValue,
94102
}
95103

96104
/// An [`init`] message to be sent to or received from a peer.
@@ -1796,6 +1804,7 @@ impl fmt::Display for DecodeError {
17961804
DecodeError::BadLengthDescriptor => f.write_str("A length descriptor in the packet didn't describe the later data correctly"),
17971805
DecodeError::Io(ref e) => fmt::Debug::fmt(e, f),
17981806
DecodeError::UnsupportedCompression => f.write_str("We don't support receiving messages with zlib-compressed fields"),
1807+
DecodeError::DangerousValue => f.write_str("Value would be dangerous to continue execution with"),
17991808
}
18001809
}
18011810
}

lightning/src/ln/peer_handler.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1551,6 +1551,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
15511551
}
15521552
(msgs::DecodeError::BadLengthDescriptor, _) => return Err(PeerHandleError { }),
15531553
(msgs::DecodeError::Io(_), _) => return Err(PeerHandleError { }),
1554+
(msgs::DecodeError::DangerousValue, _) => return Err(PeerHandleError { }),
15541555
}
15551556
}
15561557
};

lightning/src/ln/reload_tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ fn test_manager_serialize_deserialize_inconsistent_monitor() {
412412
}
413413

414414
let mut nodes_0_read = &nodes_0_serialized[..];
415-
if let Err(msgs::DecodeError::InvalidValue) =
415+
if let Err(msgs::DecodeError::DangerousValue) =
416416
<(BlockHash, ChannelManager<&test_utils::TestChainMonitor, &test_utils::TestBroadcaster, &test_utils::TestKeysInterface, &test_utils::TestKeysInterface, &test_utils::TestKeysInterface, &test_utils::TestFeeEstimator, &test_utils::TestRouter, &test_utils::TestLogger>)>::read(&mut nodes_0_read, ChannelManagerReadArgs {
417417
default_config: UserConfig::default(),
418418
entropy_source: keys_manager,

0 commit comments

Comments
 (0)