Skip to content

Commit

Permalink
Introduce Tests for Offers and Refunds Without Blinded Paths
Browse files Browse the repository at this point in the history
  • Loading branch information
shaavan committed Sep 19, 2024
1 parent 4014246 commit 3bcc420
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9038,7 +9038,9 @@ macro_rules! create_offer_builder { ($self: ident, $builder: ty) => {
let secp_ctx = &$self.secp_ctx;

let nonce = Nonce::from_entropy_source(entropy);
let context = OffersContext::InvoiceRequest { nonce };
let context = MessageContext::Offers(
OffersContext::InvoiceRequest { nonce }
);
let builder = match blinded_path {
Some(blinded_path) => {
let path = $self
Expand Down Expand Up @@ -9115,7 +9117,9 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
let secp_ctx = &$self.secp_ctx;

let nonce = Nonce::from_entropy_source(entropy);
let context = OffersContext::OutboundPayment { payment_id, nonce, hmac: None };
let context = MessageContext::Offers(
OffersContext::OutboundPayment { payment_id, nonce, hmac: None }
);

let builder = match blinded_path {
Some(blinded_path) => {
Expand Down Expand Up @@ -9573,7 +9577,7 @@ where
.collect::<Vec<_>>();

self.router
.create_blinded_paths(recipient, MessageContext::Offers(context), blinded_path, peers, secp_ctx)
.create_blinded_paths(recipient, context, blinded_path, peers, secp_ctx)
.and_then(|paths| (!paths.is_empty()).then(|| paths).ok_or(()))
}

Expand Down Expand Up @@ -10954,7 +10958,7 @@ where
nonce,
hmac: Some(hmac)
});
match self.create_blinded_paths(context) {
match self.create_blinded_paths(context, BlindedPathType::Full) {
Ok(reply_paths) => match self.enqueue_invoice_request(invoice_request, reply_paths) {
Ok(_) => {}
Err(_) => {
Expand Down
47 changes: 47 additions & 0 deletions lightning/src/ln/offers_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,53 @@ fn extract_invoice_error<'a, 'b, 'c>(
}
}

/// Checks that an offer can be created with no blinded paths.
#[test]
fn create_offer_with_no_blinded_path() {
let chanmon_cfgs = create_chanmon_cfgs(2);
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);

create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);

let alice = &nodes[0];
let alice_id = alice.node.get_our_node_id();

let offer = alice.node
.create_offer_builder(None).unwrap()
.amount_msats(10_000_000)
.build().unwrap();
assert_eq!(offer.issuer_signing_pubkey(), Some(alice_id));
assert!(offer.paths().is_empty());
}

/// Checks that a refund can be created with no blinded paths.
#[test]
fn create_refund_with_no_blinded_path() {
let chanmon_cfgs = create_chanmon_cfgs(2);
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);

create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);

let alice = &nodes[0];
let alice_id = alice.node.get_our_node_id();

let absolute_expiry = Duration::from_secs(u64::MAX);
let payment_id = PaymentId([1; 32]);

let refund = alice.node
.create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None, None)
.unwrap()
.build().unwrap();
assert_eq!(refund.amount_msats(), 10_000_000);
assert_eq!(refund.absolute_expiry(), Some(absolute_expiry));
assert_eq!(refund.payer_signing_pubkey(), alice_id);
assert!(refund.paths().is_empty());
}

/// Checks that blinded paths without Tor-only nodes are preferred when constructing an offer.
#[test]
fn prefers_non_tor_nodes_in_blinded_paths() {
Expand Down

0 comments on commit 3bcc420

Please sign in to comment.