Skip to content

Commit ff644f4

Browse files
committed
Use new ChannelError in channel_reestablish handling
1 parent ad77f72 commit ff644f4

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/ln/channel.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2014,14 +2014,17 @@ impl Channel {
20142014

20152015
/// May panic if some calls other than message-handling calls (which will all Err immediately)
20162016
/// have been called between remove_uncommitted_htlcs_and_mark_paused and this call.
2017-
pub fn channel_reestablish(&mut self, msg: &msgs::ChannelReestablish) -> Result<(Option<msgs::FundingLocked>, Option<msgs::RevokeAndACK>, Option<msgs::CommitmentUpdate>, Option<ChannelMonitor>), HandleError> {
2017+
pub fn channel_reestablish(&mut self, msg: &msgs::ChannelReestablish) -> Result<(Option<msgs::FundingLocked>, Option<msgs::RevokeAndACK>, Option<msgs::CommitmentUpdate>, Option<ChannelMonitor>), ChannelError> {
20182018
if self.channel_state & (ChannelState::PeerDisconnected as u32) == 0 {
2019-
return Err(HandleError{err: "Peer sent a loose channel_reestablish not after reconnect", action: Some(msgs::ErrorAction::SendErrorMessage{msg: msgs::ErrorMessage{data: "Peer sent a loose channel_reestablish not after reconnect".to_string(), channel_id: msg.channel_id}})});
2019+
// While BOLT 2 doesn't indicate explicitly we should error this channel here, it
2020+
// almost certainly indicates we are going to end up out-of-sync in some way, so we
2021+
// just close here instead of trying to recover.
2022+
return Err(ChannelError::Close("Peer sent a loose channel_reestablish not after reconnect"));
20202023
}
20212024

20222025
if msg.next_local_commitment_number == 0 || msg.next_local_commitment_number >= INITIAL_COMMITMENT_NUMBER ||
20232026
msg.next_remote_commitment_number == 0 || msg.next_remote_commitment_number >= INITIAL_COMMITMENT_NUMBER {
2024-
return Err(HandleError{err: "Peer send garbage channel_reestablish", action: Some(msgs::ErrorAction::SendErrorMessage{msg: msgs::ErrorMessage{data: "Peer send garbage channel_reestablish".to_string(), channel_id: msg.channel_id}})});
2027+
return Err(ChannelError::Close("Peer send garbage channel_reestablish"));
20252028
}
20262029

20272030
// Go ahead and unmark PeerDisconnected as various calls we may make check for it (and all
@@ -2041,7 +2044,7 @@ impl Channel {
20412044
next_per_commitment_point,
20422045
});
20432046
} else {
2044-
return Err(HandleError{err: "Peer attempted to reestablish channel with a very old local commitment transaction", action: Some(msgs::ErrorAction::SendErrorMessage{msg: msgs::ErrorMessage{data: "Peer attempted to reestablish channel with a very old remote commitment transaction".to_string(), channel_id: msg.channel_id}})});
2047+
return Err(ChannelError::Close("Peer attempted to reestablish channel with a very old local commitment transaction"));
20452048
}
20462049

20472050
if msg.next_local_commitment_number == INITIAL_COMMITMENT_NUMBER - self.cur_remote_commitment_transaction_number {
@@ -2065,11 +2068,12 @@ impl Channel {
20652068
match self.free_holding_cell_htlcs() {
20662069
Err(e) => {
20672070
if let &Some(msgs::ErrorAction::DisconnectPeer{msg: Some(_)}) = &e.action {
2071+
return Err(ChannelError::Close(e.err));
20682072
} else if let &Some(msgs::ErrorAction::SendErrorMessage{msg: _}) = &e.action {
2073+
return Err(ChannelError::Close(e.err));
20692074
} else {
20702075
panic!("Got non-channel-failing result from free_holding_cell_htlcs");
20712076
}
2072-
return Err(e);
20732077
},
20742078
Ok(Some((commitment_update, channel_monitor))) => return Ok((None, required_revoke, Some(commitment_update), Some(channel_monitor))),
20752079
Ok(None) => return Ok((None, required_revoke, None, None)),
@@ -2088,7 +2092,7 @@ impl Channel {
20882092
commitment_signed: self.send_commitment_no_state_update().expect("It looks like we failed to re-generate a commitment_signed we had previously sent?").0,
20892093
}), None));
20902094
} else {
2091-
return Err(HandleError{err: "Peer attempted to reestablish channel with a very old remote commitment transaction", action: Some(msgs::ErrorAction::SendErrorMessage{msg: msgs::ErrorMessage{data: "Peer attempted to reestablish channel with a very old remote commitment transaction".to_string(), channel_id: msg.channel_id}})});
2095+
return Err(ChannelError::Close("Peer attempted to reestablish channel with a very old remote commitment transaction"));
20922096
}
20932097
}
20942098

src/ln/channelmanager.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1973,7 +1973,8 @@ impl ChannelManager {
19731973
if chan.get_their_node_id() != *their_node_id {
19741974
return Err(MsgHandleErrInternal::send_err_msg_no_close("Got a message for a channel from the wrong node!", msg.channel_id));
19751975
}
1976-
let (funding_locked, revoke_and_ack, commitment_update, channel_monitor) = chan.channel_reestablish(msg).map_err(|e| MsgHandleErrInternal::from_maybe_close(e))?;
1976+
let (funding_locked, revoke_and_ack, commitment_update, channel_monitor) = chan.channel_reestablish(msg)
1977+
.map_err(|e| MsgHandleErrInternal::from_chan_maybe_close(e, msg.channel_id))?;
19771978
(Ok((funding_locked, revoke_and_ack, commitment_update)), channel_monitor)
19781979
},
19791980
None => return Err(MsgHandleErrInternal::send_err_msg_no_close("Failed to find corresponding channel", msg.channel_id))

0 commit comments

Comments
 (0)