@@ -6191,11 +6191,8 @@ where
6191
6191
Ok(decoded_onion) => decoded_onion,
6192
6192
6193
6193
Err((htlc_fail, reason)) => {
6194
- htlc_fails.push((
6195
- htlc_fail,
6196
- HTLCHandlingFailureType::InvalidOnion,
6197
- reason.into(),
6198
- ));
6194
+ let failure_type = HTLCHandlingFailureType::InvalidOnion;
6195
+ htlc_fails.push((htlc_fail, failure_type, reason.into()));
6199
6196
continue;
6200
6197
},
6201
6198
};
@@ -6329,14 +6326,7 @@ where
6329
6326
6330
6327
let mut new_events = VecDeque::new();
6331
6328
let mut failed_forwards = Vec::new();
6332
- let mut phantom_receives: Vec<(
6333
- u64,
6334
- Option<PublicKey>,
6335
- OutPoint,
6336
- ChannelId,
6337
- u128,
6338
- Vec<(PendingHTLCInfo, u64)>,
6339
- )> = Vec::new();
6329
+ let mut phantom_receives: Vec<PerSourcePendingForward> = Vec::new();
6340
6330
{
6341
6331
let mut forward_htlcs = new_hash_map();
6342
6332
mem::swap(&mut forward_htlcs, &mut self.forward_htlcs.lock().unwrap());
@@ -6540,13 +6530,10 @@ where
6540
6530
.filter_map(|chan| {
6541
6531
let balances =
6542
6532
chan.get_available_balances(&self.fee_estimator);
6543
- if outgoing_amt_msat
6544
- <= balances.next_outbound_htlc_limit_msat
6545
- && outgoing_amt_msat
6546
- >= balances.next_outbound_htlc_minimum_msat && chan
6547
- .context
6548
- .is_usable()
6549
- {
6533
+ let is_in_range = (balances.next_outbound_htlc_minimum_msat
6534
+ ..=balances.next_outbound_htlc_limit_msat)
6535
+ .contains(&outgoing_amt_msat);
6536
+ if is_in_range && chan.context.is_usable() {
6550
6537
Some((chan, balances))
6551
6538
} else {
6552
6539
None
@@ -6567,10 +6554,9 @@ where
6567
6554
{
6568
6555
chan
6569
6556
} else {
6570
- forwarding_channel_not_found!(core::iter::once(
6571
- forward_info
6572
- )
6573
- .chain(draining_pending_forwards));
6557
+ let fwd_iter = core::iter::once(forward_info)
6558
+ .chain(draining_pending_forwards);
6559
+ forwarding_channel_not_found!(fwd_iter);
6574
6560
break;
6575
6561
}
6576
6562
},
@@ -6610,16 +6596,15 @@ where
6610
6596
.and_then(Channel::as_funded_mut)
6611
6597
{
6612
6598
let data = self.get_htlc_inbound_temp_fail_data(reason);
6599
+ let failure_type = HTLCHandlingFailureType::Forward {
6600
+ node_id: Some(chan.context.get_counterparty_node_id()),
6601
+ channel_id: forward_chan_id,
6602
+ };
6613
6603
failed_forwards.push((
6614
6604
htlc_source,
6615
6605
payment_hash,
6616
6606
HTLCFailReason::reason(reason, data),
6617
- HTLCHandlingFailureType::Forward {
6618
- node_id: Some(
6619
- chan.context.get_counterparty_node_id(),
6620
- ),
6621
- channel_id: forward_chan_id,
6622
- },
6607
+ failure_type,
6623
6608
));
6624
6609
} else {
6625
6610
forwarding_channel_not_found!(core::iter::once(
@@ -6834,19 +6819,19 @@ where
6834
6819
$htlc.value,
6835
6820
self.best_block.read().unwrap().height,
6836
6821
);
6822
+ let counterparty_node_id =
6823
+ $htlc.prev_hop.counterparty_node_id;
6824
+ let incoming_packet_shared_secret =
6825
+ $htlc.prev_hop.incoming_packet_shared_secret;
6837
6826
failed_forwards.push((
6838
6827
HTLCSource::PreviousHopData(HTLCPreviousHopData {
6839
6828
short_channel_id: $htlc.prev_hop.short_channel_id,
6840
6829
user_channel_id: $htlc.prev_hop.user_channel_id,
6841
- counterparty_node_id: $htlc
6842
- .prev_hop
6843
- .counterparty_node_id,
6830
+ counterparty_node_id,
6844
6831
channel_id: prev_channel_id,
6845
6832
outpoint: prev_funding_outpoint,
6846
6833
htlc_id: $htlc.prev_hop.htlc_id,
6847
- incoming_packet_shared_secret: $htlc
6848
- .prev_hop
6849
- .incoming_packet_shared_secret,
6834
+ incoming_packet_shared_secret,
6850
6835
phantom_shared_secret,
6851
6836
blinded_failure,
6852
6837
cltv_expiry: Some(cltv_expiry),
@@ -7231,7 +7216,8 @@ where
7231
7216
for (chan_id, chan) in peer_state.channel_by_id.iter_mut()
7232
7217
.filter_map(|(chan_id, chan)| chan.as_funded_mut().map(|chan| (chan_id, chan)))
7233
7218
{
7234
- let new_feerate = if chan.funding.get_channel_type().supports_anchors_zero_fee_htlc_tx() {
7219
+ let is_anchors_chan = chan.funding.get_channel_type().supports_anchors_zero_fee_htlc_tx();
7220
+ let new_feerate = if is_anchors_chan {
7235
7221
anchor_feerate
7236
7222
} else {
7237
7223
non_anchor_feerate
@@ -7462,23 +7448,19 @@ where
7462
7448
// In this case we're not going to handle any timeouts of the parts here.
7463
7449
// This condition determining whether the MPP is complete here must match
7464
7450
// exactly the condition used in `process_pending_htlc_forwards`.
7465
- if payment.htlcs[0].total_msat
7466
- <= payment
7467
- .htlcs
7468
- .iter()
7469
- .fold(0, |total, htlc| total + htlc.sender_intended_value)
7470
- {
7451
+ let htlc_total_msat =
7452
+ payment.htlcs.iter().map(|h| h.sender_intended_value).sum();
7453
+ if payment.htlcs[0].total_msat <= htlc_total_msat {
7471
7454
return true;
7472
7455
} else if payment.htlcs.iter_mut().any(|htlc| {
7473
7456
htlc.timer_ticks += 1;
7474
7457
return htlc.timer_ticks >= MPP_TIMEOUT_TICKS;
7475
7458
}) {
7476
- timed_out_mpp_htlcs.extend(
7477
- payment
7478
- .htlcs
7479
- .drain(..)
7480
- .map(|htlc: ClaimableHTLC| (htlc.prev_hop, *payment_hash)),
7481
- );
7459
+ let htlcs = payment
7460
+ .htlcs
7461
+ .drain(..)
7462
+ .map(|htlc: ClaimableHTLC| (htlc.prev_hop, *payment_hash));
7463
+ timed_out_mpp_htlcs.extend(htlcs);
7482
7464
return false;
7483
7465
}
7484
7466
}
@@ -9943,15 +9925,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
9943
9925
9944
9926
#[inline]
9945
9927
fn forward_htlcs_without_forward_event(
9946
- &self,
9947
- per_source_pending_forwards: &mut [(
9948
- u64,
9949
- Option<PublicKey>,
9950
- OutPoint,
9951
- ChannelId,
9952
- u128,
9953
- Vec<(PendingHTLCInfo, u64)>,
9954
- )],
9928
+ &self, per_source_pending_forwards: &mut [PerSourcePendingForward],
9955
9929
) -> bool {
9956
9930
let mut push_forward_event = false;
9957
9931
for &mut (
@@ -10038,7 +10012,11 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
10038
10012
Some(prev_channel_id),
10039
10013
Some(forward_info.payment_hash),
10040
10014
);
10041
- log_info!(logger, "Failed to forward incoming HTLC: detected duplicate intercepted payment over short channel id {}", scid);
10015
+ log_info!(
10016
+ logger,
10017
+ "Failed to forward incoming HTLC: detected duplicate intercepted payment over short channel id {}",
10018
+ scid
10019
+ );
10042
10020
let htlc_source =
10043
10021
HTLCSource::PreviousHopData(HTLCPreviousHopData {
10044
10022
short_channel_id: prev_short_channel_id,
@@ -10058,15 +10036,19 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
10058
10036
.incoming_cltv_expiry(),
10059
10037
});
10060
10038
10061
- failed_intercept_forwards.push((
10062
- htlc_source,
10063
- forward_info.payment_hash,
10064
- HTLCFailReason::from_failure_code(
10065
- LocalHTLCFailureReason::UnknownNextPeer,
10066
- ),
10039
+ let payment_hash = forward_info.payment_hash;
10040
+ let reason = HTLCFailReason::from_failure_code(
10041
+ LocalHTLCFailureReason::UnknownNextPeer,
10042
+ );
10043
+ let failure_type =
10067
10044
HTLCHandlingFailureType::InvalidForward {
10068
10045
requested_forward_scid: scid,
10069
- },
10046
+ };
10047
+ failed_intercept_forwards.push((
10048
+ htlc_source,
10049
+ payment_hash,
10050
+ reason,
10051
+ failure_type,
10070
10052
));
10071
10053
},
10072
10054
}
0 commit comments