Skip to content

feat(worker): per-block subscription stream#128

Open
prajwolrg wants to merge 1 commit into
mainfrom
STR-3698-asm-worker-subscription
Open

feat(worker): per-block subscription stream#128
prajwolrg wants to merge 1 commit into
mainfrom
STR-3698-asm-worker-subscription

Conversation

@prajwolrg
Copy link
Copy Markdown
Collaborator

Description

The ASM worker had derived-state consumers (Moho-state derivation today, proof requests later) wired into its hot path. This adds a per-block notification stream so consumers can react to each committed block on their own task instead of being baked into the worker.

AsmWorkerHandle::subscribe_blocks() hands out a Subscription<L1BlockCommitment> (a Stream, with a backlog() depth signal). After each successful anchor-state commit, the service fans the new commitment out to all subscribers over unbounded channels and prunes dropped receivers via retain. send on an unbounded channel is non-blocking, so the worker never awaits a consumer and stays off the critical path. Subscribers fire only after a successful ASM commit — not on raw block arrival — hence AsmSubscribers. Mirrors strata-bridge's btc-tracker subscriber pattern.

This is the foundation for STR-3698 (moho worker); the Moho consumer PR is stacked on top of this one.

Type of Change

  • New feature/Enhancement (non-breaking change which adds functionality or enhances an existing one)

Notes to Reviewers

Pure addition to strata-asm-worker: no existing public API changed (subscribe_blocks is additive; submit_block/launch are unchanged). AsmWorkerHandle::new / AsmWorkerServiceState::new are now pub(crate) since they take the private AsmSubscribers registry, but the builder is the only constructor and nothing outside the crate called them. Unit tests cover fan-out, ordering, backlog(), dead-subscriber pruning, and stream close.

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

Part of Jira STR-3698.

@prajwolrg prajwolrg force-pushed the STR-3698-asm-worker-subscription branch from 49ac037 to 8a6d427 Compare June 2, 2026 09:59
@prajwolrg prajwolrg marked this pull request as ready for review June 2, 2026 10:00
@prajwolrg prajwolrg requested a review from evgenyzdanovich June 2, 2026 10:00
@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 2, 2026

Codecov Report

❌ Patch coverage is 93.02326% with 6 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/worker/src/handle.rs 50.00% 3 Missing ⚠️
crates/worker/src/subscription.rs 95.23% 3 Missing ⚠️
Files with missing lines Coverage Δ
crates/worker/src/builder.rs 93.02% <100.00%> (+0.16%) ⬆️
crates/worker/src/service.rs 85.71% <100.00%> (+0.17%) ⬆️
crates/worker/src/state.rs 76.41% <100.00%> (+1.27%) ⬆️
crates/worker/src/handle.rs 65.85% <50.00%> (-3.60%) ⬇️
crates/worker/src/subscription.rs 95.23% <95.23%> (ø)

... and 2 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
Copy link
Copy Markdown

github-actions Bot commented Jun 2, 2026

Commit: ed89f59
SP1 Execution Results

program cycles gas
asm-stf 136,367,055 141,452,326
moho 5,223,555 5,525,314

Consumers of committed blocks (Moho-state derivation, and later proof
requests) were wired into the ASM worker's hot path. Expose
AsmWorkerHandle::subscribe_blocks(): after each anchor write the service
fans the new L1BlockCommitment out to subscribers over unbounded
channels and prunes dropped receivers. send on an unbounded channel is
non-blocking, so the worker never awaits a consumer and stays off the
critical path.

Subscribers fire only after a successful ASM commit, not on raw block
arrival -- hence AsmSubscribers.
@prajwolrg prajwolrg force-pushed the STR-3698-asm-worker-subscription branch from 8a6d427 to 62febab Compare June 7, 2026 05:30
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