@@ -6209,7 +6209,7 @@ where
62096209
62106210 let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
62116211
6212- let mut sources = {
6212+ let sources = {
62136213 let mut claimable_payments = self.claimable_payments.lock().unwrap();
62146214 if let Some(payment) = claimable_payments.claimable_payments.remove(&payment_hash) {
62156215 let mut receiver_node_id = self.our_network_pubkey;
@@ -6304,29 +6304,30 @@ where
63046304 return;
63056305 }
63066306 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 {
63106308 let mut pending_claims = PendingMPPClaim {
63116309 channels_without_preimage: Vec::new(),
63126310 channels_with_preimage: Vec::new(),
63136311 };
6314- for htlc in sources.drain(..) {
6312+ let (source_claim_pairs, channels_without_preimage) = sources.into_iter().filter_map(|htlc| {
63156313 if let Some(cp_id) = htlc.prev_hop.counterparty_node_id {
63166314 let htlc_id = htlc.prev_hop.htlc_id;
63176315 let chan_id = htlc.prev_hop.channel_id;
63186316 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
63216323 }
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))))
63246327 } 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 {
63306331 let mut pending_mpp_claim = None;
63316332 let pending_claim_ptr = pending_claim_ptr_opt.as_ref().map(|pending_claim| {
63326333 pending_mpp_claim = mpp_claim.map(|(cp_id, chan_id, htlc_id)|
@@ -6344,9 +6345,8 @@ where
63446345 }
63456346 );
63466347 }
6347- }
6348- if !valid_mpp {
6349- for htlc in sources.drain(..) {
6348+ } else {
6349+ for htlc in sources {
63506350 let mut htlc_msat_height_data = htlc.value.to_be_bytes().to_vec();
63516351 htlc_msat_height_data.extend_from_slice(&self.best_block.read().unwrap().height.to_be_bytes());
63526352 let source = HTLCSource::PreviousHopData(htlc.prev_hop);
0 commit comments