Skip to content

Commit 2655285

Browse files
Minor outbound_payment refactor: move total_msat var.
We need to add a match arm for static invoices in this method, so this will help us keep the new arm DRY with InvoiceReceived.
1 parent c2ee56f commit 2655285

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

lightning/src/ln/outbound_payment.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,18 +1113,20 @@ impl OutboundPayments {
11131113
}
11141114
}
11151115
}
1116-
let (total_msat, recipient_onion, keysend_preimage, onion_session_privs) = {
1116+
let total_msat = route_params.final_value_msat;
1117+
let (recipient_onion, keysend_preimage, onion_session_privs) = {
11171118
let mut outbounds = self.pending_outbound_payments.lock().unwrap();
11181119
match outbounds.entry(payment_id) {
11191120
hash_map::Entry::Occupied(mut payment) => {
11201121
match payment.get() {
11211122
PendingOutboundPayment::Retryable {
1122-
total_msat, keysend_preimage, payment_secret, payment_metadata,
1123+
total_msat: retryable_total_msat, keysend_preimage, payment_secret, payment_metadata,
11231124
custom_tlvs, pending_amt_msat, ..
11241125
} => {
1126+
debug_assert_eq!(total_msat, *retryable_total_msat);
11251127
const RETRY_OVERFLOW_PERCENTAGE: u64 = 10;
11261128
let retry_amt_msat = route.get_total_amount();
1127-
if retry_amt_msat + *pending_amt_msat > *total_msat * (100 + RETRY_OVERFLOW_PERCENTAGE) / 100 {
1129+
if retry_amt_msat + *pending_amt_msat > total_msat * (100 + RETRY_OVERFLOW_PERCENTAGE) / 100 {
11281130
log_error!(logger, "retry_amt_msat of {} will put pending_amt_msat (currently: {}) more than 10% over total_payment_amt_msat of {}", retry_amt_msat, pending_amt_msat, total_msat);
11291131
abandon_with_entry!(payment, PaymentFailureReason::UnexpectedError);
11301132
return
@@ -1136,7 +1138,6 @@ impl OutboundPayments {
11361138
return
11371139
}
11381140

1139-
let total_msat = *total_msat;
11401141
let recipient_onion = RecipientOnionFields {
11411142
payment_secret: *payment_secret,
11421143
payment_metadata: payment_metadata.clone(),
@@ -1155,7 +1156,7 @@ impl OutboundPayments {
11551156

11561157
payment.get_mut().increment_attempts();
11571158

1158-
(total_msat, recipient_onion, keysend_preimage, onion_session_privs)
1159+
(recipient_onion, keysend_preimage, onion_session_privs)
11591160
},
11601161
PendingOutboundPayment::Legacy { .. } => {
11611162
log_error!(logger, "Unable to retry payments that were initially sent on LDK versions prior to 0.0.102");
@@ -1166,7 +1167,6 @@ impl OutboundPayments {
11661167
return
11671168
},
11681169
PendingOutboundPayment::InvoiceReceived { payment_hash, retry_strategy, .. } => {
1169-
let total_amount = route_params.final_value_msat;
11701170
let recipient_onion = RecipientOnionFields {
11711171
payment_secret: None,
11721172
payment_metadata: None,
@@ -1179,7 +1179,7 @@ impl OutboundPayments {
11791179
retry_strategy, payment_params, entropy_source, best_block_height
11801180
);
11811181
*payment.into_mut() = retryable_payment;
1182-
(total_amount, recipient_onion, None, onion_session_privs)
1182+
(recipient_onion, None, onion_session_privs)
11831183
},
11841184
PendingOutboundPayment::StaticInvoiceReceived { .. } => todo!(),
11851185
PendingOutboundPayment::Fulfilled { .. } => {

0 commit comments

Comments
 (0)