@@ -10582,22 +10582,32 @@ where
10582
10582
/// Queues up an outbound HTLC to send by placing it in the holding cell. You should call
10583
10583
/// [`Self::maybe_free_holding_cell_htlcs`] in order to actually generate and send the
10584
10584
/// commitment update.
10585
- #[rustfmt::skip]
10586
10585
pub fn queue_add_htlc<F: Deref, L: Deref>(
10587
- &mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32, source: HTLCSource,
10588
- onion_routing_packet: msgs::OnionPacket, skimmed_fee_msat: Option<u64>,
10589
- blinding_point: Option<PublicKey>, fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L
10586
+ &mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32,
10587
+ source: HTLCSource, onion_routing_packet: msgs::OnionPacket, skimmed_fee_msat: Option<u64>,
10588
+ blinding_point: Option<PublicKey>, fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L,
10590
10589
) -> Result<(), (LocalHTLCFailureReason, String)>
10591
- where F::Target: FeeEstimator, L::Target: Logger
10590
+ where
10591
+ F::Target: FeeEstimator,
10592
+ L::Target: Logger,
10592
10593
{
10593
- self
10594
- .send_htlc(amount_msat, payment_hash, cltv_expiry, source, onion_routing_packet, true,
10595
- skimmed_fee_msat, blinding_point, fee_estimator, logger)
10596
- .map(|msg_opt| assert!(msg_opt.is_none(), "We forced holding cell?"))
10597
- .map_err(|err| {
10598
- debug_assert!(err.0.is_temporary(), "Queuing HTLC should return temporary error");
10599
- err
10600
- })
10594
+ self.send_htlc(
10595
+ amount_msat,
10596
+ payment_hash,
10597
+ cltv_expiry,
10598
+ source,
10599
+ onion_routing_packet,
10600
+ true,
10601
+ skimmed_fee_msat,
10602
+ blinding_point,
10603
+ fee_estimator,
10604
+ logger,
10605
+ )
10606
+ .map(|msg_opt| assert!(msg_opt.is_none(), "We forced holding cell?"))
10607
+ .map_err(|err| {
10608
+ debug_assert!(err.0.is_temporary(), "Queuing HTLC should return temporary error");
10609
+ err
10610
+ })
10601
10611
}
10602
10612
10603
10613
/// Adds a pending outbound HTLC to this channel, note that you probably want
@@ -10616,18 +10626,19 @@ where
10616
10626
/// on this [`FundedChannel`] if `force_holding_cell` is false.
10617
10627
///
10618
10628
/// `Err`'s will always be temporary channel failures.
10619
- #[rustfmt::skip]
10620
10629
fn send_htlc<F: Deref, L: Deref>(
10621
- &mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32, source: HTLCSource,
10622
- onion_routing_packet: msgs::OnionPacket, mut force_holding_cell: bool,
10630
+ &mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32,
10631
+ source: HTLCSource, onion_routing_packet: msgs::OnionPacket, mut force_holding_cell: bool,
10623
10632
skimmed_fee_msat: Option<u64>, blinding_point: Option<PublicKey>,
10624
- fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L
10633
+ fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L,
10625
10634
) -> Result<Option<msgs::UpdateAddHTLC>, (LocalHTLCFailureReason, String)>
10626
- where F::Target: FeeEstimator, L::Target: Logger
10635
+ where
10636
+ F::Target: FeeEstimator,
10637
+ L::Target: Logger,
10627
10638
{
10628
- if !matches!(self.context.channel_state, ChannelState::ChannelReady(_)) ||
10629
- self.context.channel_state.is_local_shutdown_sent() ||
10630
- self.context.channel_state.is_remote_shutdown_sent()
10639
+ if !matches!(self.context.channel_state, ChannelState::ChannelReady(_))
10640
+ || self.context.channel_state.is_local_shutdown_sent()
10641
+ || self.context.channel_state.is_remote_shutdown_sent()
10631
10642
{
10632
10643
return Err((LocalHTLCFailureReason::ChannelNotReady,
10633
10644
"Cannot send HTLC until channel is fully established and we haven't started shutting down".to_owned()));
@@ -10639,13 +10650,23 @@ where
10639
10650
10640
10651
let available_balances = self.get_available_balances(fee_estimator);
10641
10652
if amount_msat < available_balances.next_outbound_htlc_minimum_msat {
10642
- return Err((LocalHTLCFailureReason::HTLCMinimum, format!("Cannot send less than our next-HTLC minimum - {} msat",
10643
- available_balances.next_outbound_htlc_minimum_msat)));
10653
+ return Err((
10654
+ LocalHTLCFailureReason::HTLCMinimum,
10655
+ format!(
10656
+ "Cannot send less than our next-HTLC minimum - {} msat",
10657
+ available_balances.next_outbound_htlc_minimum_msat
10658
+ ),
10659
+ ));
10644
10660
}
10645
10661
10646
10662
if amount_msat > available_balances.next_outbound_htlc_limit_msat {
10647
- return Err((LocalHTLCFailureReason::HTLCMaximum, format!("Cannot send more than our next-HTLC maximum - {} msat",
10648
- available_balances.next_outbound_htlc_limit_msat)));
10663
+ return Err((
10664
+ LocalHTLCFailureReason::HTLCMaximum,
10665
+ format!(
10666
+ "Cannot send more than our next-HTLC maximum - {} msat",
10667
+ available_balances.next_outbound_htlc_limit_msat
10668
+ ),
10669
+ ));
10649
10670
}
10650
10671
10651
10672
if self.context.channel_state.is_peer_disconnected() {
@@ -10655,16 +10676,26 @@ where
10655
10676
// disconnected during the time the previous hop was doing the commitment dance we may
10656
10677
// end up getting here after the forwarding delay. In any case, returning an
10657
10678
// IgnoreError will get ChannelManager to do the right thing and fail backwards now.
10658
- return Err((LocalHTLCFailureReason::PeerOffline,
10659
- "Cannot send an HTLC while disconnected from channel counterparty".to_owned()));
10679
+ return Err((
10680
+ LocalHTLCFailureReason::PeerOffline,
10681
+ "Cannot send an HTLC while disconnected from channel counterparty".to_owned(),
10682
+ ));
10660
10683
}
10661
10684
10662
10685
let need_holding_cell = !self.context.channel_state.can_generate_new_commitment();
10663
- log_debug!(logger, "Pushing new outbound HTLC with hash {} for {} msat {}",
10664
- payment_hash, amount_msat,
10665
- if force_holding_cell { "into holding cell" }
10666
- else if need_holding_cell { "into holding cell as we're awaiting an RAA or monitor" }
10667
- else { "to peer" });
10686
+ log_debug!(
10687
+ logger,
10688
+ "Pushing new outbound HTLC with hash {} for {} msat {}",
10689
+ payment_hash,
10690
+ amount_msat,
10691
+ if force_holding_cell {
10692
+ "into holding cell"
10693
+ } else if need_holding_cell {
10694
+ "into holding cell as we're awaiting an RAA or monitor"
10695
+ } else {
10696
+ "to peer"
10697
+ }
10698
+ );
10668
10699
10669
10700
if need_holding_cell {
10670
10701
force_holding_cell = true;
@@ -10952,24 +10983,42 @@ where
10952
10983
///
10953
10984
/// Shorthand for calling [`Self::send_htlc`] followed by a commitment update, see docs on
10954
10985
/// [`Self::send_htlc`] and [`Self::build_commitment_no_state_update`] for more info.
10955
- #[rustfmt::skip]
10956
10986
pub fn send_htlc_and_commit<F: Deref, L: Deref>(
10957
10987
&mut self, amount_msat: u64, payment_hash: PaymentHash, cltv_expiry: u32,
10958
10988
source: HTLCSource, onion_routing_packet: msgs::OnionPacket, skimmed_fee_msat: Option<u64>,
10959
- fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L
10989
+ fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L,
10960
10990
) -> Result<Option<ChannelMonitorUpdate>, ChannelError>
10961
- where F::Target: FeeEstimator, L::Target: Logger
10991
+ where
10992
+ F::Target: FeeEstimator,
10993
+ L::Target: Logger,
10962
10994
{
10963
- let send_res = self.send_htlc(amount_msat, payment_hash, cltv_expiry, source,
10964
- onion_routing_packet, false, skimmed_fee_msat, None, fee_estimator, logger);
10995
+ let send_res = self.send_htlc(
10996
+ amount_msat,
10997
+ payment_hash,
10998
+ cltv_expiry,
10999
+ source,
11000
+ onion_routing_packet,
11001
+ false,
11002
+ skimmed_fee_msat,
11003
+ None,
11004
+ fee_estimator,
11005
+ logger,
11006
+ );
10965
11007
// All [`LocalHTLCFailureReason`] errors are temporary, so they are [`ChannelError::Ignore`].
10966
11008
match send_res.map_err(|(_, msg)| ChannelError::Ignore(msg))? {
10967
11009
Some(_) => {
10968
11010
let monitor_update = self.build_commitment_no_status_check(logger);
10969
- self.monitor_updating_paused(false, true, false, Vec::new(), Vec::new(), Vec::new());
11011
+ self.monitor_updating_paused(
11012
+ false,
11013
+ true,
11014
+ false,
11015
+ Vec::new(),
11016
+ Vec::new(),
11017
+ Vec::new(),
11018
+ );
10970
11019
Ok(self.push_ret_blockable_mon_update(monitor_update))
10971
11020
},
10972
- None => Ok(None)
11021
+ None => Ok(None),
10973
11022
}
10974
11023
}
10975
11024
0 commit comments