@@ -6209,7 +6209,7 @@ where
6209
6209
6210
6210
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
6211
6211
6212
- let mut sources = {
6212
+ let sources = {
6213
6213
let mut claimable_payments = self.claimable_payments.lock().unwrap();
6214
6214
if let Some(payment) = claimable_payments.claimable_payments.remove(&payment_hash) {
6215
6215
let mut receiver_node_id = self.our_network_pubkey;
@@ -6304,29 +6304,30 @@ where
6304
6304
return;
6305
6305
}
6306
6306
if valid_mpp {
6307
- let mut pending_claim_ptr_opt = None;
6308
- let mut source_claim_pairs = Vec::with_capacity(sources.len());
6309
- if sources.len() > 1 {
6307
+ let (source_claim_pairs, pending_claim_ptr_opt) = if sources.len() > 1 {
6310
6308
let mut pending_claims = PendingMPPClaim {
6311
6309
channels_without_preimage: Vec::new(),
6312
6310
channels_with_preimage: Vec::new(),
6313
6311
};
6314
- for htlc in sources.drain(..) {
6312
+ let (source_claim_pairs, channels_without_preimage) = sources.into_iter().filter_map(|htlc| {
6315
6313
if let Some(cp_id) = htlc.prev_hop.counterparty_node_id {
6316
6314
let htlc_id = htlc.prev_hop.htlc_id;
6317
6315
let chan_id = htlc.prev_hop.channel_id;
6318
6316
let chan_outpoint = htlc.prev_hop.outpoint;
6319
- pending_claims.channels_without_preimage.push((cp_id, chan_outpoint, chan_id, htlc_id));
6320
- source_claim_pairs.push((htlc, Some((cp_id, chan_id, htlc_id))));
6317
+ Some((
6318
+ (htlc, Some((cp_id, chan_id, htlc_id))),
6319
+ (cp_id, chan_outpoint, chan_id, htlc_id),
6320
+ ))
6321
+ } else {
6322
+ None
6321
6323
}
6322
- }
6323
- pending_claim_ptr_opt = Some(Arc::new(Mutex::new(pending_claims)));
6324
+ }).unzip::<_, _, Vec<_>, _>();
6325
+ pending_claims.channels_without_preimage = channels_without_preimage;
6326
+ (source_claim_pairs, Some(Arc::new(Mutex::new(pending_claims))))
6324
6327
} else {
6325
- for htlc in sources.drain(..) {
6326
- source_claim_pairs.push((htlc, None));
6327
- }
6328
- }
6329
- for (htlc, mpp_claim) in source_claim_pairs.drain(..) {
6328
+ (sources.into_iter().map(|htlc| (htlc, None)).collect(), None)
6329
+ };
6330
+ for (htlc, mpp_claim) in source_claim_pairs {
6330
6331
let mut pending_mpp_claim = None;
6331
6332
let pending_claim_ptr = pending_claim_ptr_opt.as_ref().map(|pending_claim| {
6332
6333
pending_mpp_claim = mpp_claim.map(|(cp_id, chan_id, htlc_id)|
@@ -6344,9 +6345,8 @@ where
6344
6345
}
6345
6346
);
6346
6347
}
6347
- }
6348
- if !valid_mpp {
6349
- for htlc in sources.drain(..) {
6348
+ } else {
6349
+ for htlc in sources {
6350
6350
let mut htlc_msat_height_data = htlc.value.to_be_bytes().to_vec();
6351
6351
htlc_msat_height_data.extend_from_slice(&self.best_block.read().unwrap().height.to_be_bytes());
6352
6352
let source = HTLCSource::PreviousHopData(htlc.prev_hop);
0 commit comments