Skip to content

Commit 0aaab83

Browse files
refactor: use payment_nonce from PaymentSent for payer proofs
Update rust-lightning dependency to include commits from PRs #4210 (BLIP-42 contact secrets) and #4297 (payment_nonce in PaymentSent). The payment_nonce in PaymentSent allows capturing the nonce needed for payer proof construction directly from the payment success event, eliminating the need to set manually_handle_bolt12_invoices and intercept InvoiceReceived. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent d6bd984 commit 0aaab83

File tree

5 files changed

+51
-121
lines changed

5 files changed

+51
-121
lines changed

Cargo.toml

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,17 @@ default = []
3939
#lightning-liquidity = { version = "0.2.0", features = ["std"] }
4040
#lightning-macros = { version = "0.2.0" }
4141

42-
lightning = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "d5baee83aee0e2674020700f77918f46b3925ab6", features = ["std"] }
43-
lightning-types = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "d5baee83aee0e2674020700f77918f46b3925ab6" }
44-
lightning-invoice = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "d5baee83aee0e2674020700f77918f46b3925ab6", features = ["std"] }
45-
lightning-net-tokio = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "d5baee83aee0e2674020700f77918f46b3925ab6" }
46-
lightning-persister = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "d5baee83aee0e2674020700f77918f46b3925ab6", features = ["tokio"] }
47-
lightning-background-processor = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "d5baee83aee0e2674020700f77918f46b3925ab6" }
48-
lightning-rapid-gossip-sync = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "d5baee83aee0e2674020700f77918f46b3925ab6" }
49-
lightning-block-sync = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "d5baee83aee0e2674020700f77918f46b3925ab6", features = ["rest-client", "rpc-client", "tokio"] }
50-
lightning-transaction-sync = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "d5baee83aee0e2674020700f77918f46b3925ab6", features = ["esplora-async-https", "time", "electrum-rustls-ring"] }
51-
lightning-liquidity = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "d5baee83aee0e2674020700f77918f46b3925ab6", features = ["std"] }
52-
lightning-macros = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "d5baee83aee0e2674020700f77918f46b3925ab6" }
42+
lightning = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d", features = ["std"] }
43+
lightning-types = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d" }
44+
lightning-invoice = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d", features = ["std"] }
45+
lightning-net-tokio = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d" }
46+
lightning-persister = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d", features = ["tokio"] }
47+
lightning-background-processor = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d" }
48+
lightning-rapid-gossip-sync = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d" }
49+
lightning-block-sync = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d", features = ["rest-client", "rpc-client", "tokio"] }
50+
lightning-transaction-sync = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d", features = ["esplora-async-https", "time", "electrum-rustls-ring"] }
51+
lightning-liquidity = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d", features = ["std"] }
52+
lightning-macros = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d" }
5353

5454
bdk_chain = { version = "0.23.0", default-features = false, features = ["std"] }
5555
bdk_esplora = { version = "0.22.0", default-features = false, features = ["async-https-rustls", "tokio"]}
@@ -85,7 +85,7 @@ bitcoin-payment-instructions = { git = "https://github.com/joostjager/bitcoin-pa
8585
winapi = { version = "0.3", features = ["winbase"] }
8686

8787
[dev-dependencies]
88-
lightning = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "d5baee83aee0e2674020700f77918f46b3925ab6", features = ["std", "_test_utils"] }
88+
lightning = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d", features = ["std", "_test_utils"] }
8989
rand = { version = "0.9.2", default-features = false, features = ["std", "thread_rng", "os_rng"] }
9090
proptest = "1.0.0"
9191
regex = "1.5.6"
@@ -173,14 +173,14 @@ harness = false
173173
#vss-client-ng = { git = "https://github.com/lightningdevkit/vss-client", branch = "main" }
174174
#
175175
[patch."https://github.com/lightningdevkit/rust-lightning"]
176-
lightning = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "d5baee83aee0e2674020700f77918f46b3925ab6" }
177-
lightning-types = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "d5baee83aee0e2674020700f77918f46b3925ab6" }
178-
lightning-invoice = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "d5baee83aee0e2674020700f77918f46b3925ab6" }
179-
lightning-net-tokio = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "d5baee83aee0e2674020700f77918f46b3925ab6" }
180-
lightning-persister = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "d5baee83aee0e2674020700f77918f46b3925ab6" }
181-
lightning-background-processor = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "d5baee83aee0e2674020700f77918f46b3925ab6" }
182-
lightning-rapid-gossip-sync = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "d5baee83aee0e2674020700f77918f46b3925ab6" }
183-
lightning-block-sync = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "d5baee83aee0e2674020700f77918f46b3925ab6" }
184-
lightning-transaction-sync = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "d5baee83aee0e2674020700f77918f46b3925ab6" }
185-
lightning-liquidity = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "d5baee83aee0e2674020700f77918f46b3925ab6" }
186-
lightning-macros = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "d5baee83aee0e2674020700f77918f46b3925ab6" }
176+
lightning = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d" }
177+
lightning-types = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d" }
178+
lightning-invoice = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d" }
179+
lightning-net-tokio = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d" }
180+
lightning-persister = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d" }
181+
lightning-background-processor = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d" }
182+
lightning-rapid-gossip-sync = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d" }
183+
lightning-block-sync = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d" }
184+
lightning-transaction-sync = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d" }
185+
lightning-liquidity = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d" }
186+
lightning-macros = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d" }

