Skip to content

fix(flashblocks): Handle SystemTime edge case for clock adjustments #602

@refcell

Description

@refcell

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();

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-builderArea: builder cratesF-bugFlag: Something isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions