Skip to content

Commit a70953d

Browse files
committed
Add logging the probe handlers
Increae timeout of probing tests
1 parent 8963702 commit a70953d

2 files changed

Lines changed: 40 additions & 17 deletions

File tree

src/probing.rs

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,14 @@ pub struct Prober {
513513
pub(crate) locked_msat: Arc<AtomicU64>,
514514
}
515515

516+
fn fmt_path(path: &lightning::routing::router::Path) -> String {
517+
path.hops
518+
.iter()
519+
.map(|h| format!("{}(scid={})", h.pubkey, h.short_channel_id))
520+
.collect::<Vec<_>>()
521+
.join(" -> ")
522+
}
523+
516524
impl Prober {
517525
/// Returns the total millisatoshis currently locked in in-flight probes.
518526
pub fn locked_msat(&self) -> u64 {
@@ -521,16 +529,34 @@ impl Prober {
521529

522530
pub(crate) fn handle_probe_successful(&self, path: &lightning::routing::router::Path) {
523531
let amount: u64 = path.hops.iter().map(|h| h.fee_msat).sum();
524-
let _ = self
532+
let prev = self
525533
.locked_msat
526-
.fetch_update(Ordering::AcqRel, Ordering::Acquire, |v| Some(v.saturating_sub(amount)));
534+
.fetch_update(Ordering::AcqRel, Ordering::Acquire, |v| Some(v.saturating_sub(amount)))
535+
.unwrap_or(0);
536+
log_debug!(
537+
self.logger,
538+
"Probe successful: released {} msat (locked_msat {} -> {}), path: {}",
539+
amount,
540+
prev,
541+
prev.saturating_sub(amount),
542+
fmt_path(path)
543+
);
527544
}
528545

529546
pub(crate) fn handle_probe_failed(&self, path: &lightning::routing::router::Path) {
530547
let amount: u64 = path.hops.iter().map(|h| h.fee_msat).sum();
531-
let _ = self
548+
let prev = self
532549
.locked_msat
533-
.fetch_update(Ordering::AcqRel, Ordering::Acquire, |v| Some(v.saturating_sub(amount)));
550+
.fetch_update(Ordering::AcqRel, Ordering::Acquire, |v| Some(v.saturating_sub(amount)))
551+
.unwrap_or(0);
552+
log_debug!(
553+
self.logger,
554+
"Probe failed: released {} msat (locked_msat {} -> {}), path: {}",
555+
amount,
556+
prev,
557+
prev.saturating_sub(amount),
558+
fmt_path(path)
559+
);
534560
}
535561
}
536562

tests/probing_tests.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ async fn probe_budget_increments_and_decrements() {
291291
tokio::time::sleep(Duration::from_secs(3)).await;
292292
strategy.start_probing();
293293

294-
let went_up = tokio::time::timeout(Duration::from_secs(10), async {
294+
let went_up = tokio::time::timeout(Duration::from_secs(30), async {
295295
loop {
296296
if node_a.prober().map_or(0, |p| p.locked_msat()) > 0 {
297297
break;
@@ -304,7 +304,7 @@ async fn probe_budget_increments_and_decrements() {
304304
assert!(went_up, "locked_msat never increased — no probe was dispatched");
305305
println!("First probe dispatched; locked_msat = {}", node_a.prober().unwrap().locked_msat());
306306

307-
let cleared = tokio::time::timeout(Duration::from_secs(20), async {
307+
let cleared = tokio::time::timeout(Duration::from_secs(30), async {
308308
loop {
309309
if node_a.prober().map_or(1, |p| p.locked_msat()) == 0 {
310310
break;
@@ -315,7 +315,6 @@ async fn probe_budget_increments_and_decrements() {
315315
.await
316316
.is_ok();
317317
assert!(cleared, "locked_msat never returned to zero after probe resolved");
318-
println!("Probe resolved; locked_msat = 0");
319318

320319
node_a.stop().unwrap();
321320
node_b.stop().unwrap();
@@ -335,12 +334,11 @@ async fn exhausted_probe_budget_blocks_new_probes() {
335334
let node_b = setup_node(&chain_source, random_config(false));
336335
let node_c = setup_node(&chain_source, random_config(false));
337336

338-
// Use a slow probing interval so we can read capacity before the first probe fires.
339337
let mut config_a = random_config(false);
340338
let strategy = FixedDestStrategy::new(node_c.node_id(), PROBE_AMOUNT_MSAT);
341339
config_a.probing = Some(
342340
ProbingConfig::custom(strategy.clone())
343-
.interval(Duration::from_secs(10))
341+
.interval(Duration::from_millis(PROBING_INTERVAL_MILLISECONDS))
344342
.max_locked_msat(PROBE_AMOUNT_MSAT)
345343
.build(),
346344
);
@@ -373,7 +371,6 @@ async fn exhausted_probe_budget_blocks_new_probes() {
373371
expect_event!(node_b, ChannelReady);
374372
expect_event!(node_c, ChannelReady);
375373

376-
// Record capacity before the first probe fires (interval is 3s, so we have time).
377374
let capacity_at_open = node_a
378375
.list_channels()
379376
.iter()
@@ -382,10 +379,12 @@ async fn exhausted_probe_budget_blocks_new_probes() {
382379
.expect("A→B channel not found");
383380

384381
assert_eq!(node_a.prober().map_or(1, |p| p.locked_msat()), 0, "initial locked_msat is nonzero");
382+
383+
tokio::time::sleep(Duration::from_secs(3)).await;
385384
strategy.start_probing();
386385

387-
// Give gossip time to propagate to A, then wait for the first probe.
388-
let locked = tokio::time::timeout(Duration::from_secs(15), async {
386+
// Wait for the first probe to be in-flight.
387+
let locked = tokio::time::timeout(Duration::from_secs(30), async {
389388
loop {
390389
if node_a.prober().map_or(0, |p| p.locked_msat()) > 0 {
391390
break;
@@ -395,7 +394,7 @@ async fn exhausted_probe_budget_blocks_new_probes() {
395394
})
396395
.await
397396
.is_ok();
398-
assert!(locked, "no probe dispatched within 15 s");
397+
assert!(locked, "no probe dispatched within 30 s");
399398

400399
// Capacity should have decreased due to the in-flight probe HTLC.
401400
let capacity_with_probe = node_a
@@ -412,8 +411,6 @@ async fn exhausted_probe_budget_blocks_new_probes() {
412411
// Stop B while the probe HTLC is in-flight.
413412
node_b.stop().unwrap();
414413

415-
// Let several Prober ticks fire (interval is 3s); the budget is exhausted so
416-
// they must be skipped. Wait, then check both conditions at once.
417414
tokio::time::sleep(Duration::from_secs(5)).await;
418415
assert!(
419416
node_a.prober().map_or(0, |p| p.locked_msat()) > 0,
@@ -438,7 +435,7 @@ async fn exhausted_probe_budget_blocks_new_probes() {
438435
node_b.connect(node_a.node_id(), node_a_addr, false).unwrap();
439436
node_b.connect(node_c.node_id(), node_c_addr, false).unwrap();
440437

441-
let cleared = tokio::time::timeout(Duration::from_secs(15), async {
438+
let cleared = tokio::time::timeout(Duration::from_secs(30), async {
442439
loop {
443440
if node_a.prober().map_or(1, |p| p.locked_msat()) == 0 {
444441
break;
@@ -451,7 +448,7 @@ async fn exhausted_probe_budget_blocks_new_probes() {
451448
assert!(cleared, "locked_msat never cleared after B came back online");
452449

453450
// Once the budget is freed, a new probe should be dispatched within a few ticks.
454-
let new_probe = tokio::time::timeout(Duration::from_secs(10), async {
451+
let new_probe = tokio::time::timeout(Duration::from_secs(30), async {
455452
loop {
456453
if node_a.prober().map_or(0, |p| p.locked_msat()) > 0 {
457454
break;

0 commit comments

Comments
 (0)