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 = "98393b3de3d8aec897e9ab783cb2418da504e204", features = ["std"] }
lightning-types = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "98393b3de3d8aec897e9ab783cb2418da504e204" }
lightning-invoice = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "98393b3de3d8aec897e9ab783cb2418da504e204", features = ["std"] }
lightning-net-tokio = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "98393b3de3d8aec897e9ab783cb2418da504e204" }
lightning-persister = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "98393b3de3d8aec897e9ab783cb2418da504e204", features = ["tokio"] }
lightning-background-processor = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "98393b3de3d8aec897e9ab783cb2418da504e204" }
lightning-rapid-gossip-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "98393b3de3d8aec897e9ab783cb2418da504e204" }
lightning-block-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "98393b3de3d8aec897e9ab783cb2418da504e204", features = ["rest-client", "rpc-client", "tokio"] }
lightning-transaction-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "98393b3de3d8aec897e9ab783cb2418da504e204", features = ["esplora-async-https", "time", "electrum-rustls-ring"] }
lightning-liquidity = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "98393b3de3d8aec897e9ab783cb2418da504e204", features = ["std"] }
lightning-macros = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "98393b3de3d8aec897e9ab783cb2418da504e204" }
lightning = { git = "https://github.com/tnull/rust-lightning", rev = "98a9e9d56dd482ad04552dbf3a7d57e91f94aad3", features = ["std"] }
lightning-types = { git = "https://github.com/tnull/rust-lightning", rev = "98a9e9d56dd482ad04552dbf3a7d57e91f94aad3" }
lightning-invoice = { git = "https://github.com/tnull/rust-lightning", rev = "98a9e9d56dd482ad04552dbf3a7d57e91f94aad3", features = ["std"] }
lightning-net-tokio = { git = "https://github.com/tnull/rust-lightning", rev = "98a9e9d56dd482ad04552dbf3a7d57e91f94aad3" }
lightning-persister = { git = "https://github.com/tnull/rust-lightning", rev = "98a9e9d56dd482ad04552dbf3a7d57e91f94aad3", features = ["tokio"] }
lightning-background-processor = { git = "https://github.com/tnull/rust-lightning", rev = "98a9e9d56dd482ad04552dbf3a7d57e91f94aad3" }
lightning-rapid-gossip-sync = { git = "https://github.com/tnull/rust-lightning", rev = "98a9e9d56dd482ad04552dbf3a7d57e91f94aad3" }
lightning-block-sync = { git = "https://github.com/tnull/rust-lightning", rev = "98a9e9d56dd482ad04552dbf3a7d57e91f94aad3", features = ["rest-client", "rpc-client", "tokio"] }
lightning-transaction-sync = { git = "https://github.com/tnull/rust-lightning", rev = "98a9e9d56dd482ad04552dbf3a7d57e91f94aad3", features = ["esplora-async-https", "time", "electrum-rustls-ring"] }
lightning-liquidity = { git = "https://github.com/tnull/rust-lightning", rev = "98a9e9d56dd482ad04552dbf3a7d57e91f94aad3", features = ["std"] }
lightning-macros = { git = "https://github.com/tnull/rust-lightning", rev = "98a9e9d56dd482ad04552dbf3a7d57e91f94aad3" }

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/jkczyz/bitcoin-paymen
winapi = { version = "0.3", features = ["winbase"] }

