Repository navigation
3.x.x: hold block submission for the whole cluster from the ledger, whatever each frontend's switch says (#664) - #682
Conversation
…hatever each frontend's switch says (#664) 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: show is read-only, needs only PRISM_DATABASE_URL, 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]>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 21b41738a5
ℹ️ 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".
…664) Both went through DatabaseConfig::from_env, which also validates PRISM_INSTANCE_ID and PRISM_DATABASE_MAX_CONNECTIONS, so a frontend-only setting left invalid could stop an operator holding or releasing the cluster, against the documented contract. DatabaseConfig::url_from_env reads and checks the URL alone, as from_env does, and from_env now calls it. The real-binary test runs every hold command with an invalid instance ID and connection count. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep them coming! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
… lane index becomes migration 024 #682 took 023 for the cluster-wide block submission hold, which is offline and transactional. The fanout lane index is now 024: 024_fanout_lane_index.sql, REQUIRED_SCHEMA_VERSIONS, NATIVE_MIGRATIONS, ONLINE_MIGRATIONS (13, 17, 24) and derive_online, so 023 stays in the migration transaction and only 024 is built online after the commit. The 2.x.x undo drops 024's index before 023's hold; the version pins, the recovery-evidence script, the share-hash backfill test's online set, the cutover rehearsal's step label, the gated-test name and the docs say 024. claim_fanout keeps #682's hold check before the survey and the lane. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…tial index, so a claim never scans settled history (#668) (#679) Settled fanouts stay in qbit_ctv_fanout_artifacts after their 1,000th confirmation, and mainnet adds about 65,000 to 130,000 a year at #521's block rate. The claim lane matched them on its status and schedule predicates and dropped them only after reading them: a sequential scan of the whole table on every claim, which a broadcaster pass repeats once per fanout it attempts. EXPLAIN (ANALYZE, BUFFERS) on PostgreSQL 16, warm cache, prepared, per claim, 7,500 watched fanouts: 63 ms at 100,000 settled fanouts and 357 to 412 ms at 1,000,000 (1 GB heap). Migration 024 adds qbit_ctv_fanout_artifacts_lane_idx, a partial index over the fanouts the lane may still claim (to broadcast or check, or confirmed under 1,000 deep), keyed by next_broadcast_attempt_at. The lane (Ledger::fanout_lane_sql) gathers its candidates into one array first: the due ones as two ranges of that index, never attempted and scheduled at or before statement_timestamp() (stable, so the index serves it as a bound), and the deep checkpoint (FANOUT_CHECKPOINT_SQL) from qbit_prism_fanout_checkpoint_idx. It looks them up by primary key and applies its full predicate and order as before. The only change in behaviour: a fanout falling due during the claim statement itself waits for the next poll. After, same data: 1.6 ms (100,000 settled, 377 due) and 1.8 to 2.0 ms (1,000,000 settled, 377 due), the generic plan included. A claim now costs what the due fanouts cost; the settled history only deepens the primary key. When every watched fanout is due, as when the broadcaster cannot recheck each one every 5 s, it reads them all: 28 ms at 100,000 settled and 38 ms at 1,000,000, against 67 and 412 ms before. 024 is additive like 019 and 020 (no capability, no shutdown proof, not offline) and applied online like 013 (ONLINE_MIGRATIONS). On an existing ledger the runner builds the index with CREATE INDEX CONCURRENTLY after the migration transaction commits and records 24 once it is valid, so no write to the fanout table waits for the build, a found block's landing (persist_fanouts) included: about 0.6 s at 1,000,000 settled fanouts. A fresh or empty source applies the file inside the transaction. It is 024 because #682 took 023, the offline block submission hold: an upgrade from 22 applies 023 in the migration transaction and then builds 024 online. Tests: - ledger_postgres::fanout_lane_plan::a_fanout_claim_poll_never_reads_the_settled_history plans and executes both statements of a claim poll, the survey and the lane, prepared, over 20,000 settled and 500 watched fanouts, through five custom plans and the generic one: no sequential scan of the fanout table, the lane index read, at most 16 fanout rows visited by the lane (lossy-bitmap rechecks counted), the survey within the watched fanouts. The pre-024 lane fails it ("scanned the fanout table"), and so does a single IS NULL OR range filter ("visited 508 fanout rows"). - ledger_postgres::fanout_lane_plan::migration_024_builds_the_lane_index_without_blocking_fanout_writes upgrades a ledger at 23 while a fanout write is open: the build waits for it, another fanout write lands meanwhile, then the index is valid, every required version is recorded and the lane claims through it. An in-transaction build fails it with a lock timeout. - ledger::fanout::tests pin the lane's copied SQL without a database: the candidate predicate against 024's index predicate, and the checkpoint against the one FANOUT_CLAIMABLE_SQL admits. Migration pins, the share-hash backfill test's online set, the cutover rehearsal's step label, the recovery-evidence script and the gated-test list include 024; prism-ledger-ops.md and prism-rust-migration.md describe the lane, its costs and the upgrade. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Closes #664. Part of #291. Builds on #661 (the per-frontend switch) and #676 (#666's page for a held frontend).
Problem
PRISM_BLOCK_SUBMIT_ENABLED=0(#661) holds one frontend, and only a frontend started with it. On a pre-production or rehearsal deployment against a restored mainnet ledger, any frontend started without the variable would claim and offer every pending row. A leased candidate also skips the pre-offer staleness probe, so its block would reach mainnet'ssubmitblock.Change
This adds a cluster-wide hold, stored in the ledger, that every frontend obeys whatever its own variable says.
Migration 023 (offline; declares the capability
block_submission_hold = 1)qbit_prism_submission_hold: one permanent row holding the reason, when it was set and by whom. A CHECK keeps the three consistent, and a trigger refuses deleting the row.qbit_prism_submission_hold_events: an append-only journal of each set and clear that changes the hold. It records who ran it (session_userandcurrent_user), why, and how many candidates were pending, and a trigger refuses UPDATE, DELETE and TRUNCATE, like the fatal-state journal.migrateanyway.Enforcement
claim_candidateandclaim_fanoutread the hold in their writer fence and claim nothing while it is set. It is the same single statement as before, so the pinned statement counts do not change.reserve_offer_withinreads the holdFOR SHAREon the hold's own row in each of its transactions.SubmissionHeld, an error and never aRefused, so the claim is released and the row stayspendinginstead of being abandoned.submission-hold setlocks that rowFOR UPDATE. A hold therefore commits either before a reservation, which is then refused, or after one, whose single offer completes.unknown-joband never reached the node #478) reads the cluster rowFOR SHAREas before.run_passrefuses while the hold is set, logged at debug level rather than as a warning every pass.writableand the hold-aware fence share one column list and one check, so a new halt condition reaches both.Operator command:
qbit-prism-server submission-hold show|set|clearshowprints read-only JSON:held,reason,set_at,set_by,last_event,schema_supports_holdandpending_candidates.PRISM_DATABASE_URL, opens one connection, gives up after 15 s, and also reads a pre-023 ledger.set --reasonuses the operator connection, which works while frontends run and on a halted cluster. It keeps a hold already in force.clear --reason [--offer-pending-candidates]is refused while candidates are pending, unless the flag says to offer them.fatal-state clearandcandidates abandonnow share.Visibility
check-configstays offline, as documented and tested. It prints that a cluster-wide hold in the database overridesPRISM_BLOCK_SUBMIT_ENABLED, and points atsubmission-hold showandself-check.self-checkreportssubmission_holdand warns on stderr when held. The value is theshowdocument, sampled read-only beside the heartbeats, or null when unreadable.block_submission_enabledstays the frontend's own switch, as in 3.x.x: add a block submission and broadcast kill switch for rehearsals against a real node (#291) #661, so a frontend started without the variable is still visible under a hold.block_submission_holdcarriesheld,reason,set_atandset_byas the frontend last read them.heldis 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.qbit_prism_block_submission_enabledcombines the two at every health publication: 0 when either holds, 1 when neither does, and -1 when the switch is on but the frontend has not read the hold yet. It is now a live family, rendered at scrape time.PrismBlockSubmissionHeld(3.x.x: page when a production frontend runs with block submission held (qbit_prism_block_submission_enabled != 1) #666) now describes the cluster hold and an unread hold, and gives the hold's remedy.Docs
docs/prism-ledger-ops.md: a new subsection, "Holding the whole cluster (023, 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)". It covers what the hold stops (claims in every state, including the landing of already-offered rows, whilecandidates recoverstill lands accepted blocks), the commands, the journal, visibility, and the set and clear procedures for rehearsal and cutover.docs/prism-rust-migration.md: the 023 note, and the migration-transaction range now ending at 023.docs/prism-configuration.mdand the server README row for the variable.docs/mainnet-deployment.md:submission-hold showreports"held": false.Fixtures and gates for 023
UNDO_023where a fixture models an older writer.migration_rollback.rs.Tests
candidate_storm_restart::a_held_ledger_holds_a_frontend_started_without_the_switch_until_it_is_clearedcandidate_lease_tests::submit_disabled_tests::a_cluster_hold_stops_an_enabled_frontend_until_it_is_clearedcandidate_lease_tests::submit_disabled_tests::the_hold_fence_waits_for_a_hold_being_set_and_never_for_the_cluster_rowFOR UPDATE,clearand a reservation without the capture check, as a leased candidate's is, still completectv_fanout_bookkeeping::a_cluster_hold_claims_and_sends_no_fanout_until_it_is_clearedctv_fanout_bookkeeping::a_hold_set_mid_attempt_hands_the_fanout_claim_back_unsentconfig_cli::check_config_reports_the_block_submission_kill_switch_firstconfig_cli::submission_hold_set_and_clear_refuse_a_blank_reason_before_reaching_the_database--reasonis required by bothself_check_clisubmission_hold: null when unreadable, and theshowdocument on a migrated ledgermetrics::snapshots::tests::block_submission_gauge_follows_the_kill_switch_and_the_cluster_holdcoordinator::submission_hold_view_tests::a_failed_read_keeps_the_hold_last_readIn the real-binary acceptance test:
qbit-prism-server submission-hold set.PRISM_BLOCK_SUBMIT_ENABLED, with a CTV broadcaster configured, runs across two health heartbeats over 3 due candidates.submitblock, rows staypendingand unclaimed, and no dispatch slot is used. Its heartbeat reports its switch on and the hold set.submission-hold clearis refused with "while candidates are pending (3)".clear --offer-pending-candidates,showreports the journaled clear aslast_event, and the same running frontend offers each block exactly once.In the in-process PostgreSQL test:
SubmissionHeld, and its row is left untouched.health()reports the switch on and the hold set.setis idempotent and refuses a blank reason; so doesclear.clearis refused while one row is pending. Once cleared with the flag, the same frontend lands the row with one offer.Local runs, on PostgreSQL 16:
offer_lifecycle,migration_rollback(its backup and restore tests included),ledger_postgres,candidate_stormandcandidate_storm_restart(its pinned 27- and 65-statement counts), the window, epoch and orphan migrations,api_2x,audit_completeness,signing_transition,candidate_dispatch_probe,share_partitions_postgres, and the whole lib (its physical-failover tests included);scripts/test_prism_alert_deployment.pyagainst the pinned qbit-tools snapshot;-D warnings, and the settings, metrics, alert-artifact, pool-acquire, gate-read and scenario checks.Notes and risks
submitblock, and a fanout send already past its last hold check completes. A hold set before any frontend starts, as the rehearsal procedure says, has neither.pending. On a drained cutover or a discarded rehearsal there is nothing else to wait. Otherwise, an offered block's landing and a sent fanout's confirmation tracking resume when the hold clears, andcandidates recovercan land an accepted block meanwhile.PrismBlockSubmissionHeldpages. A rehearsal or cutover hold must be scoped in the alerting as the runbook says.🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.