fuzz: share a single mocked steady clock across FuzzedSock instances #35536

pull HowHsu wants to merge 1 commits into bitcoin:master from HowHsu:fuzz-fuzzedsock-shared-clock changing 11 files +45 −40
  1. HowHsu commented at 4:05 PM on June 15, 2026: contributor

    This is a follow-up of #35478 (comment), inspired by maflcko .

    Each FuzzedSock used to own its mocked steady clock and call MockableSteadyClock::SetMockTime() directly. Hold the clock by reference to an externally provided SteadyClockContext instead, so that several FuzzedSock instances sharing a test case (e.g. one per peer, or one created via Accept()) advance a single mocked clock, and the mocking goes through the SteadyClockContext RAII helper that resets mocktime on destruction.

    SteadyClockContext is a LimitOne type, so each fuzz target constructs one instance per iteration and passes it to ConsumeSock / ConsumeNode / the FuzzedSock constructor.

  2. DrahtBot added the label Fuzzing on Jun 15, 2026
  3. DrahtBot commented at 4:05 PM on June 15, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--006a51241073e994b41acfe9ec718e94-->

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/35536.

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline for information on the review process. A summary of reviews will appear here.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #35482 (fuzz: exercise the transaction-handling path in process_message(s) by HowHsu)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  4. in src/test/fuzz/util/net.h:187 in 45f690bc45
     183 | +     * Externally-provided context used to mock the steady clock in methods
     184 | +     * waiting for a given duration. It is a reference (rather than an owned
     185 | +     * member) so that several FuzzedSock instances sharing a test case (e.g.
     186 | +     * one per peer, or one created from Accept()) advance a single mocked
     187 | +     * clock: SteadyClockContext is a LimitOne type and may not be
     188 | +     * instantiated more than once at a time.
    


    maflcko commented at 7:11 AM on June 16, 2026:

    LimitOne is an implementation detail, and I think the last sentence can be removed. Otherwise, all use-sites can explain what LimitOne means. If you want to explain it further, a better place would be SteadyClockContext itself, so that the docs are only in a single place, instead of spread out.

    The underlying reason is that time is read/written from/to a single global variable. Holding several time contexts for different objects and advancing them independently is simply impossible without changing non-test code. LimitOne is just an implementation detail to serve as a linter to avoid violations here and explicitly disallow several time contexts at runtime.


    HowHsu commented at 8:38 AM on June 16, 2026:

    Updated

  5. maflcko approved
  6. maflcko commented at 7:12 AM on June 16, 2026: member

    lgtm, but the new docs could be shortened.

  7. maflcko commented at 7:16 AM on June 16, 2026: member

    A bit unrelated, but I wonder if there should be a scripted-diff to rename SteadyClockContext to FakeSteadyClock, so that the naming follows FakeNodeClock. Otherwise, there are two naming schemes for two types of the same concept.

  8. fuzz: share a single mocked steady clock across FuzzedSock instances
    Each FuzzedSock used to own its mocked steady clock and call
    MockableSteadyClock::SetMockTime() directly. Hold the clock by reference
    to an externally provided SteadyClockContext instead, so that several
    FuzzedSock instances sharing a test case (e.g. one per peer, or one
    created via Accept()) advance a single mocked clock, and the mocking goes
    through the SteadyClockContext RAII helper that resets mocktime on
    destruction.
    
    SteadyClockContext is a LimitOne type, so each fuzz target constructs one
    instance per iteration and passes it to ConsumeSock / ConsumeNode / the
    FuzzedSock constructor.
    0a270ea4ac
  9. HowHsu force-pushed on Jun 16, 2026
  10. fanquake commented at 9:56 AM on June 17, 2026: member
  11. HowHsu commented at 7:56 AM on June 18, 2026: contributor

    A bit unrelated, but I wonder if there should be a scripted-diff to rename SteadyClockContext to FakeSteadyClock, so that the naming follows FakeNodeClock. Otherwise, there are two naming schemes for two types of the same concept.

    Checked the code and agree. Submitted a PR: https://github.com/bitcoin/bitcoin/pull/35559

  12. HowHsu requested review from maflcko on Jun 18, 2026

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-06-20 23:51 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me