Skip to content

Commit 98d2148

Browse files
authored
Merge pull request #651 from tnull/2025-09-fix-lazy-remove
Account for `Arc`s and `lazy` being dropped
2 parents e4bb615 + 9ec89fe commit 98d2148

File tree

12 files changed

+74
-68
lines changed

12 files changed

+74
-68
lines changed

Cargo.toml

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -52,29 +52,29 @@ 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 = "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" }
66-
67-
#lightning = { path = "../rust-lightning/lightning", features = ["std"] }
68-
#lightning-types = { path = "../rust-lightning/lightning-types" }
69-
#lightning-invoice = { path = "../rust-lightning/lightning-invoice", features = ["std"] }
70-
#lightning-net-tokio = { path = "../rust-lightning/lightning-net-tokio" }
71-
#lightning-persister = { path = "../rust-lightning/lightning-persister", features = ["tokio"] }
72-
#lightning-background-processor = { path = "../rust-lightning/lightning-background-processor" }
73-
#lightning-rapid-gossip-sync = { path = "../rust-lightning/lightning-rapid-gossip-sync" }
74-
#lightning-block-sync = { path = "../rust-lightning/lightning-block-sync", features = ["rest-client", "rpc-client", "tokio"] }
75-
#lightning-transaction-sync = { path = "../rust-lightning/lightning-transaction-sync", features = ["esplora-async-https", "electrum-rustls-ring", "time"] }
76-
#lightning-liquidity = { path = "../rust-lightning/lightning-liquidity", features = ["std"] }
77-
#lightning-macros = { path = "../rust-lightning/lightning-macros" }
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" }
66+
67+
lightning = { path = "../rust-lightning/lightning", features = ["std"] }
68+
lightning-types = { path = "../rust-lightning/lightning-types" }
69+
lightning-invoice = { path = "../rust-lightning/lightning-invoice", features = ["std"] }
70+
lightning-net-tokio = { path = "../rust-lightning/lightning-net-tokio" }
71+
lightning-persister = { path = "../rust-lightning/lightning-persister", features = ["tokio"] }
72+
lightning-background-processor = { path = "../rust-lightning/lightning-background-processor" }
73+
lightning-rapid-gossip-sync = { path = "../rust-lightning/lightning-rapid-gossip-sync" }
74+
lightning-block-sync = { path = "../rust-lightning/lightning-block-sync", features = ["rest-client", "rpc-client", "tokio"] }
75+
lightning-transaction-sync = { path = "../rust-lightning/lightning-transaction-sync", features = ["esplora-async-https", "electrum-rustls-ring", "time"] }
76+
lightning-liquidity = { path = "../rust-lightning/lightning-liquidity", features = ["std"] }
77+
lightning-macros = { path = "../rust-lightning/lightning-macros" }
7878

7979
bdk_chain = { version = "0.23.0", default-features = false, features = ["std"] }
8080
bdk_esplora = { version = "0.22.0", default-features = false, features = ["async-https-rustls", "tokio"]}
@@ -109,8 +109,8 @@ 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 = "d0765847c85f1c3dc753c17c3e05dbcb1d300204", features = ["std", "_test_utils"] }
113-
#lightning = { path = "../rust-lightning/lightning", features = ["std", "_test_utils"] }
112+
#lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "d0765847c85f1c3dc753c17c3e05dbcb1d300204", features = ["std", "_test_utils"] }
113+
lightning = { path = "../rust-lightning/lightning", features = ["std", "_test_utils"] }
114114
proptest = "1.0.0"
115115
regex = "1.5.6"
116116

