Skip to content

Commit 26aa86e

Browse files
committed
WIP: Add LSPS2-backed BOLT12 JIT offer routing
Integrate the LSPS2 BOLT12 router into ldk-node, allowing JIT channel offers to be created and paid via the LSPS2 protocol with BOLT12. Co-Authored-By: HAL 9000
1 parent 253dc13 commit 26aa86e

File tree

8 files changed

+548
-61
lines changed

8 files changed

+548
-61
lines changed

Cargo.toml

Lines changed: 26 additions & 26 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/lightningdevkit/rust-lightning", rev = "dcf0c203e166da2348bef12b2e5eff4a250cdec7", features = ["std"] }
43-
lightning-types = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "dcf0c203e166da2348bef12b2e5eff4a250cdec7" }
44-
lightning-invoice = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "dcf0c203e166da2348bef12b2e5eff4a250cdec7", features = ["std"] }
45-
lightning-net-tokio = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "dcf0c203e166da2348bef12b2e5eff4a250cdec7" }
46-
lightning-persister = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "dcf0c203e166da2348bef12b2e5eff4a250cdec7", features = ["tokio"] }
47-
lightning-background-processor = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "dcf0c203e166da2348bef12b2e5eff4a250cdec7" }
48-
lightning-rapid-gossip-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "dcf0c203e166da2348bef12b2e5eff4a250cdec7" }
49-
lightning-block-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "dcf0c203e166da2348bef12b2e5eff4a250cdec7", features = ["rest-client", "rpc-client", "tokio"] }
50-
lightning-transaction-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "dcf0c203e166da2348bef12b2e5eff4a250cdec7", features = ["esplora-async-https", "time", "electrum-rustls-ring"] }
51-
lightning-liquidity = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "dcf0c203e166da2348bef12b2e5eff4a250cdec7", features = ["std"] }
52-
lightning-macros = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "dcf0c203e166da2348bef12b2e5eff4a250cdec7" }
42+
lightning = { git = "https://github.com/tnull/rust-lightning", rev = "71242155f2b90007e850be89daef4db78d8508f0", features = ["std"] }
43+
lightning-types = { git = "https://github.com/tnull/rust-lightning", rev = "71242155f2b90007e850be89daef4db78d8508f0" }
44+
lightning-invoice = { git = "https://github.com/tnull/rust-lightning", rev = "71242155f2b90007e850be89daef4db78d8508f0", features = ["std"] }
45+
lightning-net-tokio = { git = "https://github.com/tnull/rust-lightning", rev = "71242155f2b90007e850be89daef4db78d8508f0" }
46+
lightning-persister = { git = "https://github.com/tnull/rust-lightning", rev = "71242155f2b90007e850be89daef4db78d8508f0", features = ["tokio"] }
47+
lightning-background-processor = { git = "https://github.com/tnull/rust-lightning", rev = "71242155f2b90007e850be89daef4db78d8508f0" }
48+
lightning-rapid-gossip-sync = { git = "https://github.com/tnull/rust-lightning", rev = "71242155f2b90007e850be89daef4db78d8508f0" }
49+
lightning-block-sync = { git = "https://github.com/tnull/rust-lightning", rev = "71242155f2b90007e850be89daef4db78d8508f0", features = ["rest-client", "rpc-client", "tokio"] }
50+
lightning-transaction-sync = { git = "https://github.com/tnull/rust-lightning", rev = "71242155f2b90007e850be89daef4db78d8508f0", features = ["esplora-async-https", "time", "electrum-rustls-ring"] }
51+
lightning-liquidity = { git = "https://github.com/tnull/rust-lightning", rev = "71242155f2b90007e850be89daef4db78d8508f0", features = ["std"] }
52+
lightning-macros = { git = "https://github.com/tnull/rust-lightning", rev = "71242155f2b90007e850be89daef4db78d8508f0" }
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"]}
@@ -66,7 +66,7 @@ bip21 = { version = "0.5", features = ["std"], default-features = false }
6666
base64 = { version = "0.22.1", default-features = false, features = ["std"] }
6767
getrandom = { version = "0.3", default-features = false }
6868
chrono = { version = "0.4", default-features = false, features = ["clock"] }
69-
tokio = { version = "1.37", default-features = false, features = [ "rt-multi-thread", "time", "sync", "macros", "net" ] }
69+
tokio = { version = "1.37", default-features = false, features = [ "rt-multi-thread", "time", "sync", "macros" ] }
7070
esplora-client = { version = "0.12", default-features = false, features = ["tokio", "async-https-rustls"] }
7171
electrum-client = { version = "0.24.0", default-features = false, features = ["proxy", "use-rustls-ring"] }
7272
libc = "0.2"
@@ -79,13 +79,13 @@ async-trait = { version = "0.1", default-features = false }
7979
vss-client = { package = "vss-client-ng", version = "0.5" }
8080
prost = { version = "0.11.6", default-features = false}
8181
#bitcoin-payment-instructions = { version = "0.6" }
82-
bitcoin-payment-instructions = { git = "https://github.com/joostjager/bitcoin-payment-instructions", branch = "ldk-dcf0c203e166da2348bef12b2e5eff4a250cdec7" }
82+
bitcoin-payment-instructions = { git = "https://github.com/jkczyz/bitcoin-payment-instructions", rev = "0138feb7acefb1e49102a6fb46d7b776bf43265e" }
8383

