Skip to content

Commit b8b5073

Browse files
committed
Integrate LSPS2<>BOLT12 flow
We bump our dependency and Integrate the LSPS2-BOLT12 flow. Co-Authored-By: HAL 9000
1 parent fae2746 commit b8b5073

File tree

6 files changed

+380
-97
lines changed

6 files changed

+380
-97
lines changed

Cargo.toml

Lines changed: 24 additions & 24 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 = "98501d6e5134228c41460dcf786ab53337e41245", features = ["std"] }
43-
lightning-types = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "98501d6e5134228c41460dcf786ab53337e41245" }
44-
lightning-invoice = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "98501d6e5134228c41460dcf786ab53337e41245", features = ["std"] }
45-
lightning-net-tokio = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "98501d6e5134228c41460dcf786ab53337e41245" }
46-
lightning-persister = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "98501d6e5134228c41460dcf786ab53337e41245", features = ["tokio"] }
47-
lightning-background-processor = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "98501d6e5134228c41460dcf786ab53337e41245" }
48-
lightning-rapid-gossip-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "98501d6e5134228c41460dcf786ab53337e41245" }
49-
lightning-block-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "98501d6e5134228c41460dcf786ab53337e41245", features = ["rest-client", "rpc-client", "tokio"] }
50-
lightning-transaction-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "98501d6e5134228c41460dcf786ab53337e41245", features = ["esplora-async-https", "time", "electrum-rustls-ring"] }
51-
lightning-liquidity = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "98501d6e5134228c41460dcf786ab53337e41245", features = ["std"] }
52-
lightning-macros = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "98501d6e5134228c41460dcf786ab53337e41245" }
42+
lightning = { git = "https://github.com/tnull/rust-lightning", rev = "2cb054601134943d5c8e5a39d014e7b125c7a19a", features = ["std"] }
43+
lightning-types = { git = "https://github.com/tnull/rust-lightning", rev = "2cb054601134943d5c8e5a39d014e7b125c7a19a" }
44+
lightning-invoice = { git = "https://github.com/tnull/rust-lightning", rev = "2cb054601134943d5c8e5a39d014e7b125c7a19a", features = ["std"] }
45+
lightning-net-tokio = { git = "https://github.com/tnull/rust-lightning", rev = "2cb054601134943d5c8e5a39d014e7b125c7a19a" }
46+
lightning-persister = { git = "https://github.com/tnull/rust-lightning", rev = "2cb054601134943d5c8e5a39d014e7b125c7a19a", features = ["tokio"] }
47+
lightning-background-processor = { git = "https://github.com/tnull/rust-lightning", rev = "2cb054601134943d5c8e5a39d014e7b125c7a19a" }
48+
lightning-rapid-gossip-sync = { git = "https://github.com/tnull/rust-lightning", rev = "2cb054601134943d5c8e5a39d014e7b125c7a19a" }
49+
lightning-block-sync = { git = "https://github.com/tnull/rust-lightning", rev = "2cb054601134943d5c8e5a39d014e7b125c7a19a", features = ["rest-client", "rpc-client", "tokio"] }
50+
lightning-transaction-sync = { git = "https://github.com/tnull/rust-lightning", rev = "2cb054601134943d5c8e5a39d014e7b125c7a19a", features = ["esplora-async-https", "time", "electrum-rustls-ring"] }
51+
lightning-liquidity = { git = "https://github.com/tnull/rust-lightning", rev = "2cb054601134943d5c8e5a39d014e7b125c7a19a", features = ["std"] }
52+
lightning-macros = { git = "https://github.com/tnull/rust-lightning", rev = "2cb054601134943d5c8e5a39d014e7b125c7a19a" }
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/jkczyz/bitcoin-paymen
8585
winapi = { version = "0.3", features = ["winbase"] }
8686

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

src/builder.rs

Lines changed: 58 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ use lightning::util::persist::{
3939
};
4040
use lightning::util::ser::ReadableArgs;
4141
use lightning::util::sweep::OutputSweeper;
42+
use lightning_liquidity::lsps2::router::LSPS2BOLT12Router;
4243
use lightning_persister::fs_store::v1::FilesystemStore;
4344
use vss_client::headers::VssHeaderProvider;
4445

