Skip to content

LSPS5 -> More follow ups #3987

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
Show file tree
Hide file tree
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
9 changes: 5 additions & 4 deletions lightning-liquidity/src/lsps0/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ impl wire::Type for RawLSPSMessage {
pub struct LSPSRequestId(pub String);

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

Expand All @@ -240,9 +240,10 @@ impl LSPSDateTime {
now_seconds_since_epoch > datetime_seconds_since_epoch
}

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

/// Returns the time in seconds since the unix epoch.
Expand Down
2 changes: 1 addition & 1 deletion lightning-liquidity/src/lsps1/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ where
let order_id = self.generate_order_id();
let channel = OutboundCRChannel::new(
params.order.clone(),
created_at.clone(),
created_at,
order_id.clone(),
payment.clone(),
);
Expand Down
4 changes: 2 additions & 2 deletions lightning-liquidity/src/lsps2/msgs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl LSPS2RawOpeningFeeParams {
LSPS2OpeningFeeParams {
min_fee_msat: self.min_fee_msat,
proportional: self.proportional,
valid_until: self.valid_until.clone(),
valid_until: self.valid_until,
min_lifetime: self.min_lifetime,
max_client_to_self_delay: self.max_client_to_self_delay,
min_payment_size_msat: self.min_payment_size_msat,
Expand Down Expand Up @@ -235,7 +235,7 @@ mod tests {
let raw = LSPS2RawOpeningFeeParams {
min_fee_msat,
proportional,
valid_until: valid_until.clone().into(),
valid_until: valid_until.into(),
min_lifetime,
max_client_to_self_delay,
min_payment_size_msat,
Expand Down
16 changes: 7 additions & 9 deletions lightning-liquidity/src/lsps5/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ where
let should_prune = {
let last_pruning = self.last_pruning.lock().unwrap();
last_pruning.as_ref().map_or(true, |last_time| {
now.abs_diff(&last_time) > PRUNE_STALE_WEBHOOKS_INTERVAL_DAYS.as_secs()
now.duration_since(&last_time) > PRUNE_STALE_WEBHOOKS_INTERVAL_DAYS
})
};

Expand Down Expand Up @@ -185,7 +185,7 @@ where
Entry::Occupied(mut entry) => {
no_change = entry.get().url == params.webhook;
let (last_used, last_notification_sent) = if no_change {
(entry.get().last_used.clone(), entry.get().last_notification_sent.clone())
(entry.get().last_used, entry.get().last_notification_sent.clone())
} else {
(now, new_hash_map())
};
Expand Down Expand Up @@ -428,10 +428,8 @@ where
webhook
.last_notification_sent
.get(&notification.method)
.map(|last_sent| now.abs_diff(&last_sent))
.map_or(false, |duration| {
duration < DEFAULT_NOTIFICATION_COOLDOWN_HOURS.as_secs()
})
.map(|last_sent| now.duration_since(&last_sent))
.map_or(false, |duration| duration < DEFAULT_NOTIFICATION_COOLDOWN_HOURS)
});

if rate_limit_applies {
Expand All @@ -440,8 +438,8 @@ where
}

for (app_name, webhook) in client_webhooks.iter_mut() {
webhook.last_notification_sent.insert(notification.method.clone(), now.clone());
webhook.last_used = now.clone();
webhook.last_notification_sent.insert(notification.method.clone(), now);
webhook.last_used = now;
self.send_notification(
client_id,
app_name.clone(),
Expand Down Expand Up @@ -505,7 +503,7 @@ where
webhooks.retain(|client_id, client_webhooks| {
if !self.client_has_open_channel(client_id) {
client_webhooks.retain(|_, webhook| {
now.abs_diff(&webhook.last_used) < MIN_WEBHOOK_RETENTION_DAYS.as_secs()
now.duration_since(&webhook.last_used) < MIN_WEBHOOK_RETENTION_DAYS
});
!client_webhooks.is_empty()
} else {
Expand Down
Loading