Skip to content

3.x.x: add a block submission and broadcast kill switch for rehearsals against a real node (#291) - #661

Merged
RobertClarke merged 3 commits into
3.x.xfrom
RobertClarke/prism-submit-killswitch
Oct 5, 2026
Merged

RobertClarke merged 3 commits into
3.x.xfrom
RobertClarke/prism-submit-killswitch

Conversation

@RobertClarke

@RobertClarke RobertClarke commented Oct 5, 2026 •

Copy link
Copy Markdown
Member

Part of #291.

Problem

The production PRISM pair will run #291's rehearsals against a restored copy of the mainnet ledger and a real mainnet qbitd. Before this change:

  • run always started the submit loop. Any pending candidate would have been offered to mainnet with submitblock: a restored row, or a block a rehearsal miner found.
  • Only the CTV broadcaster could be turned off.

There was no supported way to guarantee that no block submission or transaction broadcast reaches mainnet.

Change

This adds PRISM_BLOCK_SUBMIT_ENABLED, a boolean that defaults to 1. It applies per frontend, is read at startup, and is outside the cluster fingerprint. Setting it off (0, false, no or off) has these effects.

Blocks

  • Coordinator::submit_loop claims nothing until shutdown.
  • A found block is still validated, credited and enqueued, but its outbox row stays pending. Restored rows are not reserved, offered, settled or abandoned either.
  • Backstop: process_candidate_inner refuses a claim in any state, before the probe, the reservation or a settlement. So process_candidate, or any future caller, can neither offer nor settle a held row.

Transactions

  • The CTV fanout broadcaster is PRISM's only sender of sendrawtransaction and submitpackage, and its only CPFP wallet user. PRISM 3 has no separate payout broadcaster.
  • The broadcaster is not started even with PRISM_CTV_BROADCASTER_ENABLED=1, and the frontend logs that it is held.
  • broadcast-ctv exits non-zero before it connects to anything.
  • Backstop: broadcaster::run_pass refuses before it reads the node.

Node client. Rpc::without_relay makes the structural guarantee. A held frontend talks to its node through a client that refuses every call that would relay a block or a transaction, before anything is written: submitblock, sendrawtransaction, submitpackage, and the wallet's own sends. Wallet clients made from it inherit the refusal. The offer path classifies that refusal as provably not sent, so even a reservation reached some other way returns to pending instead of becoming unknown. Config::require_block_submission is the single refusal that the processing, the broadcaster pass and broadcast-ctv share.

Reporting

  • check-config leads with WARNING: block submission is disabled by PRISM_BLOCK_SUBMIT_ENABLED: …. It adds a second warning when a configured broadcaster is held, and omits the standby-wait line, since a held frontend makes no offer. With the switch on, it prints the enabled mode.
  • self-check adds a block_submission section, filled before any connection, and repeats the warning on stderr.
  • The health payload carries block_submission_enabled. That covers /healthz and the heartbeat, so self-check's live_instances shows each running frontend's own value.
  • A new gauge, qbit_prism_block_submission_enabled: 1 or 0, and -1 (never 1) until run publishes the setting.
  • Warnings at startup.

Wiring and docs

  • compose.yaml passes the setting to both HA frontends, defaulting to 1. It is also in .env.example and the server README table.
  • docs/prism-configuration.md gains a reference section.
  • docs/prism-ledger-ops.md gains a rehearsal runbook: what is held, how to verify the mode on running frontends, held-candidate visibility, and what to do after the rehearsal.
  • docs/mainnet-deployment.md gains a go-live check.

Everything else is unchanged: templates, readiness, Stratum, share acknowledgement and every database write.

Tests

Test Kind What it shows
config::tests::the_block_submit_kill_switch_holds_the_broadcaster_and_is_per_frontend unit the mode report for each setting combination; the switch is outside the fingerprint
metrics::snapshots::tests::block_submission_gauge_follows_the_kill_switch unit the gauge reads 1 by default and follows the switch
config_cli::check_config_reports_the_block_submission_kill_switch_first CLI warnings come first in lab and production modes; an invalid value is rejected
config_cli::broadcast_ctv_refuses_before_reaching_services_when_block_submission_is_disabled CLI broadcast-ctv refuses before it touches the node or the database
self_check_cli::disabled_block_submission_is_reported_when_the_services_are_unavailable CLI the report and the stderr warning with no database or node; the existing report shapes are updated
candidate_lease_tests::submit_disabled_tests::a_submit_loop_with_block_submission_disabled_claims_nothing_until_shutdown PostgreSQL a held loop takes no claim and uses no dispatch slot over 10 drain ticks, and stops at shutdown; an enabled loop then lands the row with one offer
candidate_lease_tests::submit_disabled_tests::an_offer_on_a_frontend_with_block_submission_disabled_is_refused_before_its_reservation PostgreSQL process_candidate is refused and the row stays untouched; the enabled frontend then offers the row once
rpc_not_sent::a_client_without_relay_sends_no_relaying_call_and_every_other_call real socket a held client and its wallet client refuse every relaying method, and the node records none of them; reads still go through, and an ordinary client's submitblock arrives
offer_not_executed_tests::a_relay_refused_under_the_kill_switch_was_not_executed unit a refused submitblock is classified as provably not sent
candidate_storm_restart::a_frontend_with_block_submission_disabled_sends_its_node_no_block_until_it_is_enabled real binary the integration test, described below
ctv_fanout_bookkeeping::a_frontend_with_block_submission_disabled_claims_and_sends_no_fanout PostgreSQL a held frontend claims, attempts and sends no due fanout; its enabled peer then sends all of them
observability census ungated updated to 80 families
tests/test_mainnet_compose_contract.py::test_block_submission_kill_switch_defaults_on_and_reaches_both_frontends Docker, CI only the setting reaches both HA frontends and defaults to 1

In the integration test, the real qbit-prism-server run is started with PRISM_BLOCK_SUBMIT_ENABLED=0 and PRISM_CTV_BROADCASTER_ENABLED=1, over 3 due candidates.

  • It runs across two health heartbeats, roughly 20 drain ticks.
  • The parent's fake node counts submitblock per block hash and sees none.
  • Every row stays pending and unclaimed, the dispatch sequence never advances, the heartbeat reports block_submission_enabled=false, and both warnings appear in the log.
  • The same frontend is then relaunched with submission on, and offers each block exactly once. So the zero is not vacuous.

Mutation checks were run locally on the first revision. Removing each gate makes its test fail:

  • Removing the submit-loop hold alone fails the binary test with attempt_count: 2. The offer backstop still kept the block unoffered.
  • Removing the offer backstop fails the refused-offer test.
  • Removing the run_pass refusal fails the broadcaster test.

Risks and follow-ups

  • Leaving the switch at 0 in production holds every found block. Mitigations in this PR: warnings in check-config, self-check and the logs; the gauge and the health field; and the go-live check. The existing pending-candidate alerts also page within 15 s of a held block. A dedicated alert is not added here, because alert rules go through their own migration process. It is follow-up 3.x.x: page when a production frontend runs with block submission held (qbit_prism_block_submission_enabled != 1) #666.
  • The switch is per frontend, and fails open by default, as specified. A frontend started without it on the same database offers the held rows, and a leased candidate skips the pre-offer staleness screen. The runbook says to set the switch on every frontend, and to discard or abandon held rows before re-enabling. A database-level hold that fails closed is follow-up 3.x.x: hold a rehearsal database for every frontend that connects to it, not only frontends started with PRISM_BLOCK_SUBMIT_ENABLED=0 (#291) #664.
  • A block proof below the miner's share target is answered ledger-outcome-unknown after PRISM_SHARE_COMMIT_TIMEOUT_SECONDS, because its block never confirms. This cannot happen at mainnet difficulty.
  • The switch governs PRISM only. The runbook recommends a node RPC user that cannot call submitblock, sendrawtransaction or submitpackage, as an independent layer.

🤖 Generated with Claude Code

…s against a real node (#291)

PRISM_BLOCK_SUBMIT_ENABLED (default 1) lets the production pair run a
rehearsal against a restored mainnet ledger and a real mainnet qbitd
with no block submission or transaction broadcast reaching the network.

With PRISM_BLOCK_SUBMIT_ENABLED=0:
- the submit loop claims no candidate, so a found block is validated,
  credited and enqueued but stays pending, and submitblock is never
  called; offer_candidate also refuses before its probe and reservation,
  so no other caller can offer;
- the CTV fanout broadcaster (PRISM's only sendrawtransaction,
  submitpackage and CPFP wallet user) is not started even when
  PRISM_CTV_BROADCASTER_ENABLED=1, broadcast-ctv refuses before it
  connects, and run_pass refuses before it reads the node;
- check-config leads with a WARNING, self-check reports a
  block_submission section and warns on stderr, the health payload and
  heartbeat carry block_submission_enabled, the new
  qbit_prism_block_submission_enabled gauge reads 0, and the hold logs a
  warning at startup.

The setting is per frontend, read at startup, and outside the cluster
fingerprint. Compose passes it to both HA frontends; the ops runbook,
configuration reference, README table, .env.example and go-live checks
document it.

Tests: config and gauge unit tests; check-config, broadcast-ctv and
self-check CLI tests; in-process PostgreSQL tests of the held submit loop
and the refused offer; a real-binary test in which a held frontend
serves a due outbox for a health cadence and its counting fake node sees
no submitblock, then the same frontend relaunched enabled offers each
block exactly once; and a broadcaster test in which a held frontend
claims and sends no due fanout that its enabled peer then sends.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-05T19:23:11.511172Z 66c948f New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

…old every claim it is handed (#291)

Review follow-ups for the block submission kill switch:

- Rpc::without_relay: a frontend with PRISM_BLOCK_SUBMIT_ENABLED off
  talks to its node through a client, and wallet clients made from it,
  that refuse submitblock, sendrawtransaction, submitpackage and the
  wallet's own sends before anything is written (RpcRelayRefused). The
  offer path treats that refusal as provably not sent, so a reservation
  it ever reached would return to pending rather than become unknown.
- The processing backstop moves from offer_candidate to
  process_candidate_inner: a held frontend processes no claim in any
  state, so no caller can settle or offer a held row either.
- Config::require_block_submission is the one refusal the processing,
  the broadcaster pass and broadcast-ctv share.
- qbit_prism_block_submission_enabled is -1 until run publishes the
  setting, never 1 by default.
- Messages name the setting rather than a value, since 0, false, no and
  off all turn it off; check-config no longer prints the standby-wait
  line for a frontend that makes no offer.
- The runbook covers the node client's refusal, check-config's exit
  status and frontends still starting.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@RobertClarke

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: 39c1f2d127

ℹ️ 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".

candidate_window_switch::as_issued_snapshot_preparation_runs_off_the_runtime_on_both_write_paths
timed out writing its 300k-recipient snapshot on run 37359680165. The
failed jobs could not be re-run with the available token, so this empty
commit runs CI again.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@RobertClarke
RobertClarke merged commit ec29d74 into 3.x.x Oct 5, 2026
34 checks passed
@RobertClarke
RobertClarke deleted the RobertClarke/prism-submit-killswitch branch October 5, 2026 19:43
RobertClarke added a commit that referenced this pull request Oct 5, 2026
…holds a found block (#666) (#676)

#661's kill switch (PRISM_BLOCK_SUBMIT_ENABLED=0) holds every block a
frontend finds. A production frontend left that way paged only once a
found block had been held for a while:
PrismBlockCandidateOldestPendingCritical needs an age of 60 s and then a
3-minute dwell, which may be too late for the block.

PrismBlockSubmissionHeld (critical, page=true) pages a minute after a
frontend reports qbit_prism_block_submission_enabled != 1, whether or not
it has found anything: 0 while the switch holds submission, and -1 for a
frontend that has not published its setting. The gauge is served from the
cached metrics snapshot, so the rule is gated on a successful scrape
rather than a fresh snapshot, and a held frontend keeps paging through a
stale one. It reads the gauge's last sample over 2 minutes and requires
one successful scrape in that window, so a failed scrape's staleness
markers do not restart the dwell. No data and evaluation errors are OK,
as for the other paging rules, and an image older than #661 exports no
series.

Nine promtool scenarios cover the page and its pending dwell, a failed
scrape every 50 s, a submitting frontend, the unpublished setting, a
failed scrape, a missing series, one held frontend of a pair, and a stale
snapshot. The deployment test expects 79 rules and checks the rule's
dwell, gauge and gate; the migration table and the review-only qbit-tools
patch are regenerated. The rehearsal runbook says to scrape a rehearsal's
frontends under another job or network, or to silence this rule and the
pending-candidate rules by the rehearsal frontends' instance labels; the
configuration reference and the go-live checks name the rule.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
RobertClarke added a commit that referenced this pull request Oct 5, 2026
…hatever each frontend's switch says (#664) (#682)

#661's PRISM_BLOCK_SUBMIT_ENABLED=0 holds only a frontend started with
it. On a rehearsal against a restored mainnet ledger, a frontend started
without it would claim and offer every pending row.

Migration 023 (offline, like 021 and 022) adds a permanent one-row
table, qbit_prism_submission_hold, and an append-only journal of each
set and clear that changes it, qbit_prism_submission_hold_events, and
declares block_submission_hold = 1 so a pre-023 binary refuses the
database at connect. While the hold is set:
- claim_candidate and claim_fanout claim nothing, in the same single
  writer-fence statement as before;
- reserve_offer_within reads the hold FOR SHARE on the hold's own row
  and refuses with SubmissionHeld, leaving the row pending. Only
  submission-hold set and clear lock that row, so a hold commits either
  before a reservation or after one, and the read takes no lock on the
  cluster row, so the hold adds no wait behind a landing or blob GC;
- the CTV broadcaster refuses its pass and rechecks before every send;
  a hold set during an attempt hands its claim back unattempted,
  bounded at 5 s like the shutdown hand-back.

qbit-prism-server submission-hold show|set|clear reads only
PRISM_DATABASE_URL, so a frontend-only setting left invalid cannot stop
an operator. show is read-only, gives up after 15 s and reads pre-023
ledgers; set and clear require --reason and are journaled, and clear is
refused while candidates are pending unless --offer-pending-candidates.
fatal-state clear, candidates abandon and submission-hold share one
operator-reason rule, and writable shares its columns and checks with
the hold-aware fence.

Health and the heartbeat keep block_submission_enabled as the
frontend's own switch and add block_submission_hold as the frontend last
read it, in one statement with the payout revision: held is null until
the first read succeeds, and a later failed read keeps the last one, so
a database outage neither reports nor pages a frontend as held. A
running frontend logs when the hold appears and clears.
qbit_prism_block_submission_enabled is now live: 0 when the switch or
the hold holds, 1 when neither does, -1 when the switch is on and the
hold has not been read yet. check-config stays offline and says where
the hold is reported; self-check reports submission_hold and warns.
PrismBlockSubmissionHeld (#666) now covers the hold and its remedy.

The ops runbook documents the hold, its journal and the set and clear
procedures for rehearsal and cutover; the migration notes, the
configuration reference, the server README and the go-live checks name
it. Fixtures, capability rollbacks, the recovery-evidence script and the
pool-acquire gate cover 023.

Tests: a real-binary test (a frontend started without the switch on a
held ledger sends no submitblock until clear --offer-pending-candidates,
then offers each block once), PostgreSQL tests of the held claim and
reservation, the hold fence (a reservation waits for a hold being set,
never for the cluster row), the journal's immutability, the held
broadcaster and a hold set mid-attempt, and CLI, self-check, gauge and
hold-view tests.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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