diff --git a/Cargo.toml b/Cargo.toml index 539941677..cf6b30b50 100755 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,17 +39,17 @@ default = [] #lightning-liquidity = { version = "0.2.0", features = ["std"] } #lightning-macros = { version = "0.2.0" } -lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "dcf0c203e166da2348bef12b2e5eff4a250cdec7", features = ["std"] } -lightning-types = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "dcf0c203e166da2348bef12b2e5eff4a250cdec7" } -lightning-invoice = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "dcf0c203e166da2348bef12b2e5eff4a250cdec7", features = ["std"] } -lightning-net-tokio = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "dcf0c203e166da2348bef12b2e5eff4a250cdec7" } -lightning-persister = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "dcf0c203e166da2348bef12b2e5eff4a250cdec7", features = ["tokio"] } -lightning-background-processor = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "dcf0c203e166da2348bef12b2e5eff4a250cdec7" } -lightning-rapid-gossip-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "dcf0c203e166da2348bef12b2e5eff4a250cdec7" } -lightning-block-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "dcf0c203e166da2348bef12b2e5eff4a250cdec7", features = ["rest-client", "rpc-client", "tokio"] } -lightning-transaction-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "dcf0c203e166da2348bef12b2e5eff4a250cdec7", features = ["esplora-async-https", "time", "electrum-rustls-ring"] } -lightning-liquidity = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "dcf0c203e166da2348bef12b2e5eff4a250cdec7", features = ["std"] } -lightning-macros = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "dcf0c203e166da2348bef12b2e5eff4a250cdec7" } +lightning = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d", features = ["std"] } +lightning-types = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d" } +lightning-invoice = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d", features = ["std"] } +lightning-net-tokio = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d" } +lightning-persister = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d", features = ["tokio"] } +lightning-background-processor = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d" } +lightning-rapid-gossip-sync = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d" } +lightning-block-sync = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d", features = ["rest-client", "rpc-client", "tokio"] } +lightning-transaction-sync = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d", features = ["esplora-async-https", "time", "electrum-rustls-ring"] } +lightning-liquidity = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d", features = ["std"] } +lightning-macros = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d" } bdk_chain = { version = "0.23.0", default-features = false, features = ["std"] } 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 winapi = { version = "0.3", features = ["winbase"] } [dev-dependencies] -lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "dcf0c203e166da2348bef12b2e5eff4a250cdec7", features = ["std", "_test_utils"] } +lightning = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d", features = ["std", "_test_utils"] } rand = { version = "0.9.2", default-features = false, features = ["std", "thread_rng", "os_rng"] } proptest = "1.0.0" regex = "1.5.6" @@ -172,15 +172,15 @@ harness = false #vss-client-ng = { path = "../vss-client" } #vss-client-ng = { git = "https://github.com/lightningdevkit/vss-client", branch = "main" } # -#[patch."https://github.com/lightningdevkit/rust-lightning"] -#lightning = { path = "../rust-lightning/lightning" } -#lightning-types = { path = "../rust-lightning/lightning-types" } -#lightning-invoice = { path = "../rust-lightning/lightning-invoice" } -#lightning-net-tokio = { path = "../rust-lightning/lightning-net-tokio" } -#lightning-persister = { path = "../rust-lightning/lightning-persister" } -#lightning-background-processor = { path = "../rust-lightning/lightning-background-processor" } -#lightning-rapid-gossip-sync = { path = "../rust-lightning/lightning-rapid-gossip-sync" } -#lightning-block-sync = { path = "../rust-lightning/lightning-block-sync" } -#lightning-transaction-sync = { path = "../rust-lightning/lightning-transaction-sync" } -#lightning-liquidity = { path = "../rust-lightning/lightning-liquidity" } -#lightning-macros = { path = "../rust-lightning/lightning-macros" } +[patch."https://github.com/lightningdevkit/rust-lightning"] +lightning = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d" } +lightning-types = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d" } +lightning-invoice = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d" } +lightning-net-tokio = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d" } +lightning-persister = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d" } +lightning-background-processor = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d" } +lightning-rapid-gossip-sync = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d" } +lightning-block-sync = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d" } +lightning-transaction-sync = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d" } +lightning-liquidity = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d" } +lightning-macros = { git = "https://github.com/vincenzopalazzo/rust-lightning", rev = "f5c24c6ba870784b3d038c17ef4e4418d6a24f1d" } diff --git a/bindings/ldk_node.udl b/bindings/ldk_node.udl index 014993690..29ed4df94 100644 --- a/bindings/ldk_node.udl +++ b/bindings/ldk_node.udl @@ -185,6 +185,8 @@ enum NodeError { "FeerateEstimationUpdateTimeout", "WalletOperationFailed", "WalletOperationTimeout", + "PayerProofCreationFailed", + "PayerProofUnavailable", "OnchainTxSigningFailed", "TxSyncFailed", "TxSyncTimeout", @@ -225,6 +227,7 @@ enum NodeError { "LnurlAuthFailed", "LnurlAuthTimeout", "InvalidLnurl", + "InvalidPayerProof", }; typedef dictionary NodeStatus; diff --git a/src/builder.rs b/src/builder.rs index cd8cc184f..df54d49fd 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -56,12 +56,14 @@ use crate::gossip::GossipSource; use crate::io::sqlite_store::SqliteStore; use crate::io::utils::{ read_event_queue, read_external_pathfinding_scores_from_cache, read_network_graph, - read_node_metrics, read_output_sweeper, read_payments, read_peer_info, read_pending_payments, - read_scorer, write_node_metrics, + read_node_metrics, read_output_sweeper, read_payer_proof_contexts, read_payments, + read_peer_info, read_pending_payments, read_scorer, write_node_metrics, }; use crate::io::vss_store::VssStoreBuilder; use crate::io::{ - self, PAYMENT_INFO_PERSISTENCE_PRIMARY_NAMESPACE, PAYMENT_INFO_PERSISTENCE_SECONDARY_NAMESPACE, + self, PAYER_PROOF_CONTEXT_PERSISTENCE_PRIMARY_NAMESPACE, + PAYER_PROOF_CONTEXT_PERSISTENCE_SECONDARY_NAMESPACE, + PAYMENT_INFO_PERSISTENCE_PRIMARY_NAMESPACE, PAYMENT_INFO_PERSISTENCE_SECONDARY_NAMESPACE, PENDING_PAYMENT_INFO_PERSISTENCE_PRIMARY_NAMESPACE, PENDING_PAYMENT_INFO_PERSISTENCE_SECONDARY_NAMESPACE, }; @@ -77,8 +79,8 @@ use crate::runtime::{Runtime, RuntimeSpawner}; use crate::tx_broadcaster::TransactionBroadcaster; use crate::types::{ AsyncPersister, ChainMonitor, ChannelManager, DynStore, DynStoreRef, DynStoreWrapper, - GossipSync, Graph, KeysManager, MessageRouter, OnionMessenger, PaymentStore, PeerManager, - PendingPaymentStore, SyncAndAsyncKVStore, + GossipSync, Graph, KeysManager, MessageRouter, OnionMessenger, PayerProofContextStore, + PaymentStore, PeerManager, PendingPaymentStore, SyncAndAsyncKVStore, }; use crate::wallet::persist::KVStoreWalletPersister; use crate::wallet::Wallet; @@ -1260,14 +1262,19 @@ fn build_with_store_internal( let kv_store_ref = Arc::clone(&kv_store); let logger_ref = Arc::clone(&logger); - let (payment_store_res, node_metris_res, pending_payment_store_res) = - runtime.block_on(async move { - tokio::join!( - read_payments(&*kv_store_ref, Arc::clone(&logger_ref)), - read_node_metrics(&*kv_store_ref, Arc::clone(&logger_ref)), - read_pending_payments(&*kv_store_ref, Arc::clone(&logger_ref)) - ) - }); + let ( + payment_store_res, + node_metris_res, + pending_payment_store_res, + payer_proof_context_store_res, + ) = runtime.block_on(async move { + tokio::join!( + read_payments(&*kv_store_ref, Arc::clone(&logger_ref)), + read_node_metrics(&*kv_store_ref, Arc::clone(&logger_ref)), + read_pending_payments(&*kv_store_ref, Arc::clone(&logger_ref)), + read_payer_proof_contexts(&*kv_store_ref, Arc::clone(&logger_ref)) + ) + }); // Initialize the status fields. let node_metrics = match node_metris_res { @@ -1296,6 +1303,20 @@ fn build_with_store_internal( }, }; + let payer_proof_context_store = match payer_proof_context_store_res { + Ok(contexts) => Arc::new(PayerProofContextStore::new( + contexts, + PAYER_PROOF_CONTEXT_PERSISTENCE_PRIMARY_NAMESPACE.to_string(), + PAYER_PROOF_CONTEXT_PERSISTENCE_SECONDARY_NAMESPACE.to_string(), + Arc::clone(&kv_store), + Arc::clone(&logger), + )), + Err(e) => { + log_error!(logger, "Failed to read payer proof contexts from store: {}", e); + return Err(BuildError::ReadFailed); + }, + }; + let (chain_source, chain_tip_opt) = match chain_data_source_config { Some(ChainDataSourceConfig::Esplora { server_url, headers, sync_config }) => { let sync_config = sync_config.unwrap_or(EsploraSyncConfig::default()); @@ -1987,6 +2008,7 @@ fn build_with_store_internal( scorer, peer_store, payment_store, + payer_proof_context_store, lnurl_auth, is_running, node_metrics, diff --git a/src/error.rs b/src/error.rs index d07212b00..1fdef8360 100644 --- a/src/error.rs +++ b/src/error.rs @@ -57,6 +57,10 @@ pub enum Error { WalletOperationFailed, /// A wallet operation timed out. WalletOperationTimeout, + /// Creating a payer proof failed. + PayerProofCreationFailed, + /// A payer proof is unavailable for the requested payment. + PayerProofUnavailable, /// A signing operation for transaction failed. OnchainTxSigningFailed, /// A transaction sync operation failed. @@ -137,6 +141,8 @@ pub enum Error { LnurlAuthTimeout, /// The provided lnurl is invalid. InvalidLnurl, + /// The provided payer proof is invalid. + InvalidPayerProof, } impl fmt::Display for Error { @@ -168,6 +174,10 @@ impl fmt::Display for Error { }, Self::WalletOperationFailed => write!(f, "Failed to conduct wallet operation."), Self::WalletOperationTimeout => write!(f, "A wallet operation timed out."), + Self::PayerProofCreationFailed => write!(f, "Failed to create payer proof."), + Self::PayerProofUnavailable => { + write!(f, "A payer proof is unavailable for the requested payment.") + }, Self::OnchainTxSigningFailed => write!(f, "Failed to sign given transaction."), Self::TxSyncFailed => write!(f, "Failed to sync transactions."), Self::TxSyncTimeout => write!(f, "Syncing transactions timed out."), @@ -222,6 +232,7 @@ impl fmt::Display for Error { Self::LnurlAuthFailed => write!(f, "LNURL-auth authentication failed."), Self::LnurlAuthTimeout => write!(f, "LNURL-auth authentication timed out."), Self::InvalidLnurl => write!(f, "The provided lnurl is invalid."), + Self::InvalidPayerProof => write!(f, "The provided payer proof is invalid."), } } } diff --git a/src/event.rs b/src/event.rs index f06d701bc..e56c93e09 100644 --- a/src/event.rs +++ b/src/event.rs @@ -24,6 +24,7 @@ use lightning::events::{ use lightning::impl_writeable_tlv_based_enum; use lightning::ln::channelmanager::PaymentId; use lightning::ln::types::ChannelId; +use lightning::offers::nonce::Nonce; use lightning::routing::gossip::NodeId; use lightning::sign::EntropySource; use lightning::util::config::{ @@ -49,12 +50,14 @@ use crate::liquidity::LiquiditySource; use crate::logger::{log_debug, log_error, log_info, log_trace, LdkLogger, Logger}; use crate::payment::asynchronous::om_mailbox::OnionMessageMailbox; use crate::payment::asynchronous::static_invoice_store::StaticInvoiceStore; +use crate::payment::payer_proof_store::PayerProofContext; use crate::payment::store::{ PaymentDetails, PaymentDetailsUpdate, PaymentDirection, PaymentKind, PaymentStatus, }; use crate::runtime::Runtime; use crate::types::{ - CustomTlvRecord, DynStore, KeysManager, OnionMessenger, PaymentStore, Sweeper, Wallet, + CustomTlvRecord, DynStore, KeysManager, OnionMessenger, PayerProofContextStore, PaymentStore, + Sweeper, Wallet, }; use crate::{ hex_utils, BumpTransactionEventHandler, ChannelManager, Error, Graph, PeerInfo, PeerStore, @@ -507,6 +510,7 @@ where network_graph: Arc, liquidity_source: Option>>>, payment_store: Arc, + payer_proof_context_store: Arc, peer_store: Arc>, keys_manager: Arc, runtime: Arc, @@ -527,10 +531,11 @@ where channel_manager: Arc, connection_manager: Arc>, output_sweeper: Arc, network_graph: Arc, liquidity_source: Option>>>, - payment_store: Arc, peer_store: Arc>, - keys_manager: Arc, static_invoice_store: Option, - onion_messenger: Arc, om_mailbox: Option>, - runtime: Arc, logger: L, config: Arc, + payment_store: Arc, payer_proof_context_store: Arc, + peer_store: Arc>, keys_manager: Arc, + static_invoice_store: Option, onion_messenger: Arc, + om_mailbox: Option>, runtime: Arc, logger: L, + config: Arc, ) -> Self { Self { event_queue, @@ -542,6 +547,7 @@ where network_graph, liquidity_source, payment_store, + payer_proof_context_store, peer_store, keys_manager, logger, @@ -553,6 +559,31 @@ where } } + fn persist_payer_proof_context( + &self, payment_id: PaymentId, bolt12_invoice: &Option, + payment_nonce: Option, + ) { + let invoice = match bolt12_invoice { + Some(PaidBolt12Invoice::Bolt12Invoice(invoice)) => invoice, + _ => return, + }; + + let nonce = match payment_nonce { + Some(nonce) => nonce, + None => return, + }; + + let context = PayerProofContext { payment_id, invoice: invoice.clone(), nonce }; + if let Err(e) = self.payer_proof_context_store.insert_or_update(context) { + log_error!( + self.logger, + "Failed to persist payer proof context for {}: {}", + payment_id, + e + ); + } + } + pub async fn handle_event(&self, event: LdkEvent) -> Result<(), ReplayEvent> { match event { LdkEvent::FundingGenerationReady { @@ -860,6 +891,7 @@ where offer_id, payer_note, quantity, + bolt12_invoice: None, }; let payment = PaymentDetails::new( @@ -1065,6 +1097,7 @@ where payment_hash, fee_paid_msat, bolt12_invoice, + payment_nonce, .. } => { let payment_id = if let Some(id) = payment_id { @@ -1073,12 +1106,20 @@ where debug_assert!(false, "payment_id should always be set."); return Ok(()); }; + let bolt12_invoice = bolt12_invoice.map(Into::into); + + self.persist_payer_proof_context( + payment_id, + &bolt12_invoice, + payment_nonce, + ); let update = PaymentDetailsUpdate { hash: Some(Some(payment_hash)), preimage: Some(Some(payment_preimage)), fee_paid_msat: Some(fee_paid_msat), status: Some(PaymentStatus::Succeeded), + bolt12_invoice: Some(bolt12_invoice.clone()), ..PaymentDetailsUpdate::new(payment_id) }; @@ -1110,7 +1151,7 @@ where payment_hash, payment_preimage: Some(payment_preimage), fee_paid_msat, - bolt12_invoice: bolt12_invoice.map(Into::into), + bolt12_invoice, }; match self.event_queue.add_event(event).await { @@ -1562,20 +1603,14 @@ where }; }, LdkEvent::DiscardFunding { channel_id, funding_info } => { - if let FundingInfo::Contribution { inputs: _, outputs } = funding_info { + if let FundingInfo::Tx { transaction } = funding_info { log_info!( self.logger, "Reclaiming unused addresses from channel {} funding", channel_id, ); - let tx = bitcoin::Transaction { - version: bitcoin::transaction::Version::TWO, - lock_time: bitcoin::absolute::LockTime::ZERO, - input: vec![], - output: outputs, - }; - if let Err(e) = self.wallet.cancel_tx(&tx) { + if let Err(e) = self.wallet.cancel_tx(&transaction) { log_error!(self.logger, "Failed reclaiming unused addresses: {}", e); return Err(ReplayEvent()); } diff --git a/src/ffi/types.rs b/src/ffi/types.rs index 5a1420882..70796bd5a 100644 --- a/src/ffi/types.rs +++ b/src/ffi/types.rs @@ -31,6 +31,7 @@ pub use lightning::ln::types::ChannelId; use lightning::offers::invoice::Bolt12Invoice as LdkBolt12Invoice; pub use lightning::offers::offer::OfferId; use lightning::offers::offer::{Amount as LdkAmount, Offer as LdkOffer}; +use lightning::offers::payer_proof::PayerProof as LdkPayerProof; use lightning::offers::refund::Refund as LdkRefund; use lightning::offers::static_invoice::StaticInvoice as LdkStaticInvoice; use lightning::onion_message::dns_resolution::HumanReadableName as LdkHumanReadableName; @@ -875,6 +876,92 @@ impl Readable for PaidBolt12Invoice { } } +/// A cryptographic proof that a BOLT12 invoice was paid by this node. +#[derive(Debug, Clone, uniffi::Object)] +#[uniffi::export(Debug, Display)] +pub struct PayerProof { + pub(crate) inner: LdkPayerProof, +} + +#[uniffi::export] +impl PayerProof { + #[uniffi::constructor] + pub fn from_bytes(proof_bytes: Vec) -> Result { + let inner = LdkPayerProof::try_from(proof_bytes).map_err(|_| Error::InvalidPayerProof)?; + Ok(Self { inner }) + } + + /// The payment preimage proving the payment completed. + pub fn preimage(&self) -> PaymentPreimage { + self.inner.preimage() + } + + /// The payment hash committed to by the invoice and proven by the preimage. + pub fn payment_hash(&self) -> PaymentHash { + self.inner.payment_hash() + } + + /// The public key of the payer that authorized the payment. + pub fn payer_id(&self) -> PublicKey { + self.inner.payer_id() + } + + /// The issuer signing public key committed to by the invoice. + pub fn issuer_signing_pubkey(&self) -> PublicKey { + self.inner.issuer_signing_pubkey() + } + + /// The invoice signature bytes. + pub fn invoice_signature(&self) -> Vec { + self.inner.invoice_signature().as_ref().to_vec() + } + + /// The payer signature bytes. + pub fn payer_signature(&self) -> Vec { + self.inner.payer_signature().as_ref().to_vec() + } + + /// The optional note attached to the proof. + pub fn payer_note(&self) -> Option { + self.inner.payer_note().map(|value| value.to_string()) + } + + /// The Merkle root committed to by the proof. + pub fn merkle_root(&self) -> Vec { + self.inner.merkle_root().to_byte_array().to_vec() + } + + /// The raw TLV bytes of the proof. + pub fn bytes(&self) -> Vec { + self.inner.bytes().to_vec() + } + + /// The bech32-encoded string form of the proof. + pub fn as_string(&self) -> String { + self.inner.to_string() + } +} + +impl From for PayerProof { + fn from(inner: LdkPayerProof) -> Self { + Self { inner } + } +} + +impl Deref for PayerProof { + type Target = LdkPayerProof; + + fn deref(&self) -> &Self::Target { + &self.inner + } +} + +impl std::fmt::Display for PayerProof { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self.inner) + } +} + uniffi::custom_type!(OfferId, String, { remote, try_lift: |val| { diff --git a/src/io/mod.rs b/src/io/mod.rs index e080d39f7..d5966d61f 100644 --- a/src/io/mod.rs +++ b/src/io/mod.rs @@ -82,3 +82,7 @@ pub(crate) const STATIC_INVOICE_STORE_PRIMARY_NAMESPACE: &str = "static_invoices /// The pending payment information will be persisted under this prefix. pub(crate) const PENDING_PAYMENT_INFO_PERSISTENCE_PRIMARY_NAMESPACE: &str = "pending_payments"; pub(crate) const PENDING_PAYMENT_INFO_PERSISTENCE_SECONDARY_NAMESPACE: &str = ""; + +/// The payer proof context will be persisted under this prefix. +pub(crate) const PAYER_PROOF_CONTEXT_PERSISTENCE_PRIMARY_NAMESPACE: &str = "payer_proof_contexts"; +pub(crate) const PAYER_PROOF_CONTEXT_PERSISTENCE_SECONDARY_NAMESPACE: &str = ""; diff --git a/src/io/utils.rs b/src/io/utils.rs index eef71ec0b..2915f1d57 100644 --- a/src/io/utils.rs +++ b/src/io/utils.rs @@ -42,8 +42,11 @@ use crate::config::WALLET_KEYS_SEED_LEN; use crate::fee_estimator::OnchainFeeEstimator; use crate::io::{ NODE_METRICS_KEY, NODE_METRICS_PRIMARY_NAMESPACE, NODE_METRICS_SECONDARY_NAMESPACE, + PAYER_PROOF_CONTEXT_PERSISTENCE_PRIMARY_NAMESPACE, + PAYER_PROOF_CONTEXT_PERSISTENCE_SECONDARY_NAMESPACE, }; use crate::logger::{log_error, LdkLogger, Logger}; +use crate::payment::payer_proof_store::PayerProofContext; use crate::payment::PendingPaymentDetails; use crate::peer_store::PeerStore; use crate::types::{Broadcaster, DynStore, KeysManager, Sweeper}; @@ -298,6 +301,79 @@ where Ok(res) } +/// Read previously persisted payer proof contexts from the store. +pub(crate) async fn read_payer_proof_contexts( + kv_store: &DynStore, logger: L, +) -> Result, std::io::Error> +where + L::Target: LdkLogger, +{ + let mut res = Vec::new(); + + let mut stored_keys = KVStore::list( + &*kv_store, + PAYER_PROOF_CONTEXT_PERSISTENCE_PRIMARY_NAMESPACE, + PAYER_PROOF_CONTEXT_PERSISTENCE_SECONDARY_NAMESPACE, + ) + .await?; + + const BATCH_SIZE: usize = 50; + + let mut set = tokio::task::JoinSet::new(); + + while set.len() < BATCH_SIZE && !stored_keys.is_empty() { + if let Some(next_key) = stored_keys.pop() { + let fut = KVStore::read( + &*kv_store, + PAYER_PROOF_CONTEXT_PERSISTENCE_PRIMARY_NAMESPACE, + PAYER_PROOF_CONTEXT_PERSISTENCE_SECONDARY_NAMESPACE, + &next_key, + ); + set.spawn(fut); + debug_assert!(set.len() <= BATCH_SIZE); + } + } + + while let Some(read_res) = set.join_next().await { + let reader = read_res + .map_err(|e| { + log_error!(logger, "Failed to read PayerProofContext: {}", e); + set.abort_all(); + e + })? + .map_err(|e| { + log_error!(logger, "Failed to read PayerProofContext: {}", e); + set.abort_all(); + e + })?; + + if let Some(next_key) = stored_keys.pop() { + let fut = KVStore::read( + &*kv_store, + PAYER_PROOF_CONTEXT_PERSISTENCE_PRIMARY_NAMESPACE, + PAYER_PROOF_CONTEXT_PERSISTENCE_SECONDARY_NAMESPACE, + &next_key, + ); + set.spawn(fut); + debug_assert!(set.len() <= BATCH_SIZE); + } + + let context = PayerProofContext::read(&mut &*reader).map_err(|e| { + log_error!(logger, "Failed to deserialize PayerProofContext: {}", e); + std::io::Error::new( + std::io::ErrorKind::InvalidData, + "Failed to deserialize PayerProofContext", + ) + })?; + res.push(context); + } + + debug_assert!(set.is_empty()); + debug_assert!(stored_keys.is_empty()); + + Ok(res) +} + /// Read `OutputSweeper` state from the store. pub(crate) async fn read_output_sweeper( broadcaster: Arc, fee_estimator: Arc, diff --git a/src/lib.rs b/src/lib.rs index 2e02e996c..237f77b23 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -174,8 +174,8 @@ use runtime::Runtime; pub use tokio; use types::{ Broadcaster, BumpTransactionEventHandler, ChainMonitor, ChannelManager, DynStore, Graph, - HRNResolver, KeysManager, OnionMessenger, PaymentStore, PeerManager, Router, Scorer, Sweeper, - Wallet, + HRNResolver, KeysManager, OnionMessenger, PayerProofContextStore, PaymentStore, PeerManager, + Router, Scorer, Sweeper, Wallet, }; pub use types::{ChannelDetails, CustomTlvRecord, PeerDetails, SyncAndAsyncKVStore, UserChannelId}; pub use vss_client; @@ -233,6 +233,7 @@ pub struct Node { scorer: Arc>, peer_store: Arc>>, payment_store: Arc, + payer_proof_context_store: Arc, lnurl_auth: Arc, is_running: Arc>, node_metrics: Arc>, @@ -585,6 +586,7 @@ impl Node { Arc::clone(&self.network_graph), self.liquidity_source.clone(), Arc::clone(&self.payment_store), + Arc::clone(&self.payer_proof_context_store), Arc::clone(&self.peer_store), Arc::clone(&self.keys_manager), static_invoice_store, @@ -904,6 +906,7 @@ impl Node { Arc::clone(&self.channel_manager), Arc::clone(&self.keys_manager), Arc::clone(&self.payment_store), + Arc::clone(&self.payer_proof_context_store), Arc::clone(&self.config), Arc::clone(&self.is_running), Arc::clone(&self.logger), @@ -920,6 +923,7 @@ impl Node { Arc::clone(&self.channel_manager), Arc::clone(&self.keys_manager), Arc::clone(&self.payment_store), + Arc::clone(&self.payer_proof_context_store), Arc::clone(&self.config), Arc::clone(&self.is_running), Arc::clone(&self.logger), @@ -1776,6 +1780,7 @@ impl Node { /// Remove the payment with the given id from the store. pub fn remove_payment(&self, payment_id: &PaymentId) -> Result<(), Error> { + self.payer_proof_context_store.remove(&payment_id)?; self.payment_store.remove(&payment_id) } diff --git a/src/payment/bolt12.rs b/src/payment/bolt12.rs index 980e20696..074d74aed 100644 --- a/src/payment/bolt12.rs +++ b/src/payment/bolt12.rs @@ -14,12 +14,15 @@ use std::sync::{Arc, RwLock}; use std::time::{Duration, SystemTime, UNIX_EPOCH}; use lightning::blinded_path::message::BlindedMessagePath; +use lightning::events::PaidBolt12Invoice as LdkPaidBolt12Invoice; use lightning::ln::channelmanager::{OptionalOfferPaymentParams, PaymentId}; use lightning::ln::outbound_payment::Retry; use lightning::offers::offer::{Amount, Offer as LdkOffer, OfferFromHrn, Quantity}; use lightning::offers::parse::Bolt12SemanticError; +#[cfg(not(feature = "uniffi"))] +use lightning::offers::payer_proof::PayerProof as LdkPayerProof; use lightning::routing::router::RouteParametersConfig; -use lightning::sign::EntropySource; +use lightning::sign::{EntropySource, NodeSigner}; #[cfg(feature = "uniffi")] use lightning::util::ser::{Readable, Writeable}; use lightning_types::string::UntrustedString; @@ -28,8 +31,9 @@ use crate::config::{AsyncPaymentsRole, Config, LDK_PAYMENT_RETRY_TIMEOUT}; use crate::error::Error; use crate::ffi::{maybe_deref, maybe_wrap}; use crate::logger::{log_error, log_info, LdkLogger, Logger}; +use crate::payment::payer_proof_store::PayerProofContext; use crate::payment::store::{PaymentDetails, PaymentDirection, PaymentKind, PaymentStatus}; -use crate::types::{ChannelManager, KeysManager, PaymentStore}; +use crate::types::{ChannelManager, KeysManager, PayerProofContextStore, PaymentStore}; #[cfg(not(feature = "uniffi"))] type Bolt12Invoice = lightning::offers::invoice::Bolt12Invoice; @@ -51,6 +55,11 @@ type HumanReadableName = lightning::onion_message::dns_resolution::HumanReadable #[cfg(feature = "uniffi")] type HumanReadableName = Arc; +#[cfg(not(feature = "uniffi"))] +type PayerProof = LdkPayerProof; +#[cfg(feature = "uniffi")] +type PayerProof = Arc; + /// A payment handler allowing to create and pay [BOLT 12] offers and refunds. /// /// Should be retrieved by calling [`Node::bolt12_payment`]. @@ -62,22 +71,43 @@ pub struct Bolt12Payment { channel_manager: Arc, keys_manager: Arc, payment_store: Arc, + payer_proof_context_store: Arc, config: Arc, is_running: Arc>, logger: Arc, async_payments_role: Option, } +/// Options controlling which optional fields are disclosed in a BOLT12 payer proof. +#[derive(Clone, Debug, PartialEq, Eq, Default)] +#[cfg_attr(feature = "uniffi", derive(uniffi::Record))] +pub struct PayerProofOptions { + /// An optional note attached to the payer proof itself. + pub note: Option, + /// Whether to include the offer description in the proof. + pub include_offer_description: bool, + /// Whether to include the offer issuer in the proof. + pub include_offer_issuer: bool, + /// Whether to include the invoice amount in the proof. + pub include_invoice_amount: bool, + /// Whether to include the invoice creation timestamp in the proof. + pub include_invoice_created_at: bool, + /// Additional TLV types to include in the selective disclosure set. + pub extra_tlv_types: Vec, +} + impl Bolt12Payment { pub(crate) fn new( channel_manager: Arc, keys_manager: Arc, - payment_store: Arc, config: Arc, is_running: Arc>, - logger: Arc, async_payments_role: Option, + payment_store: Arc, payer_proof_context_store: Arc, + config: Arc, is_running: Arc>, logger: Arc, + async_payments_role: Option, ) -> Self { Self { channel_manager, keys_manager, payment_store, + payer_proof_context_store, config, is_running, logger, @@ -120,6 +150,8 @@ impl Bolt12Payment { payer_note: payer_note.clone(), retry_strategy, route_params_config: route_parameters, + contact_secrets: None, + payer_offer: None, }; let res = if let Some(hrn) = hrn { let hrn = maybe_deref(&hrn); @@ -154,6 +186,7 @@ impl Bolt12Payment { offer_id: offer.id(), payer_note: payer_note.map(UntrustedString), quantity, + bolt12_invoice: None, }; let payment = PaymentDetails::new( payment_id, @@ -179,6 +212,7 @@ impl Bolt12Payment { offer_id: offer.id(), payer_note: payer_note.map(UntrustedString), quantity, + bolt12_invoice: None, }; let payment = PaymentDetails::new( payment_id, @@ -245,6 +279,21 @@ impl Bolt12Payment { .blinded_paths_for_async_recipient(recipient_id, None) .or(Err(Error::InvalidBlindedPaths)) } + + fn payer_proof_context( + &self, payment_id: &PaymentId, + ) -> Result<(PaymentDetails, PayerProofContext), Error> { + let payment = self.payment_store.get(payment_id).ok_or(Error::PayerProofUnavailable)?; + if payment.direction != PaymentDirection::Outbound + || payment.status != PaymentStatus::Succeeded + { + return Err(Error::PayerProofUnavailable); + } + + let context = + self.payer_proof_context_store.get(payment_id).ok_or(Error::PayerProofUnavailable)?; + Ok((payment, context)) + } } #[cfg_attr(feature = "uniffi", uniffi::export)] @@ -289,6 +338,8 @@ impl Bolt12Payment { payer_note: payer_note.clone(), retry_strategy, route_params_config: route_parameters, + contact_secrets: None, + payer_offer: None, }; let res = if let Some(quantity) = quantity { self.channel_manager @@ -314,6 +365,7 @@ impl Bolt12Payment { offer_id: offer.id(), payer_note: payer_note.map(UntrustedString), quantity, + bolt12_invoice: None, }; let payment = PaymentDetails::new( payment_id, @@ -339,6 +391,7 @@ impl Bolt12Payment { offer_id: offer.id(), payer_note: payer_note.map(UntrustedString), quantity, + bolt12_invoice: None, }; let payment = PaymentDetails::new( payment_id, @@ -383,6 +436,73 @@ impl Bolt12Payment { Ok(payment_id) } + /// Create a payer proof for a previously succeeded outbound BOLT12 payment. + /// + /// This requires a standard BOLT12 invoice response that carried payer proof context. + /// Payments that completed via static invoices do not support payer proofs. + pub fn create_payer_proof( + &self, payment_id: &PaymentId, options: Option, + ) -> Result { + let (payment, context) = self.payer_proof_context(payment_id)?; + let preimage = match payment.kind { + PaymentKind::Bolt12Offer { preimage: Some(preimage), .. } + | PaymentKind::Bolt12Refund { preimage: Some(preimage), .. } => preimage, + _ => return Err(Error::PayerProofUnavailable), + }; + + let options = options.unwrap_or_default(); + let mut builder = context.invoice.payer_proof_builder(preimage).map_err(|e| { + log_error!( + self.logger, + "Failed to initialize payer proof builder for {}: {:?}", + payment_id, + e + ); + Error::PayerProofCreationFailed + })?; + + for tlv_type in options.extra_tlv_types { + builder = builder.include_type(tlv_type).map_err(|e| { + log_error!( + self.logger, + "Failed to include TLV {} in payer proof for {}: {:?}", + tlv_type, + payment_id, + e + ); + Error::PayerProofCreationFailed + })?; + } + + if options.include_offer_description { + builder = builder.include_offer_description(); + } + if options.include_offer_issuer { + builder = builder.include_offer_issuer(); + } + if options.include_invoice_amount { + builder = builder.include_invoice_amount(); + } + if options.include_invoice_created_at { + builder = builder.include_invoice_created_at(); + } + + let expanded_key = self.keys_manager.get_expanded_key(); + let proof = builder + .build_with_derived_key( + &expanded_key, + context.nonce, + *payment_id, + options.note.as_deref(), + ) + .map_err(|e| { + log_error!(self.logger, "Failed to build payer proof for {}: {:?}", payment_id, e); + Error::PayerProofCreationFailed + })?; + + Ok(maybe_wrap(proof)) + } + /// Returns a payable offer that can be used to request and receive a payment of the amount /// given. pub fn receive( @@ -444,6 +564,7 @@ impl Bolt12Payment { secret: None, payer_note: refund.payer_note().map(|note| UntrustedString(note.0.to_string())), quantity: refund.quantity(), + bolt12_invoice: Some(LdkPaidBolt12Invoice::Bolt12Invoice(invoice.clone()).into()), }; let payment = PaymentDetails::new( @@ -514,6 +635,7 @@ impl Bolt12Payment { secret: None, payer_note: payer_note.map(|note| UntrustedString(note)), quantity, + bolt12_invoice: None, }; let payment = PaymentDetails::new( payment_id, diff --git a/src/payment/mod.rs b/src/payment/mod.rs index 42b5aff3b..86a3f1154 100644 --- a/src/payment/mod.rs +++ b/src/payment/mod.rs @@ -11,13 +11,14 @@ pub(crate) mod asynchronous; mod bolt11; mod bolt12; mod onchain; +pub(crate) mod payer_proof_store; pub(crate) mod pending_payment_store; mod spontaneous; pub(crate) mod store; mod unified; pub use bolt11::Bolt11Payment; -pub use bolt12::Bolt12Payment; +pub use bolt12::{Bolt12Payment, PayerProofOptions}; pub use onchain::OnchainPayment; pub use pending_payment_store::PendingPaymentDetails; pub use spontaneous::SpontaneousPayment; diff --git a/src/payment/payer_proof_store.rs b/src/payment/payer_proof_store.rs new file mode 100644 index 000000000..2ab36633b --- /dev/null +++ b/src/payment/payer_proof_store.rs @@ -0,0 +1,87 @@ +// This file is Copyright its original authors, visible in version control history. +// +// This file is licensed under the Apache License, Version 2.0 or the MIT license , at your option. You may not use this file except in +// accordance with one or both of these licenses. + +use lightning::impl_writeable_tlv_based; +use lightning::ln::channelmanager::PaymentId; +use lightning::offers::invoice::Bolt12Invoice; +use lightning::offers::nonce::Nonce; + +use crate::data_store::{StorableObject, StorableObjectUpdate}; + +#[derive(Clone, Debug, PartialEq, Eq)] +pub(crate) struct PayerProofContext { + pub payment_id: PaymentId, + pub invoice: Bolt12Invoice, + pub nonce: Nonce, +} + +impl_writeable_tlv_based!(PayerProofContext, { + (0, payment_id, required), + (2, invoice, required), + (4, nonce, required), +}); + +#[derive(Clone, Debug, PartialEq, Eq)] +pub(crate) struct PayerProofContextUpdate { + pub payment_id: PaymentId, + pub invoice: Option, + pub nonce: Option, +} + +impl From<&PayerProofContext> for PayerProofContextUpdate { + fn from(value: &PayerProofContext) -> Self { + Self { + payment_id: value.payment_id, + invoice: Some(value.invoice.clone()), + nonce: Some(value.nonce), + } + } +} + +impl StorableObject for PayerProofContext { + type Id = PaymentId; + type Update = PayerProofContextUpdate; + + fn id(&self) -> Self::Id { + self.payment_id + } + + fn update(&mut self, update: Self::Update) -> bool { + debug_assert_eq!( + self.payment_id, update.payment_id, + "We should only ever override payer proof context for the same payment id" + ); + + let mut updated = false; + + if let Some(invoice) = update.invoice { + if self.invoice != invoice { + self.invoice = invoice; + updated = true; + } + } + + if let Some(nonce) = update.nonce { + if self.nonce != nonce { + self.nonce = nonce; + updated = true; + } + } + + updated + } + + fn to_update(&self) -> Self::Update { + self.into() + } +} + +impl StorableObjectUpdate for PayerProofContextUpdate { + fn id(&self) -> ::Id { + self.payment_id + } +} diff --git a/src/payment/store.rs b/src/payment/store.rs index 0e2de9815..a9585e9c3 100644 --- a/src/payment/store.rs +++ b/src/payment/store.rs @@ -8,6 +8,8 @@ use std::time::{Duration, SystemTime, UNIX_EPOCH}; use bitcoin::{BlockHash, Txid}; +#[cfg(not(feature = "uniffi"))] +use lightning::events::PaidBolt12Invoice; use lightning::ln::channelmanager::PaymentId; use lightning::ln::msgs::DecodeError; use lightning::offers::offer::OfferId; @@ -20,6 +22,8 @@ use lightning_types::payment::{PaymentHash, PaymentPreimage, PaymentSecret}; use lightning_types::string::UntrustedString; use crate::data_store::{StorableObject, StorableObjectId, StorableObjectUpdate}; +#[cfg(feature = "uniffi")] +use crate::ffi::PaidBolt12Invoice; use crate::hex_utils; /// Represents a payment. @@ -267,6 +271,18 @@ impl StorableObject for PaymentDetails { update_if_necessary!(self.fee_paid_msat, fee_paid_msat_opt); } + if let Some(ref bolt12_invoice_opt) = update.bolt12_invoice { + match self.kind { + PaymentKind::Bolt12Offer { ref mut bolt12_invoice, .. } => { + update_if_necessary!(*bolt12_invoice, bolt12_invoice_opt.clone()); + }, + PaymentKind::Bolt12Refund { ref mut bolt12_invoice, .. } => { + update_if_necessary!(*bolt12_invoice, bolt12_invoice_opt.clone()); + }, + _ => {}, + } + } + if let Some(skimmed_fee_msat) = update.counterparty_skimmed_fee_msat { match self.kind { PaymentKind::Bolt11Jit { ref mut counterparty_skimmed_fee_msat, .. } => { @@ -428,6 +444,8 @@ pub enum PaymentKind { /// /// This will always be `None` for payments serialized with version `v0.3.0`. quantity: Option, + /// The BOLT12 invoice associated with the payment, once available. + bolt12_invoice: Option, }, /// A [BOLT 12] 'refund' payment, i.e., a payment for a [`Refund`]. /// @@ -448,6 +466,8 @@ pub enum PaymentKind { /// /// This will always be `None` for payments serialized with version `v0.3.0`. quantity: Option, + /// The BOLT12 invoice associated with the payment, once available. + bolt12_invoice: Option, }, /// A spontaneous ("keysend") payment. Spontaneous { @@ -482,6 +502,7 @@ impl_writeable_tlv_based_enum!(PaymentKind, (3, quantity, option), (4, secret, option), (6, offer_id, required), + (8, bolt12_invoice, option), }, (8, Spontaneous) => { (0, hash, required), @@ -493,6 +514,7 @@ impl_writeable_tlv_based_enum!(PaymentKind, (2, preimage, option), (3, quantity, option), (4, secret, option), + (6, bolt12_invoice, option), } ); @@ -555,6 +577,7 @@ pub(crate) struct PaymentDetailsUpdate { pub direction: Option, pub status: Option, pub confirmation_status: Option, + pub bolt12_invoice: Option>, pub txid: Option, } @@ -571,6 +594,7 @@ impl PaymentDetailsUpdate { direction: None, status: None, confirmation_status: None, + bolt12_invoice: None, txid: None, } } @@ -578,13 +602,21 @@ impl PaymentDetailsUpdate { impl From<&PaymentDetails> for PaymentDetailsUpdate { fn from(value: &PaymentDetails) -> Self { - let (hash, preimage, secret) = match value.kind { - PaymentKind::Bolt11 { hash, preimage, secret, .. } => (Some(hash), preimage, secret), - PaymentKind::Bolt11Jit { hash, preimage, secret, .. } => (Some(hash), preimage, secret), - PaymentKind::Bolt12Offer { hash, preimage, secret, .. } => (hash, preimage, secret), - PaymentKind::Bolt12Refund { hash, preimage, secret, .. } => (hash, preimage, secret), - PaymentKind::Spontaneous { hash, preimage, .. } => (Some(hash), preimage, None), - _ => (None, None, None), + let (hash, preimage, secret, bolt12_invoice) = match &value.kind { + PaymentKind::Bolt11 { hash, preimage, secret, .. } => { + (Some(*hash), *preimage, *secret, None) + }, + PaymentKind::Bolt11Jit { hash, preimage, secret, .. } => { + (Some(*hash), *preimage, *secret, None) + }, + PaymentKind::Bolt12Offer { hash, preimage, secret, bolt12_invoice, .. } => { + (*hash, *preimage, *secret, Some(bolt12_invoice.clone())) + }, + PaymentKind::Bolt12Refund { hash, preimage, secret, bolt12_invoice, .. } => { + (*hash, *preimage, *secret, Some(bolt12_invoice.clone())) + }, + PaymentKind::Spontaneous { hash, preimage, .. } => (Some(*hash), *preimage, None, None), + _ => (None, None, None, None), }; let (confirmation_status, txid) = match &value.kind { @@ -592,9 +624,9 @@ impl From<&PaymentDetails> for PaymentDetailsUpdate { _ => (None, None), }; - let counterparty_skimmed_fee_msat = match value.kind { + let counterparty_skimmed_fee_msat = match &value.kind { PaymentKind::Bolt11Jit { counterparty_skimmed_fee_msat, .. } => { - Some(counterparty_skimmed_fee_msat) + Some(*counterparty_skimmed_fee_msat) }, _ => None, }; @@ -610,6 +642,7 @@ impl From<&PaymentDetails> for PaymentDetailsUpdate { direction: Some(value.direction), status: Some(value.status), confirmation_status, + bolt12_invoice, txid, } } diff --git a/src/types.rs b/src/types.rs index dae315ae0..04650cfc6 100644 --- a/src/types.rs +++ b/src/types.rs @@ -37,6 +37,7 @@ use crate::data_store::DataStore; use crate::fee_estimator::OnchainFeeEstimator; use crate::logger::Logger; use crate::message_handler::NodeCustomMessageHandler; +use crate::payment::payer_proof_store::PayerProofContext; use crate::payment::{PaymentDetails, PendingPaymentDetails}; use crate::runtime::RuntimeSpawner; @@ -349,6 +350,7 @@ pub(crate) type BumpTransactionEventHandler = >; pub(crate) type PaymentStore = DataStore>; +pub(crate) type PayerProofContextStore = DataStore>; /// A local, potentially user-provided, identifier of a channel. /// diff --git a/tests/integration_tests_rust.rs b/tests/integration_tests_rust.rs index 413b2d44a..0e20020ff 100644 --- a/tests/integration_tests_rust.rs +++ b/tests/integration_tests_rust.rs @@ -1115,12 +1115,14 @@ async fn simple_bolt12_send_receive() { offer_id, quantity: ref qty, payer_note: ref note, + bolt12_invoice: ref invoice, } => { assert!(hash.is_some()); assert!(preimage.is_some()); assert_eq!(offer_id, offer.id()); assert_eq!(&expected_quantity, qty); assert_eq!(expected_payer_note.unwrap(), note.clone().unwrap().0); + assert!(invoice.is_some()); // TODO: We should eventually set and assert the secret sender-side, too, but the BOLT12 // API currently doesn't allow to do that. }, @@ -1182,12 +1184,14 @@ async fn simple_bolt12_send_receive() { offer_id, quantity: ref qty, payer_note: ref note, + bolt12_invoice: ref invoice, } => { assert!(hash.is_some()); assert!(preimage.is_some()); assert_eq!(offer_id, offer.id()); assert_eq!(&expected_quantity, qty); assert_eq!(expected_payer_note.unwrap(), note.clone().unwrap().0); + assert!(invoice.is_some()); // TODO: We should eventually set and assert the secret sender-side, too, but the BOLT12 // API currently doesn't allow to do that. hash.unwrap() @@ -1255,11 +1259,13 @@ async fn simple_bolt12_send_receive() { secret: _, quantity: ref qty, payer_note: ref note, + bolt12_invoice: ref invoice, } => { assert!(hash.is_some()); assert!(preimage.is_some()); assert_eq!(&expected_quantity, qty); - assert_eq!(expected_payer_note.unwrap(), note.clone().unwrap().0) + assert_eq!(expected_payer_note.unwrap(), note.clone().unwrap().0); + assert!(invoice.is_some()); // TODO: We should eventually set and assert the secret sender-side, too, but the BOLT12 // API currently doesn't allow to do that. },