-
Notifications
You must be signed in to change notification settings - Fork 278
fix(flashblocks): Handle SystemTime edge case for clock adjustments #602
Copy link
Copy link
Labels
A-builderArea: builder cratesArea: builder cratesF-bugFlag: Something isn't workingFlag: Something isn't working
Description
Summary
Replace SystemTime::now().duration_since(UNIX_EPOCH).unwrap() with fallback handling to prevent panics when system clock is adjusted backward.
Problem
Three locations call .duration_since(UNIX_EPOCH).unwrap() on SystemTime::now(). If the system clock is adjusted backward (e.g., NTP correction, VM clock sync, or leap second handling), duration_since returns an Err and the node crashes.
While rare, this is a known edge case that can occur in production environments.
Affected Files
crates/builder/op-rbuilder/src/flashblocks/generator.rs(line 473)crates/builder/op-rbuilder/src/flashblocks/payload.rs(line 656)crates/client/node/src/test_utils/node.rs(line 77)
Current Code
let unix_now = SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs();Proposed Solution
Use unwrap_or_else with a sensible fallback. If the duration is zero, meaning the .unwrap_or_else is hit, log a warning.
let unix_now = SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap_or_else(|e| {
tracing::warn!(error = %e, "System clock went backward, using zero duration");
Duration::ZERO
})
.as_secs();Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-builderArea: builder cratesArea: builder cratesF-bugFlag: Something isn't workingFlag: Something isn't working