Skip to content

Commit 53d4f0a

Browse files
committed
Account for LiquidityManager persistence
We recently implemented persistence for the `lightning-liquidity` service state. Here we make corresponding changes in LDK Node to have our service state persisted.
1 parent 70404ed commit 53d4f0a

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
@@ -1559,6 +1559,7 @@ fn build_with_store_internal(
15591559
Arc::clone(&channel_manager),
15601560
Arc::clone(&keys_manager),
15611561
Arc::clone(&chain_source),
1562+
Arc::clone(&kv_store),
15621563
Arc::clone(&config),
15631564
Arc::clone(&logger),
15641565
);
@@ -1592,7 +1593,8 @@ fn build_with_store_internal(
15921593
liquidity_source_builder.lsps2_service(promise_secret, config.clone())
15931594
});
15941595

1595-
let liquidity_source = Arc::new(liquidity_source_builder.build());
1596+
let liquidity_source = runtime
1597+
.block_on(async move { liquidity_source_builder.build().await.map(Arc::new) })?;
15961598
let custom_message_handler =
15971599
Arc::new(NodeCustomMessageHandler::new_liquidity(Arc::clone(&liquidity_source)));
15981600
(Some(liquidity_source), custom_message_handler)

src/event.rs

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

1263-
let fee_earned = total_fee_earned_msat.unwrap_or(0);
1264-
if claim_from_onchain_tx {
1265-
log_info!(
1269+
let fee_earned = total_fee_earned_msat.unwrap_or(0);
1270+
if claim_from_onchain_tx {
1271+
log_info!(
12661272
self.logger,
12671273
"Forwarded payment{}{} of {}msat, earning {}msat in fees from claiming onchain.",
12681274
from_prev_str,
12691275
to_next_str,
12701276
outbound_amount_forwarded_msat.unwrap_or(0),
12711277
fee_earned,
12721278
);
1273-
} else {
1274-
log_info!(
1275-
self.logger,
1276-
"Forwarded payment{}{} of {}msat, earning {}msat in fees.",
1277-
from_prev_str,
1278-
to_next_str,
1279-
outbound_amount_forwarded_msat.unwrap_or(0),
1280-
fee_earned,
1281-
);
1279+
} else {
1280+
log_info!(
1281+
self.logger,
1282+
"Forwarded payment{}{} of {}msat, earning {}msat in fees.",
1283+
from_prev_str,
1284+
to_next_str,
1285+
outbound_amount_forwarded_msat.unwrap_or(0),
1286+
fee_earned,
1287+
);
1288+
}
12821289
}
12831290

12841291
if let Some(liquidity_source) = self.liquidity_source.as_ref() {
1285-
liquidity_source.handle_payment_forwarded(next_channel_id);
1292+
liquidity_source.handle_payment_forwarded(next_channel_id).await;
12861293
}
12871294

12881295
let event = Event::PaymentForwarded {
@@ -1375,11 +1382,9 @@ where
13751382
);
13761383

13771384
if let Some(liquidity_source) = self.liquidity_source.as_ref() {
1378-
liquidity_source.handle_channel_ready(
1379-
user_channel_id,
1380-
&channel_id,
1381-
&counterparty_node_id,
1382-
);
1385+
liquidity_source
1386+
.handle_channel_ready(user_channel_id, &channel_id, &counterparty_node_id)
1387+
.await;
13831388
}
13841389

13851390
let event = Event::ChannelReady {
@@ -1428,12 +1433,14 @@ where
14281433
..
14291434
} => {
14301435
if let Some(liquidity_source) = self.liquidity_source.as_ref() {
1431-
liquidity_source.handle_htlc_intercepted(
1432-
requested_next_hop_scid,
1433-
intercept_id,
1434-
expected_outbound_amount_msat,
1435-
payment_hash,
1436-
);
1436+
liquidity_source
1437+
.handle_htlc_intercepted(
1438+
requested_next_hop_scid,
1439+
intercept_id,
1440+
expected_outbound_amount_msat,
1441+
payment_hash,
1442+
)
1443+
.await;
14371444
}
14381445
},
14391446
LdkEvent::InvoiceReceived { .. } => {

0 commit comments

Comments
 (0)