Skip to content

Commit 506367e

Browse files
committed
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.
1 parent 5d6e759 commit 506367e

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

lightning/src/ln/channel.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -713,17 +713,19 @@ pub const MIN_THEIR_CHAN_RESERVE_SATOSHIS: u64 = 1000;
713713
pub(super) enum ChannelError {
714714
Ignore(String),
715715
Warn(String),
716+
WarnAndDisconnect(String),
716717
Close((String, ClosureReason)),
717718
SendError(String),
718719
}
719720

720721
impl fmt::Debug for ChannelError {
721722
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
722723
match self {
723-
&ChannelError::Ignore(ref e) => write!(f, "Ignore : {}", e),
724-
&ChannelError::Warn(ref e) => write!(f, "Warn : {}", e),
725-
&ChannelError::Close((ref e, _)) => write!(f, "Close : {}", e),
726-
&ChannelError::SendError(ref e) => write!(f, "Not Found : {}", e),
724+
&ChannelError::Ignore(ref e) => write!(f, "Ignore: {}", e),
725+
&ChannelError::Warn(ref e) => write!(f, "Warn: {}", e),
726+
&ChannelError::WarnAndDisconnect(ref e) => write!(f, "Disconnecting with warning: {}", e),
727+
&ChannelError::Close((ref e, _)) => write!(f, "Close: {}", e),
728+
&ChannelError::SendError(ref e) => write!(f, "Not Found: {}", e),
727729
}
728730
}
729731
}
@@ -733,6 +735,7 @@ impl fmt::Display for ChannelError {
733735
match self {
734736
&ChannelError::Ignore(ref e) => write!(f, "{}", e),
735737
&ChannelError::Warn(ref e) => write!(f, "{}", e),
738+
&ChannelError::WarnAndDisconnect(ref e) => write!(f, "{}", e),
736739
&ChannelError::Close((ref e, _)) => write!(f, "{}", e),
737740
&ChannelError::SendError(ref e) => write!(f, "{}", e),
738741
}

lightning/src/ln/channelmanager.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,15 @@ impl MsgHandleErrInternal {
840840
log_level: Level::Warn,
841841
},
842842
},
843+
ChannelError::WarnAndDisconnect(msg) => LightningError {
844+
err: msg.clone(),
845+
action: msgs::ErrorAction::DisconnectPeerWithWarning {
846+
msg: msgs::WarningMessage {
847+
channel_id,
848+
data: msg
849+
},
850+
},
851+
},
843852
ChannelError::Ignore(msg) => LightningError {
844853
err: msg,
845854
action: msgs::ErrorAction::IgnoreError,
@@ -3069,6 +3078,9 @@ macro_rules! convert_channel_err {
30693078
ChannelError::Warn(msg) => {
30703079
(false, MsgHandleErrInternal::from_chan_no_close(ChannelError::Warn(msg), *$channel_id))
30713080
},
3081+
ChannelError::WarnAndDisconnect(msg) => {
3082+
(false, MsgHandleErrInternal::from_chan_no_close(ChannelError::WarnAndDisconnect(msg), *$channel_id))
3083+
},
30723084
ChannelError::Ignore(msg) => {
30733085
(false, MsgHandleErrInternal::from_chan_no_close(ChannelError::Ignore(msg), *$channel_id))
30743086
},

0 commit comments

Comments
 (0)