Skip to content

Commit 93f5e01

Browse files
committed
Simplify send_htlc return value
1 parent d53ab19 commit 93f5e01

File tree

1 file changed

+11
-21
lines changed

1 file changed

+11
-21
lines changed

lightning/src/ln/channel.rs

Lines changed: 11 additions & 21 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) => {
7241+
Ok(can_add_htlc) => {
72427242
// `send_htlc` only returns `Ok(None)`, when an update goes into
72437243
// the holding cell, but since we're currently freeing it, we should
72447244
// always expect to see the `update_add` go out.
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;
@@ -10603,7 +10603,7 @@ where
1060310603
fee_estimator,
1060410604
logger,
1060510605
)
10606-
.map(|msg_opt| assert!(msg_opt.is_none(), "We forced holding cell?"))
10606+
.map(|can_add_htlc| assert!(!can_add_htlc, "We forced holding cell?"))
1060710607
.map_err(|err| {
1060810608
debug_assert!(err.0.is_temporary(), "Queuing HTLC should return temporary error");
1060910609
err
@@ -10613,8 +10613,9 @@ where
1061310613
/// Adds a pending outbound HTLC to this channel, note that you probably want
1061410614
/// [`Self::send_htlc_and_commit`] instead cause you'll want both messages at once.
1061510615
///
10616-
/// This returns an optional UpdateAddHTLC as we may be in a state where we cannot add HTLCs on
10617-
/// the wire:
10616+
/// This returns a boolean indicating whether we are in a state where we can add HTLCs on the wire.
10617+
/// Reasons we may not be able to add HTLCs on the wire include:
10618+
///
1061810619
/// * In cases where we're waiting on the remote peer to send us a revoke_and_ack, we
1061910620
/// wouldn't be able to determine what they actually ACK'ed if we have two sets of updates
1062010621
/// awaiting ACK.
@@ -10631,7 +10632,7 @@ where
1063110632
source: HTLCSource, onion_routing_packet: msgs::OnionPacket, mut force_holding_cell: bool,
1063210633
skimmed_fee_msat: Option<u64>, blinding_point: Option<PublicKey>,
1063310634
fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L,
10634-
) -> Result<Option<msgs::UpdateAddHTLC>, (LocalHTLCFailureReason, String)>
10635+
) -> Result<bool, (LocalHTLCFailureReason, String)>
1063510636
where
1063610637
F::Target: FeeEstimator,
1063710638
L::Target: Logger,
@@ -10712,7 +10713,7 @@ where
1071210713
skimmed_fee_msat,
1071310714
blinding_point,
1071410715
});
10715-
return Ok(None);
10716+
return Ok(false);
1071610717
}
1071710718

1071810719
// Record the approximate time when the HTLC is sent to the peer. This timestamp is later used to calculate the
@@ -10733,20 +10734,9 @@ where
1073310734
skimmed_fee_msat,
1073410735
send_timestamp,
1073510736
});
10736-
10737-
let res = msgs::UpdateAddHTLC {
10738-
channel_id: self.context.channel_id,
10739-
htlc_id: self.context.next_holder_htlc_id,
10740-
amount_msat,
10741-
payment_hash,
10742-
cltv_expiry,
10743-
onion_routing_packet,
10744-
skimmed_fee_msat,
10745-
blinding_point,
10746-
};
1074710737
self.context.next_holder_htlc_id += 1;
1074810738

10749-
Ok(Some(res))
10739+
Ok(true)
1075010740
}
1075110741

1075210742
#[rustfmt::skip]
@@ -11006,7 +10996,7 @@ where
1100610996
);
1100710997
// All [`LocalHTLCFailureReason`] errors are temporary, so they are [`ChannelError::Ignore`].
1100810998
match send_res.map_err(|(_, msg)| ChannelError::Ignore(msg))? {
11009-
Some(_) => {
10999+
true => {
1101011000
let monitor_update = self.build_commitment_no_status_check(logger);
1101111001
self.monitor_updating_paused(
1101211002
false,
@@ -11018,7 +11008,7 @@ where
1101811008
);
1101911009
Ok(self.push_ret_blockable_mon_update(monitor_update))
1102011010
},
11021-
None => Ok(None),
11011+
false => Ok(None),
1102211012
}
1102311013
}
1102411014

0 commit comments

Comments
 (0)