Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs
- index a4f02f625..1d459135e 100644
- --- a/lightning/src/ln/channelmanager.rs
- +++ b/lightning/src/ln/channelmanager.rs
- @@ -3439,7 +3439,7 @@ where
- panic!("short_channel_id == 0 should imply any pending_forward entries are of type Receive");
- }
- };
- - let mut claimable_htlc = ClaimableHTLC {
- + let claimable_htlc = ClaimableHTLC {
- prev_hop: HTLCPreviousHopData {
- short_channel_id: prev_short_channel_id,
- outpoint: prev_funding_outpoint,
- @@ -3489,7 +3489,7 @@ where
- }
- macro_rules! check_total_value {
- - ($payment_data: expr, $payment_preimage: expr, $is_keysend: expr) => {{
- + ($payment_secret: expr, $payment_preimage: expr, $total_msat: expr, $is_keysend: expr) => {{
- let mut payment_claimable_generated = false;
- let purpose = if $is_keysend {
- events::PaymentPurpose::SpontaneousPayment(
- @@ -3498,13 +3498,17 @@ where
- } else {
- events::PaymentPurpose::InvoicePayment {
- payment_preimage: $payment_preimage,
- - payment_secret: $payment_data.payment_secret,
- + payment_secret: $payment_secret.unwrap(),
- }
- };
- let mut claimable_payments = self.claimable_payments.lock().unwrap();
- if claimable_payments.pending_claiming_payments.contains_key(&payment_hash) {
- fail_htlc!(claimable_htlc, payment_hash);
- }
- + if $is_keysend && $payment_secret.is_none() && claimable_payments.claimable_payments.get(&payment_hash).is_some() {
- + log_trace!(self.logger, "Failing new keysend HTLC with payment_hash {} for a duplicative payment hash", log_bytes!(payment_hash.0));
- + fail_htlc!(claimable_htlc, payment_hash);
- + }
- let ref mut claimable_payment = claimable_payments.claimable_payments
- .entry(payment_hash)
- // Note that if we insert here we MUST NOT fail_htlc!()
- @@ -3533,9 +3537,9 @@ where
- for htlc in htlcs.iter() {
- total_value += htlc.sender_intended_value;
- earliest_expiry = cmp::min(earliest_expiry, htlc.cltv_expiry);
- - if htlc.total_msat != $payment_data.total_msat {
- + if htlc.total_msat != $total_msat {
- log_trace!(self.logger, "Failing HTLCs with payment_hash {} as the HTLCs had inconsistent total values (eg {} and {})",
- - log_bytes!(payment_hash.0), $payment_data.total_msat, htlc.total_msat);
- + log_bytes!(payment_hash.0), $total_msat, htlc.total_msat);
- total_value = msgs::MAX_VALUE_MSAT;
- }
- if total_value >= msgs::MAX_VALUE_MSAT { break; }
- @@ -3544,11 +3548,11 @@ where
- // match exactly the condition used in `timer_tick_occurred`
- if total_value >= msgs::MAX_VALUE_MSAT {
- fail_htlc!(claimable_htlc, payment_hash);
- - } else if total_value - claimable_htlc.sender_intended_value >= $payment_data.total_msat {
- + } else if total_value - claimable_htlc.sender_intended_value >= $total_msat {
- log_trace!(self.logger, "Failing HTLC with payment_hash {} as payment is already claimable",
- log_bytes!(payment_hash.0));
- fail_htlc!(claimable_htlc, payment_hash);
- - } else if total_value >= $payment_data.total_msat {
- + } else if total_value >= $total_msat {
- #[allow(unused_assignments)] {
- committed_to_claimable = true;
- }
- @@ -3607,45 +3611,10 @@ where
- fail_htlc!(claimable_htlc, payment_hash);
- }
- }
- - check_total_value!(payment_data, payment_preimage, false);
- + check_total_value!(Some(payment_data.payment_secret), payment_preimage, payment_data.total_msat, false);
- },
- OnionPayload::Spontaneous(preimage) => {
- - if let Some(payment_data) = payment_data {
- - check_total_value!(payment_data, Some(preimage), true);
- - } else {
- - let mut claimable_payments = self.claimable_payments.lock().unwrap();
- - if claimable_payments.pending_claiming_payments.contains_key(&payment_hash) {
- - fail_htlc!(claimable_htlc, payment_hash);
- - }
- - match claimable_payments.claimable_payments.entry(payment_hash) {
- - hash_map::Entry::Vacant(e) => {
- - let amount_msat = claimable_htlc.value;
- - claimable_htlc.total_value_received = Some(amount_msat);
- - let claim_deadline = Some(claimable_htlc.cltv_expiry - HTLC_FAIL_BACK_BUFFER);
- - let purpose = events::PaymentPurpose::SpontaneousPayment(preimage);
- - e.insert(ClaimablePayment {
- - purpose: purpose.clone(),
- - onion_fields: Some(onion_fields.clone()),
- - htlcs: vec![claimable_htlc],
- - });
- - let prev_channel_id = prev_funding_outpoint.to_channel_id();
- - new_events.push(events::Event::PaymentClaimable {
- - receiver_node_id: Some(receiver_node_id),
- - payment_hash,
- - amount_msat,
- - purpose,
- - via_channel_id: Some(prev_channel_id),
- - via_user_channel_id: Some(prev_user_channel_id),
- - claim_deadline,
- - onion_fields: Some(onion_fields),
- - });
- - },
- - hash_map::Entry::Occupied(_) => {
- - log_trace!(self.logger, "Failing new keysend HTLC with payment_hash {} for a duplicative payment hash", log_bytes!(payment_hash.0));
- - fail_htlc!(claimable_htlc, payment_hash);
- - }
- - }
- - }
- + check_total_value!(payment_data.as_ref().map(|d| d.payment_secret), Some(preimage), payment_data.as_ref().map_or(claimable_htlc.value, |d| d.total_msat), true);
- }
- }
- },
- @@ -3663,7 +3632,7 @@ where
- log_bytes!(payment_hash.0), payment_data.total_msat, inbound_payment.get().min_value_msat.unwrap());
- fail_htlc!(claimable_htlc, payment_hash);
- } else {
- - let payment_claimable_generated = check_total_value!(payment_data, inbound_payment.get().payment_preimage, false);
- + let payment_claimable_generated = check_total_value!(Some(payment_data.payment_secret), inbound_payment.get().payment_preimage, payment_data.total_msat, false);
- if payment_claimable_generated {
- inbound_payment.remove_entry();
- }
Add Comment
Please, Sign In to add comment