Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 24 additions & 24 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]}
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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" }
3 changes: 3 additions & 0 deletions bindings/ldk_node.udl
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ enum NodeError {
"FeerateEstimationUpdateTimeout",
"WalletOperationFailed",
"WalletOperationTimeout",
"PayerProofCreationFailed",
"PayerProofUnavailable",
"OnchainTxSigningFailed",
"TxSyncFailed",
"TxSyncTimeout",
Expand Down Expand Up @@ -225,6 +227,7 @@ enum NodeError {
"LnurlAuthFailed",
"LnurlAuthTimeout",
"InvalidLnurl",
"InvalidPayerProof",
};

typedef dictionary NodeStatus;
Expand Down
48 changes: 35 additions & 13 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand All @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -1987,6 +2008,7 @@ fn build_with_store_internal(
scorer,
peer_store,
payment_store,
payer_proof_context_store,
lnurl_auth,
is_running,
node_metrics,
Expand Down
11 changes: 11 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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."),
Expand Down Expand Up @@ -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."),
}
}
}
Expand Down
63 changes: 49 additions & 14 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand All @@ -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,
Expand Down Expand Up @@ -507,6 +510,7 @@ where
network_graph: Arc<Graph>,
liquidity_source: Option<Arc<LiquiditySource<Arc<Logger>>>>,
payment_store: Arc<PaymentStore>,
payer_proof_context_store: Arc<PayerProofContextStore>,
peer_store: Arc<PeerStore<L>>,
keys_manager: Arc<KeysManager>,
runtime: Arc<Runtime>,
Expand All @@ -527,10 +531,11 @@ where
channel_manager: Arc<ChannelManager>, connection_manager: Arc<ConnectionManager<L>>,
output_sweeper: Arc<Sweeper>, network_graph: Arc<Graph>,
liquidity_source: Option<Arc<LiquiditySource<Arc<Logger>>>>,
payment_store: Arc<PaymentStore>, peer_store: Arc<PeerStore<L>>,
keys_manager: Arc<KeysManager>, static_invoice_store: Option<StaticInvoiceStore>,
onion_messenger: Arc<OnionMessenger>, om_mailbox: Option<Arc<OnionMessageMailbox>>,
runtime: Arc<Runtime>, logger: L, config: Arc<Config>,
payment_store: Arc<PaymentStore>, payer_proof_context_store: Arc<PayerProofContextStore>,
peer_store: Arc<PeerStore<L>>, keys_manager: Arc<KeysManager>,
static_invoice_store: Option<StaticInvoiceStore>, onion_messenger: Arc<OnionMessenger>,
om_mailbox: Option<Arc<OnionMessageMailbox>>, runtime: Arc<Runtime>, logger: L,
config: Arc<Config>,
) -> Self {
Self {
event_queue,
Expand All @@ -542,6 +547,7 @@ where
network_graph,
liquidity_source,
payment_store,
payer_proof_context_store,
peer_store,
keys_manager,
logger,
Expand All @@ -553,6 +559,31 @@ where
}
}

fn persist_payer_proof_context(
&self, payment_id: PaymentId, bolt12_invoice: &Option<PaidBolt12Invoice>,
payment_nonce: Option<Nonce>,
) {
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 {
Expand Down Expand Up @@ -860,6 +891,7 @@ where
offer_id,
payer_note,
quantity,
bolt12_invoice: None,
};

let payment = PaymentDetails::new(
Expand Down Expand Up @@ -1065,6 +1097,7 @@ where
payment_hash,
fee_paid_msat,
bolt12_invoice,
payment_nonce,
..
} => {
let payment_id = if let Some(id) = payment_id {
Expand All @@ -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)
};

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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());
}
Expand Down
Loading
Loading