Skip to content

Commit b909174

Browse files
store static invoice inside the PendingOutboundPayment::StaticInvoiceReceived
Inject the static invoice inside the PendingOutboundPayment::StaticInvoiceReceived to allow to use the static invoice inside the PendingOutboundPayment::PaymentReceived. Signed-off-by: Vincenzo Palazzo <[email protected]>
1 parent 46ea200 commit b909174

File tree

3 files changed

+57
-7
lines changed

3 files changed

+57
-7
lines changed

lightning/src/ln/async_payments_tests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::blinded_path::message::{MessageContext, OffersContext};
1111
use crate::blinded_path::payment::PaymentContext;
1212
use crate::blinded_path::payment::{AsyncBolt12OfferContext, BlindedPaymentTlvs};
1313
use crate::chain::channelmonitor::{HTLC_FAIL_BACK_BUFFER, LATENCY_GRACE_PERIOD_BLOCKS};
14-
use crate::events::{Event, HTLCDestination, PaidInvoice, PaymentFailureReason};
14+
use crate::events::{Event, HTLCDestination, PaidBolt12Invoice, PaymentFailureReason};
1515
use crate::ln::blinded_payment_tests::{fail_blinded_htlc_backwards, get_blinded_route_parameters};
1616
use crate::ln::channelmanager::{PaymentId, RecipientOnionFields};
1717
use crate::ln::functional_test_utils::*;
@@ -444,7 +444,7 @@ fn async_receive_flow_success() {
444444
let res =
445445
claim_payment_along_route(ClaimAlongRouteArgs::new(&nodes[0], route, keysend_preimage));
446446
assert!(res.is_some());
447-
assert_eq!(res, Some(PaidInvoice::StaticInvoice(static_invoice)));
447+
assert_eq!(res, Some(PaidBolt12Invoice::StaticInvoice(static_invoice)));
448448
}
449449

450450
#[cfg_attr(feature = "std", ignore)]

