Skip to content

Commit d00e550

Browse files
authored
Merge pull request #3028 from jkczyz/2024-04-offer-id-followups
Follow-ups to #2970
2 parents 8701b1b + 33b6162 commit d00e550

File tree

3 files changed

+25
-60
lines changed

3 files changed

+25
-60
lines changed

lightning/src/ln/channelmanager.rs

+18-28
Original file line numberDiff line numberDiff line change
@@ -357,11 +357,6 @@ enum OnionPayload {
357357
/// This is only here for backwards-compatibility in serialization, in the future it can be
358358
/// removed, breaking clients running 0.0.106 and earlier.
359359
_legacy_hop_data: Option<msgs::FinalOnionHopData>,
360-
/// The context of the payment included by the recipient in a blinded path, or `None` if a
361-
/// blinded path was not used.
362-
///
363-
/// Used in part to determine the [`events::PaymentPurpose`].
364-
payment_context: Option<PaymentContext>,
365360
},
366361
/// Contains the payer-provided preimage.
367362
Spontaneous(PaymentPreimage),
@@ -5346,7 +5341,7 @@ where
53465341
}
53475342
}) => {
53485343
let blinded_failure = routing.blinded_failure();
5349-
let (cltv_expiry, onion_payload, payment_data, phantom_shared_secret, mut onion_fields) = match routing {
5344+
let (cltv_expiry, onion_payload, payment_data, payment_context, phantom_shared_secret, mut onion_fields) = match routing {
53505345
PendingHTLCRouting::Receive {
53515346
payment_data, payment_metadata, payment_context,
53525347
incoming_cltv_expiry, phantom_shared_secret, custom_tlvs,
@@ -5355,8 +5350,8 @@ where
53555350
let _legacy_hop_data = Some(payment_data.clone());
53565351
let onion_fields = RecipientOnionFields { payment_secret: Some(payment_data.payment_secret),
53575352
payment_metadata, custom_tlvs };
5358-
(incoming_cltv_expiry, OnionPayload::Invoice { _legacy_hop_data, payment_context },
5359-
Some(payment_data), phantom_shared_secret, onion_fields)
5353+
(incoming_cltv_expiry, OnionPayload::Invoice { _legacy_hop_data },
5354+
Some(payment_data), payment_context, phantom_shared_secret, onion_fields)
53605355
},
53615356
PendingHTLCRouting::ReceiveKeysend {
53625357
payment_data, payment_preimage, payment_metadata,
@@ -5368,7 +5363,7 @@ where
53685363
custom_tlvs,
53695364
};
53705365
(incoming_cltv_expiry, OnionPayload::Spontaneous(payment_preimage),
5371-
payment_data, None, onion_fields)
5366+
payment_data, None, None, onion_fields)
53725367
},
53735368
_ => {
53745369
panic!("short_channel_id == 0 should imply any pending_forward entries are of type Receive");
@@ -5530,7 +5525,7 @@ where
55305525
match payment_secrets.entry(payment_hash) {
55315526
hash_map::Entry::Vacant(_) => {
55325527
match claimable_htlc.onion_payload {
5533-
OnionPayload::Invoice { ref payment_context, .. } => {
5528+
OnionPayload::Invoice { .. } => {
55345529
let payment_data = payment_data.unwrap();
55355530
let (payment_preimage, min_final_cltv_expiry_delta) = match inbound_payment::verify(payment_hash, &payment_data, self.highest_seen_timestamp.load(Ordering::Acquire) as u64, &self.inbound_payment_key, &self.logger) {
55365531
Ok(result) => result,
@@ -5548,9 +5543,9 @@ where
55485543
}
55495544
}
55505545
let purpose = events::PaymentPurpose::from_parts(
5551-
payment_preimage.clone(),
5546+
payment_preimage,
55525547
payment_data.payment_secret,
5553-
payment_context.clone(),
5548+
payment_context,
55545549
);
55555550
check_total_value!(purpose);
55565551
},
@@ -5561,13 +5556,10 @@ where
55615556
}
55625557
},
55635558
hash_map::Entry::Occupied(inbound_payment) => {
5564-
let payment_context = match claimable_htlc.onion_payload {
5565-
OnionPayload::Spontaneous(_) => {
5566-
log_trace!(self.logger, "Failing new keysend HTLC with payment_hash {} because we already have an inbound payment with the same payment hash", &payment_hash);
5567-
fail_htlc!(claimable_htlc, payment_hash);
5568-
},
5569-
OnionPayload::Invoice { ref payment_context, .. } => payment_context,
5570-
};
5559+
if let OnionPayload::Spontaneous(_) = claimable_htlc.onion_payload {
5560+
log_trace!(self.logger, "Failing new keysend HTLC with payment_hash {} because we already have an inbound payment with the same payment hash", &payment_hash);
5561+
fail_htlc!(claimable_htlc, payment_hash);
5562+
}
55715563
let payment_data = payment_data.unwrap();
55725564
if inbound_payment.get().payment_secret != payment_data.payment_secret {
55735565
log_trace!(self.logger, "Failing new HTLC with payment_hash {} as it didn't match our expected payment secret.", &payment_hash);
@@ -5580,7 +5572,7 @@ where
55805572
let purpose = events::PaymentPurpose::from_parts(
55815573
inbound_payment.get().payment_preimage,
55825574
payment_data.payment_secret,
5583-
payment_context.clone(),
5575+
payment_context,
55845576
);
55855577
let payment_claimable_generated = check_total_value!(purpose);
55865578
if payment_claimable_generated {
@@ -10815,11 +10807,11 @@ impl_writeable_tlv_based!(HTLCPreviousHopData, {
1081510807

1081610808
impl Writeable for ClaimableHTLC {
1081710809
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
10818-
let (payment_data, keysend_preimage, payment_context) = match &self.onion_payload {
10819-
OnionPayload::Invoice { _legacy_hop_data, payment_context } => {
10820-
(_legacy_hop_data.as_ref(), None, payment_context.as_ref())
10810+
let (payment_data, keysend_preimage) = match &self.onion_payload {
10811+
OnionPayload::Invoice { _legacy_hop_data } => {
10812+
(_legacy_hop_data.as_ref(), None)
1082110813
},
10822-
OnionPayload::Spontaneous(preimage) => (None, Some(preimage), None),
10814+
OnionPayload::Spontaneous(preimage) => (None, Some(preimage)),
1082310815
};
1082410816
write_tlv_fields!(writer, {
1082510817
(0, self.prev_hop, required),
@@ -10831,7 +10823,6 @@ impl Writeable for ClaimableHTLC {
1083110823
(6, self.cltv_expiry, required),
1083210824
(8, keysend_preimage, option),
1083310825
(10, self.counterparty_skimmed_fee_msat, option),
10834-
(11, payment_context, option),
1083510826
});
1083610827
Ok(())
1083710828
}
@@ -10849,7 +10840,6 @@ impl Readable for ClaimableHTLC {
1084910840
(6, cltv_expiry, required),
1085010841
(8, keysend_preimage, option),
1085110842
(10, counterparty_skimmed_fee_msat, option),
10852-
(11, payment_context, option),
1085310843
});
1085410844
let payment_data: Option<msgs::FinalOnionHopData> = payment_data_opt;
1085510845
let value = value_ser.0.unwrap();
@@ -10870,7 +10860,7 @@ impl Readable for ClaimableHTLC {
1087010860
}
1087110861
total_msat = Some(payment_data.as_ref().unwrap().total_msat);
1087210862
}
10873-
OnionPayload::Invoice { _legacy_hop_data: payment_data, payment_context }
10863+
OnionPayload::Invoice { _legacy_hop_data: payment_data }
1087410864
},
1087510865
};
1087610866
Ok(Self {
@@ -12108,7 +12098,7 @@ where
1210812098
return Err(DecodeError::InvalidValue);
1210912099
}
1211012100
let purpose = match &htlcs[0].onion_payload {
12111-
OnionPayload::Invoice { _legacy_hop_data, payment_context: _ } => {
12101+
OnionPayload::Invoice { _legacy_hop_data } => {
1211212102
if let Some(hop_data) = _legacy_hop_data {
1211312103
events::PaymentPurpose::Bolt11InvoicePayment {
1211412104
payment_preimage: match pending_inbound_payments.get(&payment_hash) {

lightning/src/ln/offers_tests.rs

-7
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ use crate::blinded_path::{BlindedPath, IntroductionNode};
4646
use crate::blinded_path::payment::{Bolt12OfferContext, Bolt12RefundContext, PaymentContext};
4747
use crate::events::{Event, MessageSendEventsProvider, PaymentPurpose};
4848
use crate::ln::channelmanager::{PaymentId, RecentPaymentDetails, Retry, self};
49-
use crate::ln::features::InvoiceRequestFeatures;
5049
use crate::ln::functional_test_utils::*;
5150
use crate::ln::msgs::{ChannelMessageHandler, Init, NodeAnnouncement, OnionMessage, OnionMessageHandler, RoutingMessageHandler, SocketAddress, UnsignedGossipMessage, UnsignedNodeAnnouncement};
5251
use crate::offers::invoice::Bolt12Invoice;
@@ -412,8 +411,6 @@ fn creates_and_pays_for_offer_using_two_hop_blinded_path() {
412411
offer_id: offer.id(),
413412
invoice_request: InvoiceRequestFields {
414413
payer_id: invoice_request.payer_id(),
415-
amount_msats: None,
416-
features: InvoiceRequestFeatures::empty(),
417414
quantity: None,
418415
payer_note_truncated: None,
419416
},
@@ -565,8 +562,6 @@ fn creates_and_pays_for_offer_using_one_hop_blinded_path() {
565562
offer_id: offer.id(),
566563
invoice_request: InvoiceRequestFields {
567564
payer_id: invoice_request.payer_id(),
568-
amount_msats: None,
569-
features: InvoiceRequestFeatures::empty(),
570565
quantity: None,
571566
payer_note_truncated: None,
572567
},
@@ -687,8 +682,6 @@ fn pays_for_offer_without_blinded_paths() {
687682
offer_id: offer.id(),
688683
invoice_request: InvoiceRequestFields {
689684
payer_id: invoice_request.payer_id(),
690-
amount_msats: None,
691-
features: InvoiceRequestFeatures::empty(),
692685
quantity: None,
693686
payer_note_truncated: None,
694687
},

lightning/src/offers/invoice_request.rs

+7-25
Original file line numberDiff line numberDiff line change
@@ -877,14 +877,12 @@ impl VerifiedInvoiceRequest {
877877
let InvoiceRequestContents {
878878
payer_id,
879879
inner: InvoiceRequestContentsWithoutPayerId {
880-
payer: _, offer: _, chain: _, amount_msats, features, quantity, payer_note
880+
payer: _, offer: _, chain: _, amount_msats: _, features: _, quantity, payer_note
881881
},
882882
} = &self.inner.contents;
883883

884884
InvoiceRequestFields {
885885
payer_id: *payer_id,
886-
amount_msats: *amount_msats,
887-
features: features.clone(),
888886
quantity: *quantity,
889887
payer_note_truncated: payer_note.clone()
890888
.map(|mut s| { s.truncate(PAYER_NOTE_LIMIT); UntrustedString(s) }),
@@ -1126,15 +1124,6 @@ pub struct InvoiceRequestFields {
11261124
/// A possibly transient pubkey used to sign the invoice request.
11271125
pub payer_id: PublicKey,
11281126

1129-
/// The amount to pay in msats (i.e., the minimum lightning-payable unit for [`chain`]), which
1130-
/// must be greater than or equal to [`Offer::amount`], converted if necessary.
1131-
///
1132-
/// [`chain`]: InvoiceRequest::chain
1133-
pub amount_msats: Option<u64>,
1134-
1135-
/// Features pertaining to requesting an invoice.
1136-
pub features: InvoiceRequestFeatures,
1137-
11381127
/// The quantity of the offer's item conforming to [`Offer::is_valid_quantity`].
11391128
pub quantity: Option<u64>,
11401129

@@ -1150,10 +1139,8 @@ impl Writeable for InvoiceRequestFields {
11501139
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
11511140
write_tlv_fields!(writer, {
11521141
(0, self.payer_id, required),
1153-
(2, self.amount_msats.map(|v| HighZeroBytesDroppedBigSize(v)), option),
1154-
(4, WithoutLength(&self.features), required),
1155-
(6, self.quantity.map(|v| HighZeroBytesDroppedBigSize(v)), option),
1156-
(8, self.payer_note_truncated.as_ref().map(|s| WithoutLength(&s.0)), option),
1142+
(2, self.quantity.map(|v| HighZeroBytesDroppedBigSize(v)), option),
1143+
(4, self.payer_note_truncated.as_ref().map(|s| WithoutLength(&s.0)), option),
11571144
});
11581145
Ok(())
11591146
}
@@ -1163,15 +1150,13 @@ impl Readable for InvoiceRequestFields {
11631150
fn read<R: io::Read>(reader: &mut R) -> Result<Self, DecodeError> {
11641151
_init_and_read_len_prefixed_tlv_fields!(reader, {
11651152
(0, payer_id, required),
1166-
(2, amount_msats, (option, encoding: (u64, HighZeroBytesDroppedBigSize))),
1167-
(4, features, (option, encoding: (InvoiceRequestFeatures, WithoutLength))),
1168-
(6, quantity, (option, encoding: (u64, HighZeroBytesDroppedBigSize))),
1169-
(8, payer_note_truncated, (option, encoding: (String, WithoutLength))),
1153+
(2, quantity, (option, encoding: (u64, HighZeroBytesDroppedBigSize))),
1154+
(4, payer_note_truncated, (option, encoding: (String, WithoutLength))),
11701155
});
1171-
let features = features.unwrap_or(InvoiceRequestFeatures::empty());
11721156

11731157
Ok(InvoiceRequestFields {
1174-
payer_id: payer_id.0.unwrap(), amount_msats, features, quantity,
1158+
payer_id: payer_id.0.unwrap(),
1159+
quantity,
11751160
payer_note_truncated: payer_note_truncated.map(|s| UntrustedString(s)),
11761161
})
11771162
}
@@ -2264,7 +2249,6 @@ mod tests {
22642249

22652250
let invoice_request = offer.request_invoice(vec![1; 32], payer_pubkey()).unwrap()
22662251
.chain(Network::Testnet).unwrap()
2267-
.amount_msats(1001).unwrap()
22682252
.quantity(1).unwrap()
22692253
.payer_note("0".repeat(PAYER_NOTE_LIMIT * 2))
22702254
.build().unwrap()
@@ -2277,8 +2261,6 @@ mod tests {
22772261
fields,
22782262
InvoiceRequestFields {
22792263
payer_id: payer_pubkey(),
2280-
amount_msats: Some(1001),
2281-
features: InvoiceRequestFeatures::empty(),
22822264
quantity: Some(1),
22832265
payer_note_truncated: Some(UntrustedString("0".repeat(PAYER_NOTE_LIMIT))),
22842266
}

0 commit comments

Comments
 (0)