[dev-dependencies]
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "98393b3de3d8aec897e9ab783cb2418da504e204", features = ["std", "_test_utils"] }
lightning = { git = "https://github.com/tnull/rust-lightning", rev = "98a9e9d56dd482ad04552dbf3a7d57e91f94aad3", 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 @@ -171,15 +171,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/tnull/rust-lightning", rev = "98a9e9d56dd482ad04552dbf3a7d57e91f94aad3" }
lightning-types = { git = "https://github.com/tnull/rust-lightning", rev = "98a9e9d56dd482ad04552dbf3a7d57e91f94aad3" }
lightning-invoice = { git = "https://github.com/tnull/rust-lightning", rev = "98a9e9d56dd482ad04552dbf3a7d57e91f94aad3" }
lightning-net-tokio = { git = "https://github.com/tnull/rust-lightning", rev = "98a9e9d56dd482ad04552dbf3a7d57e91f94aad3" }
lightning-persister = { git = "https://github.com/tnull/rust-lightning", rev = "98a9e9d56dd482ad04552dbf3a7d57e91f94aad3" }
lightning-background-processor = { git = "https://github.com/tnull/rust-lightning", rev = "98a9e9d56dd482ad04552dbf3a7d57e91f94aad3" }
lightning-rapid-gossip-sync = { git = "https://github.com/tnull/rust-lightning", rev = "98a9e9d56dd482ad04552dbf3a7d57e91f94aad3" }
lightning-block-sync = { git = "https://github.com/tnull/rust-lightning", rev = "98a9e9d56dd482ad04552dbf3a7d57e91f94aad3" }
lightning-transaction-sync = { git = "https://github.com/tnull/rust-lightning", rev = "98a9e9d56dd482ad04552dbf3a7d57e91f94aad3" }
lightning-liquidity = { git = "https://github.com/tnull/rust-lightning", rev = "98a9e9d56dd482ad04552dbf3a7d57e91f94aad3" }
lightning-macros = { git = "https://github.com/tnull/rust-lightning", rev = "98a9e9d56dd482ad04552dbf3a7d57e91f94aad3" }
118 changes: 67 additions & 51 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ use lightning::util::persist::{
};
use lightning::util::ser::ReadableArgs;
use lightning::util::sweep::OutputSweeper;
use lightning_liquidity::lsps2::router::LSPS2BOLT12Router;
use lightning_persister::fs_store::v1::FilesystemStore;
use vss_client::headers::VssHeaderProvider;

Expand Down Expand Up @@ -77,8 +78,8 @@ use crate::runtime::{Runtime, RuntimeSpawner};
use crate::tx_broadcaster::TransactionBroadcaster;
use crate::types::{
AsyncPersister, ChainMonitor, ChannelManager, DynStore, DynStoreWrapper, GossipSync, Graph,
KeysManager, MessageRouter, OnionMessenger, PaymentStore, PeerManager, PendingPaymentStore,
Persister, SyncAndAsyncKVStore,
InnerMessageRouter, KeysManager, MessageRouter, OnionMessenger, PaymentStore, PeerManager,
PendingPaymentStore, Persister, SyncAndAsyncKVStore,
};
use crate::wallet::persist::KVStoreWalletPersister;
use crate::wallet::Wallet;
Expand Down Expand Up @@ -1547,6 +1548,7 @@ fn build_with_store_internal(
Arc::clone(&persister),
Arc::clone(&keys_manager),
peer_storage_key,
false,
));

// Initialize the network graph, scorer, and router
Expand Down Expand Up @@ -1627,12 +1629,19 @@ fn build_with_store_internal(
}

