Skip to content

3.x.x: capture own blocks found on same-parent superseded payout work (#478) - #504

Merged
djh58 merged 1 commit into
3.x.xfrom
djh58/prism-b478-block-capture
Sep 24, 2026
Merged

djh58 merged 1 commit into
3.x.xfrom
djh58/prism-b478-block-capture

Conversation

@djh58

@djh58 djh58 commented Sep 24, 2026 •

Copy link
Copy Markdown
Member

Closes #478 (option B: capture). Adds migration 020 and one setting, PRISM_CAPTURE_OVERPAY_CEILING_BPS (default 100; 0 turns capture off).

Problem

Each own landing bumps the payout revision twice on the same parent. The observe bump comes when a frontend sees the new tip, and the settlement bump when the block confirms. Work issued between the two carries the earlier revision. 3.x.x refused a block found on that work stale-job (pinned by readiness_rpc), which dropped a valid coinbase. 2.x.x would have submitted it.

Measured on base at the #275 bar (2 frontends, 2,000 sessions, 400k window, 15 own landings):

  • G, from the observe bump to the settlement bump: 4.80 s p50.
  • W, from the settlement bump to the new-revision work: 1.04 s p50, 1.35 s max.

Blocks found during G are current and offered. The loss is only W: a pool with share p loses f = p·W/T of its own blocks. With T = 60 s that is 0.52% to 0.68% at p = 30%, about 2.2 to 2.9 full coinbases a day out of roughly 432.

Change

  • Capture. A block-pass proof on the current tip is accepted whatever its payout revision.

    • The block is enqueued and offered.
    • It lands with the prior balances its work was issued with (as-issued).
    • Any divergence from the canonical balances becomes additive carry-forward debt. On-chain amounts equal the coinbases, and qbit_carry_forward_integrity_report() stays clean.
    • The share is deferred and credited at confirmation.
  • Block-only work. A same-parent replacement retires the session's job to JobKind::BlockOnly.

    • submit_share fences it before any grace branch, so it never earns share credit.
    • Its captured block defers no share, and its share is answered stale-job once the enqueue settles.
    • The graveyard drops block-only work at a parent change and caps it per kind (N credit plus N block-only). The reservation lookup walks burial order.
  • Overpay ceiling. A captured block can pay a balance that an earlier landing already paid down.

    • Whatever the order of confirmations, the debt it creates is at most F: the sum of max(0, issued(m)) over its own as-issued snapshot. The proof is in the ledger/divergence.rs module docs.
    • The offer reservation reads the revision FOR SHARE. A block still current is reserved in that transaction.
    • A superseded block is reserved only if F is within PRISM_CAPTURE_OVERPAY_CEILING_BPS of its coinbase value. The decision and the reservation commit together; otherwise the block is abandoned unoffered, with a WARN log line.
    • An abandoned capture answers stale-job, never ledger-confirmation-failed, so it stays out of the share-append failure series. It counts under payout_revision for a ceiling or capture-off refusal, and under parent_grace for a lost race.
    • A bound that cannot be computed reserves nothing and abandons nothing; the offer is retried.
    • 0 restores the pre-3.x.x: An own block found 9 s after the previous landing was refused unknown-job and never reached the node #478 behaviour.
  • Records (migration 020):

    • qbit_prism_payout_divergences: the offer decision, offered, abandoned or disabled, with F and the ceiling. At confirmation it adds the debt the block created and the debt after.
    • qbit_prism_payout_divergence_accounts: one row per overpaid account.
    • qbit_prism_payout_divergence_report().
    • Confirmation records are written in the transaction that makes the block's rows count, in both the settlement and the chain reconciler. A re-confirmation replaces them.
    • /audit/carry-forward-integrity and self-check carry a payout_divergence line, which never fails a check.
  • Metrics:

    • qbit_prism_capture_offer_decisions_total{decision=offered|abandoned_ceiling|abandoned_disabled}
    • qbit_prism_divergent_landings_total
    • qbit_prism_divergent_landing_overpay_sats_total
    • the qbit_prism_carry_forward_debt_sats gauge, read from the balances after every confirmation or deactivation and at every full refresh snapshot.

    Census: 57 families, 238 series at startup, 672 populated.

  • Docs:

    • prism-ledger-ops.md gains "Block capture and payout divergence (3.x.x: An own block found 9 s after the previous landing was refused unknown-job and never reached the node #478)". It covers the mechanism, the bound, what the ceiling bounds and what it does not, the records, the accepted cost, sizing the ceiling, known record limitations, rolling upgrade, fatal-state clear, rejection causes and acknowledgement.
    • It also corrects the pre-existing claim "nothing is paid a third time".
    • prism-rejections.md, the metric metadata and inventory, the migration guide and the deleted-test map are updated.

Accepted cost and sizing the ceiling

  • Per captured block: the debt is at most F, and F is at most the ceiling: 1% of the coinbase by default.
  • Per day at the 2.x.x: bound accepted-preview publication latency during dense accepted-tip cadence #224 cadence (at most 840 own blocks): at most 840 times the ceiling. That worst case needs every own block to be a capture that realizes its whole float.
  • Who bears it: a miner's debt is recovered only from that miner's later gross. A departed miner's debt is borne by the remaining miners. That is the accepted price of keeping a coinbase that was previously lost whole; each capture keeps at least 99% of it.
  • The default has to be checked against the live float. F is roughly the pool's positive carry float, which grows with the number of miners below the 14,720-sat payout floor:
    • at 2,000 such miners it is at most about 29M sats, against the 50M-sat default (1% of 5·10⁹);
    • at about 3,400 miners near the floor it can exceed the default on its own, and every capture is then refused (the pre-3.x.x: An own block found 9 s after the previous landing was refused unknown-job and never reached the node #478 loss).
    • The live float is the sum of /owed-balances, or SELECT sum(owed_balance_sats) FROM qbit_current_owed_balances(). Each decision row also records the F it was checked against.
    • If captures show up as abandoned_ceiling, in the counter, the report's offers_abandoned_by_ceiling or the WARN log, raise the ceiling on every frontend and restart them all.
  • The ceiling is per frontend. It is read at startup and is not in the cluster fingerprint. Adding it would change every pinned fingerprint and make a kill-switch change an offline policy transition. Set one value for all frontends; Compose passes one value.
  • Rolling upgrade. An old frontend abandons a captured block exactly as before and writes no divergence record. The records can undercount until every frontend runs this release, while debt_sats stays exact.

Verification

All PostgreSQL-backed runs used a private PostgreSQL 16 cluster (fsync on), PRISM_TEST_REQUIRE_INTEGRATION=1, and a worktree-local target.

  • Full gated suite: 81 runs.
    • Covered: every qbit-prism-server test binary including live_regtest, the lib, bins, qbit-prism-load, pool-builder, test-gate, prism-core, and the ignored runs including compact_runtime_scale --release.
    • check_gate_manifest.py reported all 707 expected gated tests executed.
    • 80 of 81 runs passed. The failure was candidate_storm_restart's pinned statement count (67 against 62). The confirmation record was trimmed to 2 statements per recovered row and the pin re-derived at 64.
    • The 17 runs that preceded that change were re-run on the final code, and all passed.
  • Checks: clippy --all-targets -D warnings and cargo fmt --check are clean. The pool-acquire inventory, generate_prism_metrics.py --check, settings, gate-env reads, toolchain pin, deleted-test map and manifest sort all pass.
  • After the fix-delta verification: only docs/prism-ledger-ops.md changed (sizing the ceiling, the divergent_accounts wording, known record limitations). No code changed.

Real-process evidence (STEP 5)

Setup: 2 frontends, 2,000 sessions, the 400k window, 8 external tips, a 120 s warm-up, a 2 s blockpoll and 15 own landings per run. Each run held an exclusive timing lock. Both binaries were built on 8fc94faf.

Run Gaps Landed / 15 Refused Captures G p50 / max W p50 / max New-tip work p50 Exit
base dense #224 (9-20 s) 15 0 n/a 4.27 / 4.65 s 0.89 / 1.65 s 0.909 s 0
candidate dense #224 15 0 0 4.33 / 4.65 s 0.91 / 1.59 s 0.910 s 0
base race 5 s 8 7 stale-job, blocks lost n/a 4.27 / 4.55 s 1.27 / 1.63 s 0.902 s 0
candidate race 5 s 15 0 14 (F = 0) 4.35 / 4.68 s 1.52 / 1.56 s (n=2) 0.955 s 0
candidate, PostgreSQL restarts at the 4th and 10th candidate #224 15 blocks on chain 1 share stale-job (block-only work, block captured) 1 (F = 0) 4.48 / 7.80 s 0.92 / 1.56 s 0.914 s 0, no durability finding
  • No timing regression at equal load: in the dense pair, new-tip work is 0.909 s on base and 0.910 s on the candidate.
  • The race pair is not an equal-load pair. The candidate lands twice as many blocks, and each landing costs two rebuilds.
  • An earlier round on the previous base (b61747ec) gave the same loss and capture: base 8/15, candidate 15/15. Its PostgreSQL-restart run found a bug: block-only work was acknowledged result: true with no share written, and the harness caught it (exit 4, "acknowledged share missing"). The fix answers stale-job after the capture, and the table above is on the fixed code.
  • F was 0 in every run. These settlement bumps moved no carried balance, so the realized-overpay paths are covered by the PostgreSQL tests, not by STEP 5.

Known limitations and proposed follow-ups

These are records-only issues or design follow-ups. The balances, debt_sats and the debt gauge are exact in every case.

  1. Reorg record order (integrity fix-delta n1). If one reconciliation confirms an own block below an own block it deactivates, the lower block's record is measured against balances that still count the higher block. It can under- or over-state that record's overpay_sats. The case needs own blocks on both branches of a reorg.
    • Follow-up: in reconcile_blocks_in, run deactivations first, then confirmations and their records in height order, pinned by the reviewer's test pair.
    • This is not a pure reorder. A mature-disconnect fatal returns partway through the pass, and the caller commits what the pass already did. Moving the fatal check into a first pass changes what a fatal pass commits, so it needs its own look.
  2. Observed revision lag (general fix-delta n1). offer_observed_payout_revision can be one bump behind the revision at the decision. F does not depend on it, and a stale abandon fails require_revision and retries.
    • Follow-up: re-read the revision in the decision transaction.
  3. The float in the report. The payout_divergence line shows debt, not the live positive float. Follow-up: add the float to the line so the ceiling can be checked from the report alone.
  4. F is conservative (integrity fix-delta note). A block superseded only by a balance-neutral bump is still held to F. Follow-up: reserve as current when the as-issued digest equals the current digest.
  5. Migration 020 column comment (general fix-delta n4). It still says "the divergent accounts". The ops doc now explains that divergent_accounts counts every account whose balance moved, over- or underpaid, and that the overpaid ones are the accounts table. The SQL comment is left unchanged because no code changed after verification.
  6. A per-account debt rule ("no capture while an earlier capture's debt is outstanding for the same accounts") and a submit-time capture counter were not built; the offer decision counter counts captures.
  7. Resume limitation. A reconnecting miner's block found on superseded work is still dropped.
  8. Option C2, projecting the pending landing into new-tip work, would remove the settlement-cause gap structurally. It needs a fence change and its own payout-integrity review. Capture remains useful under C2 for the other same-tip bumps (maturity, fatal-state clear, policy transition). C1, waiting for the landing before issuing new-tip work, is rejected: its cost lands on new-tip latency and liveness.

Note for anyone who ran an earlier build of this branch: migration 020's contents changed under the same version during review. Rebuild any scratch database that applied an earlier version. No released database has it.

Review ledger

Two rounds, each by an independent general reviewer and an independent payout-integrity reviewer, then a fix-delta verification by both. Every finding and its disposition follows.

Round 1, general: BLOCKERS 1 (1 blocker, 1 major, 7 minor)

Finding Disposition
B1: buried superseded jobs earn stale-grace credit after a parent flip Fixed at the source: JobKind::BlockOnly, fenced before any grace branch, dropped at a parent change. Pinned on every credit path, and by a PostgreSQL test with grace false and true.
M1: RetainedJobs::permit order-dependent with permit-less jobs Fixed: burial order with find_map. Pinned over 64 map orders.
m1: block-only cap allows 2N Fixed: retire before bury, per-kind cap. The capacity test pins N=1 and N=64.
m2: a captured share-pass block holds the connection until confirmation Kept by design: the same 60 s bound as every block-only proof, usually sub-second. Block-only work is no longer held; its share is answered after the enqueue.
m3: observability gaps Fixed: records, metrics and the report line.
m4: imprecise readiness pin Fixed: the capture happens before the refresh past the bump, and the pin asserts the outcome, the outbox state and one deferred share.
m5: tests did not exercise production paths Fixed: the hand-built-row test is removed and replaced by real-landing tests.
m6: mixed-version and restart residuals Rolling upgrade documented. The resume limitation is follow-up 7.
m7: implicit marker, duplication, retained contexts Fixed: explicit kind and one cap helper. Retained contexts end at the next parent change.

Round 1, payout integrity: BLOCKERS 1 (1 blocker, 2 major, 6 minor; plus 1 pre-existing major)

Finding Disposition
B1: block-only buried jobs earn stale-grace credit The same fix. The reviewer's test is adopted verbatim.
M1: the double-pay bound and recovery claims were wrong The claims are withdrawn and a ceiling added. The bound itself was redone in round 2. The accepted cost is documented.
M2: divergence invisible to the report and metrics Migration 020, the metrics and the report line.
m1: session stall until confirmation; a lost-race abandon answered ledger-confirmation-failed The stall is as general m2. The answer was fixed in round 2 (general M1).
m2: the block-only marker was permit.is_none() Fixed: explicit kind.
m3: rolling upgrade Documented.
m4: the fatal-state clear bump no longer invalidates same-tip candidates Documented: a pre-fatal pending block on the current tip is offered within the ceiling.
m5: rejection-metric semantics shift Documented in prism-rejections.md and the metric text.
m6: evidence gaps Fixed by the real-landing tests and the grace-after-flip PostgreSQL pin.
Pre-existing: the ops doc said "nothing is paid a third time", disproved on base Corrected.

Round 2, general: NO BLOCKERS (1 major, 6 minor)

Finding Disposition
M1: an abandoned capture answered ledger-confirmation-failed, feeding the share-append failure alert Fixed: SaveOutcome::Superseded(cause) answers stale-job with the right cause, and node rejections and orphans keep the old answer. Checked against the #493/#496 rules: none fires on a pre-offer abandon.
m1: an unlocked revision pre-read let a bump bypass the ceiling Fixed: FOR SHARE read, reserved in the same transaction. Pinned by a concurrent-bump test. The docs state what the ceiling does not bound: a block reserved current, and leased candidates.
m2: capture-off refusals labelled as ceiling abandons Fixed: decision disabled, a separate counter label and report field.
m3: the patch did not apply to the current base Rebased onto 8fc94faf, with the census re-derived.
m4: rollout note Documented.
m5: metric text Fixed. The submit-time capture counter is not added (follow-up 6).
m6: settlement lock held across snapshot parsing Fixed, then removed: the round-2 integrity fix needs no settlement lock on the offer path.

Round 2, payout integrity: BLOCKERS 1 (1 blocker, 1 major, 3 minor; 1 pre-existing item)

Finding Disposition
B1: the round-1 bound U was not a bound when a later current block confirmed first Fixed: the ceiling holds F, which bounds the realized debt in every order. The reviewer's real-policy test is adopted (realized 10,000 = F).
M1: records and metrics written at landing, but debt is realized at confirmation Fixed: records, counters and account rows are written at confirmation, in both writers. The gauge is read from the balances. The reviewer's interleave test is adopted (records = debt = gauge).
m1: the ordinary capture-off path wrote no record Fixed: record_capture_disabled. The reviewer's test is adopted.
m2: mixed-version records Documented.
m3: per-frontend ceiling Documented, not fingerprinted (see above).
Pre-existing: leased candidates skip the check Documented in "what the ceiling bounds".

Fix-delta verification, general: NO BLOCKERS (3 minor, 1 doc nit)

All round-2 findings were verified fixed by the reviewer's own probes, including one on the chain-reconciler confirmation path.

Note Disposition
n1: offer_observed_payout_revision can lag the decision by one bump Known, bounded, records-only. Documented; follow-up 2.
n2: at scale the 100 bps default may refuse most captures Default kept. Sizing against the live float, the example numbers, and "raise the ceiling on abandoned_ceiling" are in the ops doc and above.
n3: every offer takes a share lock on the cluster singleton row Noted. Holds are milliseconds; the dense STEP 5 pair shows no regression.
n4: divergent_accounts is not "overpaid accounts" Ops doc fixed. The migration comment is follow-up 5.

Fix-delta verification, payout integrity: NO BLOCKERS (1 minor, 2 notes)

All round-2 findings were verified fixed. Every changed file was confirmed byte-identical to the reviewed tree.

Item Disposition
n1: reorg record order Known, bounded, records-only. Documented; follow-up 1, with the fatal-path caveat.
Note: F refuses balance-neutral supersessions Documented; follow-up 4.
Note: migration 020 changed under the same version during review See the note above; no released database is affected.

Codex

Not run.

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

…#478)

Each own landing bumps the payout revision twice on the same parent: once
when a frontend observes the new tip, and again when the block confirms.
Work issued between the two carries the earlier revision, and 3.x.x refused
a block found on it `stale-job`, dropping a valid coinbase that 2.x.x
would have submitted. At the #275 bar the exposure window W (settlement bump
to new-revision work) measured 1.04 s p50 and 1.35 s max, so with a 60 s
target spacing a pool with share p loses f = p*W/T of its own blocks:
0.52% to 0.68% at p = 30%, about 2 to 3 coinbases a day.

A block-pass proof on the current tip is now captured whatever its payout
revision. The block is enqueued and offered, lands with the prior balances
its work was issued with, and any divergence from the canonical balances
becomes additive carry-forward debt; on-chain amounts and the integrity
report stay exact. The share is deferred and credited at confirmation.

- Block-only work. A same-parent replacement retires a session's job to
  JobKind::BlockOnly. submit_share fences it before any grace branch: it
  never earns share credit, its captured block defers no share, and its
  share is answered `stale-job` once the enqueue settles. The graveyard
  drops block-only work at a parent change and caps it per kind, and the
  reservation lookup walks burial order.
- Overpay ceiling. A captured block can pay a balance that an earlier
  landing already paid down. In every order of confirmations, the debt it
  creates is at most F, the sum of the positive balances in its own
  as-issued snapshot. The offer reservation reads the revision FOR SHARE: a
  block still current is reserved at once; a superseded one is reserved
  only if F is within PRISM_CAPTURE_OVERPAY_CEILING_BPS of its coinbase
  value (default 100, range 0 to 10000, 0 turns capture off), and is
  otherwise abandoned unoffered. An abandoned capture answers `stale-job`
  (payout_revision, or parent_grace for a lost race), never
  `ledger-confirmation-failed`. A bound that cannot be computed reserves
  nothing and abandons nothing.
- Records. Migration 020 adds qbit_prism_payout_divergences (the offer
  decision, F and the ceiling; at confirmation, the debt the block
  created), qbit_prism_payout_divergence_accounts and
  qbit_prism_payout_divergence_report(). Confirmation records are written in
  the transaction that makes the block's rows count, in the settlement and
  in the chain reconciler. The carry-forward integrity report and
  self-check gain a payout_divergence line that never fails a check.
- Metrics: qbit_prism_capture_offer_decisions_total{decision},
  qbit_prism_divergent_landings_total,
  qbit_prism_divergent_landing_overpay_sats_total and the
  qbit_prism_carry_forward_debt_sats gauge.
- Docs: a ledger-ops section on capture, the bound, sizing the ceiling
  against the live positive carry float, the records, the accepted cost,
  known record limitations and rolling upgrade; rejection-cause notes; the
  metric inventory and migration guide.

Tests: new b478_capture_overpay (10 gated), b478_payout_integrity (the
payout-integrity reviewer's 3 tests) and b478_stale_revision_block binaries;
lib tests for the block-only fence on every credit path, the retained-job
cap and lookup, and the bound; the readiness_rpc capture pin; stratum
protocol tests for job kinds; the candidate_storm_restart statement pin
re-derived at 64. The full gated suite executed all 707 expected gated
tests. Real-process runs at the #275 bar with 5 s landing gaps: base lands
8 of 15 own blocks and refuses 7; this change lands 15 of 15, 14 as
captures, with no timing regression at equal load.

Review: two rounds by a general reviewer and a payout-integrity reviewer,
then a fix-delta verification by both, ending with no blockers. The
per-finding ledger is in the pull request. Codex was not run.

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

djh58 commented Sep 24, 2026

Copy link
Copy Markdown
Member Author

@cursor review

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 5724ea4. Configure here.

@djh58

djh58 commented Sep 24, 2026

Copy link
Copy Markdown
Member Author

Review ledger (/deep-review), head 5724ea4f

High-stakes: payout and carry-forward balances, settlement records, and schema migration 020.

Independent review

Both independent reviewers were read-only Claude reviewers. Each reviewed round 2 and then verified the fix delta on the full 66-file tree applied to 8fc94faf. That tree is byte-identical to this commit apart from a docs-only change to docs/prism-ledger-ops.md, which was reviewed separately. Round 1, round 2 and every disposition are in the PR description.

  • Independent reviewer, payout-integrity lens: round 2 had BLOCKERS: 1, fixed. Fix-delta verification: NO BLOCKERS.
    • Minor n1, reorg record order: a reconciliation that confirms an own block below an own block it deactivates records the lower block against balances that still count the higher one. Records only; balances and debt_sats are exact. Follow-up 1 in the description.
    • Note: F is conservative for balance-neutral supersessions. Follow-up 4.
    • Note: migration 020 changed under the same version during review. No released database is affected.
  • Independent reviewer, general lens: round 2 had no blockers and 1 major, fixed. Fix-delta verification: NO BLOCKERS.
    • Minor n1: offer_observed_payout_revision can lag the decision by one bump. Records only. Follow-up 2.
    • Minor n2: at scale the 100 bps default can refuse most captures. The default is kept, and the ops doc now says to size it against the live positive float.
    • Minor n3: every offer takes a share lock on the cluster row. No regression was measured at equal load.
    • Doc nit n4: divergent_accounts counts underpaid accounts too. The ops doc is fixed; the migration comment is follow-up 5.

This pass

The author session ran three passes inline: code review, a maintainability review and an adversarial review. It found no blockers and no majors. A cross-model (Codex) lane was not run. Cursor Bugbot reviewed 5724ea4f and found no new issues.

ID Finding Disposition
thermo-1 tests/readiness_rpc.rs grows past 1,000 lines (925 to 1,016). Rejected. It is a test file, and the growth is the capture pin the round-1 review required.
thermo-2 Capture-off handling is duplicated: the pre-offer check (coordinator.rs) and the offer reservation's zero-ceiling branch each record disabled, count abandoned_disabled and abandon with the base reason. Deferred (follow-up A). Merging them changes the revision and the moment at which the block is abandoned, on the payout path.
adv-1 An operator candidate abandon of a pending block-only candidate, while its miner still waits within the 60 s acknowledgement bound, is answered stale-job counted under payout_revision. Base answered ledger-confirmation-failed. Deferred (follow-up B). stale-job is the right answer, since the pool decided not to offer the block and the ledger did not fail. Only the cause label is imprecise, in an operator-driven edge case.
adv-2 qbit_prism_carry_forward_debt_sats can briefly show an older value. A refresh snapshot that read balances before a confirmation can commit after it and set the pre-confirmation debt. Deferred (follow-up C). It corrects itself within one refresh: the confirmation's revision bump makes the refresh window non-reusable, and the next snapshot re-reads the balances. The report's debt_sats reads the balances directly and is exact.

Follow-ups to file after merge

  • A. Handle capture off in one place, the offer reservation, with the abandon revision and timing kept explicit.
  • B. Give an operator abandon of a block-only candidate its own rejection cause, or no cause label.
  • C. Stamp the carry-forward debt gauge with the payout revision it was read at, and ignore older values.

These sit alongside follow-ups 1 to 8 in the PR description.

CI

All 21 checks pass on 5724ea4f, including the Rust tests, Rust lints, the four PRISM PostgreSQL and multi-instance shards, and "Prove every Rust PRISM gated test executed". [code]smith was skipped.

@djh58
djh58 merged commit e1457e3 into 3.x.x Sep 24, 2026
22 checks passed
djh58 added a commit that referenced this pull request Sep 24, 2026
…-paging

Both sides add metric families. Conflicts resolved by hand in the census
tests only: `tests/observability/cardinality.rs` re-derived from the merged
registry (60 families; 241 startup and 675 populated series: #504's four
families and six series plus this branch's three unlabeled gauges), and
`tests/observability/contract.rs` keeps both sides' gauge names. #502 and
#507 touch no metrics files. The auto-merged registry, metrics, coordinator,
ledger, metadata, inventory and gated-test list were checked: every family
and constant from both sides is present, the metadata names all resolve in
the registry, the inventory is regenerated, and the gated list is byte-sorted
with no duplicates.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
RobertClarke added a commit that referenced this pull request Oct 5, 2026
…hare's commit, instead of losing it to the append's fence (#657) (#674)

* 3.x.x: capture a found block whose payout revision moves before its share's commit, instead of losing it to the append's fence (#657)

A block-bearing share was admitted on the credit path at payout revision
R, and its candidate rode in the share's append. append_prepared re-read
the revision under ORDER_LOCK. If a same-parent settlement had committed
in between, it bailed with "payout revision changed before share commit"
before append_in and the candidate insert. The transaction rolled back
with the candidate in it, the miner got ledger-confirmation-failed, and
nothing enqueued the block: the found block was never offered. #504
(#478) captures a block found on same-parent superseded work only when
the supersession is already visible at the submit check.

The fence now captures the block instead, in the same transaction. A
fenced append's candidate is prepared in two forms before the
transaction opens: the credited one, and its capture. The capture is the
same document with the solver share as deferred_share, its digest, and
the deferred share row. The block and the as-issued balances are skipped
fields, so the capture costs one more O(1) serialization, and the
transaction still inserts only prepared bytes.

When the revision moved, append_prepared writes the capture and commits
it. It does so under the same ORDER_LOCK and FOR SHARE read, through the
same writer fence, as-issued snapshot and #619 window probe as any
enqueue, and never also appends the share. A share without a block keeps
the refusal, now the typed PayoutRevisionChanged, still answered
ledger-confirmation-failed. AppendResult.captured reports the capture,
and SubmitLedger returns Appended::{Inserted, Recorded, Captured}.

The share path answers a capture the way it answers a block-only proof.
It waits up to share_commit_timeout for the block's disposition, using
deferred_share_disposition, extracted unchanged from persist_block_only.
The share is accepted once confirmation credits the deferred share,
answered stale-job if the capture is abandoned, and answered unknown at
the bound. The capture is the append's own work, so an append still
running past its acknowledgement deadline captures its block in the
background.

The capture is byte for byte the row capture_stale enqueues, and a test
pins that. So its offer is held to PRISM_CAPTURE_OVERPAY_CEILING_BPS
(offered, abandoned or disabled), it lands as issued, and its share is
credited once on confirmation.

Tests:
- coordinator::commit_reconcile_tests, PostgreSQL. The test holds
  ORDER_LOCK, bumps the revision behind a queued append and releases the
  lock. Four cases:
  - a block is captured, offered once, landed with its audit bundle and
    credited once; integrity is clean, accepted shares equal credited
    headers, and a resubmission adds nothing;
  - an append queued past its deadline is answered unknown and still
    captures;
  - with capture off the block is abandoned with the disabled decision
    and never offered;
  - a plain share writes nothing.
  Against the base product code the three block tests fail with no
  candidate ever enqueued.
- ledger::candidates::capture_form_tests: the capture form equals
  capture_stale's preparation.
- coordinator::miner_tests::fence_capture: #657's MemoryLedger
  reproduction, now captured; MemoryLedger models the fence as production
  does.

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

* 3.x.x: #657 review: a resubmitted credited block is a duplicate at the fence, and capture off refuses as before

- The fence's capture probes for the share first, with the probe
  persist_block_only uses. A proof already credited with its candidate,
  resubmitted as the revision moves, is answered duplicate-share and
  writes nothing, instead of failing on "candidate identity conflict".
- With PRISM_CAPTURE_OVERPAY_CEILING_BPS=0 the fence refuses a
  block-bearing share as before (MovedRevision::Refuse), as the submit
  check refuses one whose revision already moved. No capture form is
  prepared when capture is off.
- The capture and the credited append share one commit-gate tail.
- persist_share_pass takes the block hash from submit_share, which
  removes the unreachable no-block arm. The sync-rep guard no longer
  checks the gate state first.
- The disposition poll's retry log names its path.
- scripts/prism_pool_acquires.json: the acquire that moved into
  deferred_share_disposition is classified there, which fixes CI Python
  shard 2.
- Tests: the capture-off refusal (unit and PostgreSQL), and a credited
  block resubmitted into a moving revision is a duplicate (PostgreSQL,
  gated). The capture-off docs are updated.

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

---------

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