Skip to content

refactor(prover): extract a prover-worker crate from asm-runner#143

Open
prajwolrg wants to merge 8 commits into
STR-3698-asm-worker-subscriptionfrom
STR-3699-prover-worker
Open

refactor(prover): extract a prover-worker crate from asm-runner#143
prajwolrg wants to merge 8 commits into
STR-3698-asm-worker-subscriptionfrom
STR-3699-prover-worker

Conversation

@prajwolrg

@prajwolrg prajwolrg commented Jun 7, 2026

Copy link
Copy Markdown
Collaborator

Description

Proof scheduling and reconciliation lived inside the asm-runner binary at bin/asm-runner/src/prover/, hard-wired to the concrete SledProofDb, so the orchestrator could not be tested against fakes or reused outside the binary. This PR extracts that logic into a dedicated strata-asm-prover-worker crate (grouped under a new crates/extensions/prover/ tree), runs it on the strata-service framework, and drives it from a worker commit subscription instead of an ad-hoc loop.

The new worker mirrors the ASM worker's shape: it defines a ProverContext umbrella trait (proof storage + remote-job tracking + chain/state reads) and drives the orchestrator generically over it, while the binary supplies the concrete impl (AsmProverContext) that wires the sled stores and the Bitcoin client together — the same split as strata-asm-worker + asm-storage + the binary's worker_context.rs.

Each commit compiles on its own. Grouped by theme:

Crate extraction (mechanical + the original substance)

  • relocate proof-types crate under extensions/prover — move + rename strata-asm-proof-typesstrata-asm-prover-types.
  • relocate proof-db crate as extensions/prover/storage — move + rename strata-asm-proof-dbstrata-asm-prover-storage.
  • extract proof orchestration into a prover-worker crate — introduce ProverContext, make the orchestrator generic, split the proving backend into native/sp1 modules, and rewire the binary.

Subscription-driven orchestration on the service framework

  • add Subscription::try_recv for non-blocking drain — lets a periodically-ticking consumer drain the backlog without parking on the channel.
  • drive proof orchestration from the ASM commit subscription — replace the ad-hoc polling loop with the worker's per-block commit stream overlaid with a periodic tick.
  • run prover worker on the strata-service framework — the proving path is now Send, so the service runs on the standard async framework.

Subscribe to the Moho stream, not the ASM stream

  • generalize the commit-subscriber registry over its item — make AsmSubscribers a generic Subscribers<T> so both the ASM and Moho workers can expose the identical commit stream. No behavior change.
  • drive proof orchestration from the Moho commit stream — the Moho worker now re-emits each block after persisting its MohoState, and the prover subscribes to that stream instead of the ASM one.

The strata-asm-proof-impl (guest statements) crate intentionally stays in crates/proof/.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature/Enhancement (non-breaking change which adds functionality or enhances an existing one)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactor
  • New or updated tests
  • Dependency update
  • Security fix

Notes to Reviewers

Stacked on #129 (the Moho worker). This PR's base is STR-3698-moho-worker, so review #129 first — the last two commits here depend on the Moho worker it introduces. The diff will shrink to just this PR's commits once #129 merges and the base retargets to main.

