Skip to content

Commit dad5932

Browse files
committed
Account for LiquidityManager persistence
We recently implmented persistence for the `lightning-liquidity` service state. Here we make corresponding changes in LDK Node to have our service state persisted.
1 parent 8c2ff8f commit dad5932

File tree

5 files changed

+130
-107
lines changed

5 files changed

+130
-107
lines changed

Cargo.toml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,17 @@ default = []
5252
#lightning-liquidity = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main" }
5353
#lightning-macros = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main" }
5454

55-
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "3e21ba37a133977d4247e86f25df983b39326994", features = ["std"] }
56-
lightning-types = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "3e21ba37a133977d4247e86f25df983b39326994" }
57-
lightning-invoice = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "3e21ba37a133977d4247e86f25df983b39326994", features = ["std"] }
58-
lightning-net-tokio = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "3e21ba37a133977d4247e86f25df983b39326994" }
59-
lightning-persister = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "3e21ba37a133977d4247e86f25df983b39326994", features = ["tokio"] }
60-
lightning-background-processor = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "3e21ba37a133977d4247e86f25df983b39326994" }
61-
lightning-rapid-gossip-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "3e21ba37a133977d4247e86f25df983b39326994" }
62-
lightning-block-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "3e21ba37a133977d4247e86f25df983b39326994", features = ["rest-client", "rpc-client", "tokio"] }
63-
lightning-transaction-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "3e21ba37a133977d4247e86f25df983b39326994", features = ["esplora-async-https", "electrum-rustls-ring", "time"] }
64-
lightning-liquidity = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "3e21ba37a133977d4247e86f25df983b39326994" }
65-
lightning-macros = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "3e21ba37a133977d4247e86f25df983b39326994" }
55+
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "d0765847c85f1c3dc753c17c3e05dbcb1d300204", features = ["std"] }
56+
lightning-types = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "d0765847c85f1c3dc753c17c3e05dbcb1d300204" }
57+
lightning-invoice = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "d0765847c85f1c3dc753c17c3e05dbcb1d300204", features = ["std"] }
58+
lightning-net-tokio = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "d0765847c85f1c3dc753c17c3e05dbcb1d300204" }
59+
lightning-persister = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "d0765847c85f1c3dc753c17c3e05dbcb1d300204", features = ["tokio"] }
60+
lightning-background-processor = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "d0765847c85f1c3dc753c17c3e05dbcb1d300204" }
61+
lightning-rapid-gossip-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "d0765847c85f1c3dc753c17c3e05dbcb1d300204" }
62+
lightning-block-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "d0765847c85f1c3dc753c17c3e05dbcb1d300204", features = ["rest-client", "rpc-client", "tokio"] }
63+
lightning-transaction-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "d0765847c85f1c3dc753c17c3e05dbcb1d300204", features = ["esplora-async-https", "electrum-rustls-ring", "time"] }
64+
lightning-liquidity = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "d0765847c85f1c3dc753c17c3e05dbcb1d300204" }
65+
lightning-macros = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "d0765847c85f1c3dc753c17c3e05dbcb1d300204" }
6666

6767
#lightning = { path = "../rust-lightning/lightning", features = ["std"] }
6868
#lightning-types = { path = "../rust-lightning/lightning-types" }
@@ -109,7 +109,7 @@ winapi = { version = "0.3", features = ["winbase"] }
109109
[dev-dependencies]
110110
#lightning = { version = "0.1.0", features = ["std", "_test_utils"] }
111111
#lightning = { git = "https://github.com/lightningdevkit/rust-lightning", branch="main", features = ["std", "_test_utils"] }
112-
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "3e21ba37a133977d4247e86f25df983b39326994", features = ["std", "_test_utils"] }
112+
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "d0765847c85f1c3dc753c17c3e05dbcb1d300204", features = ["std", "_test_utils"] }
113113
#lightning = { path = "../rust-lightning/lightning", features = ["std", "_test_utils"] }
114114
proptest = "1.0.0"
115115
regex = "1.5.6"

src/builder.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1510,6 +1510,7 @@ fn build_with_store_internal(
15101510
Arc::clone(&channel_manager),
15111511
Arc::clone(&keys_manager),
15121512
Arc::clone(&chain_source),
1513+
Arc::clone(&kv_store),
15131514
Arc::clone(&config),
15141515
Arc::clone(&logger),
15151516
);
@@ -1543,7 +1544,8 @@ fn build_with_store_internal(
15431544
liquidity_source_builder.lsps2_service(promise_secret, config.clone())
15441545
});
15451546

1546-
let liquidity_source = Arc::new(liquidity_source_builder.build());
1547+
let liquidity_source = runtime
1548+
.block_on(async move { liquidity_source_builder.build().await.map(Arc::new) })?;
15471549
let custom_message_handler =
15481550
Arc::new(NodeCustomMessageHandler::new_liquidity(Arc::clone(&liquidity_source)));
15491551
(Some(liquidity_source), custom_message_handler)

src/event.rs

