Skip to content

Commit 23f6a43

Browse files
joostjagerclaude
andcommitted
Switch to chain monitor deferred writes mode
Patch LDK dependencies to use the chain-mon-internal-deferred-writes branch and enable deferred writes by passing `true` to the ChainMonitor constructor. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 7ad0d63 commit 23f6a43

4 files changed

Lines changed: 27 additions & 13 deletions

File tree

Cargo.toml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -170,15 +170,15 @@ harness = false
170170
#vss-client-ng = { path = "../vss-client" }
171171
#vss-client-ng = { git = "https://github.com/lightningdevkit/vss-client", branch = "main" }
172172
#
173-
#[patch."https://github.com/lightningdevkit/rust-lightning"]
174-
#lightning = { path = "../rust-lightning/lightning" }
175-
#lightning-types = { path = "../rust-lightning/lightning-types" }
176-
#lightning-invoice = { path = "../rust-lightning/lightning-invoice" }
177-
#lightning-net-tokio = { path = "../rust-lightning/lightning-net-tokio" }
178-
#lightning-persister = { path = "../rust-lightning/lightning-persister" }
179-
#lightning-background-processor = { path = "../rust-lightning/lightning-background-processor" }
180-
#lightning-rapid-gossip-sync = { path = "../rust-lightning/lightning-rapid-gossip-sync" }
181-
#lightning-block-sync = { path = "../rust-lightning/lightning-block-sync" }
182-
#lightning-transaction-sync = { path = "../rust-lightning/lightning-transaction-sync" }
183-
#lightning-liquidity = { path = "../rust-lightning/lightning-liquidity" }
184-
#lightning-macros = { path = "../rust-lightning/lightning-macros" }
173+
[patch."https://github.com/lightningdevkit/rust-lightning"]
174+
lightning = { git = "https://github.com/joostjager/rust-lightning", branch = "chain-mon-internal-deferred-writes-ldk-node-based" }
175+
lightning-types = { git = "https://github.com/joostjager/rust-lightning", branch = "chain-mon-internal-deferred-writes-ldk-node-based" }
176+
lightning-invoice = { git = "https://github.com/joostjager/rust-lightning", branch = "chain-mon-internal-deferred-writes-ldk-node-based" }
177+
lightning-net-tokio = { git = "https://github.com/joostjager/rust-lightning", branch = "chain-mon-internal-deferred-writes-ldk-node-based" }
178+
lightning-persister = { git = "https://github.com/joostjager/rust-lightning", branch = "chain-mon-internal-deferred-writes-ldk-node-based" }
179+
lightning-background-processor = { git = "https://github.com/joostjager/rust-lightning", branch = "chain-mon-internal-deferred-writes-ldk-node-based" }
180+
lightning-rapid-gossip-sync = { git = "https://github.com/joostjager/rust-lightning", branch = "chain-mon-internal-deferred-writes-ldk-node-based" }
181+
lightning-block-sync = { git = "https://github.com/joostjager/rust-lightning", branch = "chain-mon-internal-deferred-writes-ldk-node-based" }
182+
lightning-transaction-sync = { git = "https://github.com/joostjager/rust-lightning", branch = "chain-mon-internal-deferred-writes-ldk-node-based" }
183+
lightning-liquidity = { git = "https://github.com/joostjager/rust-lightning", branch = "chain-mon-internal-deferred-writes-ldk-node-based" }
184+
lightning-macros = { git = "https://github.com/joostjager/rust-lightning", branch = "chain-mon-internal-deferred-writes-ldk-node-based" }

src/builder.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,6 +1370,7 @@ fn build_with_store_internal(
13701370
Arc::clone(&persister),
13711371
Arc::clone(&keys_manager),
13721372
peer_storage_key,
1373+
true,
13731374
));
13741375

13751376
// Initialize the network graph, scorer, and router

src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,12 @@ impl Node {
761761
}
762762
}
763763

764+
/// Returns the number of pending deferred chain monitor operations that have not
765+
/// been flushed yet by the background processor.
766+
pub fn pending_monitor_operation_count(&self) -> usize {
767+
self.chain_monitor.pending_operation_count()
768+
}
769+
764770
/// Returns the config with which the [`Node`] was initialized.
765771
pub fn config(&self) -> Config {
766772
self.config.as_ref().clone()

tests/common/mod.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1211,8 +1211,15 @@ pub(crate) async fn do_channel_full_cycle<E: ElectrumApi>(
12111211
);
12121212

12131213
println!("\nB close_channel (force: {})", force_close);
1214+
// Wait for the background processor to flush deferred monitor writes so that
1215+
// the channel state no longer has monitor_update_in_progress set.
1216+
exponential_backoff_poll(|| {
1217+
(node_a.pending_monitor_operation_count() == 0
1218+
&& node_b.pending_monitor_operation_count() == 0)
1219+
.then_some(())
1220+
})
1221+
.await;
12141222
if force_close {
1215-
tokio::time::sleep(Duration::from_secs(1)).await;
12161223
node_a.force_close_channel(&user_channel_id_a, node_b.node_id(), None).unwrap();
12171224
} else {
12181225
node_a.close_channel(&user_channel_id_a, node_b.node_id()).unwrap();

0 commit comments

Comments
 (0)