Skip to content

chore: scaffold parallel onBlock task structure#720

Draft
zclawz wants to merge 3 commits into
mainfrom
feat/parallelize-onblock-719
Draft

chore: scaffold parallel onBlock task structure#720
zclawz wants to merge 3 commits into
mainfrom
feat/parallelize-onblock-719

Conversation

@zclawz
Copy link
Copy Markdown
Contributor

@zclawz zclawz commented Apr 12, 2026

Closes #719

Summary

This PR scaffolds the parallelization structure for onBlock chain processing as described in #719.

What this PR does

Annotates the two independent parallel tasks within onBlock and marks the barrier point before forkchoice import:

  • Task A — verifySignatures: XMSS signature verification (CPU-bound, read-only inputs)
  • Task B — apply_transition: State transition (read-only pre_state clone → mutates post_state)
  • Barrier: forkChoice.onBlock (forkchoice import) is gated on both A and B completing successfully

Both tasks are currently still sequential. The annotations provide clear anchors for the actual threading implementation in follow-up PRs.

Phases

Phase Description Status
1a Dispatch verifySignatures + apply_transition to spawned threads concurrently 🔲 TODO
1b Join at barrier; proceed to forkchoice only if both succeed 🔲 TODO
2 Parallelize independent post-state compute segments 🔲 TODO
3 Execution/proof verification (future) 🔲 Future

Design notes

  • Tasks A and B share no mutable state — A operates on pre_state (read-only) + public_key_cache (read-only); B operates on a cloned cpost_state
  • std.Thread.WaitGroup (or equivalent) is the natural join primitive
  • Forkchoice import remains sequential — only the pre-import work is parallelised

cc @GrapeBaBa @anshalshukla @gr3999

zclawz and others added 3 commits April 12, 2026 17:16
Annotate the two independent parallel tasks within onBlock:
  - Task A: verifySignatures (XMSS sig verification, CPU-bound)
  - Task B: apply_transition (state transition, independent of A)

Both are currently sequential. This commit marks the barrier point
(forkchoice import) and the task dispatch sites with TODOs and
design comments so the actual threading implementation has clear
anchors to build on.

Phase 1 goal: dispatch A and B to spawned threads concurrently,
join at the barrier, then proceed to forkchoice import only if both
succeed. Phase 2 will parallelize post-state compute segments.
Execution/proof verification (Phase 3) is future work.

Closes #719 (partial — scaffolding only)
#719)

Spawn two threads inside the computedstate block:
- Task A: stf.verifySignatures (XMSS sig verification, read-only inputs)
- Task B: stf.apply_transition (state transition, writes to cpost_state only)

Both run concurrently. The main thread joins both before proceeding to
forkchoice import, acting as the barrier described in #719.

self.allocator is wrapped in std.heap.ThreadSafeAllocator so both tasks
can allocate safely. If std.Thread.spawn fails for either task, it falls
back to inline (sequential) execution, preserving correctness.

Also removes the now-redundant scaffold barrier comment.
…id OOM on macOS

Task A (XMSS sig verification) and Task B (STF) previously shared the
same chain allocator via ThreadSafeAllocator, causing peak memory to
double vs the sequential baseline (both tasks allocate concurrently).

Give Task A its own temporary ArenaAllocator so its allocations are
freed when it completes. Task B continues to use the chain allocator for
cpost_state, which must outlive the task.

Fixes the consistent SIGKILL (OOM) on the macos-latest CI runner.
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.

Parallelize onBlock chain processing segments

1 participant