src/config.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,6 @@ pub(crate) fn default_user_config(config: &Config) -> UserConfig {
342342
user_config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx =
343343
config.anchor_channels_config.is_some();
344344
user_config.reject_inbound_splices = false;
345-
user_config.manually_handle_bolt12_invoices = true;
346345

347346
if may_announce_channel(config).is_err() {
348347
user_config.accept_forwards_to_priv_channels = false;

src/event.rs

Lines changed: 24 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use std::sync::{Arc, Mutex};
1414
use bitcoin::blockdata::locktime::absolute::LockTime;
1515
use bitcoin::secp256k1::PublicKey;
1616
use bitcoin::{Amount, OutPoint};
17-
use lightning::blinded_path::message::OffersContext;
1817
use lightning::events::bump_transaction::BumpTransactionEvent;
1918
#[cfg(not(feature = "uniffi"))]
2019
use lightning::events::PaidBolt12Invoice;
@@ -24,13 +23,8 @@ use lightning::events::{
2423
};
2524
use lightning::impl_writeable_tlv_based_enum;
2625
use lightning::ln::channelmanager::PaymentId;
27-
use lightning::ln::outbound_payment::Bolt12PaymentError;
2826
use lightning::ln::types::ChannelId;
29-
use lightning::offers::invoice::Bolt12Invoice;
30-
use lightning::offers::invoice_error::InvoiceError;
31-
use lightning::offers::parse::Bolt12SemanticError;
32-
use lightning::onion_message::messenger::Responder;
33-
use lightning::onion_message::offers::OffersMessage;
27+
use lightning::offers::nonce::Nonce;
3428
use lightning::routing::gossip::NodeId;
3529
use lightning::sign::EntropySource;
3630
use lightning::util::config::{
@@ -566,62 +560,27 @@ where
566560
}
567561

568562
fn persist_payer_proof_context(
569-
&self, payment_id: PaymentId, invoice: &Bolt12Invoice, context: Option<&OffersContext>,
570-
) -> Result<(), ReplayEvent> {
571-
if let Some(context) =
572-
PayerProofContext::from_invoice_received(payment_id, invoice, context)
573-
{
574-
match self.payer_proof_context_store.insert_or_update(context) {
575-
Ok(_) => {},
576-
Err(e) => {
577-
log_error!(
578-
self.logger,
579-
"Failed to persist payer proof context for {}: {}",
580-
payment_id,
581-
e
582-
);
583-
return Err(ReplayEvent());
584-
},
585-
}
586-
}
563+
&self, payment_id: PaymentId, bolt12_invoice: &Option<PaidBolt12Invoice>,
564+
payment_nonce: Option<Nonce>,
565+
) {
566+
let invoice = match bolt12_invoice {
567+
Some(PaidBolt12Invoice::Bolt12Invoice(invoice)) => invoice,
568+
_ => return,
569+
};
587570

588-
Ok(())
589-
}
571+
let nonce = match payment_nonce {
572+
Some(nonce) => nonce,
573+
None => return,
574+
};
590575

591-
fn remove_payer_proof_context(&self, payment_id: &PaymentId) -> Result<(), ReplayEvent> {
592-
self.payer_proof_context_store.remove(payment_id).map_err(|e| {
576+
let context = PayerProofContext { payment_id, invoice: invoice.clone(), nonce };
577+
if let Err(e) = self.payer_proof_context_store.insert_or_update(context) {
593578
log_error!(
594579
self.logger,
595-
"Failed to remove payer proof context for {}: {}",
580+
"Failed to persist payer proof context for {}: {}",
596581
payment_id,
597582
e
598583
);
599-
ReplayEvent()
600-
})
601-
}
602-
603-
fn respond_to_invoice_error(&self, error: Bolt12PaymentError, responder: Option<Responder>) {
604-
let error = match error {
605-
Bolt12PaymentError::UnknownRequiredFeatures => {
606-
InvoiceError::from(Bolt12SemanticError::UnknownRequiredFeatures)
607-
},
608-
Bolt12PaymentError::SendingFailed(e) => InvoiceError::from_string(format!("{:?}", e)),
609-
Bolt12PaymentError::BlindedPathCreationFailed => InvoiceError::from_string(
610-
"Failed to create a blinded path back to ourselves".to_string(),
611-
),
612-
Bolt12PaymentError::UnexpectedInvoice | Bolt12PaymentError::DuplicateInvoice => return,
613-
};
614-
615-
let Some(responder) = responder else {
616-
log_trace!(self.logger, "No reply path available for invoice_error response");
617-
return;
618-
};
619-
620-
if let Err(e) = self
621-
.onion_messenger
622-
.handle_onion_message_response(OffersMessage::InvoiceError(error), responder.respond())
623-
{
624-
log_error!(self.logger, "Failed to send invoice_error response: {:?}", e);
625584
}
626585
}
627586

@@ -1138,6 +1097,7 @@ where
11381097
payment_hash,
11391098
fee_paid_msat,
11401099
bolt12_invoice,
1100+
payment_nonce,
11411101
..
11421102
} => {
11431103
let payment_id = if let Some(id) = payment_id {
@@ -1148,6 +1108,12 @@ where
11481108
};
11491109
let bolt12_invoice = bolt12_invoice.map(Into::into);
11501110

1111+
self.persist_payer_proof_context(
1112+
payment_id,
1113+
&bolt12_invoice,
1114+
payment_nonce,
1115+
);
1116+
11511117
let update = PaymentDetailsUpdate {
11521118
hash: Some(Some(payment_hash)),
11531119
preimage: Some(Some(payment_preimage)),
@@ -1216,7 +1182,6 @@ where
12161182
return Err(ReplayEvent());
12171183
},
12181184
};
1219-
self.remove_payer_proof_context(&payment_id)?;
12201185

12211186
let event =
12221187
Event::PaymentFailed { payment_id: Some(payment_id), payment_hash, reason };
@@ -1669,25 +1634,8 @@ where
16691634
.await;
16701635
}
16711636
},
1672-
LdkEvent::InvoiceReceived { payment_id, invoice, context, responder } => {
1673-
self.persist_payer_proof_context(payment_id, &invoice, context.as_ref())?;
1674-
1675-
match self
1676-
.channel_manager
1677-
.send_payment_for_bolt12_invoice(&invoice, context.as_ref())
1678-
{
1679-
Ok(()) => {},
1680-
Err(e) => {
1681-
log_error!(
1682-
self.logger,
1683-
"Failed to initiate payment for BOLT12 invoice {}: {:?}",
1684-
payment_id,
1685-
e
1686-
);
1687-
self.remove_payer_proof_context(&payment_id)?;
1688-
self.respond_to_invoice_error(e, responder);
1689-
},
1690-
}
1637+
LdkEvent::InvoiceReceived { .. } => {
1638+
debug_assert!(false, "We currently don't handle BOLT12 invoices manually, so this event should never be emitted.");
16911639
},
16921640
LdkEvent::ConnectionNeeded { node_id, addresses } => {
16931641
let spawn_logger = self.logger.clone();

src/payment/bolt12.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ impl Bolt12Payment {
150150
payer_note: payer_note.clone(),
151151
retry_strategy,
152152
route_params_config: route_parameters,
153+
contact_secrets: None,
154+
payer_offer: None,
153155
};
154156
let res = if let Some(hrn) = hrn {
155157
let hrn = maybe_deref(&hrn);
@@ -336,6 +338,8 @@ impl Bolt12Payment {
336338
payer_note: payer_note.clone(),
337339
retry_strategy,
338340
route_params_config: route_parameters,
341+
contact_secrets: None,
342+
payer_offer: None,
339343
};
340344
let res = if let Some(quantity) = quantity {
341345
self.channel_manager

src/payment/payer_proof_store.rs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
// http://opensource.org/licenses/MIT>, at your option. You may not use this file except in
66
// accordance with one or both of these licenses.
77

8-
use lightning::blinded_path::message::OffersContext;
98
use lightning::impl_writeable_tlv_based;
109
use lightning::ln::channelmanager::PaymentId;
1110
use lightning::offers::invoice::Bolt12Invoice;
@@ -20,26 +19,6 @@ pub(crate) struct PayerProofContext {
2019
pub nonce: Nonce,
2120
}
2221

23-
impl PayerProofContext {
24-
pub(crate) fn from_invoice_received(
25-
payment_id: PaymentId, invoice: &Bolt12Invoice, context: Option<&OffersContext>,
26-
) -> Option<Self> {
27-
match context {
28-
Some(OffersContext::OutboundPaymentForOffer {
29-
payment_id: context_payment_id,
30-
nonce,
31-
})
32-
| Some(OffersContext::OutboundPaymentForRefund {
33-
payment_id: context_payment_id,
34-
nonce,
35-
}) if *context_payment_id == payment_id => {
36-
Some(Self { payment_id, invoice: invoice.clone(), nonce: *nonce })
37-
},
38-
_ => None,
39-
}
40-
}
41-
}
42-
4322
impl_writeable_tlv_based!(PayerProofContext, {
4423
(0, payment_id, required),
4524
(2, invoice, required),

0 commit comments

Comments
 (0)