Skip to content

Commit c8450bf

Browse files
authored
Merge pull request #3987 from martinsaposnic/lsps5-and-more-follow-ups
LSPS5 -> More follow ups
2 parents de2005a + 552d8e4 commit c8450bf

File tree

4 files changed

+15
-16
lines changed

4 files changed

+15
-16
lines changed

lightning-liquidity/src/lsps0/ser.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ impl wire::Type for RawLSPSMessage {
218218
pub struct LSPSRequestId(pub String);
219219

220220
/// An object representing datetimes as described in bLIP-50 / LSPS0.
221-
#[derive(Clone, Debug, PartialEq, Eq, Hash, Deserialize, Serialize)]
221+
#[derive(Clone, Debug, Copy, PartialEq, Eq, Hash, Deserialize, Serialize)]
222222
#[serde(transparent)]
223223
pub struct LSPSDateTime(pub chrono::DateTime<chrono::Utc>);
224224

@@ -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/lsps1/service.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ where
266266
let order_id = self.generate_order_id();
267267
let channel = OutboundCRChannel::new(
268268
params.order.clone(),
269-
created_at.clone(),
269+
created_at,
270270
order_id.clone(),
271271
payment.clone(),
272272
);

lightning-liquidity/src/lsps2/msgs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl LSPS2RawOpeningFeeParams {
7272
LSPS2OpeningFeeParams {
7373
min_fee_msat: self.min_fee_msat,
7474
proportional: self.proportional,
75-
valid_until: self.valid_until.clone(),
75+
valid_until: self.valid_until,
7676
min_lifetime: self.min_lifetime,
7777
max_client_to_self_delay: self.max_client_to_self_delay,
7878
min_payment_size_msat: self.min_payment_size_msat,
@@ -235,7 +235,7 @@ mod tests {
235235
let raw = LSPS2RawOpeningFeeParams {
236236
min_fee_msat,
237237
proportional,
238-
valid_until: valid_until.clone().into(),
238+
valid_until: valid_until.into(),
239239
min_lifetime,
240240
max_client_to_self_delay,
241241
min_payment_size_msat,

lightning-liquidity/src/lsps5/service.rs

Lines changed: 7 additions & 9 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

@@ -185,7 +185,7 @@ where
185185
Entry::Occupied(mut entry) => {
186186
no_change = entry.get().url == params.webhook;
187187
let (last_used, last_notification_sent) = if no_change {
188-
(entry.get().last_used.clone(), entry.get().last_notification_sent.clone())
188+
(entry.get().last_used, entry.get().last_notification_sent.clone())
189189
} else {
190190
(now, new_hash_map())
191191
};
@@ -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 {
@@ -440,8 +438,8 @@ where
440438
}
441439

442440
for (app_name, webhook) in client_webhooks.iter_mut() {
443-
webhook.last_notification_sent.insert(notification.method.clone(), now.clone());
444-
webhook.last_used = now.clone();
441+
webhook.last_notification_sent.insert(notification.method.clone(), now);
442+
webhook.last_used = now;
445443
self.send_notification(
446444
client_id,
447445
app_name.clone(),
@@ -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)