Lines changed: 62 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,7 +1048,7 @@ where
10481048
LdkEvent::ProbeFailed { .. } => {},
10491049
LdkEvent::HTLCHandlingFailed { failure_type, .. } => {
10501050
if let Some(liquidity_source) = self.liquidity_source.as_ref() {
1051-
liquidity_source.handle_htlc_handling_failed(failure_type);
1051+
liquidity_source.handle_htlc_handling_failed(failure_type).await;
10521052
}
10531053
},
10541054
LdkEvent::SpendableOutputs { outputs, channel_id } => {
@@ -1231,60 +1231,67 @@ where
12311231
claim_from_onchain_tx,
12321232
outbound_amount_forwarded_msat,
12331233
} => {
1234-
let read_only_network_graph = self.network_graph.read_only();
1235-
let nodes = read_only_network_graph.nodes();
1236-
let channels = self.channel_manager.list_channels();
1237-
1238-
let node_str = |channel_id: &Option<ChannelId>| {
1239-
channel_id
1240-
.and_then(|channel_id| channels.iter().find(|c| c.channel_id == channel_id))
1241-
.and_then(|channel| {
1242-
nodes.get(&NodeId::from_pubkey(&channel.counterparty.node_id))
1243-
})
1244-
.map_or("private_node".to_string(), |node| {
1245-
node.announcement_info
1246-
.as_ref()
1247-
.map_or("unnamed node".to_string(), |ann| {
1248-
format!("node {}", ann.alias())
1249-
})
1250-
})
1251-
};
1252-
let channel_str = |channel_id: &Option<ChannelId>| {
1253-
channel_id
1254-
.map(|channel_id| format!(" with channel {}", channel_id))
1255-
.unwrap_or_default()
1256-
};
1257-
let from_prev_str = format!(
1258-
" from {}{}",
1259-
node_str(&prev_channel_id),
1260-
channel_str(&prev_channel_id)
1261-
);
1262-
let to_next_str =
1263-
format!(" to {}{}", node_str(&next_channel_id), channel_str(&next_channel_id));
1234+
{
1235+
let read_only_network_graph = self.network_graph.read_only();
1236+
let nodes = read_only_network_graph.nodes();
1237+
let channels = self.channel_manager.list_channels();
1238+
1239+
let node_str = |channel_id: &Option<ChannelId>| {
1240+
channel_id
1241+
.and_then(|channel_id| {
1242+
channels.iter().find(|c| c.channel_id == channel_id)
1243+
})
1244+
.and_then(|channel| {
1245+
nodes.get(&NodeId::from_pubkey(&channel.counterparty.node_id))
1246+
})
1247+
.map_or("private_node".to_string(), |node| {
1248+
node.announcement_info
1249+
.as_ref()
1250+
.map_or("unnamed node".to_string(), |ann| {
1251+
format!("node {}", ann.alias())
1252+
})
1253+
})
1254+
};
1255+
let channel_str = |channel_id: &Option<ChannelId>| {
1256+
channel_id
1257+
.map(|channel_id| format!(" with channel {}", channel_id))
1258+
.unwrap_or_default()
1259+
};
1260+
let from_prev_str = format!(
1261+
" from {}{}",
1262+
node_str(&prev_channel_id),
1263+
channel_str(&prev_channel_id)
1264+
);
1265+
let to_next_str = format!(
1266+
" to {}{}",
1267+
node_str(&next_channel_id),
1268+
channel_str(&next_channel_id)
1269+
);
12641270

1265-
let fee_earned = total_fee_earned_msat.unwrap_or(0);
1266-
if claim_from_onchain_tx {
1267-
log_info!(
1271+
let fee_earned = total_fee_earned_msat.unwrap_or(0);
1272+
if claim_from_onchain_tx {
1273+
log_info!(
12681274
self.logger,
12691275
"Forwarded payment{}{} of {}msat, earning {}msat in fees from claiming onchain.",
12701276
from_prev_str,
12711277
to_next_str,
12721278
outbound_amount_forwarded_msat.unwrap_or(0),
12731279
fee_earned,
12741280
);
1275-
} else {
1276-
log_info!(
1277-
self.logger,
1278-
"Forwarded payment{}{} of {}msat, earning {}msat in fees.",
1279-
from_prev_str,
1280-
to_next_str,
1281-
outbound_amount_forwarded_msat.unwrap_or(0),
1282-
fee_earned,
1283-
);
1281+
} else {
1282+
log_info!(
1283+
self.logger,
1284+
"Forwarded payment{}{} of {}msat, earning {}msat in fees.",
1285+
from_prev_str,
1286+
to_next_str,
1287+
outbound_amount_forwarded_msat.unwrap_or(0),
1288+
fee_earned,
1289+
);
1290+
}
12841291
}
12851292

12861293
if let Some(liquidity_source) = self.liquidity_source.as_ref() {
1287-
liquidity_source.handle_payment_forwarded(next_channel_id);
1294+
liquidity_source.handle_payment_forwarded(next_channel_id).await;
12881295
}
12891296

12901297
let event = Event::PaymentForwarded {
@@ -1377,11 +1384,9 @@ where
13771384
);
13781385

13791386
if let Some(liquidity_source) = self.liquidity_source.as_ref() {
1380-
liquidity_source.handle_channel_ready(
1381-
user_channel_id,
1382-
&channel_id,
1383-
&counterparty_node_id,
1384-
);
1387+
liquidity_source
1388+
.handle_channel_ready(user_channel_id, &channel_id, &counterparty_node_id)
1389+
.await;
13851390
}
13861391

13871392
let event = Event::ChannelReady {
@@ -1430,12 +1435,14 @@ where
14301435
..
14311436
} => {
14321437
if let Some(liquidity_source) = self.liquidity_source.as_ref() {
1433-
liquidity_source.handle_htlc_intercepted(
1434-
requested_next_hop_scid,
1435-
intercept_id,
1436-
expected_outbound_amount_msat,
1437-
payment_hash,
1438-
);
1438+
liquidity_source
1439+
.handle_htlc_intercepted(
1440+
requested_next_hop_scid,
1441+
intercept_id,
1442+
expected_outbound_amount_msat,
1443+
payment_hash,
1444+
)
1445+
.await;
14391446
}
14401447
},
14411448
LdkEvent::InvoiceReceived { .. } => {

0 commit comments

Comments
 (0)