8484
[target.'cfg(windows)'.dependencies]
8585
winapi = { version = "0.3", features = ["winbase"] }
8686

8787
[dev-dependencies]
88-
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "dcf0c203e166da2348bef12b2e5eff4a250cdec7", features = ["std", "_test_utils"] }
88+
lightning = { git = "https://github.com/tnull/rust-lightning", rev = "71242155f2b90007e850be89daef4db78d8508f0", 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"
@@ -172,15 +172,15 @@ harness = false
172172
#vss-client-ng = { path = "../vss-client" }
173173
#vss-client-ng = { git = "https://github.com/lightningdevkit/vss-client", branch = "main" }
174174
#
175-
#[patch."https://github.com/lightningdevkit/rust-lightning"]
176-
#lightning = { path = "../rust-lightning/lightning" }
177-
#lightning-types = { path = "../rust-lightning/lightning-types" }
178-
#lightning-invoice = { path = "../rust-lightning/lightning-invoice" }
179-
#lightning-net-tokio = { path = "../rust-lightning/lightning-net-tokio" }
180-
#lightning-persister = { path = "../rust-lightning/lightning-persister" }
181-
#lightning-background-processor = { path = "../rust-lightning/lightning-background-processor" }
182-
#lightning-rapid-gossip-sync = { path = "../rust-lightning/lightning-rapid-gossip-sync" }
183-
#lightning-block-sync = { path = "../rust-lightning/lightning-block-sync" }
184-
#lightning-transaction-sync = { path = "../rust-lightning/lightning-transaction-sync" }
185-
#lightning-liquidity = { path = "../rust-lightning/lightning-liquidity" }
186-
#lightning-macros = { path = "../rust-lightning/lightning-macros" }
175+
[patch."https://github.com/lightningdevkit/rust-lightning"]
176+
lightning = { git = "https://github.com/tnull/rust-lightning", rev = "71242155f2b90007e850be89daef4db78d8508f0" }
177+
lightning-types = { git = "https://github.com/tnull/rust-lightning", rev = "71242155f2b90007e850be89daef4db78d8508f0" }
178+
lightning-invoice = { git = "https://github.com/tnull/rust-lightning", rev = "71242155f2b90007e850be89daef4db78d8508f0" }
179+
lightning-net-tokio = { git = "https://github.com/tnull/rust-lightning", rev = "71242155f2b90007e850be89daef4db78d8508f0" }
180+
lightning-persister = { git = "https://github.com/tnull/rust-lightning", rev = "71242155f2b90007e850be89daef4db78d8508f0" }
181+
lightning-background-processor = { git = "https://github.com/tnull/rust-lightning", rev = "71242155f2b90007e850be89daef4db78d8508f0" }
182+
lightning-rapid-gossip-sync = { git = "https://github.com/tnull/rust-lightning", rev = "71242155f2b90007e850be89daef4db78d8508f0" }
183+
lightning-block-sync = { git = "https://github.com/tnull/rust-lightning", rev = "71242155f2b90007e850be89daef4db78d8508f0" }
184+
lightning-transaction-sync = { git = "https://github.com/tnull/rust-lightning", rev = "71242155f2b90007e850be89daef4db78d8508f0" }
185+
lightning-liquidity = { git = "https://github.com/tnull/rust-lightning", rev = "71242155f2b90007e850be89daef4db78d8508f0" }
186+
lightning-macros = { git = "https://github.com/tnull/rust-lightning", rev = "71242155f2b90007e850be89daef4db78d8508f0" }

src/builder.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use lightning::ln::peer_handler::{IgnoringMessageHandler, MessageHandler};
2727
use lightning::log_trace;
2828
use lightning::routing::gossip::NodeAlias;
2929
use lightning::routing::router::DefaultRouter;
30+
use lightning_liquidity::lsps2::router::LSPS2BOLT12Router;
3031
use lightning::routing::scoring::{
3132
CombinedScorer, ProbabilisticScorer, ProbabilisticScoringDecayParameters,
3233
ProbabilisticScoringFeeParameters,
@@ -77,7 +78,7 @@ use crate::runtime::{Runtime, RuntimeSpawner};
7778
use crate::tx_broadcaster::TransactionBroadcaster;
7879
use crate::types::{
7980
AsyncPersister, ChainMonitor, ChannelManager, DynStore, DynStoreRef, DynStoreWrapper,
80-
GossipSync, Graph, KeysManager, MessageRouter, OnionMessenger, PaymentStore, PeerManager,
81+
GossipSync, Graph, InnerMessageRouter, KeysManager, OnionMessenger, PaymentStore, PeerManager,
8182
PendingPaymentStore, SyncAndAsyncKVStore,
8283
};
8384
use crate::wallet::persist::KVStoreWalletPersister;
@@ -1622,12 +1623,19 @@ fn build_with_store_internal(
16221623
}
16231624

16241625
let scoring_fee_params = ProbabilisticScoringFeeParameters::default();
1625-
let router = Arc::new(DefaultRouter::new(
1626+
let inner_router = DefaultRouter::new(
16261627
Arc::clone(&network_graph),
16271628
Arc::clone(&logger),
16281629
Arc::clone(&keys_manager),
16291630
Arc::clone(&scorer),
16301631
scoring_fee_params,
1632+
);
1633+
let inner_message_router =
1634+
InnerMessageRouter::new(Arc::clone(&network_graph), Arc::clone(&keys_manager));
1635+
let router = Arc::new(LSPS2BOLT12Router::new(
1636+
inner_router,
1637+
inner_message_router,
1638+
Arc::clone(&keys_manager),
16311639
));
16321640

16331641
let mut user_config = default_user_config(&config);
@@ -1656,8 +1664,7 @@ fn build_with_store_internal(
16561664
}
16571665
}
16581666

1659-
let message_router =
1660-
Arc::new(MessageRouter::new(Arc::clone(&network_graph), Arc::clone(&keys_manager)));
1667+
let message_router = Arc::clone(&router);
16611668

16621669
// Initialize the ChannelManager
16631670
let channel_manager = {
@@ -1791,6 +1798,7 @@ fn build_with_store_internal(
17911798
Arc::clone(&wallet),
17921799
Arc::clone(&channel_manager),
17931800
Arc::clone(&keys_manager),
1801+
Arc::clone(&router),
17941802
Arc::clone(&tx_broadcaster),
17951803
Arc::clone(&kv_store),
17961804
Arc::clone(&config),
@@ -1828,6 +1836,8 @@ fn build_with_store_internal(
18281836

18291837
let liquidity_source = runtime
18301838
.block_on(async move { liquidity_source_builder.build().await.map(Arc::new) })?;
1839+
// TODO: Rehydrate persisted intercept SCID -> LSPS2Bolt12InvoiceParameters mappings here
1840+
// for client nodes and call `router.register_intercept_scid(...)` before startup completes.
18311841
let custom_message_handler =
18321842
Arc::new(NodeCustomMessageHandler::new_liquidity(Arc::clone(&liquidity_source)));
18331843
(Some(liquidity_source), custom_message_handler)

src/event.rs

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,6 +1333,12 @@ where
13331333
claim_from_onchain_tx,
13341334
outbound_amount_forwarded_msat,
13351335
} => {
1336+
let prev_channel_id = prev_htlcs.first().map(|h| h.channel_id);
1337+
let next_channel_id = next_htlcs.first().map(|h| h.channel_id);
1338+
let prev_user_channel_id = prev_htlcs.first().and_then(|h| h.user_channel_id);
1339+
let next_user_channel_id = next_htlcs.first().and_then(|h| h.user_channel_id);
1340+
let prev_node_id = prev_htlcs.first().and_then(|h| h.node_id);
1341+
let next_node_id = next_htlcs.first().and_then(|h| h.node_id);
13361342
{
13371343
let read_only_network_graph = self.network_graph.read_only();
13381344
let nodes = read_only_network_graph.nodes();
@@ -1653,14 +1659,25 @@ where
16531659

16541660
self.bump_tx_event_handler.handle_event(&bte).await;
16551661
},
1656-
LdkEvent::OnionMessageIntercepted { peer_node_id, message } => {
1657-
if let Some(om_mailbox) = self.om_mailbox.as_ref() {
1658-
om_mailbox.onion_message_intercepted(peer_node_id, message);
1659-
} else {
1660-
log_trace!(
1661-
self.logger,
1662-
"Onion message intercepted, but no onion message mailbox available"
1663-
);
1662+
LdkEvent::OnionMessageIntercepted { next_hop, message } => {
1663+
match next_hop {
1664+
lightning::blinded_path::message::NextMessageHop::NodeId(peer_node_id) => {
1665+
if let Some(om_mailbox) = self.om_mailbox.as_ref() {
1666+
om_mailbox.onion_message_intercepted(peer_node_id, message);
1667+
} else {
1668+
log_trace!(
1669+
self.logger,
1670+
"Onion message intercepted, but no onion message mailbox available"
1671+
);
1672+
}
1673+
},
1674+
lightning::blinded_path::message::NextMessageHop::ShortChannelId(scid) => {
1675+
log_trace!(
1676+
self.logger,
1677+
"Onion message intercepted for unknown SCID {}, ignoring",
1678+
scid
1679+
);
1680+
},
16641681
}
16651682
},
16661683
LdkEvent::OnionMessagePeerConnected { peer_node_id } => {

src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -901,9 +901,13 @@ impl Node {
901901
#[cfg(not(feature = "uniffi"))]
902902
pub fn bolt12_payment(&self) -> Bolt12Payment {
903903
Bolt12Payment::new(
904+
Arc::clone(&self.runtime),
904905
Arc::clone(&self.channel_manager),
906+
Arc::clone(&self.connection_manager),
907+
self.liquidity_source.clone(),
905908
Arc::clone(&self.keys_manager),
906909
Arc::clone(&self.payment_store),
910+
Arc::clone(&self.peer_store),
907911
Arc::clone(&self.config),
908912
Arc::clone(&self.is_running),
909913
Arc::clone(&self.logger),
@@ -917,9 +921,13 @@ impl Node {
917921
#[cfg(feature = "uniffi")]
918922
pub fn bolt12_payment(&self) -> Arc<Bolt12Payment> {
919923
Arc::new(Bolt12Payment::new(
924+
Arc::clone(&self.runtime),
920925
Arc::clone(&self.channel_manager),
926+
Arc::clone(&self.connection_manager),
927+
self.liquidity_source.clone(),
921928
Arc::clone(&self.keys_manager),
922929
Arc::clone(&self.payment_store),
930+
Arc::clone(&self.peer_store),
923931
Arc::clone(&self.config),
924932
Arc::clone(&self.is_running),
925933
Arc::clone(&self.logger),

0 commit comments

Comments
 (0)