The relationship this PR establishes: ASM → Moho → prover. The Moho worker (from #129) folds a new MohoState for every block the ASM worker commits. Before this PR, the prover orchestrator and the Moho worker each subscribed to the ASM worker's commit stream independently, so a block's proof input could be assembled before the Moho worker had persisted that block's MohoState. Reading the parent's MohoState made a stall unlikely in practice, but the ordering was no longer guaranteed once MohoState moved out of the ASM worker's inline write (that was flagged as a FIXME(STR-3699/STR-3698)). This PR closes that gap: the Moho worker re-emits each block on its own subscription only after the MohoState is durably committed, and the prover chains off that stream — so every block the prover sees already has its MohoState available. The generic Subscribers<T> is what lets both workers hand out the same stream type interchangeably.

This is therefore not a pure no-op extraction: the final two commits are a deliberate behavioral change (serializing the proof pipeline to remove the race). The earlier extraction/relocation commits remain behavior-preserving. Startup catch-up (sync_to_tip) deliberately stays silent, matching the no-replay semantics of the ASM commit stream — the prover, like before, relies on its periodic tick to reconcile in-flight proofs rather than on replay.

Verified with cargo check/clippy/test across the affected crates under both default and sp1 features; the migrated queue/scheduling unit tests, the new Moho emit/no-emit tests, and the runner/rpc tests pass.

Now that the orchestrator is decoupled from sled, a fake ProverContext can exercise the full reconcile/schedule loop end-to-end — left as a follow-up rather than expanding this PR's scope.

Checklist

  • I have performed a self-review of my code.
  • I have commented my code where necessary.
  • I have updated the documentation if needed.
  • My changes do not introduce new warnings.
  • I have added tests that prove my changes are effective or that my feature works.
  • New and existing tests pass with my changes.

Related Issues

STR-3699, STR-3698

@codecov

codecov Bot commented Jun 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.35236% with 110 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/extensions/prover/worker/src/backend/sp1.rs 0.00% 36 Missing ⚠️
bin/asm-runner/src/prover_context.rs 75.39% 31 Missing ⚠️
crates/extensions/prover/worker/src/service.rs 92.39% 20 Missing ⚠️
...tes/extensions/prover/worker/src/backend/native.rs 71.42% 6 Missing ⚠️
crates/extensions/prover/worker/src/handle.rs 33.33% 6 Missing ⚠️
crates/extensions/prover/worker/src/backend/mod.rs 80.76% 5 Missing ⚠️
crates/extensions/prover/worker/src/builder.rs 95.31% 3 Missing ⚠️
crates/extensions/prover/worker/src/input.rs 95.74% 2 Missing ⚠️
crates/extensions/moho/worker/src/builder.rs 87.50% 1 Missing ⚠️
Files with missing lines Coverage Δ
bin/asm-runner/src/block_watcher.rs 82.00% <100.00%> (-1.34%) ⬇️
bin/asm-runner/src/bootstrap.rs 99.11% <100.00%> (-0.09%) ⬇️
bin/asm-runner/src/config.rs 100.00% <ø> (ø)
bin/asm-runner/src/main.rs 92.45% <ø> (ø)
bin/asm-runner/src/rpc_server.rs 97.76% <ø> (ø)
crates/extensions/moho/worker/src/handle.rs 80.00% <100.00%> (+30.00%) ⬆️
crates/extensions/moho/worker/src/service.rs 88.40% <100.00%> (+0.17%) ⬆️
crates/extensions/moho/worker/src/state.rs 97.03% <100.00%> (+0.85%) ⬆️
crates/extensions/prover/storage/src/sled/mod.rs 100.00% <ø> (ø)
...tes/extensions/prover/storage/src/sled/proof_db.rs 100.00% <ø> (ø)
... and 22 more

... and 22 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions

github-actions Bot commented Jun 7, 2026

Copy link
Copy Markdown

Commit: 79ea607
SP1 Execution Results

program cycles gas
asm-stf 136,406,388 141,501,215
moho 5,223,555 5,525,314

@prajwolrg prajwolrg force-pushed the STR-3699-prover-worker branch 2 times, most recently from 60daeca to 9a71376 Compare June 9, 2026 03:36
@prajwolrg prajwolrg changed the base branch from main to STR-3698-moho-worker June 9, 2026 03:37
@prajwolrg prajwolrg marked this pull request as ready for review June 10, 2026 14:32
@prajwolrg prajwolrg force-pushed the STR-3699-prover-worker branch from 9a71376 to 3b4d6c0 Compare June 11, 2026 14:30
@prajwolrg prajwolrg force-pushed the STR-3698-moho-worker branch 2 times, most recently from f75ef6c to 1beadbd Compare June 16, 2026 16:09
Begin grouping the prover stack under a single crates/extensions/prover tree.
Move the proof types crate there and rename it strata-asm-prover-types so the
naming matches the forthcoming prover-worker and prover-storage crates. Pure
relocation and rename; no logic changes.
Move the proof database crate alongside the relocated types crate and rename it
strata-asm-prover-storage, framing it as the prover's storage layer (the
analogue of asm-storage for the ASM worker). Pure relocation and rename; the
storage traits and sled implementations are unchanged.
Proof scheduling and reconciliation lived inside the asm-runner binary,
hard-wired to the concrete SledProofDb, so the orchestrator could not be
tested against fakes or reused outside the binary.

