Skip to content

Commit 148c797

Browse files
authored
Merge pull request #393 from ariard/2019-11-send-cmt-error-handling
Fulfill error handling for send_commitment in processing htlcs forward
2 parents 2e1b7ab + 6de1755 commit 148c797

File tree

1 file changed

+32
-5
lines changed

1 file changed

+32
-5
lines changed

src/ln/channelmanager.rs

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,12 +1373,39 @@ impl ChannelManager {
13731373
let (commitment_msg, monitor) = match chan.get_mut().send_commitment() {
13741374
Ok(res) => res,
13751375
Err(e) => {
1376-
if let ChannelError::Ignore(_) = e {
1377-
panic!("Stated return value requirements in send_commitment() were not met");
1376+
// We surely failed send_commitment due to bad keys, in that case
1377+
// close channel and then send error message to peer.
1378+
let their_node_id = chan.get().get_their_node_id();
1379+
let err: Result<(), _> = match e {
1380+
ChannelError::Ignore(_) => {
1381+
panic!("Stated return value requirements in send_commitment() were not met");
1382+
},
1383+
ChannelError::Close(msg) => {
1384+
log_trace!(self, "Closing channel {} due to Close-required error: {}", log_bytes!(chan.key()[..]), msg);
1385+
let (channel_id, mut channel) = chan.remove_entry();
1386+
if let Some(short_id) = channel.get_short_channel_id() {
1387+
channel_state.short_to_id.remove(&short_id);
1388+
}
1389+
Err(MsgHandleErrInternal::from_finish_shutdown(msg, channel_id, channel.force_shutdown(), self.get_channel_update(&channel).ok()))
1390+
},
1391+
ChannelError::CloseDelayBroadcast { .. } => { panic!("Wait is only generated on receipt of channel_reestablish, which is handled by try_chan_entry, we don't bother to support it here"); }
1392+
};
1393+
match handle_error!(self, err) {
1394+
Ok(_) => unreachable!(),
1395+
Err(e) => {
1396+
if let Some(msgs::ErrorAction::IgnoreError) = e.action {
1397+
} else {
1398+
log_error!(self, "Got bad keys: {}!", e.err);
1399+
let mut channel_state = self.channel_state.lock().unwrap();
1400+
channel_state.pending_msg_events.push(events::MessageSendEvent::HandleError {
1401+
node_id: their_node_id,
1402+
action: e.action,
1403+
});
1404+
}
1405+
continue;
1406+
},
13781407
}
1379-
//TODO: Handle...this is bad!
1380-
continue;
1381-
},
1408+
}
13821409
};
13831410
if let Err(e) = self.monitor.add_update_monitor(monitor.get_funding_txo().unwrap(), monitor) {
13841411
handle_errors.push((chan.get().get_their_node_id(), handle_monitor_err!(self, e, channel_state, chan, RAACommitmentOrder::CommitmentFirst, false, true)));

0 commit comments

Comments
 (0)