Skip to content

Commit 1833070

Browse files
committed
Correct confusing docs on Channel methods
The methods return `Ok(())` always, they just happen to never return in the case of a duplicate claim if debug assertions are enabled.
1 parent aa9630b commit 1833070

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

lightning/src/ln/channel.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1947,8 +1947,9 @@ impl<Signer: Sign> Channel<Signer> {
19471947
/// however, fail more than once as we wait for an upstream failure to be irrevocably committed
19481948
/// before we fail backwards.
19491949
///
1950-
/// If we do fail twice, we debug_assert!(false) and return Ok(()). Thus, will always return
1951-
/// Ok(()) if debug assertions are turned on or preconditions are met.
1950+
/// If we do fail twice, we `debug_assert!(false)` and return `Ok(None)`. Thus, this will always
1951+
/// return `Ok(_)` if preconditions are met. In any case, `Err`s will only be
1952+
/// [`ChannelError::Ignore`].
19521953
pub fn queue_fail_htlc<L: Deref>(&mut self, htlc_id_arg: u64, err_packet: msgs::OnionErrorPacket, logger: &L)
19531954
-> Result<(), ChannelError> where L::Target: Logger {
19541955
self.fail_htlc(htlc_id_arg, err_packet, true, logger)
@@ -1959,8 +1960,10 @@ impl<Signer: Sign> Channel<Signer> {
19591960
/// an HTLC more than once or fulfill once and then attempt to fail after reconnect. We cannot,
19601961
/// however, fail more than once as we wait for an upstream failure to be irrevocably committed
19611962
/// before we fail backwards.
1962-
/// If we do fail twice, we debug_assert!(false) and return Ok(None). Thus, will always return
1963-
/// Ok(_) if debug assertions are turned on or preconditions are met.
1963+
///
1964+
/// If we do fail twice, we `debug_assert!(false)` and return `Ok(None)`. Thus, this will always
1965+
/// return `Ok(_)` if preconditions are met. In any case, `Err`s will only be
1966+
/// [`ChannelError::Ignore`].
19641967
fn fail_htlc<L: Deref>(&mut self, htlc_id_arg: u64, err_packet: msgs::OnionErrorPacket, mut force_holding_cell: bool, logger: &L)
19651968
-> Result<Option<msgs::UpdateFailHTLC>, ChannelError> where L::Target: Logger {
19661969
if (self.channel_state & (ChannelState::ChannelReady as u32)) != (ChannelState::ChannelReady as u32) {
@@ -2001,7 +2004,7 @@ impl<Signer: Sign> Channel<Signer> {
20012004
}
20022005

20032006
if (self.channel_state & (ChannelState::AwaitingRemoteRevoke as u32 | ChannelState::PeerDisconnected as u32 | ChannelState::MonitorUpdateInProgress as u32)) != 0 {
2004-
debug_assert!(force_holding_cell, "We don't expect to need to use the holding cell if we weren't trying to");
2007+
debug_assert!(force_holding_cell, "!force_holding_cell is only called when emptying the holding cell, so we shouldn't end up back in it!");
20052008
force_holding_cell = true;
20062009
}
20072010

@@ -5501,8 +5504,14 @@ impl<Signer: Sign> Channel<Signer> {
55015504
pub fn queue_add_htlc<L: Deref>(&mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32, source: HTLCSource,
55025505
onion_routing_packet: msgs::OnionPacket, logger: &L)
55035506
-> Result<(), ChannelError> where L::Target: Logger {
5504-
self.send_htlc(amount_msat, payment_hash, cltv_expiry, source, onion_routing_packet, true, logger)
5507+
self
5508+
.send_htlc(amount_msat, payment_hash, cltv_expiry, source, onion_routing_packet, true, logger)
55055509
.map(|msg_opt| assert!(msg_opt.is_none(), "We forced holding cell?"))
5510+
.map_err(|err| {
5511+
if let ChannelError::Ignore(_) = err { /* fine */ }
5512+
else { debug_assert!(false, "Queueing cannot trigger channel failure"); }
5513+
err
5514+
})
55065515
}
55075516

55085517
/// Adds a pending outbound HTLC to this channel, note that you probably want

0 commit comments

Comments
 (0)