Skip to content

Commit 6e06fab

Browse files
committed
Wait for channel readiness in probing tests
1 parent 8791583 commit 6e06fab

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
@@ -695,6 +695,37 @@ pub(crate) async fn wait_for_outpoint_spend<E: ElectrumApi>(electrs: &E, outpoin
695695
.await;
696696
}
697697

698+
/// Polls the channel from `source_node` to `counterparty_node` until it reports `is_usable`
699+
/// and can carry an HTLC of `min_amount_msat` from `source_node`'s side.
700+
///
701+
/// After `ChannelReady`, channel-monitor persistence can lag for tens of seconds on slow
702+
/// CI runners; during that window `send_probe`/`send_payment` reject with
703+
/// `ParameterError("...monitor update is in progress...")`. This helper gives tests a
704+
/// deterministic readiness gate instead of racing the monitor-update pipeline.
705+
pub(crate) async fn wait_for_channel_ready_to_send(
706+
source_node: &TestNode, counterparty_node: &TestNode, min_amount_msat: u64,
707+
) {
708+
let counterparty = counterparty_node.node_id();
709+
let deadline = tokio::time::Instant::now() + Duration::from_secs(180);
710+
while tokio::time::Instant::now() < deadline {
711+
let ready = source_node.list_channels().iter().any(|c| {
712+
c.counterparty_node_id == counterparty
713+
&& c.is_usable
714+
&& c.next_outbound_htlc_limit_msat >= min_amount_msat
715+
});
716+
if ready {
717+
return;
718+
}
719+
tokio::time::sleep(Duration::from_millis(100)).await;
720+
}
721+
panic!(
722+
"channel from {} to {} not ready to send {} msat within 180s",
723+
source_node.node_id(),
724+
counterparty,
725+
min_amount_msat,
726+
);
727+
}
728+
698729
pub(crate) async fn exponential_backoff_poll<T, F>(mut poll: F) -> T
699730
where
700731
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)