@@ -7245,12 +7245,12 @@ where
7245
7245
fee_estimator,
7246
7246
logger,
7247
7247
) {
7248
- Ok(update_add_msg_opt ) => {
7249
- // `send_htlc` only returns `Ok(None )`, when an update goes into
7248
+ Ok(can_add_htlc ) => {
7249
+ // `send_htlc` only returns `Ok(false )`, when an update goes into
7250
7250
// the holding cell, but since we're currently freeing it, we should
7251
- // always expect to see the `update_add` go out .
7251
+ // always expect to see the htlc added .
7252
7252
debug_assert!(
7253
- update_add_msg_opt.is_some() ,
7253
+ can_add_htlc ,
7254
7254
"Must generate new update if we're freeing the holding cell"
7255
7255
);
7256
7256
update_add_count += 1;
@@ -10581,34 +10581,43 @@ where
10581
10581
))
10582
10582
}
10583
10583
10584
- // Send stuff to our remote peers:
10585
-
10586
10584
/// Queues up an outbound HTLC to send by placing it in the holding cell. You should call
10587
10585
/// [`Self::maybe_free_holding_cell_htlcs`] in order to actually generate and send the
10588
10586
/// commitment update.
10589
- #[rustfmt::skip]
10590
10587
pub fn queue_add_htlc<F: Deref, L: Deref>(
10591
- &mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32, source: HTLCSource,
10592
- onion_routing_packet: msgs::OnionPacket, skimmed_fee_msat: Option<u64>,
10593
- blinding_point: Option<PublicKey>, fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L
10588
+ &mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32,
10589
+ source: HTLCSource, onion_routing_packet: msgs::OnionPacket, skimmed_fee_msat: Option<u64>,
10590
+ blinding_point: Option<PublicKey>, fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L,
10594
10591
) -> Result<(), (LocalHTLCFailureReason, String)>
10595
- where F::Target: FeeEstimator, L::Target: Logger
10592
+ where
10593
+ F::Target: FeeEstimator,
10594
+ L::Target: Logger,
10596
10595
{
10597
- self
10598
- .send_htlc(amount_msat, payment_hash, cltv_expiry, source, onion_routing_packet, true,
10599
- skimmed_fee_msat, blinding_point, fee_estimator, logger)
10600
- .map(|msg_opt| assert!(msg_opt.is_none(), "We forced holding cell?"))
10601
- .map_err(|err| {
10602
- debug_assert!(err.0.is_temporary(), "Queuing HTLC should return temporary error");
10603
- err
10604
- })
10596
+ self.send_htlc(
10597
+ amount_msat,
10598
+ payment_hash,
10599
+ cltv_expiry,
10600
+ source,
10601
+ onion_routing_packet,
10602
+ true,
10603
+ skimmed_fee_msat,
10604
+ blinding_point,
10605
+ fee_estimator,
10606
+ logger,
10607
+ )
10608
+ .map(|can_add_htlc| assert!(!can_add_htlc, "We forced holding cell?"))
10609
+ .map_err(|err| {
10610
+ debug_assert!(err.0.is_temporary(), "Queuing HTLC should return temporary error");
10611
+ err
10612
+ })
10605
10613
}
10606
10614
10607
10615
/// Adds a pending outbound HTLC to this channel, note that you probably want
10608
10616
/// [`Self::send_htlc_and_commit`] instead cause you'll want both messages at once.
10609
10617
///
10610
- /// This returns an optional UpdateAddHTLC as we may be in a state where we cannot add HTLCs on
10611
- /// the wire:
10618
+ /// This returns a boolean indicating whether we are in a state where we can add HTLCs on the wire.
10619
+ /// Reasons we may not be able to add HTLCs on the wire include:
10620
+ ///
10612
10621
/// * In cases where we're waiting on the remote peer to send us a revoke_and_ack, we
10613
10622
/// wouldn't be able to determine what they actually ACK'ed if we have two sets of updates
10614
10623
/// awaiting ACK.
@@ -10620,18 +10629,19 @@ where
10620
10629
/// on this [`FundedChannel`] if `force_holding_cell` is false.
10621
10630
///
10622
10631
/// `Err`'s will always be temporary channel failures.
10623
- #[rustfmt::skip]
10624
10632
fn send_htlc<F: Deref, L: Deref>(
10625
- &mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32, source: HTLCSource,
10626
- onion_routing_packet: msgs::OnionPacket, mut force_holding_cell: bool,
10633
+ &mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32,
10634
+ source: HTLCSource, onion_routing_packet: msgs::OnionPacket, mut force_holding_cell: bool,
10627
10635
skimmed_fee_msat: Option<u64>, blinding_point: Option<PublicKey>,
10628
- fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L
10629
- ) -> Result<Option<msgs::UpdateAddHTLC>, (LocalHTLCFailureReason, String)>
10630
- where F::Target: FeeEstimator, L::Target: Logger
10636
+ fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L,
10637
+ ) -> Result<bool, (LocalHTLCFailureReason, String)>
10638
+ where
10639
+ F::Target: FeeEstimator,
10640
+ L::Target: Logger,
10631
10641
{
10632
- if !matches!(self.context.channel_state, ChannelState::ChannelReady(_)) ||
10633
- self.context.channel_state.is_local_shutdown_sent() ||
10634
- self.context.channel_state.is_remote_shutdown_sent()
10642
+ if !matches!(self.context.channel_state, ChannelState::ChannelReady(_))
10643
+ || self.context.channel_state.is_local_shutdown_sent()
10644
+ || self.context.channel_state.is_remote_shutdown_sent()
10635
10645
{
10636
10646
return Err((LocalHTLCFailureReason::ChannelNotReady,
10637
10647
"Cannot send HTLC until channel is fully established and we haven't started shutting down".to_owned()));
@@ -10643,13 +10653,23 @@ where
10643
10653
10644
10654
let available_balances = self.get_available_balances(fee_estimator);
10645
10655
if amount_msat < available_balances.next_outbound_htlc_minimum_msat {
10646
- return Err((LocalHTLCFailureReason::HTLCMinimum, format!("Cannot send less than our next-HTLC minimum - {} msat",
10647
- available_balances.next_outbound_htlc_minimum_msat)));
10656
+ return Err((
10657
+ LocalHTLCFailureReason::HTLCMinimum,
10658
+ format!(
10659
+ "Cannot send less than our next-HTLC minimum - {} msat",
10660
+ available_balances.next_outbound_htlc_minimum_msat
10661
+ ),
10662
+ ));
10648
10663
}
10649
10664
10650
10665
if amount_msat > available_balances.next_outbound_htlc_limit_msat {
10651
- return Err((LocalHTLCFailureReason::HTLCMaximum, format!("Cannot send more than our next-HTLC maximum - {} msat",
10652
- available_balances.next_outbound_htlc_limit_msat)));
10666
+ return Err((
10667
+ LocalHTLCFailureReason::HTLCMaximum,
10668
+ format!(
10669
+ "Cannot send more than our next-HTLC maximum - {} msat",
10670
+ available_balances.next_outbound_htlc_limit_msat
10671
+ ),
10672
+ ));
10653
10673
}
10654
10674
10655
10675
if self.context.channel_state.is_peer_disconnected() {
@@ -10659,16 +10679,26 @@ where
10659
10679
// disconnected during the time the previous hop was doing the commitment dance we may
10660
10680
// end up getting here after the forwarding delay. In any case, returning an
10661
10681
// IgnoreError will get ChannelManager to do the right thing and fail backwards now.
10662
- return Err((LocalHTLCFailureReason::PeerOffline,
10663
- "Cannot send an HTLC while disconnected from channel counterparty".to_owned()));
10682
+ return Err((
10683
+ LocalHTLCFailureReason::PeerOffline,
10684
+ "Cannot send an HTLC while disconnected from channel counterparty".to_owned(),
10685
+ ));
10664
10686
}
10665
10687
10666
10688
let need_holding_cell = !self.context.channel_state.can_generate_new_commitment();
10667
- log_debug!(logger, "Pushing new outbound HTLC with hash {} for {} msat {}",
10668
- payment_hash, amount_msat,
10669
- if force_holding_cell { "into holding cell" }
10670
- else if need_holding_cell { "into holding cell as we're awaiting an RAA or monitor" }
10671
- else { "to peer" });
10689
+ log_debug!(
10690
+ logger,
10691
+ "Pushing new outbound HTLC with hash {} for {} msat {}",
10692
+ payment_hash,
10693
+ amount_msat,
10694
+ if force_holding_cell {
10695
+ "into holding cell"
10696
+ } else if need_holding_cell {
10697
+ "into holding cell as we're awaiting an RAA or monitor"
10698
+ } else {
10699
+ "to peer"
10700
+ }
10701
+ );
10672
10702
10673
10703
if need_holding_cell {
10674
10704
force_holding_cell = true;
@@ -10685,7 +10715,7 @@ where
10685
10715
skimmed_fee_msat,
10686
10716
blinding_point,
10687
10717
});
10688
- return Ok(None );
10718
+ return Ok(false );
10689
10719
}
10690
10720
10691
10721
// Record the approximate time when the HTLC is sent to the peer. This timestamp is later used to calculate the
@@ -10706,20 +10736,9 @@ where
10706
10736
skimmed_fee_msat,
10707
10737
send_timestamp,
10708
10738
});
10709
-
10710
- let res = msgs::UpdateAddHTLC {
10711
- channel_id: self.context.channel_id,
10712
- htlc_id: self.context.next_holder_htlc_id,
10713
- amount_msat,
10714
- payment_hash,
10715
- cltv_expiry,
10716
- onion_routing_packet,
10717
- skimmed_fee_msat,
10718
- blinding_point,
10719
- };
10720
10739
self.context.next_holder_htlc_id += 1;
10721
10740
10722
- Ok(Some(res) )
10741
+ Ok(true )
10723
10742
}
10724
10743
10725
10744
#[rustfmt::skip]
@@ -10956,24 +10975,35 @@ where
10956
10975
///
10957
10976
/// Shorthand for calling [`Self::send_htlc`] followed by a commitment update, see docs on
10958
10977
/// [`Self::send_htlc`] and [`Self::build_commitment_no_state_update`] for more info.
10959
- #[rustfmt::skip]
10960
10978
pub fn send_htlc_and_commit<F: Deref, L: Deref>(
10961
10979
&mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32,
10962
10980
source: HTLCSource, onion_routing_packet: msgs::OnionPacket, skimmed_fee_msat: Option<u64>,
10963
- fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L
10981
+ fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L,
10964
10982
) -> Result<Option<ChannelMonitorUpdate>, ChannelError>
10965
- where F::Target: FeeEstimator, L::Target: Logger
10983
+ where
10984
+ F::Target: FeeEstimator,
10985
+ L::Target: Logger,
10966
10986
{
10967
- let send_res = self.send_htlc(amount_msat, payment_hash, cltv_expiry, source,
10968
- onion_routing_packet, false, skimmed_fee_msat, None, fee_estimator, logger);
10987
+ let send_res = self.send_htlc(
10988
+ amount_msat,
10989
+ payment_hash,
10990
+ cltv_expiry,
10991
+ source,
10992
+ onion_routing_packet,
10993
+ false,
10994
+ skimmed_fee_msat,
10995
+ None,
10996
+ fee_estimator,
10997
+ logger,
10998
+ );
10969
10999
// All [`LocalHTLCFailureReason`] errors are temporary, so they are [`ChannelError::Ignore`].
10970
- match send_res.map_err(|(_, msg)| ChannelError::Ignore(msg))? {
10971
- Some(_) => {
10972
- let monitor_update = self.build_commitment_no_status_check(logger);
10973
- self.monitor_updating_paused(false, true, false, Vec::new(), Vec::new(), Vec::new());
10974
- Ok(self.push_ret_blockable_mon_update(monitor_update))
10975
- },
10976
- None => Ok(None)
11000
+ let can_add_htlc = send_res.map_err(|(_, msg)| ChannelError::Ignore(msg))?;
11001
+ if can_add_htlc {
11002
+ let monitor_update = self.build_commitment_no_status_check(logger);
11003
+ self.monitor_updating_paused(false, true, false, Vec::new(), Vec::new(), Vec::new());
11004
+ Ok(self.push_ret_blockable_mon_update(monitor_update))
11005
+ } else {
11006
+ Ok(None)
10977
11007
}
10978
11008
}
10979
11009
0 commit comments