Skip to content

Commit 7303833

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 65db31d commit 7303833

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

lightning/src/ln/channel.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,7 @@ pub const MIN_THEIR_CHAN_RESERVE_SATOSHIS: u64 = 1000;
712712
pub(super) enum ChannelError {
713713
Ignore(String),
714714
Warn(String),
715+
WarnAndDisconnect(String),
715716
Close((String, ClosureReason)),
716717
SendError(String),
717718
}
@@ -721,6 +722,7 @@ impl fmt::Debug for ChannelError {
721722
match self {
722723
&ChannelError::Ignore(ref e) => write!(f, "Ignore : {}", e),
723724
&ChannelError::Warn(ref e) => write!(f, "Warn : {}", e),
725+
&ChannelError::WarnAndDisconnect(ref e) => write!(f, "Disconnecting with warning : {}", e),
724726
&ChannelError::Close((ref e, _)) => write!(f, "Close : {}", e),
725727
&ChannelError::SendError(ref e) => write!(f, "Not Found : {}", e),
726728
}
@@ -732,6 +734,7 @@ impl fmt::Display for ChannelError {
732734
match self {
733735
&ChannelError::Ignore(ref e) => write!(f, "{}", e),
734736
&ChannelError::Warn(ref e) => write!(f, "{}", e),
737+
&ChannelError::WarnAndDisconnect(ref e) => write!(f, "Warn : {}", e),
735738
&ChannelError::Close((ref e, _)) => write!(f, "{}", e),
736739
&ChannelError::SendError(ref e) => write!(f, "{}", e),
737740
}

lightning/src/ln/channelmanager.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,15 @@ impl MsgHandleErrInternal {
816816
log_level: Level::Warn,
817817
},
818818
},
819+
ChannelError::WarnAndDisconnect(msg) => LightningError {
820+
err: msg.clone(),
821+
action: msgs::ErrorAction::DisconnectPeerWithWarning {
822+
msg: msgs::WarningMessage {
823+
channel_id,
824+
data: msg
825+
},
826+
},
827+
},
819828
ChannelError::Ignore(msg) => LightningError {
820829
err: msg,
821830
action: msgs::ErrorAction::IgnoreError,
@@ -3036,6 +3045,9 @@ macro_rules! convert_channel_err {
30363045
ChannelError::Warn(msg) => {
30373046
(false, MsgHandleErrInternal::from_chan_no_close(ChannelError::Warn(msg), *$channel_id))
30383047
},
3048+
ChannelError::WarnAndDisconnect(msg) => {
3049+
(false, MsgHandleErrInternal::from_chan_no_close(ChannelError::WarnAndDisconnect(msg), *$channel_id))
3050+
},
30393051
ChannelError::Ignore(msg) => {
30403052
(false, MsgHandleErrInternal::from_chan_no_close(ChannelError::Ignore(msg), *$channel_id))
30413053
},

0 commit comments

Comments
 (0)