Skip to content

Commit 1923c1b

Browse files
committed
Update probes_for_diversity to test datapoint time updating
It turns out `probes_for_diversity` wasn't actually testing that the datapoint update time logic worked as it was indicating a payment failed while trying to fully saturate a channel (which teaches us nothing). Instead, we need to "send" less over the channel and update twice to get the channel last-update-time logic tested.
1 parent a245ca7 commit 1923c1b

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

lightning/src/routing/scoring.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4139,21 +4139,24 @@ mod tests {
41394139
short_channel_id: 42,
41404140
});
41414141

4142-
// Apply some update to set the last-update time to now
4143-
scorer.payment_path_failed(&payment_path_for_amount(1000), 42, Duration::ZERO);
4142+
// Initialize the state for channel 42
4143+
scorer.payment_path_failed(&payment_path_for_amount(500), 42, Duration::ZERO);
4144+
4145+
// Apply an update to set the last-update time to 1 second
4146+
scorer.payment_path_failed(&payment_path_for_amount(490), 42, Duration::from_secs(1));
41444147

41454148
// If no time has passed, we get the full probing_diversity_penalty_msat
41464149
assert_eq!(scorer.channel_penalty_msat(&candidate, usage, &params), 1_000_000);
41474150

41484151
// As time passes the penalty decreases.
4149-
scorer.time_passed(Duration::from_secs(1));
4152+
scorer.time_passed(Duration::from_secs(2));
41504153
assert_eq!(scorer.channel_penalty_msat(&candidate, usage, &params), 999_976);
41514154

4152-
scorer.time_passed(Duration::from_secs(2));
4155+
scorer.time_passed(Duration::from_secs(3));
41534156
assert_eq!(scorer.channel_penalty_msat(&candidate, usage, &params), 999_953);
41544157

41554158
// Once we've gotten halfway through the day our penalty is 1/4 the configured value.
4156-
scorer.time_passed(Duration::from_secs(86400/2));
4159+
scorer.time_passed(Duration::from_secs(86400/2 + 1));
41574160
assert_eq!(scorer.channel_penalty_msat(&candidate, usage, &params), 250_000);
41584161
}
41594162
}

0 commit comments

Comments
 (0)