Skip to content

Commit 50cef5e

Browse files
committed
f cleaner code from val
1 parent 995080b commit 50cef5e

File tree

1 file changed

+21
-24
lines changed

1 file changed

+21
-24
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6304,35 +6304,32 @@ where
63046304
return;
63056305
}
63066306
if valid_mpp {
6307-
let (source_claim_pairs, pending_claim_ptr_opt) = if sources.len() > 1 {
6308-
let mut pending_claims = PendingMPPClaim {
6309-
channels_without_preimage: Vec::new(),
6310-
channels_with_preimage: Vec::new(),
6311-
};
6312-
let (source_claim_pairs, channels_without_preimage) = sources.into_iter().filter_map(|htlc| {
6307+
let pending_mpp_claim_ptr_opt = if sources.len() > 1 {
6308+
let channels_without_preimage = sources.iter().filter_map(|htlc| {
63136309
if let Some(cp_id) = htlc.prev_hop.counterparty_node_id {
6314-
let htlc_id = htlc.prev_hop.htlc_id;
6315-
let chan_id = htlc.prev_hop.channel_id;
6316-
let chan_outpoint = htlc.prev_hop.outpoint;
6317-
Some((
6318-
(htlc, Some((cp_id, chan_id, htlc_id))),
6319-
(cp_id, chan_outpoint, chan_id, htlc_id),
6320-
))
6310+
let prev_hop = &htlc.prev_hop;
6311+
Some((cp_id, prev_hop.outpoint, prev_hop.channel_id, prev_hop.htlc_id))
63216312
} else {
63226313
None
63236314
}
6324-
}).unzip::<_, _, Vec<_>, _>();
6325-
pending_claims.channels_without_preimage = channels_without_preimage;
6326-
(source_claim_pairs, Some(Arc::new(Mutex::new(pending_claims))))
6315+
}).collect();
6316+
Some(Arc::new(Mutex::new(PendingMPPClaim {
6317+
channels_without_preimage,
6318+
channels_with_preimage: Vec::new(),
6319+
})))
63276320
} else {
6328-
(sources.into_iter().map(|htlc| (htlc, None)).collect(), None)
6321+
None
63296322
};
6330-
for (htlc, mpp_claim) in source_claim_pairs {
6331-
let mut pending_mpp_claim = None;
6332-
let pending_claim_ptr = pending_claim_ptr_opt.as_ref().map(|pending_claim| {
6333-
pending_mpp_claim = mpp_claim.map(|(cp_id, chan_id, htlc_id)|
6334-
(cp_id, chan_id, htlc_id, PendingMPPClaimPointer(Arc::clone(pending_claim)))
6335-
);
6323+
for htlc in sources {
6324+
let this_mpp_claim = pending_mpp_claim_ptr_opt.as_ref().map(|pending_mpp_claim|
6325+
if let Some(cp_id) = htlc.prev_hop.counterparty_node_id {
6326+
let claim_ptr = PendingMPPClaimPointer(Arc::clone(pending_mpp_claim));
6327+
Some((cp_id, htlc.prev_hop.channel_id, htlc.prev_hop.htlc_id, claim_ptr))
6328+
} else {
6329+
None
6330+
}
6331+
).flatten();
6332+
let raa_blocker = pending_mpp_claim_ptr_opt.as_ref().map(|pending_claim| {
63366333
RAAMonitorUpdateBlockingAction::ClaimedMPPPayment {
63376334
pending_claim: PendingMPPClaimPointer(Arc::clone(pending_claim)),
63386335
}
@@ -6341,7 +6338,7 @@ where
63416338
htlc.prev_hop, payment_preimage,
63426339
|_, definitely_duplicate| {
63436340
debug_assert!(!definitely_duplicate, "We shouldn't claim duplicatively from a payment");
6344-
(Some(MonitorUpdateCompletionAction::PaymentClaimed { payment_hash, pending_mpp_claim }), pending_claim_ptr)
6341+
(Some(MonitorUpdateCompletionAction::PaymentClaimed { payment_hash, pending_mpp_claim: this_mpp_claim }), raa_blocker)
63456342
}
63466343
);
63476344
}

0 commit comments

Comments
 (0)