Skip to content

Commit 5e77f88

Browse files
committed
Wait for channel readiness in probing tests
1 parent 8acd55d commit 5e77f88

2 files changed

Lines changed: 37 additions & 3 deletions

File tree

tests/common/mod.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,37 @@ pub(crate) async fn wait_for_outpoint_spend<E: ElectrumApi>(electrs: &E, outpoin
610610
.await;
611611
}
612612

613+
/// Polls the channel from `source_node` to `counterparty_node` until it reports `is_usable`
614+
/// and can carry an HTLC of `min_amount_msat` from `source_node`'s side.
615+
///
616+
/// After `ChannelReady`, channel-monitor persistence can lag for tens of seconds on slow
617+
/// CI runners; during that window `send_probe`/`send_payment` reject with
618+
/// `ParameterError("...monitor update is in progress...")`. This helper gives tests a
619+
/// deterministic readiness gate instead of racing the monitor-update pipeline.
620+
pub(crate) async fn wait_for_channel_ready_to_send(
621+
source_node: &TestNode, counterparty_node: &TestNode, min_amount_msat: u64,
622+
) {
623+
let counterparty = counterparty_node.node_id();
624+
let deadline = tokio::time::Instant::now() + Duration::from_secs(180);
625+
while tokio::time::Instant::now() < deadline {
626+
let ready = source_node.list_channels().iter().any(|c| {
627+
c.counterparty_node_id == counterparty
628+
&& c.is_usable
629+
&& c.next_outbound_htlc_limit_msat >= min_amount_msat
630+
});
631+
if ready {
632+
return;
633+
}
634+
tokio::time::sleep(Duration::from_millis(100)).await;
635+
}
636+
panic!(
637+
"channel from {} to {} not ready to send {} msat within 180s",
638+
source_node.node_id(),
639+
counterparty,
640+
min_amount_msat,
641+
);
642+
}
643+
613644
pub(crate) async fn exponential_backoff_poll<T, F>(mut poll: F) -> T
614645
where
615646
F: FnMut() -> Option<T>,

tests/probing_tests.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use std::sync::atomic::{AtomicBool, Ordering};
1616
use common::{
1717
expect_channel_ready_event, expect_event, generate_blocks_and_wait, open_channel,
1818
premine_and_distribute_funds, random_chain_source, random_config, setup_bitcoind_and_electrsd,
19-
setup_node, TestNode,
19+
setup_node, wait_for_channel_ready_to_send, TestNode,
2020
};
2121

2222
use ldk_node::bitcoin::Amount;
@@ -159,7 +159,9 @@ async fn probe_budget_increments_and_decrements() {
159159

160160
// Build the probe path now that channels are ready, then enable probing.
161161
strategy.set_path(build_probe_path(&node_a, &node_b, &node_c, PROBE_AMOUNT_MSAT));
162-
tokio::time::sleep(Duration::from_secs(3)).await;
162+
// First hop carries amount + per-hop fee; second hop carries just amount.
163+
wait_for_channel_ready_to_send(&node_a, &node_b, PROBE_AMOUNT_MSAT + 1000).await;
164+
wait_for_channel_ready_to_send(&node_b, &node_c, PROBE_AMOUNT_MSAT).await;
163165
strategy.start_probing();
164166

165167
let went_up = tokio::time::timeout(Duration::from_secs(30), async {
@@ -243,7 +245,8 @@ async fn exhausted_probe_budget_blocks_new_probes() {
243245
assert_eq!(node_a.prober().map_or(1, |p| p.locked_msat()), 0, "initial locked_msat is nonzero");
244246

245247
strategy.set_path(build_probe_path(&node_a, &node_b, &node_c, PROBE_AMOUNT_MSAT));
246-
tokio::time::sleep(Duration::from_secs(3)).await;
248+
wait_for_channel_ready_to_send(&node_a, &node_b, PROBE_AMOUNT_MSAT + 1000).await;
249+
wait_for_channel_ready_to_send(&node_b, &node_c, PROBE_AMOUNT_MSAT).await;
247250
strategy.start_probing();
248251

249252
// Sample locked_msat across multiple probe cycles and assert the budget cap is never exceeded

0 commit comments

Comments
 (0)