lightning/src/ln/outbound_payment.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ pub(crate) enum PendingOutboundPayment {
9393
retry_strategy: Retry,
9494
route_params: RouteParameters,
9595
invoice_request: InvoiceRequest,
96+
static_invoice: StaticInvoice,
9697
},
9798
Retryable {
9899
retry_strategy: Option<Retry>,
@@ -1160,6 +1161,7 @@ impl OutboundPayments {
11601161
.take()
11611162
.ok_or(Bolt12PaymentError::UnexpectedInvoice)?
11621163
.invoice_request,
1164+
static_invoice: invoice.clone(),
11631165
};
11641166
return Ok(())
11651167
},
@@ -1188,22 +1190,22 @@ impl OutboundPayments {
11881190
IH: Fn() -> InFlightHtlcs,
11891191
SP: Fn(SendAlongPathArgs) -> Result<(), APIError>,
11901192
{
1191-
let (payment_hash, keysend_preimage, route_params, retry_strategy, invoice_request) =
1193+
let (payment_hash, keysend_preimage, route_params, retry_strategy, invoice_request, invoice) =
11921194
match self.pending_outbound_payments.lock().unwrap().entry(payment_id) {
11931195
hash_map::Entry::Occupied(entry) => match entry.get() {
11941196
PendingOutboundPayment::StaticInvoiceReceived {
1195-
payment_hash, route_params, retry_strategy, keysend_preimage, invoice_request, ..
1197+
payment_hash, route_params, retry_strategy, keysend_preimage, invoice_request, static_invoice, ..
11961198
} => {
11971199
(*payment_hash, *keysend_preimage, route_params.clone(), *retry_strategy,
1198-
invoice_request.clone())
1200+
invoice_request.clone(), static_invoice.clone())
11991201
},
12001202
_ => return Err(Bolt12PaymentError::DuplicateInvoice),
12011203
},
12021204
hash_map::Entry::Vacant(_) => return Err(Bolt12PaymentError::UnexpectedInvoice),
12031205
};
1204-
1206+
let invoice = PaidBolt12Invoice::StaticInvoice(invoice);
12051207
self.send_payment_for_bolt12_invoice_internal(
1206-
payment_id, payment_hash, Some(keysend_preimage), Some(&invoice_request), None, route_params,
1208+
payment_id, payment_hash, Some(keysend_preimage), Some(&invoice_request), Some(invoice), route_params,
12071209
retry_strategy, router, first_hops, inflight_htlcs, entropy_source, node_signer,
12081210
node_id_lookup, secp_ctx, best_block_height, logger, pending_events, send_payment_along_path
12091211
)
@@ -2527,6 +2529,7 @@ impl_writeable_tlv_based_enum_upgradable!(PendingOutboundPayment,
25272529
(4, retry_strategy, required),
25282530
(6, route_params, required),
25292531
(8, invoice_request, required),
2532+
(10, static_invoice, required),
25302533
},
25312534
// Added in 0.1. Prior versions will drop these outbounds on downgrade, which is safe because
25322535
// no HTLCs are in-flight.
@@ -3157,6 +3160,7 @@ mod tests {
31573160
retry_strategy: Retry::Attempts(0),
31583161
route_params,
31593162
invoice_request: dummy_invoice_request(),
3163+
static_invoice: dummy_static_invoice(),
31603164
};
31613165
outbounds.insert(payment_id, outbound);
31623166
core::mem::drop(outbounds);
@@ -3204,6 +3208,7 @@ mod tests {
32043208
retry_strategy: Retry::Attempts(0),
32053209
route_params,
32063210
invoice_request: dummy_invoice_request(),
3211+
static_invoice: dummy_static_invoice(),
32073212
};
32083213
outbounds.insert(payment_id, outbound);
32093214
core::mem::drop(outbounds);

lightning/src/offers/test_utils.rs

+45
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
use bitcoin::secp256k1::schnorr::Signature;
1313
use bitcoin::secp256k1::{Keypair, PublicKey, Secp256k1, SecretKey};
1414

15+
use crate::blinded_path::message::BlindedMessagePath;
1516
use crate::blinded_path::payment::{BlindedPayInfo, BlindedPaymentPath};
1617
use crate::blinded_path::BlindedHop;
18+
use crate::ln::inbound_payment::ExpandedKey;
1719
use crate::offers::merkle::TaggedHash;
1820
use crate::sign::EntropySource;
1921
use crate::types::features::BlindedHopFeatures;
@@ -23,6 +25,10 @@ use core::time::Duration;
2325
#[allow(unused_imports)]
2426
use crate::prelude::*;
2527

28+
use super::nonce::Nonce;
29+
use super::offer::OfferBuilder;
30+
use super::static_invoice::{StaticInvoice, StaticInvoiceBuilder};
31+
2632
pub(crate) fn fail_sign<T: AsRef<TaggedHash>>(_message: &T) -> Result<Signature, ()> {
2733
Err(())
2834
}
@@ -120,3 +126,42 @@ impl EntropySource for FixedEntropy {
120126
[42; 32]
121127
}
122128
}
129+
130+
pub fn blinded_path() -> BlindedMessagePath {
131+
BlindedMessagePath::from_blinded_path(
132+
pubkey(40),
133+
pubkey(41),
134+
vec![
135+
BlindedHop { blinded_node_id: pubkey(42), encrypted_payload: vec![0; 43] },
136+
BlindedHop { blinded_node_id: pubkey(43), encrypted_payload: vec![0; 44] },
137+
],
138+
)
139+
}
140+
141+
pub fn dummy_static_invoice() -> StaticInvoice {
142+
let node_id = recipient_pubkey();
143+
let payment_paths = payment_paths();
144+
let now = now();
145+
let expanded_key = ExpandedKey::new([42; 32]);
146+
let entropy = FixedEntropy {};
147+
let nonce = Nonce::from_entropy_source(&entropy);
148+
let secp_ctx = Secp256k1::new();
149+
150+
let offer = OfferBuilder::deriving_signing_pubkey(node_id, &expanded_key, nonce, &secp_ctx)
151+
.path(blinded_path())
152+
.build()
153+
.unwrap();
154+
155+
StaticInvoiceBuilder::for_offer_using_derived_keys(
156+
&offer,
157+
payment_paths.clone(),
158+
vec![blinded_path()],
159+
now,
160+
&expanded_key,
161+
nonce,
162+
&secp_ctx,
163+
)
164+
.unwrap()
165+
.build_and_sign(&secp_ctx)
166+
.unwrap()
167+
}

0 commit comments

Comments
 (0)