Skip to content
This repository was archived by the owner on Jan 6, 2025. It is now read-only.

Commit 27b1ffa

Browse files
use SystemTime instead of chrono with clock to test validity
1 parent a3259cc commit 27b1ffa

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ lightning-invoice = "0.25.0"
1313

1414
bitcoin = "0.29.0"
1515

16-
chrono = { version = "0.4.31", default-features = false, features = ["std", "serde", "clock"] }
16+
chrono = { version = "0.4.31", default-features = false, features = ["std", "serde"] }
1717
serde = { version = "1.0", default-features = false, features = ["derive", "alloc"] }
1818
serde_json = "1.0"

src/jit_channel/utils.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,21 @@ use bitcoin::hashes::hmac::{Hmac, HmacEngine};
22
use bitcoin::hashes::sha256::Hash as Sha256;
33
use bitcoin::hashes::{Hash, HashEngine};
44

5+
use std::time::{SystemTime, UNIX_EPOCH};
6+
57
use crate::jit_channel::msgs::OpeningFeeParams;
68
use crate::utils;
79

810
/// Determines if the given parameters are valid given the secret used to generate the promise.
911
pub fn is_valid_opening_fee_params(
1012
fee_params: &OpeningFeeParams, promise_secret: &[u8; 32],
1113
) -> bool {
12-
if chrono::Utc::now() > fee_params.valid_until {
14+
let seconds_since_epoch = SystemTime::now()
15+
.duration_since(UNIX_EPOCH)
16+
.expect("system clock to be ahead of the unix epoch")
17+
.as_secs();
18+
let valid_until_seconds_since_epoch = fee_params.valid_until.timestamp().unsigned_abs();
19+
if seconds_since_epoch > valid_until_seconds_since_epoch {
1320
return false;
1421
}
1522

0 commit comments

Comments
 (0)