Skip to content

Commit 9df659a

Browse files
authored
Merge pull request #3118 from valentinewallace/2024-06-bolt12-paths-renames
Rename BOLT 12 message paths fields and methods
2 parents 144a24b + 42ca4b7 commit 9df659a

3 files changed

Lines changed: 42 additions & 32 deletions

File tree

lightning/src/offers/flow.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1270,7 +1270,7 @@ impl<MR: MessageRouter, L: Logger> OffersMessageFlow<MR, L> {
12701270
let message = AsyncPaymentsMessage::HeldHtlcAvailable(HeldHtlcAvailable {});
12711271
enqueue_onion_message_with_reply_paths(
12721272
message,
1273-
invoice.message_paths(),
1273+
invoice.held_htlc_available_paths(),
12741274
reply_paths,
12751275
&mut pending_async_payments_messages,
12761276
);

lightning/src/offers/invoice.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,7 +1428,7 @@ impl InvoiceFields {
14281428
fallbacks: self.fallbacks.as_ref(),
14291429
features,
14301430
node_id: Some(&self.signing_pubkey),
1431-
message_paths: None,
1431+
held_htlc_available_paths: None,
14321432
},
14331433
ExperimentalInvoiceTlvStreamRef {
14341434
#[cfg(test)]
@@ -1511,7 +1511,7 @@ tlv_stream!(InvoiceTlvStream, InvoiceTlvStreamRef<'a>, INVOICE_TYPES, {
15111511
(174, features: (Bolt12InvoiceFeatures, WithoutLength)),
15121512
(176, node_id: PublicKey),
15131513
// Only present in `StaticInvoice`s.
1514-
(236, message_paths: (Vec<BlindedMessagePath>, WithoutLength)),
1514+
(236, held_htlc_available_paths: (Vec<BlindedMessagePath>, WithoutLength)),
15151515
});
15161516

15171517
/// Valid type range for experimental invoice TLV records.
@@ -1700,7 +1700,7 @@ impl TryFrom<PartialInvoiceTlvStream> for InvoiceContents {
17001700
fallbacks,
17011701
features,
17021702
node_id,
1703-
message_paths,
1703+
held_htlc_available_paths,
17041704
},
17051705
experimental_offer_tlv_stream,
17061706
experimental_invoice_request_tlv_stream,
@@ -1710,7 +1710,7 @@ impl TryFrom<PartialInvoiceTlvStream> for InvoiceContents {
17101710
},
17111711
) = tlv_stream;
17121712

