Skip to content

Commit 2bfde03

Browse files
committed
f avoid using "padding" to refer to dummy hops as its overloaded
1 parent c57f781 commit 2bfde03

File tree

3 files changed

+42
-42
lines changed

3 files changed

+42
-42
lines changed

lightning/src/ln/offers_tests.rs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ use crate::offers::invoice_error::InvoiceError;
6060
use crate::offers::invoice_request::{InvoiceRequest, InvoiceRequestFields, InvoiceRequestVerifiedFromOffer};
6161
use crate::offers::nonce::Nonce;
6262
use crate::offers::parse::Bolt12SemanticError;
63-
use crate::onion_message::messenger::{DefaultMessageRouter, Destination, MessageSendInstructions, NodeIdMessageRouter, NullMessageRouter, PeeledOnion, PADDED_PATH_LENGTH, QR_CODED_PADDED_PATH_LENGTH};
63+
use crate::onion_message::messenger::{DefaultMessageRouter, Destination, MessageSendInstructions, NodeIdMessageRouter, NullMessageRouter, PeeledOnion, DUMMY_HOPS_PATH_LENGTH, QR_CODED_DUMMY_HOPS_PATH_LENGTH};
6464
use crate::onion_message::offers::OffersMessage;
6565
use crate::routing::gossip::{NodeAlias, NodeId};
6666
use crate::routing::router::{PaymentParameters, RouteParameters, RouteParametersConfig};
@@ -469,7 +469,7 @@ fn check_dummy_hop_pattern_in_offer() {
469469
let bob_id = bob.node.get_our_node_id();
470470

471471
// Case 1: DefaultMessageRouter → uses compact blinded paths (via SCIDs)
472-
// Expected: Padded to QR_CODED_PADDED_PATH_LENGTH for QR code size optimization
472+
// Expected: Padded to QR_CODED_DUMMY_HOPS_PATH_LENGTH for QR code size optimization
473473
let default_router = DefaultMessageRouter::new(alice.network_graph, alice.keys_manager);
474474

475475
let compact_offer = alice.node
@@ -481,8 +481,8 @@ fn check_dummy_hop_pattern_in_offer() {
481481

482482
for path in compact_offer.paths() {
483483
assert_eq!(
484-
path.blinded_hops().len(), QR_CODED_PADDED_PATH_LENGTH,
485-
"Compact offer paths are padded to QR_CODED_PADDED_PATH_LENGTH"
484+
path.blinded_hops().len(), QR_CODED_DUMMY_HOPS_PATH_LENGTH,
485+
"Compact offer paths are padded to QR_CODED_DUMMY_HOPS_PATH_LENGTH"
486486
);
487487
}
488488

@@ -494,10 +494,10 @@ fn check_dummy_hop_pattern_in_offer() {
494494

495495
assert_eq!(invoice_request.amount_msats(), Some(10_000_000));
496496
assert_ne!(invoice_request.payer_signing_pubkey(), bob_id);
497-
assert!(check_dummy_hopd_path_length(&reply_path, alice, bob_id, PADDED_PATH_LENGTH));
497+
assert!(check_dummy_hopd_path_length(&reply_path, alice, bob_id, DUMMY_HOPS_PATH_LENGTH));
498498

499499
// Case 2: NodeIdMessageRouter → uses node ID-based blinded paths
500-
// Expected: Also padded to QR_CODED_PADDED_PATH_LENGTH for QR code size optimization
500+
// Expected: Also padded to QR_CODED_DUMMY_HOPS_PATH_LENGTH for QR code size optimization
501501
let node_id_router = NodeIdMessageRouter::new(alice.network_graph, alice.keys_manager);
502502

503503
let padded_offer = alice.node
@@ -506,7 +506,7 @@ fn check_dummy_hop_pattern_in_offer() {
506506
.build().unwrap();
507507

508508
assert!(!padded_offer.paths().is_empty());
509-
assert!(padded_offer.paths().iter().all(|path| path.blinded_hops().len() == QR_CODED_PADDED_PATH_LENGTH));
509+
assert!(padded_offer.paths().iter().all(|path| path.blinded_hops().len() == QR_CODED_DUMMY_HOPS_PATH_LENGTH));
510510

511511
let payment_id = PaymentId([2; 32]);
512512
bob.node.pay_for_offer(&padded_offer, None, payment_id, Default::default()).unwrap();
@@ -516,7 +516,7 @@ fn check_dummy_hop_pattern_in_offer() {
516516

517517
assert_eq!(invoice_request.amount_msats(), Some(10_000_000));
518518
assert_ne!(invoice_request.payer_signing_pubkey(), bob_id);
519-
assert!(check_dummy_hopd_path_length(&reply_path, alice, bob_id, PADDED_PATH_LENGTH));
519+
assert!(check_dummy_hopd_path_length(&reply_path, alice, bob_id, DUMMY_HOPS_PATH_LENGTH));
520520
}
521521

522522
/// Checks that blinded paths are compact for short-lived offers.
@@ -701,7 +701,7 @@ fn creates_and_pays_for_offer_using_two_hop_blinded_path() {
701701
});
702702
assert_eq!(invoice_request.amount_msats(), Some(10_000_000));
703703
assert_ne!(invoice_request.payer_signing_pubkey(), david_id);
704-
assert!(check_dummy_hopd_path_length(&reply_path, bob, charlie_id, PADDED_PATH_LENGTH));
704+
assert!(check_dummy_hopd_path_length(&reply_path, bob, charlie_id, DUMMY_HOPS_PATH_LENGTH));
705705

706706
let onion_message = alice.onion_messenger.next_onion_message_for_peer(charlie_id).unwrap();
707707
charlie.onion_messenger.handle_onion_message(alice_id, &onion_message);
@@ -720,8 +720,8 @@ fn creates_and_pays_for_offer_using_two_hop_blinded_path() {
720720
// to Alice when she's handling the message. Therefore, either Bob or Charlie could
721721
// serve as the introduction node for the reply path back to Alice.
722722
assert!(
723-
check_dummy_hopd_path_length(&reply_path, david, bob_id, PADDED_PATH_LENGTH) ||
724-
check_dummy_hopd_path_length(&reply_path, david, charlie_id, PADDED_PATH_LENGTH)
723+
check_dummy_hopd_path_length(&reply_path, david, bob_id, DUMMY_HOPS_PATH_LENGTH) ||
724+
check_dummy_hopd_path_length(&reply_path, david, charlie_id, DUMMY_HOPS_PATH_LENGTH)
725725
);
726726

727727
route_bolt12_payment(david, &[charlie, bob, alice], &invoice);
@@ -804,7 +804,7 @@ fn creates_and_pays_for_refund_using_two_hop_blinded_path() {
804804
for path in invoice.payment_paths() {
805805
assert_eq!(path.introduction_node(), &IntroductionNode::NodeId(bob_id));
806806
}
807-
assert!(check_dummy_hopd_path_length(&reply_path, alice, bob_id, PADDED_PATH_LENGTH));
807+
assert!(check_dummy_hopd_path_length(&reply_path, alice, bob_id, DUMMY_HOPS_PATH_LENGTH));
808808

809809
route_bolt12_payment(david, &[charlie, bob, alice], &invoice);
810810
expect_recent_payment!(david, RecentPaymentDetails::Pending, payment_id);
@@ -859,7 +859,7 @@ fn creates_and_pays_for_offer_using_one_hop_blinded_path() {
859859
});
860860
assert_eq!(invoice_request.amount_msats(), Some(10_000_000));
861861
assert_ne!(invoice_request.payer_signing_pubkey(), bob_id);
862-
assert!(check_dummy_hopd_path_length(&reply_path, alice, bob_id, PADDED_PATH_LENGTH));
862+
assert!(check_dummy_hopd_path_length(&reply_path, alice, bob_id, DUMMY_HOPS_PATH_LENGTH));
863863

864864
let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
865865
bob.onion_messenger.handle_onion_message(alice_id, &onion_message);
@@ -871,7 +871,7 @@ fn creates_and_pays_for_offer_using_one_hop_blinded_path() {
871871
for path in invoice.payment_paths() {
872872
assert_eq!(path.introduction_node(), &IntroductionNode::NodeId(alice_id));
873873
}
874-
assert!(check_dummy_hopd_path_length(&reply_path, bob, alice_id, PADDED_PATH_LENGTH));
874+
assert!(check_dummy_hopd_path_length(&reply_path, bob, alice_id, DUMMY_HOPS_PATH_LENGTH));
875875

876876
route_bolt12_payment(bob, &[alice], &invoice);
877877
expect_recent_payment!(bob, RecentPaymentDetails::Pending, payment_id);
@@ -927,7 +927,7 @@ fn creates_and_pays_for_refund_using_one_hop_blinded_path() {
927927
for path in invoice.payment_paths() {
928928
assert_eq!(path.introduction_node(), &IntroductionNode::NodeId(alice_id));
929929
}
930-
assert!(check_dummy_hopd_path_length(&reply_path, bob, alice_id, PADDED_PATH_LENGTH));
930+
assert!(check_dummy_hopd_path_length(&reply_path, bob, alice_id, DUMMY_HOPS_PATH_LENGTH));
931931

932932
route_bolt12_payment(bob, &[alice], &invoice);
933933
expect_recent_payment!(bob, RecentPaymentDetails::Pending, payment_id);
@@ -1104,7 +1104,7 @@ fn send_invoice_requests_with_distinct_reply_path() {
11041104
alice.onion_messenger.handle_onion_message(bob_id, &onion_message);
11051105

11061106
let (_, reply_path) = extract_invoice_request(alice, &onion_message);
1107-
assert!(check_dummy_hopd_path_length(&reply_path, alice, charlie_id, PADDED_PATH_LENGTH));
1107+
assert!(check_dummy_hopd_path_length(&reply_path, alice, charlie_id, DUMMY_HOPS_PATH_LENGTH));
11081108

11091109
// Send, extract and verify the second Invoice Request message
11101110
let onion_message = david.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
@@ -1114,7 +1114,7 @@ fn send_invoice_requests_with_distinct_reply_path() {
11141114
alice.onion_messenger.handle_onion_message(bob_id, &onion_message);
11151115

11161116
let (_, reply_path) = extract_invoice_request(alice, &onion_message);
1117-
assert!(check_dummy_hopd_path_length(&reply_path, alice, frank_id, PADDED_PATH_LENGTH));
1117+
assert!(check_dummy_hopd_path_length(&reply_path, alice, frank_id, DUMMY_HOPS_PATH_LENGTH));
11181118
}
11191119

11201120
/// This test checks that when multiple potential introduction nodes are available for the payee,
@@ -1185,7 +1185,7 @@ fn send_invoice_for_refund_with_distinct_reply_path() {
11851185
let onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap();
11861186

11871187
let (_, reply_path) = extract_invoice(alice, &onion_message);
1188-
assert!(check_dummy_hopd_path_length(&reply_path, alice, charlie_id, PADDED_PATH_LENGTH));
1188+
assert!(check_dummy_hopd_path_length(&reply_path, alice, charlie_id, DUMMY_HOPS_PATH_LENGTH));
11891189

11901190
// Send, extract and verify the second Invoice Request message
11911191
let onion_message = david.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
@@ -1194,7 +1194,7 @@ fn send_invoice_for_refund_with_distinct_reply_path() {
11941194
let onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap();
11951195

11961196
let (_, reply_path) = extract_invoice(alice, &onion_message);
1197-
assert!(check_dummy_hopd_path_length(&reply_path, alice, nodes[6].node.get_our_node_id(), PADDED_PATH_LENGTH));
1197+
assert!(check_dummy_hopd_path_length(&reply_path, alice, nodes[6].node.get_our_node_id(), DUMMY_HOPS_PATH_LENGTH));
11981198
}
11991199

12001200
/// Verifies that the invoice request message can be retried if it fails to reach the
@@ -1248,7 +1248,7 @@ fn creates_and_pays_for_offer_with_retry() {
12481248
});
12491249
assert_eq!(invoice_request.amount_msats(), Some(10_000_000));
12501250
assert_ne!(invoice_request.payer_signing_pubkey(), bob_id);
1251-
assert!(check_dummy_hopd_path_length(&reply_path, alice, bob_id, PADDED_PATH_LENGTH));
1251+
assert!(check_dummy_hopd_path_length(&reply_path, alice, bob_id, DUMMY_HOPS_PATH_LENGTH));
12521252
let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
12531253
bob.onion_messenger.handle_onion_message(alice_id, &onion_message);
12541254

@@ -1549,7 +1549,7 @@ fn fails_authentication_when_handling_invoice_request() {
15491549
let (invoice_request, reply_path) = extract_invoice_request(alice, &onion_message);
15501550
assert_eq!(invoice_request.amount_msats(), Some(10_000_000));
15511551
assert_ne!(invoice_request.payer_signing_pubkey(), david_id);
1552-
assert!(check_dummy_hopd_path_length(&reply_path, david, charlie_id, PADDED_PATH_LENGTH));
1552+
assert!(check_dummy_hopd_path_length(&reply_path, david, charlie_id, DUMMY_HOPS_PATH_LENGTH));
15531553

15541554
assert_eq!(alice.onion_messenger.next_onion_message_for_peer(charlie_id), None);
15551555

@@ -1578,7 +1578,7 @@ fn fails_authentication_when_handling_invoice_request() {
15781578
let (invoice_request, reply_path) = extract_invoice_request(alice, &onion_message);
15791579
assert_eq!(invoice_request.amount_msats(), Some(10_000_000));
15801580
assert_ne!(invoice_request.payer_signing_pubkey(), david_id);
1581-
assert!(check_dummy_hopd_path_length(&reply_path, david, charlie_id, PADDED_PATH_LENGTH));
1581+
assert!(check_dummy_hopd_path_length(&reply_path, david, charlie_id, DUMMY_HOPS_PATH_LENGTH));
15821582

15831583
assert_eq!(alice.onion_messenger.next_onion_message_for_peer(charlie_id), None);
15841584
}
@@ -1678,7 +1678,7 @@ fn fails_authentication_when_handling_invoice_for_offer() {
16781678
let (invoice_request, reply_path) = extract_invoice_request(alice, &onion_message);
16791679
assert_eq!(invoice_request.amount_msats(), Some(10_000_000));
16801680
assert_ne!(invoice_request.payer_signing_pubkey(), david_id);
1681-
assert!(check_dummy_hopd_path_length(&reply_path, david, charlie_id, PADDED_PATH_LENGTH));
1681+
assert!(check_dummy_hopd_path_length(&reply_path, david, charlie_id, DUMMY_HOPS_PATH_LENGTH));
16821682

16831683
let onion_message = alice.onion_messenger.next_onion_message_for_peer(charlie_id).unwrap();
16841684
charlie.onion_messenger.handle_onion_message(alice_id, &onion_message);

lightning/src/offers/flow.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ use crate::onion_message::async_payments::{
5252
StaticInvoicePersisted,
5353
};
5454
use crate::onion_message::messenger::{
55-
Destination, MessageRouter, MessageSendInstructions, Responder, PADDED_PATH_LENGTH,
55+
Destination, MessageRouter, MessageSendInstructions, Responder, DUMMY_HOPS_PATH_LENGTH,
5656
};
5757
use crate::onion_message::offers::OffersMessage;
5858
use crate::onion_message::packet::OnionMessageContents;
@@ -1312,7 +1312,7 @@ where
13121312
prev_outbound_scid_alias,
13131313
htlc_id,
13141314
});
1315-
let num_dummy_hops = PADDED_PATH_LENGTH.saturating_sub(1);
1315+
let num_dummy_hops = DUMMY_HOPS_PATH_LENGTH.saturating_sub(1);
13161316
BlindedMessagePath::new_with_dummy_hops(
13171317
&[],
13181318
self.get_our_node_id(),

lightning/src/onion_message/messenger.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -524,11 +524,11 @@ pub trait MessageRouter {
524524

525525
/// A [`MessageRouter`] that can only route to a directly connected [`Destination`].
526526
///
527-
/// [`DefaultMessageRouter`] tries to construct compact and padded [`BlindedMessagePath`]s based on
527+
/// [`DefaultMessageRouter`] tries to construct compact or private [`BlindedMessagePath`]s based on
528528
/// the [`MessageContext`] given to [`MessageRouter::create_blinded_paths`]. That is, if the
529529
/// provided context implies the path may be used in a BOLT 12 object which might appear in a QR
530-
/// code, it reduces the amount of padding and prefers building compact paths when short channel
531-
/// IDs (SCIDs) are available for intermediate peers.
530+
/// code, it reduces the amount of padding and dummy hops and prefers building compact paths when
531+
/// short channel IDs (SCIDs) are available for intermediate peers.
532532
///
533533
/// # Compact Blinded Paths
534534
///
@@ -548,7 +548,7 @@ pub trait MessageRouter {
548548
/// it will create a one-hop path using the recipient as the introduction node if it is an announced
549549
/// node. Otherwise, there is no way to find a path to the introduction node in order to send a
550550
/// message, and thus an `Err` is returned. The impact of this may be somewhat muted when
551-
/// additional padding is added to the blinded path, but this protection is not complete.
551+
/// additional dummy hops are added to the blinded path, but this protection is not complete.
552552
pub struct DefaultMessageRouter<G: Deref<Target = NetworkGraph<L>>, L: Deref, ES: Deref>
553553
where
554554
L::Target: Logger,
@@ -560,14 +560,14 @@ where
560560

561561
// Target total length (in hops) for blinded paths used outside of QR codes.
562562
//
563-
// We pad with dummy hops until the path reaches this length (including the recipient).
564-
pub(crate) const PADDED_PATH_LENGTH: usize = 4;
563+
// We add dummy hops until the path reaches this length (including the recipient).
564+
pub(crate) const DUMMY_HOPS_PATH_LENGTH: usize = 4;
565565

566566
// Target total length (in hops) for blinded paths which are included in objects which may appear
567567
// in a QR code.
568568
//
569-
// We pad with dummy hops until the path reaches this length (including the recipient).
570-
pub(crate) const QR_CODED_PADDED_PATH_LENGTH: usize = 2;
569+
// We add dummy hops until the path reaches this length (including the recipient).
570+
pub(crate) const QR_CODED_DUMMY_HOPS_PATH_LENGTH: usize = 2;
571571

572572
impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, ES: Deref> DefaultMessageRouter<G, L, ES>
573573
where
@@ -598,13 +598,13 @@ where
598598
let is_recipient_announced =
599599
network_graph.nodes().contains_key(&NodeId::from_pubkey(&recipient));
600600

601-
let (mut compact_paths, padded_path_len) = match &context {
601+
let (mut compact_paths, dummy_hopd_path_len) = match &context {
602602
MessageContext::Offers(OffersContext::InvoiceRequest { .. })
603603
| MessageContext::Offers(OffersContext::OutboundPaymentInRefund { .. }) => {
604604
// When embedding blinded paths within BOLT 12 objects which are generally embedded
605605
// in QR codes, we sadly need to be conservative about size, especially if the QR
606606
// code ultimately also includes an on-chain address.
607-
(true, QR_CODED_PADDED_PATH_LENGTH)
607+
(true, QR_CODED_DUMMY_HOPS_PATH_LENGTH)
608608
},
609609
MessageContext::Offers(OffersContext::StaticInvoiceRequested { .. }) => {
610610
// Async Payments aggressively embeds the entire `InvoiceRequest` in the payment
@@ -615,9 +615,9 @@ where
615615
(true, 0)
616616
},
617617
_ => {
618-
// If there's no need to be small, pad the path more and never use SCID-based
619-
// next-hops as they carry additional expiry risk.
620-
(false, PADDED_PATH_LENGTH)
618+
// If there's no need to be small, add additional dummy hops and never use
619+
// SCID-based next-hops as they carry additional expiry risk.
620+
(false, DUMMY_HOPS_PATH_LENGTH)
621621
},
622622
};
623623

@@ -653,7 +653,7 @@ where
653653

654654
let build_path = |intermediate_hops: &[MessageForwardNode]| {
655655
// Calculate the dummy hops given the total hop count target (including the recipient).
656-
let dummy_hops_count = padded_path_len.saturating_sub(intermediate_hops.len() + 1);
656+
let dummy_hops_count = dummy_hopd_path_len.saturating_sub(intermediate_hops.len() + 1);
657657

658658
BlindedMessagePath::new_with_dummy_hops(
659659
intermediate_hops,
@@ -770,8 +770,8 @@ where
770770

771771
/// This message router is similar to [`DefaultMessageRouter`], but it always creates
772772
/// non-compact blinded paths, using the peer's [`NodeId`]. It uses the same heuristics as
773-
/// [`DefaultMessageRouter`] for deciding when to pad the generated blinded paths with additional
774-
/// hops.
773+
/// [`DefaultMessageRouter`] for deciding when to add additional dummy hops to the generated blinded
774+
/// paths.
775775
///
776776
/// This message router can only route to a directly connected [`Destination`].
777777
///
@@ -781,7 +781,7 @@ where
781781
/// it will create a one-hop path using the recipient as the introduction node if it is an announced
782782
/// node. Otherwise, there is no way to find a path to the introduction node in order to send a
783783
/// message, and thus an `Err` is returned. The impact of this may be somewhat muted when
784-
/// additional padding is added to the blinded path, but this protection is not complete.
784+
/// additional dummy hops are added to the blinded path, but this protection is not complete.
785785
pub struct NodeIdMessageRouter<G: Deref<Target = NetworkGraph<L>>, L: Deref, ES: Deref>
786786
where
787787
L::Target: Logger,

0 commit comments

Comments
 (0)