Skip to content

Commit a2d4889

Browse files
committed
panic on invalid calls to Channel::send_commitment instead of Err
1 parent 33fa278 commit a2d4889

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/ln/channel.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2390,12 +2390,13 @@ impl Channel {
23902390
/// Creates a signed commitment transaction to send to the remote peer.
23912391
/// Always returns a Channel-failing HandleError::action if an immediately-preceding (read: the
23922392
/// last call to this Channel) send_htlc returned Ok(Some(_)) and there is an Err.
2393+
/// May panic if called except immediately after a successful, Ok(Some(_))-returning send_htlc.
23932394
pub fn send_commitment(&mut self) -> Result<(msgs::CommitmentSigned, ChannelMonitor), HandleError> {
23942395
if (self.channel_state & (ChannelState::ChannelFunded as u32)) != (ChannelState::ChannelFunded as u32) {
2395-
return Err(HandleError{err: "Cannot create commitment tx until channel is fully established", action: None});
2396+
panic!("Cannot create commitment tx until channel is fully established");
23962397
}
23972398
if (self.channel_state & (ChannelState::AwaitingRemoteRevoke as u32)) == (ChannelState::AwaitingRemoteRevoke as u32) {
2398-
return Err(HandleError{err: "Cannot create commitment tx until remote revokes their previous commitment", action: None});
2399+
panic!("Cannot create commitment tx until remote revokes their previous commitment");
23992400
}
24002401
let mut have_updates = false; // TODO initialize with "have we sent a fee update?"
24012402
for htlc in self.pending_htlcs.iter() {
@@ -2405,7 +2406,7 @@ impl Channel {
24052406
if have_updates { break; }
24062407
}
24072408
if !have_updates {
2408-
return Err(HandleError{err: "Cannot create commitment tx until we have some updates to send", action: None});
2409+
panic!("Cannot create commitment tx until we have some updates to send");
24092410
}
24102411
self.send_commitment_no_status_check()
24112412
}

0 commit comments

Comments
 (0)