Skip to content

fix(dkg): relax started atomic ordering from SeqCst to Relaxed#550

Open
varex83 wants to merge 1 commit into
mainfrom
perf/relax-dkg-started-atomic
Open

fix(dkg): relax started atomic ordering from SeqCst to Relaxed#550
varex83 wants to merge 1 commit into
mainfrom
perf/relax-dkg-started-atomic

Conversation

@varex83

@varex83 varex83 commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator

Summary

Audited all production atomic-ordering usage in the workspace. The vast majority of sites already use the optimal ordering; this PR addresses the single inefficiency found.

crates/dkg/src/sync/server.rs — the started AtomicBool used SeqCst for its store/load (3 sites). The flag is a standalone signal: it publishes no data of its own (server state lives behind the RwLock, wake-ups come from Notify), and it is the only atomic in play. A global total order (SeqCst) is therefore unnecessary — it just adds fences (dmb ish + ldar/stlr on AArch64; xchg/mfence vs. plain mov on x86). Downgraded to Relaxed, which is sufficient for the register-then-check Notify idiom (correctness comes from registering notified() before the load, not from the atomic's ordering).

Also added an explanatory comment on the QBFT runner's decided flag documenting why its existing Relaxed load is already correct (visibility is guaranteed by the spawn_blocking join, not the atomic ordering).

Audit result (production sites)

Location Atomic Ordering Verdict
consensus/instance.rs 3× flags Relaxed already optimal (claim tokens; resources behind Mutex)
consensus/qbft/p2p.rs, parsigex/behaviour.rs request-id counters Relaxed already optimal (uniqueness only)
consensus/qbft/runner.rs decided Relaxed correct (join provides happens-before) — comment added
dkg/sync/server.rs started SeqCstRelaxed this PR

No correctness bugs were found — no Relaxed site was dangerously under-strengthened.

Testing

  • cargo build -p pluto-dkg -p pluto-consensus
  • cargo clippy -p pluto-dkg -p pluto-consensus --all-targets --all-features -- -D warnings

The `started` flag in the DKG sync server is a standalone signal that
publishes no data of its own: server state lives behind an `RwLock` and
wake-ups are delivered via `Notify`. There is only one atomic involved,
so the global total order imposed by `SeqCst` is unnecessary; `Relaxed`
is sufficient and avoids the extra fences (notably on AArch64).

Also document why `Relaxed` is already correct for the QBFT runner's
`decided` flag, whose visibility is guaranteed by the spawn_blocking
join rather than the atomic ordering.
@varex83 varex83 changed the title perf(dkg): relax started atomic ordering from SeqCst to Relaxed fix(dkg): relax started atomic ordering from SeqCst to Relaxed Jul 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants