Skip to content

Commit b83aa6d

Browse files
fixup! add the bolt12 invoice to the PaymentSend event
Signed-off-by: Vincenzo Palazzo <[email protected]>
1 parent 365548b commit b83aa6d

File tree

5 files changed

+25
-23
lines changed

5 files changed

+25
-23
lines changed

lightning/src/events/mod.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@ use crate::blinded_path::payment::{Bolt12OfferContext, Bolt12RefundContext, Paym
2323
use crate::chain::transaction;
2424
use crate::ln::channelmanager::{InterceptId, PaymentId, RecipientOnionFields};
2525
use crate::ln::channel::FUNDING_CONF_DEADLINE_BLOCKS;
26+
use crate::offers::invoice::Bolt12Invoice;
27+
use crate::offers::static_invoice::StaticInvoice;
2628
use crate::types::features::ChannelTypeFeatures;
2729
use crate::ln::msgs;
2830
use crate::ln::types::ChannelId;
2931
use crate::types::payment::{PaymentPreimage, PaymentHash, PaymentSecret};
30-
use crate::offers::invoice::Bolt12Invoice;
3132
use crate::onion_message::messenger::Responder;
3233
use crate::routing::gossip::NetworkUpdate;
3334
use crate::routing::router::{BlindedTail, Path, RouteHop, RouteParameters};
@@ -956,9 +957,11 @@ pub enum Event {
956957
/// showing the invoice and confirming that the payment hash matches
957958
/// the hash of the payment preimage.
958959
///
959-
/// However, the [`PaidInvoice`] can also be of type [`crate::offers::static_invoice::StaticInvoice`], which
960+
/// However, the [`PaidBolt12Invoice`] can also be of type [`StaticInvoice`], which
960961
/// is a special [`Bolt12Invoice`] where proof of payment is not possible.
961-
bolt12_invoice: Option<PaidInvoice>,
962+
///
963+
/// [`StaticInvoice`]: crate::offers::static_invoice::StaticInvoice
964+
bolt12_invoice: Option<PaidBolt12Invoice>,
962965
},
963966
/// Indicates an outbound payment failed. Individual [`Event::PaymentPathFailed`] events
964967
/// provide failure information for each path attempt in the payment, including retries.
@@ -2455,14 +2458,14 @@ impl<T: EventHandler> EventHandler for Arc<T> {
24552458

24562459
/// The BOLT 12 invoice that was paid, surfaced in [`Event::PaymentSent::bolt12_invoice`].
24572460
#[derive(Clone, Debug, PartialEq, Eq)]
2458-
pub enum PaidInvoice {
2461+
pub enum PaidBolt12Invoice {
24592462
///
2460-
Bolt12Invoice(crate::offers::invoice::Bolt12Invoice),
2463+
Bolt12Invoice(Bolt12Invoice),
24612464
///
2462-
StaticInvoice(crate::offers::static_invoice::StaticInvoice),
2465+
StaticInvoice(StaticInvoice),
24632466
}
24642467

2465-
impl_writeable_tlv_based_enum!(PaidInvoice,
2468+
impl_writeable_tlv_based_enum!(PaidBolt12Invoice,
24662469
{0, Bolt12Invoice} => (),
24672470
{2, StaticInvoice} => (),
24682471
);

lightning/src/ln/functional_test_utils.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use crate::chain::{BestBlock, ChannelMonitorUpdateStatus, Confirm, Listen, Watch, chainmonitor::Persist};
1414
use crate::chain::channelmonitor::ChannelMonitor;
1515
use crate::chain::transaction::OutPoint;
16-
use crate::events::{ClaimedHTLC, ClosureReason, Event, HTLCDestination, PaidInvoice, PathFailure, PaymentFailureReason, PaymentPurpose};
16+
use crate::events::{ClaimedHTLC, ClosureReason, Event, HTLCDestination, PaidBolt12Invoice, PathFailure, PaymentFailureReason, PaymentPurpose};
1717
use crate::events::bump_transaction::{BumpTransactionEvent, BumpTransactionEventHandler, Wallet, WalletSource};
1818
use crate::ln::types::ChannelId;
1919
use crate::types::payment::{PaymentPreimage, PaymentHash, PaymentSecret};
@@ -2294,7 +2294,7 @@ macro_rules! expect_payment_claimed {
22942294
pub fn expect_payment_sent<CM: AChannelManager, H: NodeHolder<CM=CM>>(node: &H,
22952295
expected_payment_preimage: PaymentPreimage, expected_fee_msat_opt: Option<Option<u64>>,
22962296
expect_per_path_claims: bool, expect_post_ev_mon_update: bool,
2297-
) -> Option<PaidInvoice> {
2297+
) -> Option<PaidBolt12Invoice> {
22982298
let events = node.node().get_and_clear_pending_events();
22992299
let expected_payment_hash = PaymentHash(
23002300
bitcoin::hashes::sha256::Hash::hash(&expected_payment_preimage.0).to_byte_array());
@@ -2307,8 +2307,7 @@ pub fn expect_payment_sent<CM: AChannelManager, H: NodeHolder<CM=CM>>(node: &H,
23072307
check_added_monitors(node, 1);
23082308
}
23092309
// We return the invoice because some test may want to check the invoice details.
2310-
#[allow(unused_assignments)]
2311-
let mut invoice = None;
2310+
let invoice;
23122311
let expected_payment_id = match events[0] {
23132312
Event::PaymentSent { ref payment_id, ref payment_preimage, ref payment_hash, ref amount_msat, ref fee_paid_msat, ref bolt12_invoice } => {
23142313
assert_eq!(expected_payment_preimage, *payment_preimage);
@@ -3111,7 +3110,7 @@ pub fn pass_claimed_payment_along_route(args: ClaimAlongRouteArgs) -> u64 {
31113110

31123111
expected_total_fee_msat
31133112
}
3114-
pub fn claim_payment_along_route(args: ClaimAlongRouteArgs) -> Option<PaidInvoice> {
3113+
pub fn claim_payment_along_route(args: ClaimAlongRouteArgs) -> Option<PaidBolt12Invoice> {
31153114
let origin_node = args.origin_node;
31163115
let payment_preimage = args.payment_preimage;
31173116
let skip_last = args.skip_last;
@@ -3123,7 +3122,7 @@ pub fn claim_payment_along_route(args: ClaimAlongRouteArgs) -> Option<PaidInvoic
31233122
}
31243123
}
31253124

3126-
pub fn claim_payment<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_route: &[&Node<'a, 'b, 'c>], our_payment_preimage: PaymentPreimage) -> Option<PaidInvoice> {
3125+
pub fn claim_payment<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_route: &[&Node<'a, 'b, 'c>], our_payment_preimage: PaymentPreimage) -> Option<PaidBolt12Invoice> {
31273126
claim_payment_along_route(
31283127
ClaimAlongRouteArgs::new(origin_node, &[expected_route], our_payment_preimage)
31293128
)

lightning/src/ln/offers_tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ use crate::blinded_path::IntroductionNode;
4747
use crate::blinded_path::message::BlindedMessagePath;
4848
use crate::blinded_path::payment::{Bolt12OfferContext, Bolt12RefundContext, PaymentContext};
4949
use crate::blinded_path::message::OffersContext;
50-
use crate::events::{ClosureReason, Event, HTLCDestination, PaidInvoice, PaymentFailureReason, PaymentPurpose};
50+
use crate::events::{ClosureReason, Event, HTLCDestination, PaidBolt12Invoice, PaymentFailureReason, PaymentPurpose};
5151
use crate::ln::channelmanager::{Bolt12PaymentError, MAX_SHORT_LIVED_RELATIVE_EXPIRY, PaymentId, RecentPaymentDetails, RecipientOnionFields, Retry, self};
5252
use crate::types::features::Bolt12InvoiceFeatures;
5353
use crate::ln::functional_test_utils::*;
@@ -188,7 +188,7 @@ fn claim_bolt12_payment<'a, 'b, 'c>(
188188
_ => panic!("Unexpected payment purpose: {:?}", payment_purpose),
189189
}
190190
if let Some(inv) = claim_payment(node, path, payment_preimage) {
191-
assert_eq!(inv, PaidInvoice::Bolt12Invoice(invoice.to_owned()));
191+
assert_eq!(inv, PaidBolt12Invoice::Bolt12Invoice(invoice.to_owned()));
192192
} else {
193193
panic!("Expected PaidInvoice::Bolt12Invoice");
194194
};

lightning/src/ln/outbound_payment.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use bitcoin::secp256k1::{self, Secp256k1, SecretKey};
1515
use lightning_invoice::Bolt11Invoice;
1616

1717
use crate::blinded_path::{IntroductionNode, NodeIdLookUp};
18-
use crate::events::{self, PaidInvoice, PaymentFailureReason};
18+
use crate::events::{self, PaidBolt12Invoice, PaymentFailureReason};
1919
use crate::ln::channel_state::ChannelDetails;
2020
use crate::ln::channelmanager::{EventCompletionAction, HTLCSource, PaymentId};
2121
use crate::ln::onion_utils;
@@ -107,7 +107,7 @@ pub(crate) enum PendingOutboundPayment {
107107
invoice_request: Option<InvoiceRequest>,
108108
// Storing the BOLT 12 invoice here to allow Proof of Payment after
109109
// the payment is made.
110-
bolt12_invoice: Option<PaidInvoice>,
110+
bolt12_invoice: Option<PaidBolt12Invoice>,
111111
custom_tlvs: Vec<(u64, Vec<u8>)>,
112112
pending_amt_msat: u64,
113113
/// Used to track the fee paid. Present iff the payment was serialized on 0.0.103+.
@@ -157,7 +157,7 @@ impl_writeable_tlv_based!(RetryableInvoiceRequest, {
157157
});
158158

159159
impl PendingOutboundPayment {
160-
fn bolt12_invoice(&self) -> Option<&PaidInvoice> {
160+
fn bolt12_invoice(&self) -> Option<&PaidBolt12Invoice> {
161161
match self {
162162
PendingOutboundPayment::Retryable { bolt12_invoice, .. } => bolt12_invoice.as_ref(),
163163
_ => None,
@@ -966,7 +966,7 @@ impl OutboundPayments {
966966
if let Some(max_fee_msat) = params_config.max_total_routing_fee_msat {
967967
route_params.max_total_routing_fee_msat = Some(max_fee_msat);
968968
}
969-
let invoice = PaidInvoice::Bolt12Invoice(invoice.clone());
969+
let invoice = PaidBolt12Invoice::Bolt12Invoice(invoice.clone());
970970
self.send_payment_for_bolt12_invoice_internal(
971971
payment_id, payment_hash, None, None, Some(invoice), route_params, retry_strategy, router, first_hops,
972972
inflight_htlcs, entropy_source, node_signer, node_id_lookup, secp_ctx, best_block_height,
@@ -979,7 +979,7 @@ impl OutboundPayments {
979979
>(
980980
&self, payment_id: PaymentId, payment_hash: PaymentHash,
981981
keysend_preimage: Option<PaymentPreimage>, invoice_request: Option<&InvoiceRequest>,
982-
bolt12_invoice: Option<PaidInvoice>,
982+
bolt12_invoice: Option<PaidBolt12Invoice>,
983983
mut route_params: RouteParameters, retry_strategy: Retry, router: &R,
984984
first_hops: Vec<ChannelDetails>, inflight_htlcs: IH, entropy_source: &ES, node_signer: &NS,
985985
node_id_lookup: &NL, secp_ctx: &Secp256k1<secp256k1::All>, best_block_height: u32, logger: &L,
@@ -1727,7 +1727,7 @@ impl OutboundPayments {
17271727
&self, payment_hash: PaymentHash, recipient_onion: RecipientOnionFields, payment_id: PaymentId,
17281728
keysend_preimage: Option<PaymentPreimage>, route: &Route, retry_strategy: Option<Retry>,
17291729
payment_params: Option<PaymentParameters>, entropy_source: &ES, best_block_height: u32,
1730-
bolt12_invoice: Option<PaidInvoice>
1730+
bolt12_invoice: Option<PaidBolt12Invoice>
17311731
) -> Result<Vec<[u8; 32]>, PaymentSendFailure> where ES::Target: EntropySource {
17321732
let mut pending_outbounds = self.pending_outbound_payments.lock().unwrap();
17331733
match pending_outbounds.entry(payment_id) {
@@ -1746,7 +1746,7 @@ impl OutboundPayments {
17461746
fn create_pending_payment<ES: Deref>(
17471747
payment_hash: PaymentHash, recipient_onion: RecipientOnionFields,
17481748
keysend_preimage: Option<PaymentPreimage>, invoice_request: Option<InvoiceRequest>,
1749-
bolt12_invoice: Option<PaidInvoice>, route: &Route, retry_strategy: Option<Retry>,
1749+
bolt12_invoice: Option<PaidBolt12Invoice>, route: &Route, retry_strategy: Option<Retry>,
17501750
payment_params: Option<PaymentParameters>, entropy_source: &ES, best_block_height: u32
17511751
) -> (PendingOutboundPayment, Vec<[u8; 32]>)
17521752
where

lightning/src/offers/invoice_macros.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ macro_rules! invoice_builder_methods_test_common { (
8787
$self: ident, $self_type: ty, $invoice_fields: expr, $return_type: ty, $return_value: expr
8888
$(, $self_mut: tt)?
8989
) => {
90-
#[allow(dead_code)]
90+
#[allow(dead_code)] // TODO: mode to `#[cfg_attr(c_bindings, allow(dead_code))]` once we remove the `async_payments` cfg flag
9191
pub(crate) fn features_unchecked(
9292
$($self_mut)* $self: $self_type, features: Bolt12InvoiceFeatures
9393
) -> $return_type {

0 commit comments

Comments
 (0)