Skip to content

Commit 61e2291

Browse files
committed
Add ChannelError::NotFound variant
When moving ChannelPhase logic from ChannelManager into Channel, it is useful to error when a Channel is not in the expected state. Add a ChannelError::NotFound variant for this purpose, which results in sending an error message without closing the channel.
1 parent 4055c8b commit 61e2291

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lightning/src/ln/channel.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,7 @@ pub(super) enum ChannelError {
713713
Ignore(String),
714714
Warn(String),
715715
Close((String, ClosureReason)),
716+
NotFound(String),
716717
}
717718

718719
impl fmt::Debug for ChannelError {
@@ -721,6 +722,7 @@ impl fmt::Debug for ChannelError {
721722
&ChannelError::Ignore(ref e) => write!(f, "Ignore : {}", e),
722723
&ChannelError::Warn(ref e) => write!(f, "Warn : {}", e),
723724
&ChannelError::Close((ref e, _)) => write!(f, "Close : {}", e),
725+
&ChannelError::NotFound(ref e) => write!(f, "Not Found : {}", e),
724726
}
725727
}
726728
}
@@ -731,6 +733,7 @@ impl fmt::Display for ChannelError {
731733
&ChannelError::Ignore(ref e) => write!(f, "{}", e),
732734
&ChannelError::Warn(ref e) => write!(f, "{}", e),
733735
&ChannelError::Close((ref e, _)) => write!(f, "{}", e),
736+
&ChannelError::NotFound(ref e) => write!(f, "{}", e),
734737
}
735738
}
736739
}

lightning/src/ln/channelmanager.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ impl MsgHandleErrInternal {
792792
err: msg,
793793
action: msgs::ErrorAction::IgnoreError,
794794
},
795-
ChannelError::Close((msg, _reason)) => LightningError {
795+
ChannelError::Close((msg, _)) | ChannelError::NotFound(msg) => LightningError {
796796
err: msg.clone(),
797797
action: msgs::ErrorAction::SendErrorMessage {
798798
msg: msgs::ErrorMessage {
@@ -3022,6 +3022,9 @@ macro_rules! convert_channel_err {
30223022
MsgHandleErrInternal::from_finish_shutdown(msg, *$channel_id, shutdown_res, $channel_update);
30233023
(true, err)
30243024
},
3025+
ChannelError::NotFound(msg) => {
3026+
(false, MsgHandleErrInternal::from_chan_no_close(ChannelError::NotFound(msg), *$channel_id))
3027+
},
30253028
}
30263029
};
30273030
($self: ident, $peer_state: expr, $err: expr, $funded_channel: expr, $channel_id: expr, FUNDED_CHANNEL) => {

0 commit comments

Comments
 (0)