Introduce strata-asm-prover-worker, mirroring the ASM worker's shape: it
defines a ProverContext umbrella trait and drives the orchestrator generically
over it, while the binary supplies the concrete impl (AsmProverContext) wiring
the sled stores and the Bitcoin client. The proving backend is split into
native and sp1 modules behind the existing feature gate.
A periodically-ticking consumer (the prover orchestrator) needs to drain
every buffered commitment at the top of each tick without parking on the
channel, and to learn that the worker has shut down once the backlog is
empty. recv() can only await; try_recv() covers both via Empty/Disconnected.
Proof requests were enqueued from the block watcher before the ASM worker
had committed the block. Subscribe the orchestrator to the worker's
post-commit stream instead: it expands each committed L1BlockCommitment
into its ASM step proof and Moho recursive proof internally, so proofs are
requested only for durably-stored blocks.

The subscription becomes the orchestrator's sole input, dropping the
ProverWorkerHandle/request_proof channel; the block watcher returns to
only feeding blocks to the worker.
Replace the hand-rolled `ProofOrchestrator` loop with the same Service/State
pattern the ASM worker uses: a logic-only `ProverService` over a data-only
`ProverServiceState`, launched via `launch_async` and returning a
`ProverWorkerHandle`. The ASM commit subscription becomes the service input
through `StreamInput` + `TickingInput`.

This removes the dedicated current-thread-runtime + LocalSet workaround in
bootstrap. That workaround existed because the proving path was `!Send`; with
the host trait now `Send`, the only remaining `!Send` sources were our own
`L1BlockProvider` futures (now bounded `+ Send`) and the
`ZkVmRemoteProgram::start_proving` wrapper (now inlined to call the host
directly). A TODO tracks reverting both once zkaleido is updated.
…item

The prover needs to chain off Moho-state commits rather than ASM commits,
which means the Moho worker must fan out a post-commit notification the same
way the ASM worker does. Rather than duplicate the subscriber registry, make
`AsmSubscribers` a generic `Subscribers<T>` so both workers share one type;
`Subscription<T>` was already generic. The prover can then subscribe to either
worker's stream interchangeably, since both emit `L1BlockCommitment`.

No behavior change: the ASM worker keeps emitting exactly as before.
The prover orchestrator and the Moho worker each subscribed to the ASM
worker's commit stream independently, so a block's proof input could be
assembled before the Moho worker had persisted that block's MohoState — the
read of the parent's MohoState made this unlikely in practice but the ordering
was no longer guaranteed once MohoState moved out of the ASM worker's inline
write. Serialize the chain ASM -> Moho -> prover instead.

The Moho worker now owns a subscriber registry and emits each block on its own
stream after the MohoState is durably committed, and exposes subscribe_blocks()
on its handle, mirroring the ASM worker. The prover subscribes to that stream,
so every block it sees already has its MohoState available. Startup catch-up
(sync_to_tip) deliberately stays silent, matching the no-replay semantics of
the ASM commit stream.
@prajwolrg prajwolrg force-pushed the STR-3699-prover-worker branch from a3b9179 to 3edaaee Compare June 16, 2026 17:04
@prajwolrg prajwolrg changed the base branch from STR-3698-moho-worker to STR-3698-asm-worker-subscription June 16, 2026 17:04
@prajwolrg

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: 3edaaee893

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

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.

1 participant