Skip to content

Commit 42243e8

Browse files
Change abs_diff to duration_since, so it returns a Duration
1 parent 7c5491d commit 42243e8

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

lightning-liquidity/src/lsps0/ser.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,10 @@ impl LSPSDateTime {
240240
now_seconds_since_epoch > datetime_seconds_since_epoch
241241
}
242242

243-
/// Returns the time in seconds since the unix epoch.
244-
pub fn abs_diff(&self, other: &Self) -> u64 {
245-
self.0.timestamp().abs_diff(other.0.timestamp())
243+
/// Returns the absolute difference between two datetimes as a `Duration`.
244+
pub fn duration_since(&self, other: &Self) -> Duration {
245+
let diff_secs = self.0.timestamp().abs_diff(other.0.timestamp());
246+
Duration::from_secs(diff_secs)
246247
}
247248

248249
/// Returns the time in seconds since the unix epoch.

lightning-liquidity/src/lsps5/service.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ where
156156
let should_prune = {
157157
let last_pruning = self.last_pruning.lock().unwrap();
158158
last_pruning.as_ref().map_or(true, |last_time| {
159-
now.abs_diff(&last_time) > PRUNE_STALE_WEBHOOKS_INTERVAL_DAYS.as_secs()
159+
now.duration_since(&last_time) > PRUNE_STALE_WEBHOOKS_INTERVAL_DAYS
160160
})
161161
};
162162

@@ -428,10 +428,8 @@ where
428428
webhook
429429
.last_notification_sent
430430
.get(&notification.method)
431-
.map(|last_sent| now.abs_diff(&last_sent))
432-
.map_or(false, |duration| {
433-
duration < DEFAULT_NOTIFICATION_COOLDOWN_HOURS.as_secs()
434-
})
431+
.map(|last_sent| now.duration_since(&last_sent))
432+
.map_or(false, |duration| duration < DEFAULT_NOTIFICATION_COOLDOWN_HOURS)
435433
});
436434

437435
if rate_limit_applies {
@@ -505,7 +503,7 @@ where
505503
webhooks.retain(|client_id, client_webhooks| {
506504
if !self.client_has_open_channel(client_id) {
507505
client_webhooks.retain(|_, webhook| {
508-
now.abs_diff(&webhook.last_used) < MIN_WEBHOOK_RETENTION_DAYS.as_secs()
506+
now.duration_since(&webhook.last_used) < MIN_WEBHOOK_RETENTION_DAYS
509507
});
510508
!client_webhooks.is_empty()
511509
} else {

0 commit comments

Comments
 (0)