let scoring_fee_params = ProbabilisticScoringFeeParameters::default();
let router = Arc::new(DefaultRouter::new(
let inner_router = DefaultRouter::new(
Arc::clone(&network_graph),
Arc::clone(&logger),
Arc::clone(&keys_manager),
Arc::clone(&scorer),
scoring_fee_params,
);
let inner_message_router =
InnerMessageRouter::new(Arc::clone(&network_graph), Arc::clone(&keys_manager));
let router = Arc::new(LSPS2BOLT12Router::new(
inner_router,
inner_message_router,
Arc::clone(&keys_manager),
));

let mut user_config = default_user_config(&config);
Expand Down Expand Up @@ -1661,8 +1670,7 @@ fn build_with_store_internal(
}
}

let message_router =
Arc::new(MessageRouter::new(Arc::clone(&network_graph), Arc::clone(&keys_manager)));
let message_router = Arc::clone(&router);

// Initialize the ChannelManager
let channel_manager = {
Expand Down Expand Up @@ -1790,56 +1798,64 @@ fn build_with_store_internal(
},
};

let (liquidity_source, custom_message_handler) =
if let Some(lsc) = liquidity_source_config.as_ref() {
let mut liquidity_source_builder = LiquiditySourceBuilder::new(
Arc::clone(&wallet),
Arc::clone(&channel_manager),
Arc::clone(&keys_manager),
Arc::clone(&chain_source),
Arc::clone(&tx_broadcaster),
Arc::clone(&kv_store),
Arc::clone(&config),
Arc::clone(&logger),
);
let (liquidity_source, custom_message_handler) = if let Some(lsc) =
liquidity_source_config.as_ref()
{
let mut liquidity_source_builder = LiquiditySourceBuilder::new(
Arc::clone(&wallet),
Arc::clone(&channel_manager),
Arc::clone(&keys_manager),
Arc::clone(&router),
Arc::clone(&chain_source),
Arc::clone(&tx_broadcaster),
Arc::clone(&kv_store),
Arc::clone(&config),
Some(Arc::clone(&onion_messenger)
as Arc<
dyn lightning::onion_message::messenger::OnionMessageInterceptor + Send + Sync,
>),
Arc::clone(&logger),
);

lsc.lsps1_client.as_ref().map(|config| {
liquidity_source_builder.lsps1_client(
config.node_id,
config.address.clone(),
config.token.clone(),
)
});
lsc.lsps1_client.as_ref().map(|config| {
liquidity_source_builder.lsps1_client(
config.node_id,
config.address.clone(),
config.token.clone(),
)
});

lsc.lsps2_client.as_ref().map(|config| {
liquidity_source_builder.lsps2_client(
config.node_id,
config.address.clone(),
config.token.clone(),
)
});
lsc.lsps2_client.as_ref().map(|config| {
liquidity_source_builder.lsps2_client(
config.node_id,
config.address.clone(),
config.token.clone(),
)
});

let promise_secret = {
let lsps_xpriv = derive_xprv(
Arc::clone(&config),
&seed_bytes,
LSPS_HARDENED_CHILD_INDEX,
Arc::clone(&logger),
)?;
lsps_xpriv.private_key.secret_bytes()
};
lsc.lsps2_service.as_ref().map(|config| {
liquidity_source_builder.lsps2_service(promise_secret, config.clone())
});

let liquidity_source = runtime
.block_on(async move { liquidity_source_builder.build().await.map(Arc::new) })?;
let custom_message_handler =
Arc::new(NodeCustomMessageHandler::new_liquidity(Arc::clone(&liquidity_source)));
(Some(liquidity_source), custom_message_handler)
} else {
(None, Arc::new(NodeCustomMessageHandler::new_ignoring()))
let promise_secret = {
let lsps_xpriv = derive_xprv(
Arc::clone(&config),
&seed_bytes,
LSPS_HARDENED_CHILD_INDEX,
Arc::clone(&logger),
)?;
lsps_xpriv.private_key.secret_bytes()
};
lsc.lsps2_service
.as_ref()
.map(|config| liquidity_source_builder.lsps2_service(promise_secret, config.clone()));

let liquidity_source = runtime
.block_on(async move { liquidity_source_builder.build().await.map(Arc::new) })?;
// TODO: Rehydrate persisted `OfferId -> LSPS2Bolt12InvoiceParameters` mappings here for
// client nodes and call `router.register_offer(...)` before startup completes.
let custom_message_handler =
Arc::new(NodeCustomMessageHandler::new_liquidity(Arc::clone(&liquidity_source)));
(Some(liquidity_source), custom_message_handler)
} else {
(None, Arc::new(NodeCustomMessageHandler::new_ignoring()))
};

let msg_handler = match gossip_source.as_gossip_sync() {
GossipSync::P2P(p2p_gossip_sync) => MessageHandler {
Expand Down
14 changes: 8 additions & 6 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1306,17 +1306,19 @@ where
}
},
LdkEvent::PaymentForwarded {
prev_channel_id,
next_channel_id,
prev_user_channel_id,
next_user_channel_id,
prev_node_id,
next_node_id,
prev_htlcs,
next_htlcs,
total_fee_earned_msat,
skimmed_fee_msat,
claim_from_onchain_tx,
outbound_amount_forwarded_msat,
} => {
let prev_channel_id = prev_htlcs.first().map(|h| h.channel_id);
let next_channel_id = next_htlcs.first().map(|h| h.channel_id);
let prev_user_channel_id = prev_htlcs.first().and_then(|h| h.user_channel_id);
let next_user_channel_id = next_htlcs.first().and_then(|h| h.user_channel_id);
let prev_node_id = prev_htlcs.first().and_then(|h| h.node_id);
let next_node_id = next_htlcs.first().and_then(|h| h.node_id);
{
let read_only_network_graph = self.network_graph.read_only();
let nodes = read_only_network_graph.nodes();
Expand Down
8 changes: 8 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -901,9 +901,13 @@ impl Node {
#[cfg(not(feature = "uniffi"))]
pub fn bolt12_payment(&self) -> Bolt12Payment {
Bolt12Payment::new(
Arc::clone(&self.runtime),
Arc::clone(&self.channel_manager),
Arc::clone(&self.connection_manager),
self.liquidity_source.clone(),
Arc::clone(&self.keys_manager),
Arc::clone(&self.payment_store),
Arc::clone(&self.peer_store),
Arc::clone(&self.config),
Arc::clone(&self.is_running),
Arc::clone(&self.logger),
Expand All @@ -917,9 +921,13 @@ impl Node {
#[cfg(feature = "uniffi")]
pub fn bolt12_payment(&self) -> Arc<Bolt12Payment> {
Arc::new(Bolt12Payment::new(
Arc::clone(&self.runtime),
Arc::clone(&self.channel_manager),
Arc::clone(&self.connection_manager),
self.liquidity_source.clone(),
Arc::clone(&self.keys_manager),
Arc::clone(&self.payment_store),
Arc::clone(&self.peer_store),
Arc::clone(&self.config),
Arc::clone(&self.is_running),
Arc::clone(&self.logger),
Expand Down
Loading
Loading