src/builder.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,6 +1557,7 @@ fn build_with_store_internal(
15571557
Arc::clone(&channel_manager),
15581558
Arc::clone(&keys_manager),
15591559
Arc::clone(&chain_source),
1560+
Arc::clone(&tx_broadcaster),
15601561
Arc::clone(&kv_store),
15611562
Arc::clone(&config),
15621563
Arc::clone(&logger),

src/data_store.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ where
103103
&self.primary_namespace,
104104
&self.secondary_namespace,
105105
&store_key,
106-
false,
107106
)
108107
.map_err(|e| {
109108
log_error!(

src/event.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1289,7 +1289,16 @@ where
12891289
}
12901290

12911291
if let Some(liquidity_source) = self.liquidity_source.as_ref() {
1292-
liquidity_source.handle_payment_forwarded(next_channel_id).await;
1292+
if let Some(skimmed_fee_msat) = skimmed_fee_msat {
1293+
liquidity_source
1294+
.handle_payment_forwarded(next_channel_id, skimmed_fee_msat)
1295+
.await;
1296+
} else {
1297+
debug_assert!(
1298+
false,
1299+
"We expect skimmed_fee_msat to be set since LDK 0.0.122"
1300+
);
1301+
}
12931302
}
12941303

12951304
let event = Event::PaymentForwarded {

src/io/sqlite_store/mod.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ impl KVStore for SqliteStore {
137137
}
138138

139139
fn remove(
140-
&self, primary_namespace: &str, secondary_namespace: &str, key: &str, lazy: bool,
140+
&self, primary_namespace: &str, secondary_namespace: &str, key: &str,
141141
) -> Pin<Box<dyn Future<Output = Result<(), io::Error>> + Send>> {
142142
let locking_key = self.build_locking_key(primary_namespace, secondary_namespace, key);
143143
let (inner_lock_ref, version) = self.get_new_version_and_lock_ref(locking_key.clone());
@@ -153,7 +153,6 @@ impl KVStore for SqliteStore {
153153
&primary_namespace,
154154
&secondary_namespace,
155155
&key,
156-
lazy,
157156
)
158157
});
159158
Box::pin(async move {
@@ -206,7 +205,7 @@ impl KVStoreSync for SqliteStore {
206205
}
207206

208207
fn remove(
209-
&self, primary_namespace: &str, secondary_namespace: &str, key: &str, lazy: bool,
208+
&self, primary_namespace: &str, secondary_namespace: &str, key: &str,
210209
) -> io::Result<()> {
211210
let locking_key = self.build_locking_key(primary_namespace, secondary_namespace, key);
212211
let (inner_lock_ref, version) = self.get_new_version_and_lock_ref(locking_key.clone());
@@ -217,7 +216,6 @@ impl KVStoreSync for SqliteStore {
217216
primary_namespace,
218217
secondary_namespace,
219218
key,
220-
lazy,
221219
)
222220
}
223221

@@ -402,7 +400,7 @@ impl SqliteStoreInner {
402400

403401
fn remove_internal(
404402
&self, inner_lock_ref: Arc<Mutex<u64>>, locking_key: String, version: u64,
405-
primary_namespace: &str, secondary_namespace: &str, key: &str, _lazy: bool,
403+
primary_namespace: &str, secondary_namespace: &str, key: &str,
406404
) -> io::Result<()> {
407405
check_namespace_key_validity(primary_namespace, secondary_namespace, Some(key), "remove")?;
408406

src/io/test_utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub(crate) fn do_read_write_remove_list_persist<K: KVStoreSync + RefUnwindSafe>(
5555
let read_data = kv_store.read(primary_namespace, secondary_namespace, key).unwrap();
5656
assert_eq!(data, &*read_data);
5757

58-
kv_store.remove(primary_namespace, secondary_namespace, key, false).unwrap();
58+
kv_store.remove(primary_namespace, secondary_namespace, key).unwrap();
5959

6060
let listed_keys = kv_store.list(primary_namespace, secondary_namespace).unwrap();
6161
assert_eq!(listed_keys.len(), 0);
@@ -71,7 +71,7 @@ pub(crate) fn do_read_write_remove_list_persist<K: KVStoreSync + RefUnwindSafe>(
7171
let read_data = kv_store.read(&max_chars, &max_chars, &max_chars).unwrap();
7272
assert_eq!(data, &*read_data);
7373

74-
kv_store.remove(&max_chars, &max_chars, &max_chars, false).unwrap();
74+
kv_store.remove(&max_chars, &max_chars, &max_chars).unwrap();
7575

7676
let listed_keys = kv_store.list(&max_chars, &max_chars).unwrap();
7777
assert_eq!(listed_keys.len(), 0);

src/io/utils.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ use lightning::util::persist::{
3232
SCORER_PERSISTENCE_SECONDARY_NAMESPACE,
3333
};
3434
use lightning::util::ser::{Readable, ReadableArgs, Writeable};
35-
use lightning::util::sweep::OutputSweeper;
3635
use lightning_types::string::PrintableString;
3736
use rand::{thread_rng, RngCore};
3837

@@ -256,10 +255,11 @@ pub(crate) fn read_output_sweeper(
256255
kv_store,
257256
logger.clone(),
258257
);
259-
OutputSweeper::read(&mut reader, args).map_err(|e| {
258+
let (_, sweeper) = <(_, Sweeper)>::read(&mut reader, args).map_err(|e| {
260259
log_error!(logger, "Failed to deserialize OutputSweeper: {}", e);
261260
std::io::Error::new(std::io::ErrorKind::InvalidData, "Failed to deserialize OutputSweeper")
262-
})
261+
})?;
262+
Ok(sweeper)
263263
}
264264

265265
pub(crate) fn read_node_metrics<L: Deref>(

src/io/vss_store.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ impl KVStoreSync for VssStore {
116116
}
117117

118118
fn remove(
119-
&self, primary_namespace: &str, secondary_namespace: &str, key: &str, lazy: bool,
119+
&self, primary_namespace: &str, secondary_namespace: &str, key: &str,
120120
) -> io::Result<()> {
121121
let locking_key = self.build_locking_key(primary_namespace, secondary_namespace, key);
122122
let (inner_lock_ref, version) = self.get_new_version_and_lock_ref(locking_key.clone());
@@ -127,7 +127,6 @@ impl KVStoreSync for VssStore {
127127
primary_namespace,
128128
secondary_namespace,
129129
key,
130-
lazy,
131130
);
132131
self.runtime.block_on(fut)
133132
}
@@ -174,7 +173,7 @@ impl KVStore for VssStore {
174173
})
175174
}
176175
fn remove(
177-
&self, primary_namespace: &str, secondary_namespace: &str, key: &str, lazy: bool,
176+
&self, primary_namespace: &str, secondary_namespace: &str, key: &str,
178177
) -> Pin<Box<dyn Future<Output = Result<(), io::Error>> + Send>> {
179178
let locking_key = self.build_locking_key(primary_namespace, secondary_namespace, key);
180179
let (inner_lock_ref, version) = self.get_new_version_and_lock_ref(locking_key.clone());
@@ -191,7 +190,6 @@ impl KVStore for VssStore {
191190
&primary_namespace,
192191
&secondary_namespace,
193192
&key,
194-
lazy,
195193
)
196194
.await
197195
})
@@ -369,7 +367,7 @@ impl VssStoreInner {
369367

370368
async fn remove_internal(
371369
&self, inner_lock_ref: Arc<tokio::sync::Mutex<u64>>, locking_key: String, version: u64,
372-
primary_namespace: &str, secondary_namespace: &str, key: &str, _lazy: bool,
370+
primary_namespace: &str, secondary_namespace: &str, key: &str,
373371
) -> io::Result<()> {
374372
check_namespace_key_validity(primary_namespace, secondary_namespace, Some(key), "remove")?;
375373

src/liquidity.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ use crate::chain::ChainSource;
4343
use crate::connection::ConnectionManager;
4444
use crate::logger::{log_debug, log_error, log_info, LdkLogger, Logger};
4545
use crate::runtime::Runtime;
46-
use crate::types::{ChannelManager, DynStore, KeysManager, LiquidityManager, PeerManager, Wallet};
46+
use crate::types::{
47+
Broadcaster, ChannelManager, DynStore, KeysManager, LiquidityManager, PeerManager, Wallet,
48+
};
4749
use crate::{total_anchor_channels_reserve_sats, Config, Error};
4850

4951
const LIQUIDITY_REQUEST_TIMEOUT_SECS: u64 = 5;
@@ -141,6 +143,7 @@ where
141143
channel_manager: Arc<ChannelManager>,
142144
keys_manager: Arc<KeysManager>,
143145
chain_source: Arc<ChainSource>,
146+
tx_broadcaster: Arc<Broadcaster>,
144147
kv_store: Arc<DynStore>,
145148
config: Arc<Config>,
146149
logger: L,
@@ -152,7 +155,8 @@ where
152155
{
153156
pub(crate) fn new(
154157
wallet: Arc<Wallet>, channel_manager: Arc<ChannelManager>, keys_manager: Arc<KeysManager>,
155-
chain_source: Arc<ChainSource>, kv_store: Arc<DynStore>, config: Arc<Config>, logger: L,
158+
chain_source: Arc<ChainSource>, tx_broadcaster: Arc<Broadcaster>, kv_store: Arc<DynStore>,
159+
config: Arc<Config>, logger: L,
156160
) -> Self {
157161
let lsps1_client = None;
158162
let lsps2_client = None;
@@ -165,6 +169,7 @@ where
165169
channel_manager,
166170
keys_manager,
167171
chain_source,
172+
tx_broadcaster,
168173
kv_store,
169174
config,
170175
logger,
@@ -241,6 +246,7 @@ where
241246
Some(Arc::clone(&self.chain_source)),
242247
None,
243248
Arc::clone(&self.kv_store),
249+
Arc::clone(&self.tx_broadcaster),
244250
liquidity_service_config,
245251
liquidity_client_config,
246252
)
@@ -1302,10 +1308,14 @@ where
13021308
}
13031309
}
13041310

1305-
pub(crate) async fn handle_payment_forwarded(&self, next_channel_id: Option<ChannelId>) {
1311+
pub(crate) async fn handle_payment_forwarded(
1312+
&self, next_channel_id: Option<ChannelId>, skimmed_fee_msat: u64,
1313+
) {
13061314
if let Some(next_channel_id) = next_channel_id {
13071315
if let Some(lsps2_service_handler) = self.liquidity_manager.lsps2_service_handler() {
1308-
if let Err(e) = lsps2_service_handler.payment_forwarded(next_channel_id).await {
1316+
if let Err(e) =
1317+
lsps2_service_handler.payment_forwarded(next_channel_id, skimmed_fee_msat).await
1318+
{
13091319
log_error!(
13101320
self.logger,
13111321
"LSPS2 service failed to handle PaymentForwarded: {:?}",

src/types.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ pub(crate) type LiquidityManager = lightning_liquidity::LiquidityManager<
7676
Arc<ChannelManager>,
7777
Arc<ChainSource>,
7878
Arc<DynStore>,
79-
Arc<DefaultTimeProvider>,
79+
DefaultTimeProvider,
80+
Arc<Broadcaster>,
8081
>;
8182

8283
pub(crate) type ChannelManager = lightning::ln::channelmanager::ChannelManager<

0 commit comments

Comments
 (0)