@@ -1518,13 +1519,14 @@ fn build_with_store_internal(
15181519
}
15191520

15201521
let scoring_fee_params = ProbabilisticScoringFeeParameters::default();
1521-
let router = Arc::new(DefaultRouter::new(
1522+
let inner_router = DefaultRouter::new(
15221523
Arc::clone(&network_graph),
15231524
Arc::clone(&logger),
15241525
Arc::clone(&keys_manager),
15251526
Arc::clone(&scorer),
15261527
scoring_fee_params,
1527-
));
1528+
);
1529+
let router = Arc::new(LSPS2BOLT12Router::new(inner_router, Arc::clone(&keys_manager)));
15281530

15291531
let mut user_config = default_user_config(&config);
15301532

@@ -1681,56 +1683,64 @@ fn build_with_store_internal(
16811683
},
16821684
};
16831685

1684-
let (liquidity_source, custom_message_handler) =
1685-
if let Some(lsc) = liquidity_source_config.as_ref() {
1686-
let mut liquidity_source_builder = LiquiditySourceBuilder::new(
1687-
Arc::clone(&wallet),
1688-
Arc::clone(&channel_manager),
1689-
Arc::clone(&keys_manager),
1690-
Arc::clone(&chain_source),
1691-
Arc::clone(&tx_broadcaster),
1692-
Arc::clone(&kv_store),
1693-
Arc::clone(&config),
1694-
Arc::clone(&logger),
1695-
);
1686+
let (liquidity_source, custom_message_handler) = if let Some(lsc) =
1687+
liquidity_source_config.as_ref()
1688+
{
1689+
let mut liquidity_source_builder = LiquiditySourceBuilder::new(
1690+
Arc::clone(&wallet),
1691+
Arc::clone(&channel_manager),
1692+
Arc::clone(&keys_manager),
1693+
Arc::clone(&router),
1694+
Arc::clone(&chain_source),
1695+
Arc::clone(&tx_broadcaster),
1696+
Arc::clone(&kv_store),
1697+
Arc::clone(&config),
1698+
Some(Arc::clone(&onion_messenger)
1699+
as Arc<
1700+
dyn lightning::onion_message::messenger::OnionMessageInterceptor + Send + Sync,
1701+
>),
1702+
Arc::clone(&logger),
1703+
);
16961704

1697-
lsc.lsps1_client.as_ref().map(|config| {
1698-
liquidity_source_builder.lsps1_client(
1699-
config.node_id,
1700-
config.address.clone(),
1701-
config.token.clone(),
1702-
)
1703-
});
1705+
lsc.lsps1_client.as_ref().map(|config| {
1706+
liquidity_source_builder.lsps1_client(
1707+
config.node_id,
1708+
config.address.clone(),
1709+
config.token.clone(),
1710+
)
1711+
});
17041712

1705-
lsc.lsps2_client.as_ref().map(|config| {
1706-
liquidity_source_builder.lsps2_client(
1707-
config.node_id,
1708-
config.address.clone(),
1709-
config.token.clone(),
1710-
)
1711-
});
1713+
lsc.lsps2_client.as_ref().map(|config| {
1714+
liquidity_source_builder.lsps2_client(
1715+
config.node_id,
1716+
config.address.clone(),
1717+
config.token.clone(),
1718+
)
1719+
});
17121720

1713-
let promise_secret = {
1714-
let lsps_xpriv = derive_xprv(
1715-
Arc::clone(&config),
1716-
&seed_bytes,
1717-
LSPS_HARDENED_CHILD_INDEX,
1718-
Arc::clone(&logger),
1719-
)?;
1720-
lsps_xpriv.private_key.secret_bytes()
1721-
};
1722-
lsc.lsps2_service.as_ref().map(|config| {
1723-
liquidity_source_builder.lsps2_service(promise_secret, config.clone())
1724-
});
1725-
1726-
let liquidity_source = runtime
1727-
.block_on(async move { liquidity_source_builder.build().await.map(Arc::new) })?;
1728-
let custom_message_handler =
1729-
Arc::new(NodeCustomMessageHandler::new_liquidity(Arc::clone(&liquidity_source)));
1730-
(Some(liquidity_source), custom_message_handler)
1731-
} else {
1732-
(None, Arc::new(NodeCustomMessageHandler::new_ignoring()))
1721+
let promise_secret = {
1722+
let lsps_xpriv = derive_xprv(
1723+
Arc::clone(&config),
1724+
&seed_bytes,
1725+
LSPS_HARDENED_CHILD_INDEX,
1726+
Arc::clone(&logger),
1727+
)?;
1728+
lsps_xpriv.private_key.secret_bytes()
17331729
};
1730+
lsc.lsps2_service
1731+
.as_ref()
1732+
.map(|config| liquidity_source_builder.lsps2_service(promise_secret, config.clone()));
1733+
1734+
let liquidity_source = runtime
1735+
.block_on(async move { liquidity_source_builder.build().await.map(Arc::new) })?;
1736+
// TODO: Rehydrate persisted `OfferId -> LSPS2Bolt12InvoiceParameters` mappings here for
1737+
// client nodes and call `router.register_offer(...)` before startup completes.
1738+
let custom_message_handler =
1739+
Arc::new(NodeCustomMessageHandler::new_liquidity(Arc::clone(&liquidity_source)));
1740+
(Some(liquidity_source), custom_message_handler)
1741+
} else {
1742+
(None, Arc::new(NodeCustomMessageHandler::new_ignoring()))
1743+
};
17341744

17351745
let msg_handler = match gossip_source.as_gossip_sync() {
17361746
GossipSync::P2P(p2p_gossip_sync) => MessageHandler {

src/lib.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -897,9 +897,13 @@ impl Node {
897897
#[cfg(not(feature = "uniffi"))]
898898
pub fn bolt12_payment(&self) -> Bolt12Payment {
899899
Bolt12Payment::new(
900+
Arc::clone(&self.runtime),
900901
Arc::clone(&self.channel_manager),
902+
Arc::clone(&self.connection_manager),
903+
self.liquidity_source.clone(),
901904
Arc::clone(&self.keys_manager),
902905
Arc::clone(&self.payment_store),
906+
Arc::clone(&self.peer_store),
903907
Arc::clone(&self.config),
904908
Arc::clone(&self.is_running),
905909
Arc::clone(&self.logger),
@@ -913,9 +917,13 @@ impl Node {
913917
#[cfg(feature = "uniffi")]
914918
pub fn bolt12_payment(&self) -> Arc<Bolt12Payment> {
915919
Arc::new(Bolt12Payment::new(
920+
Arc::clone(&self.runtime),
916921
Arc::clone(&self.channel_manager),
922+
Arc::clone(&self.connection_manager),
923+
self.liquidity_source.clone(),
917924
Arc::clone(&self.keys_manager),
918925
Arc::clone(&self.payment_store),
926+
Arc::clone(&self.peer_store),
919927
Arc::clone(&self.config),
920928
Arc::clone(&self.is_running),
921929
Arc::clone(&self.logger),
@@ -1463,7 +1471,12 @@ impl Node {
14631471

14641472
let funding_template = self
14651473
.channel_manager
1466-
.splice_channel(&channel_details.channel_id, &counterparty_node_id, fee_rate)
1474+
.splice_channel(
1475+
&channel_details.channel_id,
1476+
&counterparty_node_id,
1477+
fee_rate,
1478+
fee_rate,
1479+
)
14671480
.map_err(|e| {
14681481
log_error!(self.logger, "Failed to splice channel: {:?}", e);
14691482
Error::ChannelSplicingFailed
@@ -1572,7 +1585,12 @@ impl Node {
15721585

15731586
let funding_template = self
15741587
.channel_manager
1575-
.splice_channel(&channel_details.channel_id, &counterparty_node_id, fee_rate)
1588+
.splice_channel(
1589+
&channel_details.channel_id,
1590+
&counterparty_node_id,
1591+
fee_rate,
1592+
fee_rate,
1593+
)
15761594
.map_err(|e| {
15771595
log_error!(self.logger, "Failed to splice channel: {:?}", e);
15781596
Error::ChannelSplicingFailed

0 commit comments

Comments
 (0)