Add ChannelError::WarnAndDisconnect variant

The existing `ChannelError::Warn` variant only sends the warning and
does not disconnect. There are certain cases where we want to just send
a warning, and other cases where we want to also disconnect, so we
keep both variants around.
This commit is contained in:
Wilmer Paulino 2025-02-11 18:26:17 -08:00
parent 5d6e759613
commit 506367e8a9
No known key found for this signature in database
GPG key ID: 634FE5FC544DCA31
2 changed files with 19 additions and 4 deletions

View file

@ -713,6 +713,7 @@ pub const MIN_THEIR_CHAN_RESERVE_SATOSHIS: u64 = 1000;
pub(super) enum ChannelError {
Ignore(String),
Warn(String),
WarnAndDisconnect(String),
Close((String, ClosureReason)),
SendError(String),
}
@ -720,10 +721,11 @@ pub(super) enum ChannelError {
impl fmt::Debug for ChannelError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
&ChannelError::Ignore(ref e) => write!(f, "Ignore : {}", e),
&ChannelError::Warn(ref e) => write!(f, "Warn : {}", e),
&ChannelError::Close((ref e, _)) => write!(f, "Close : {}", e),
&ChannelError::SendError(ref e) => write!(f, "Not Found : {}", e),
&ChannelError::Ignore(ref e) => write!(f, "Ignore: {}", e),
&ChannelError::Warn(ref e) => write!(f, "Warn: {}", e),
&ChannelError::WarnAndDisconnect(ref e) => write!(f, "Disconnecting with warning: {}", e),
&ChannelError::Close((ref e, _)) => write!(f, "Close: {}", e),
&ChannelError::SendError(ref e) => write!(f, "Not Found: {}", e),
}
}
}
@ -733,6 +735,7 @@ impl fmt::Display for ChannelError {
match self {
&ChannelError::Ignore(ref e) => write!(f, "{}", e),
&ChannelError::Warn(ref e) => write!(f, "{}", e),
&ChannelError::WarnAndDisconnect(ref e) => write!(f, "{}", e),
&ChannelError::Close((ref e, _)) => write!(f, "{}", e),
&ChannelError::SendError(ref e) => write!(f, "{}", e),
}

View file

@ -840,6 +840,15 @@ impl MsgHandleErrInternal {
log_level: Level::Warn,
},
},
ChannelError::WarnAndDisconnect(msg) => LightningError {
err: msg.clone(),
action: msgs::ErrorAction::DisconnectPeerWithWarning {
msg: msgs::WarningMessage {
channel_id,
data: msg
},
},
},
ChannelError::Ignore(msg) => LightningError {
err: msg,
action: msgs::ErrorAction::IgnoreError,
@ -3069,6 +3078,9 @@ macro_rules! convert_channel_err {
ChannelError::Warn(msg) => {
(false, MsgHandleErrInternal::from_chan_no_close(ChannelError::Warn(msg), *$channel_id))
},
ChannelError::WarnAndDisconnect(msg) => {
(false, MsgHandleErrInternal::from_chan_no_close(ChannelError::WarnAndDisconnect(msg), *$channel_id))
},
ChannelError::Ignore(msg) => {
(false, MsgHandleErrInternal::from_chan_no_close(ChannelError::Ignore(msg), *$channel_id))
},