1713-
if message_paths.is_some() {
1713+
if held_htlc_available_paths.is_some() {
17141714
return Err(Bolt12SemanticError::UnexpectedPaths);
17151715
}
17161716

@@ -2037,7 +2037,7 @@ mod tests {
20372037
fallbacks: None,
20382038
features: None,
20392039
node_id: Some(&recipient_pubkey()),
2040-
message_paths: None,
2040+
held_htlc_available_paths: None,
20412041
},
20422042
SignatureTlvStreamRef { signature: Some(&invoice.signature()) },
20432043
ExperimentalOfferTlvStreamRef { experimental_foo: None },
@@ -2140,7 +2140,7 @@ mod tests {
21402140
fallbacks: None,
21412141
features: None,
21422142
node_id: Some(&recipient_pubkey()),
2143-
message_paths: None,
2143+
held_htlc_available_paths: None,
21442144
},
21452145
SignatureTlvStreamRef { signature: Some(&invoice.signature()) },
21462146
ExperimentalOfferTlvStreamRef { experimental_foo: None },
@@ -3558,7 +3558,7 @@ mod tests {
35583558
}
35593559

35603560
#[test]
3561-
fn fails_parsing_invoice_with_message_paths() {
3561+
fn fails_parsing_invoice_with_held_htlc_available_paths() {
35623562
let expanded_key = ExpandedKey::new([42; 32]);
35633563
let entropy = FixedEntropy {};
35643564
let nonce = Nonce::from_entropy_source(&entropy);
@@ -3590,8 +3590,8 @@ mod tests {
35903590
);
35913591

35923592
let mut tlv_stream = invoice.as_tlv_stream();
3593-
let message_paths = vec![blinded_path];
3594-
tlv_stream.3.message_paths = Some(&message_paths);
3593+
let held_htlc_available_paths = vec![blinded_path];
3594+
tlv_stream.3.held_htlc_available_paths = Some(&held_htlc_available_paths);
35953595

35963596
match Bolt12Invoice::try_from(tlv_stream.to_bytes()) {
35973597
Ok(_) => panic!("expected error"),

lightning/src/offers/static_invoice.rs

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ struct InvoiceContents {
9999
fallbacks: Option<Vec<FallbackAddress>>,
100100
features: Bolt12InvoiceFeatures,
101101
signing_pubkey: PublicKey,
102-
message_paths: Vec<BlindedMessagePath>,
102+
held_htlc_available_paths: Vec<BlindedMessagePath>,
103103
#[cfg(test)]
104104
experimental_baz: Option<u64>,
105105
}
@@ -122,14 +122,17 @@ impl<'a> StaticInvoiceBuilder<'a> {
122122
/// overridden by [`StaticInvoiceBuilder::relative_expiry`].
123123
pub fn for_offer_using_derived_keys<T: secp256k1::Signing>(
124124
offer: &'a Offer, payment_paths: Vec<BlindedPaymentPath>,
125-
message_paths: Vec<BlindedMessagePath>, created_at: Duration, expanded_key: &ExpandedKey,
126-
nonce: Nonce, secp_ctx: &Secp256k1<T>,
125+
held_htlc_available_paths: Vec<BlindedMessagePath>, created_at: Duration,
126+
expanded_key: &ExpandedKey, nonce: Nonce, secp_ctx: &Secp256k1<T>,
127127
) -> Result<Self, Bolt12SemanticError> {
128128
if offer.chains().len() > 1 {
129129
return Err(Bolt12SemanticError::UnexpectedChain);
130130
}
131131

132-
if payment_paths.is_empty() || message_paths.is_empty() || offer.paths().is_empty() {
132+
if payment_paths.is_empty()
133+
|| held_htlc_available_paths.is_empty()
134+
|| offer.paths().is_empty()
135+
{
133136
return Err(Bolt12SemanticError::MissingPaths);
134137
}
135138

@@ -147,8 +150,13 @@ impl<'a> StaticInvoiceBuilder<'a> {
147150
return Err(Bolt12SemanticError::InvalidSigningPubkey);
148151
}
149152

150-
let invoice =
151-
InvoiceContents::new(offer, payment_paths, message_paths, created_at, signing_pubkey);
153+
let invoice = InvoiceContents::new(
154+
offer,
155+
payment_paths,
156+
held_htlc_available_paths,
157+
created_at,
158+
signing_pubkey,
159+
);
152160

153161
Ok(Self { offer_bytes: &offer.bytes, invoice, keys })
154162
}
@@ -264,8 +272,8 @@ macro_rules! invoice_accessors { ($self: ident, $contents: expr) => {
264272

265273
/// Paths to the recipient for indicating that a held HTLC is available to claim when they next
266274
/// come online.
267-
pub fn message_paths(&$self) -> &[BlindedMessagePath] {
268-
$contents.message_paths()
275+
pub fn held_htlc_available_paths(&$self) -> &[BlindedMessagePath] {
276+
$contents.held_htlc_available_paths()
269277
}
270278

271279
/// The quantity of items supported, from [`Offer::supported_quantity`].
@@ -438,12 +446,13 @@ impl InvoiceContents {
438446

439447
fn new(
440448
offer: &Offer, payment_paths: Vec<BlindedPaymentPath>,
441-
message_paths: Vec<BlindedMessagePath>, created_at: Duration, signing_pubkey: PublicKey,
449+
held_htlc_available_paths: Vec<BlindedMessagePath>, created_at: Duration,
450+
signing_pubkey: PublicKey,
442451
) -> Self {
443452
Self {
444453
offer: offer.contents.clone(),
445454
payment_paths,
446-
message_paths,
455+
held_htlc_available_paths,
447456
created_at,
448457
relative_expiry: None,
449458
fallbacks: None,
@@ -465,7 +474,7 @@ impl InvoiceContents {
465474

466475
let invoice = InvoiceTlvStreamRef {
467476
paths: Some(Iterable(self.payment_paths.iter().map(|path| path.inner_blinded_path()))),
468-
message_paths: Some(self.message_paths.as_ref()),
477+
held_htlc_available_paths: Some(self.held_htlc_available_paths.as_ref()),
469478
blindedpay: Some(Iterable(self.payment_paths.iter().map(|path| &path.payinfo))),
470479
created_at: Some(self.created_at.as_secs()),
471480
relative_expiry: self.relative_expiry.map(|duration| duration.as_secs() as u32),
@@ -519,8 +528,8 @@ impl InvoiceContents {
519528
self.offer.paths()
520529
}
521530

522-
fn message_paths(&self) -> &[BlindedMessagePath] {
523-
&self.message_paths[..]
531+
fn held_htlc_available_paths(&self) -> &[BlindedMessagePath] {
532+
&self.held_htlc_available_paths[..]
524533
}
525534

526535
fn supported_quantity(&self) -> Quantity {
@@ -670,7 +679,7 @@ impl TryFrom<PartialInvoiceTlvStream> for InvoiceContents {
670679
fallbacks,
671680
features,
672681
node_id,
673-
message_paths,
682+
held_htlc_available_paths,
674683
payment_hash,
675684
amount,
676685
},
@@ -689,7 +698,8 @@ impl TryFrom<PartialInvoiceTlvStream> for InvoiceContents {
689698
}
690699

691700
let payment_paths = construct_payment_paths(blindedpay, paths)?;
692-
let message_paths = message_paths.ok_or(Bolt12SemanticError::MissingPaths)?;
701+
let held_htlc_available_paths =
702+
held_htlc_available_paths.ok_or(Bolt12SemanticError::MissingPaths)?;
693703

694704
let created_at = match created_at {
695705
None => return Err(Bolt12SemanticError::MissingCreationTime),
@@ -713,7 +723,7 @@ impl TryFrom<PartialInvoiceTlvStream> for InvoiceContents {
713723
Ok(InvoiceContents {
714724
offer: OfferContents::try_from((offer_tlv_stream, experimental_offer_tlv_stream))?,
715725
payment_paths,
716-
message_paths,
726+
held_htlc_available_paths,
717727
created_at,
718728
relative_expiry,
719729
fallbacks,
@@ -875,7 +885,7 @@ mod tests {
875885
assert_eq!(invoice.offer_features(), &OfferFeatures::empty());
876886
assert_eq!(invoice.absolute_expiry(), None);
877887
assert_eq!(invoice.offer_message_paths(), &[blinded_path()]);
878-
assert_eq!(invoice.message_paths(), &[blinded_path()]);
888+
assert_eq!(invoice.held_htlc_available_paths(), &[blinded_path()]);
879889
assert_eq!(invoice.issuer(), None);
880890
assert_eq!(invoice.supported_quantity(), Quantity::One);
881891
assert_ne!(invoice.signing_pubkey(), recipient_pubkey());
@@ -921,7 +931,7 @@ mod tests {
921931
fallbacks: None,
922932
features: None,
923933
node_id: Some(&signing_pubkey),
924-
message_paths: Some(&paths),
934+
held_htlc_available_paths: Some(&paths),
925935
},
926936
SignatureTlvStreamRef { signature: Some(&invoice.signature()) },
927937
ExperimentalOfferTlvStreamRef { experimental_foo: None },
@@ -1318,10 +1328,10 @@ mod tests {
13181328
},
13191329
}
13201330

1321-
// Error if message paths are missing.
1322-
let missing_message_paths_invoice = invoice();
1323-
let mut tlv_stream = missing_message_paths_invoice.as_tlv_stream();
1324-
tlv_stream.1.message_paths = None;
1331+
// Error if held_htlc_available_paths are missing.
1332+
let missing_held_htlc_available_paths_invoice = invoice();
1333+
let mut tlv_stream = missing_held_htlc_available_paths_invoice.as_tlv_stream();
1334+
tlv_stream.1.held_htlc_available_paths = None;
13251335
match StaticInvoice::try_from(tlv_stream_to_bytes(&tlv_stream)) {
13261336
Ok(_) => panic!("expected error"),
13271337
Err(e) => {

0 commit comments

Comments
 (0)