tests: use timemono not time_now() for duration measurement.
What changed, and why it matters
This commit only changes two internal test files to use a monotonic clock instead of the current wall-clock time when measuring how long test operations take. It does not change any production code, cryptographic algorithms, or network behavior. There is no security issue here.
No security action needed. This is a benign test-quality improvement.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch replaces struct timeabs with struct timemono and time_now() with time_mono() in bitcoin/test/run-secret_eq_consttime.c and onchaind/test/run-grind_feerate.c. It also updates the duration calculations to use timemono_between(). This is a test-only correctness improvement: monotonic clocks are preferred for measuring elapsed durations because they are not affected by system clock adjustments (NTP skew, leap seconds, manual changes). The change does not affect runtime behavior of Core Lightning.
Changed components
bitcoin/test/run-secret_eq_consttime.conchaind/test/run-grind_feerate.cInspect captured patch +13 / −13
diff --git a/bitcoin/test/run-secret_eq_consttime.c b/bitcoin/test/run-secret_eq_consttime.c
index 6d4cb414..58933d5f 100644
--- a/bitcoin/test/run-secret_eq_consttime.c
+++ b/bitcoin/test/run-secret_eq_consttime.c
@@ -16,7 +16,7 @@ static struct timerel const_time_test(struct secret *s1,
struct secret *s2,
size_t off)
{
- struct timeabs start, end;
+ struct timemono start, end;
int result = 0;
memset(s1, 0, RUNS * sizeof(*s1));
@@ -25,16 +25,16 @@ static struct timerel const_time_test(struct secret *s1,
for (size_t i = 0; i < RUNS; i++)
s2[i].data[off] = i;
- start = time_now();
+ start = time_mono();
for (size_t i = 0; i < RUNS; i++)
result += secret_eq_consttime(&s1[i], &s2[i]);
- end = time_now();
+ end = time_mono();
if (result != RUNS / 256)
errx(1, "Expected %u successes at offset %zu, not %u!",
RUNS / 256, off, result);
- return time_between(end, start);
+ return timemono_between(end, start);
}
static inline bool secret_eq_nonconst(const struct secret *a,
@@ -47,7 +47,7 @@ static struct timerel nonconst_time_test(struct secret *s1,
struct secret *s2,
size_t off)
{
- struct timeabs start, end;
+ struct timemono start, end;
int result = 0;
memset(s1, 0, RUNS * sizeof(*s1));
@@ -56,16 +56,16 @@ static struct timerel nonconst_time_test(struct secret *s1,
for (size_t i = 0; i < RUNS; i++)
s2[i].data[off] = i;
- start = time_now();
+ start = time_mono();
for (size_t i = 0; i < RUNS; i++)
result += secret_eq_nonconst(&s1[i], &s2[i]);
- end = time_now();
+ end = time_mono();
if (result != RUNS / 256)
errx(1, "Expected %u successes at offset %zu, not %u!",
RUNS / 256, off, result);
- return time_between(end, start);
+ return timemono_between(end, start);
}
static struct secret *s1, *s2;
diff --git a/onchaind/test/run-grind_feerate.c b/onchaind/test/run-grind_feerate.c
index 75933137..1acff25e 100644
--- a/onchaind/test/run-grind_feerate.c
+++ b/onchaind/test/run-grind_feerate.c
@@ -111,7 +111,7 @@ int main(int argc, char *argv[])
struct amount_sat fee;
struct pubkey htlc_key;
struct keyset *keys;
- struct timeabs start, end;
+ struct timemono start, end;
int iterations = 1000;
u8 *spk = tal_arr(tmpctx, u8, 1);
spk[0] = 0x00;
@@ -143,15 +143,15 @@ int main(int argc, char *argv[])
max_possible_feerate = 250000;
min_possible_feerate = max_possible_feerate + 1 - iterations;
- start = time_now();
+ start = time_mono();
if (!grind_htlc_tx_fee(&fee, tx, &sig, wscript, 663))
abort();
- end = time_now();
+ end = time_mono();
assert(amount_sat_eq(fee, AMOUNT_SAT(165750)));
printf("%u iterations in %"PRIu64" msec = %"PRIu64" nsec each\n",
iterations,
- time_to_msec(time_between(end, start)),
- time_to_nsec(time_divide(time_between(end, start), iterations)));
+ time_to_msec(timemono_between(end, start)),
+ time_to_nsec(time_divide(timemono_between(end, start), iterations)));
common_shutdown();
return 0;
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.