Skip to content

Commit 5e3af3b

Browse files
committed
Simplify send_htlc return value
1 parent 29aab5d commit 5e3af3b

File tree

1 file changed

+18
-35
lines changed

1 file changed

+18
-35
lines changed

lightning/src/ln/channel.rs

Lines changed: 18 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7238,12 +7238,12 @@ where
72387238
fee_estimator,
72397239
logger,
72407240
) {
7241-
Ok(update_add_msg_opt) => {
7242-
// `send_htlc` only returns `Ok(None)`, when an update goes into
7241+
Ok(can_add_htlc) => {
7242+
// `send_htlc` only returns `Ok(false)`, when an update goes into
72437243
// the holding cell, but since we're currently freeing it, we should
7244-
// always expect to see the `update_add` go out.
7244+
// always expect to see the htlc added.
72457245
debug_assert!(
7246-
update_add_msg_opt.is_some(),
7246+
can_add_htlc,
72477247
"Must generate new update if we're freeing the holding cell"
72487248
);
72497249
update_add_count += 1;
@@ -10601,7 +10601,7 @@ where
1060110601
fee_estimator,
1060210602
logger,
1060310603
)
10604-
.map(|msg_opt| assert!(msg_opt.is_none(), "We forced holding cell?"))
10604+
.map(|can_add_htlc| assert!(!can_add_htlc, "We forced holding cell?"))
1060510605
.map_err(|err| {
1060610606
debug_assert!(err.0.is_temporary(), "Queuing HTLC should return temporary error");
1060710607
err
@@ -10611,8 +10611,9 @@ where
1061110611
/// Adds a pending outbound HTLC to this channel, note that you probably want
1061210612
/// [`Self::send_htlc_and_commit`] instead cause you'll want both messages at once.
1061310613
///
10614-
/// This returns an optional UpdateAddHTLC as we may be in a state where we cannot add HTLCs on
10615-
/// the wire:
10614+
/// This returns a boolean indicating whether we are in a state where we can add HTLCs on the wire.
10615+
/// Reasons we may not be able to add HTLCs on the wire include:
10616+
///
1061610617
/// * In cases where we're waiting on the remote peer to send us a revoke_and_ack, we
1061710618
/// wouldn't be able to determine what they actually ACK'ed if we have two sets of updates
1061810619
/// awaiting ACK.
@@ -10629,7 +10630,7 @@ where
1062910630
source: HTLCSource, onion_routing_packet: msgs::OnionPacket, mut force_holding_cell: bool,
1063010631
skimmed_fee_msat: Option<u64>, blinding_point: Option<PublicKey>,
1063110632
fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L,
10632-
) -> Result<Option<msgs::UpdateAddHTLC>, (LocalHTLCFailureReason, String)>
10633+
) -> Result<bool, (LocalHTLCFailureReason, String)>
1063310634
where
1063410635
F::Target: FeeEstimator,
1063510636
L::Target: Logger,
@@ -10710,7 +10711,7 @@ where
1071010711
skimmed_fee_msat,
1071110712
blinding_point,
1071210713
});
10713-
return Ok(None);
10714+
return Ok(false);
1071410715
}
1071510716

1071610717
// Record the approximate time when the HTLC is sent to the peer. This timestamp is later used to calculate the
@@ -10731,20 +10732,9 @@ where
1073110732
skimmed_fee_msat,
1073210733
send_timestamp,
1073310734
});
10734-
10735-
let res = msgs::UpdateAddHTLC {
10736-
channel_id: self.context.channel_id,
10737-
htlc_id: self.context.next_holder_htlc_id,
10738-
amount_msat,
10739-
payment_hash,
10740-
cltv_expiry,
10741-
onion_routing_packet,
10742-
skimmed_fee_msat,
10743-
blinding_point,
10744-
};
1074510735
self.context.next_holder_htlc_id += 1;
1074610736

10747-
Ok(Some(res))
10737+
Ok(true)
1074810738
}
1074910739

1075010740
#[rustfmt::skip]
@@ -11003,20 +10993,13 @@ where
1100310993
logger,
1100410994
);
1100510995
// All [`LocalHTLCFailureReason`] errors are temporary, so they are [`ChannelError::Ignore`].
11006-
match send_res.map_err(|(_, msg)| ChannelError::Ignore(msg))? {
11007-
Some(_) => {
11008-
let monitor_update = self.build_commitment_no_status_check(logger);
11009-
self.monitor_updating_paused(
11010-
false,
11011-
true,
11012-
false,
11013-
Vec::new(),
11014-
Vec::new(),
11015-
Vec::new(),
11016-
);
11017-
Ok(self.push_ret_blockable_mon_update(monitor_update))
11018-
},
11019-
None => Ok(None),
10996+
let can_add_htlc = send_res.map_err(|(_, msg)| ChannelError::Ignore(msg))?;
10997+
if can_add_htlc {
10998+
let monitor_update = self.build_commitment_no_status_check(logger);
10999+
self.monitor_updating_paused(false, true, false, Vec::new(), Vec::new(), Vec::new());
11000+
Ok(self.push_ret_blockable_mon_update(monitor_update))
11001+
} else {
11002+
Ok(None)
1102011003
}
1102111004
}
1102211005

0 commit comments

Comments
 (0)