Guest User

Untitled

a guest
Apr 26th, 2023
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.66 KB | None | 0 0
  1. diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs
  2. index a4f02f625..1d459135e 100644
  3. --- a/lightning/src/ln/channelmanager.rs
  4. +++ b/lightning/src/ln/channelmanager.rs
  5. @@ -3439,7 +3439,7 @@ where
  6. panic!("short_channel_id == 0 should imply any pending_forward entries are of type Receive");
  7. }
  8. };
  9. - let mut claimable_htlc = ClaimableHTLC {
  10. + let claimable_htlc = ClaimableHTLC {
  11. prev_hop: HTLCPreviousHopData {
  12. short_channel_id: prev_short_channel_id,
  13. outpoint: prev_funding_outpoint,
  14. @@ -3489,7 +3489,7 @@ where
  15. }
  16.  
  17. macro_rules! check_total_value {
  18. - ($payment_data: expr, $payment_preimage: expr, $is_keysend: expr) => {{
  19. + ($payment_secret: expr, $payment_preimage: expr, $total_msat: expr, $is_keysend: expr) => {{
  20. let mut payment_claimable_generated = false;
  21. let purpose = if $is_keysend {
  22. events::PaymentPurpose::SpontaneousPayment(
  23. @@ -3498,13 +3498,17 @@ where
  24. } else {
  25. events::PaymentPurpose::InvoicePayment {
  26. payment_preimage: $payment_preimage,
  27. - payment_secret: $payment_data.payment_secret,
  28. + payment_secret: $payment_secret.unwrap(),
  29. }
  30. };
  31. let mut claimable_payments = self.claimable_payments.lock().unwrap();
  32. if claimable_payments.pending_claiming_payments.contains_key(&payment_hash) {
  33. fail_htlc!(claimable_htlc, payment_hash);
  34. }
  35. + if $is_keysend && $payment_secret.is_none() && claimable_payments.claimable_payments.get(&payment_hash).is_some() {
  36. + log_trace!(self.logger, "Failing new keysend HTLC with payment_hash {} for a duplicative payment hash", log_bytes!(payment_hash.0));
  37. + fail_htlc!(claimable_htlc, payment_hash);
  38. + }
  39. let ref mut claimable_payment = claimable_payments.claimable_payments
  40. .entry(payment_hash)
  41. // Note that if we insert here we MUST NOT fail_htlc!()
  42. @@ -3533,9 +3537,9 @@ where
  43. for htlc in htlcs.iter() {
  44. total_value += htlc.sender_intended_value;
  45. earliest_expiry = cmp::min(earliest_expiry, htlc.cltv_expiry);
  46. - if htlc.total_msat != $payment_data.total_msat {
  47. + if htlc.total_msat != $total_msat {
  48. log_trace!(self.logger, "Failing HTLCs with payment_hash {} as the HTLCs had inconsistent total values (eg {} and {})",
  49. - log_bytes!(payment_hash.0), $payment_data.total_msat, htlc.total_msat);
  50. + log_bytes!(payment_hash.0), $total_msat, htlc.total_msat);
  51. total_value = msgs::MAX_VALUE_MSAT;
  52. }
  53. if total_value >= msgs::MAX_VALUE_MSAT { break; }
  54. @@ -3544,11 +3548,11 @@ where
  55. // match exactly the condition used in `timer_tick_occurred`
  56. if total_value >= msgs::MAX_VALUE_MSAT {
  57. fail_htlc!(claimable_htlc, payment_hash);
  58. - } else if total_value - claimable_htlc.sender_intended_value >= $payment_data.total_msat {
  59. + } else if total_value - claimable_htlc.sender_intended_value >= $total_msat {
  60. log_trace!(self.logger, "Failing HTLC with payment_hash {} as payment is already claimable",
  61. log_bytes!(payment_hash.0));
  62. fail_htlc!(claimable_htlc, payment_hash);
  63. - } else if total_value >= $payment_data.total_msat {
  64. + } else if total_value >= $total_msat {
  65. #[allow(unused_assignments)] {
  66. committed_to_claimable = true;
  67. }
  68. @@ -3607,45 +3611,10 @@ where
  69. fail_htlc!(claimable_htlc, payment_hash);
  70. }
  71. }
  72. - check_total_value!(payment_data, payment_preimage, false);
  73. + check_total_value!(Some(payment_data.payment_secret), payment_preimage, payment_data.total_msat, false);
  74. },
  75. OnionPayload::Spontaneous(preimage) => {
  76. - if let Some(payment_data) = payment_data {
  77. - check_total_value!(payment_data, Some(preimage), true);
  78. - } else {
  79. - let mut claimable_payments = self.claimable_payments.lock().unwrap();
  80. - if claimable_payments.pending_claiming_payments.contains_key(&payment_hash) {
  81. - fail_htlc!(claimable_htlc, payment_hash);
  82. - }
  83. - match claimable_payments.claimable_payments.entry(payment_hash) {
  84. - hash_map::Entry::Vacant(e) => {
  85. - let amount_msat = claimable_htlc.value;
  86. - claimable_htlc.total_value_received = Some(amount_msat);
  87. - let claim_deadline = Some(claimable_htlc.cltv_expiry - HTLC_FAIL_BACK_BUFFER);
  88. - let purpose = events::PaymentPurpose::SpontaneousPayment(preimage);
  89. - e.insert(ClaimablePayment {
  90. - purpose: purpose.clone(),
  91. - onion_fields: Some(onion_fields.clone()),
  92. - htlcs: vec![claimable_htlc],
  93. - });
  94. - let prev_channel_id = prev_funding_outpoint.to_channel_id();
  95. - new_events.push(events::Event::PaymentClaimable {
  96. - receiver_node_id: Some(receiver_node_id),
  97. - payment_hash,
  98. - amount_msat,
  99. - purpose,
  100. - via_channel_id: Some(prev_channel_id),
  101. - via_user_channel_id: Some(prev_user_channel_id),
  102. - claim_deadline,
  103. - onion_fields: Some(onion_fields),
  104. - });
  105. - },
  106. - hash_map::Entry::Occupied(_) => {
  107. - log_trace!(self.logger, "Failing new keysend HTLC with payment_hash {} for a duplicative payment hash", log_bytes!(payment_hash.0));
  108. - fail_htlc!(claimable_htlc, payment_hash);
  109. - }
  110. - }
  111. - }
  112. + 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);
  113. }
  114. }
  115. },
  116. @@ -3663,7 +3632,7 @@ where
  117. log_bytes!(payment_hash.0), payment_data.total_msat, inbound_payment.get().min_value_msat.unwrap());
  118. fail_htlc!(claimable_htlc, payment_hash);
  119. } else {
  120. - let payment_claimable_generated = check_total_value!(payment_data, inbound_payment.get().payment_preimage, false);
  121. + let payment_claimable_generated = check_total_value!(Some(payment_data.payment_secret), inbound_payment.get().payment_preimage, payment_data.total_msat, false);
  122. if payment_claimable_generated {
  123. inbound_payment.remove_entry();
  124. }
  125.  
Add Comment
Please, Sign In to add comment