Skip to content

Update probes_for_diversity to test datapoint time updating #3713

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions lightning/src/routing/scoring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1556,6 +1556,7 @@ DirectedChannelLiquidity<L, HT, T> {
chan_descr, existing_max_msat, amount_msat);
}
self.update_history_buckets(0, duration_since_epoch);
*self.last_datapoint_time = duration_since_epoch;
}

/// Adjusts the channel liquidity balance bounds when failing to route `amount_msat` downstream.
Expand All @@ -1571,6 +1572,7 @@ DirectedChannelLiquidity<L, HT, T> {
chan_descr, existing_min_msat, amount_msat);
}
self.update_history_buckets(0, duration_since_epoch);
*self.last_datapoint_time = duration_since_epoch;
}

/// Adjusts the channel liquidity balance bounds when successfully routing `amount_msat`.
Expand All @@ -1580,6 +1582,7 @@ DirectedChannelLiquidity<L, HT, T> {
let max_liquidity_msat = self.max_liquidity_msat().checked_sub(amount_msat).unwrap_or(0);
log_debug!(logger, "Subtracting {} from max liquidity of {} (setting it to {})", amount_msat, chan_descr, max_liquidity_msat);
self.set_max_liquidity_msat(max_liquidity_msat, duration_since_epoch);
*self.last_datapoint_time = duration_since_epoch;
self.update_history_buckets(amount_msat, duration_since_epoch);
}

Expand All @@ -1603,7 +1606,6 @@ DirectedChannelLiquidity<L, HT, T> {
*self.max_liquidity_offset_msat = 0;
}
*self.last_updated = duration_since_epoch;
*self.last_datapoint_time = duration_since_epoch;
}

/// Adjusts the upper bound of the channel liquidity balance in this direction.
Expand All @@ -1613,7 +1615,6 @@ DirectedChannelLiquidity<L, HT, T> {
*self.min_liquidity_offset_msat = 0;
}
*self.last_updated = duration_since_epoch;
*self.last_datapoint_time = duration_since_epoch;
}
}

Expand Down Expand Up @@ -4139,21 +4140,24 @@ mod tests {
short_channel_id: 42,
});

// Apply some update to set the last-update time to now
scorer.payment_path_failed(&payment_path_for_amount(1000), 42, Duration::ZERO);
// Initialize the state for channel 42
scorer.payment_path_failed(&payment_path_for_amount(500), 42, Duration::ZERO);

// Apply an update to set the last-update time to 1 second
scorer.payment_path_failed(&payment_path_for_amount(500), 42, Duration::from_secs(1));

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

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

scorer.time_passed(Duration::from_secs(2));
scorer.time_passed(Duration::from_secs(3));
assert_eq!(scorer.channel_penalty_msat(&candidate, usage, &params), 999_953);

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