Repository navigation
3.x.x: capture own blocks found on same-parent superseded payout work (#478) - #504
Conversation
…#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]>
|
@cursor review |
There was a problem hiding this comment.
✅ 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.
Review ledger (/deep-review), head
|
| 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.
…-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]>
…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]>
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 byreadiness_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
Gare current and offered. The loss is onlyW: a pool with shareplosesf = p·W/Tof its own blocks. WithT= 60 s that is 0.52% to 0.68% atp= 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.
qbit_carry_forward_integrity_report()stays clean.Block-only work. A same-parent replacement retires the session's job to
JobKind::BlockOnly.submit_sharefences it before any grace branch, so it never earns share credit.stale-jobonce the enqueue settles.Overpay ceiling. A captured block can pay a balance that an earlier landing already paid down.
F: the sum ofmax(0, issued(m))over its own as-issued snapshot. The proof is in theledger/divergence.rsmodule docs.FOR SHARE. A block still current is reserved in that transaction.Fis withinPRISM_CAPTURE_OVERPAY_CEILING_BPSof its coinbase value. The decision and the reservation commit together; otherwise the block is abandoned unoffered, with a WARN log line.stale-job, neverledger-confirmation-failed, so it stays out of the share-append failure series. It counts underpayout_revisionfor a ceiling or capture-off refusal, and underparent_gracefor a lost race.0restores the pre-3.x.x: An own block found 9 s after the previous landing was refusedunknown-joband never reached the node #478 behaviour.Records (migration 020):
qbit_prism_payout_divergences: the offer decision,offered,abandonedordisabled, withFand 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()./audit/carry-forward-integrityandself-checkcarry apayout_divergenceline, which never fails a check.Metrics:
qbit_prism_capture_offer_decisions_total{decision=offered|abandoned_ceiling|abandoned_disabled}qbit_prism_divergent_landings_totalqbit_prism_divergent_landing_overpay_sats_totalqbit_prism_carry_forward_debt_satsgauge, 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.mdgains "Block capture and payout divergence (3.x.x: An own block found 9 s after the previous landing was refusedunknown-joband 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.prism-rejections.md, the metric metadata and inventory, the migration guide and the deleted-test map are updated.Accepted cost and sizing the ceiling
F, andFis at most the ceiling: 1% of the coinbase by default.Fis roughly the pool's positive carry float, which grows with the number of miners below the 14,720-sat payout floor:unknown-joband never reached the node #478 loss)./owed-balances, orSELECT sum(owed_balance_sats) FROM qbit_current_owed_balances(). Each decision row also records theFit was checked against.abandoned_ceiling, in the counter, the report'soffers_abandoned_by_ceilingor the WARN log, raise the ceiling on every frontend and restart them all.debt_satsstays exact.Verification
All PostgreSQL-backed runs used a private PostgreSQL 16 cluster (fsync on),
PRISM_TEST_REQUIRE_INTEGRATION=1, and a worktree-local target.qbit-prism-servertest binary includinglive_regtest, the lib, bins,qbit-prism-load, pool-builder, test-gate, prism-core, and the ignored runs includingcompact_runtime_scale --release.check_gate_manifest.pyreported all 707 expected gated tests executed.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.--all-targets -D warningsandcargo fmt --checkare clean. The pool-acquire inventory,generate_prism_metrics.py --check, settings, gate-env reads, toolchain pin, deleted-test map and manifest sort all pass.docs/prism-ledger-ops.mdchanged (sizing the ceiling, thedivergent_accountswording, 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.stale-job, blocks loststale-job(block-only work, block captured)b61747ec) gave the same loss and capture: base 8/15, candidate 15/15. Its PostgreSQL-restart run found a bug: block-only work was acknowledgedresult: truewith no share written, and the harness caught it (exit 4, "acknowledged share missing"). The fix answersstale-jobafter the capture, and the table above is on the fixed code.Fwas 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_satsand the debt gauge are exact in every case.overpay_sats. The case needs own blocks on both branches of a reorg.reconcile_blocks_in, run deactivations first, then confirmations and their records in height order, pinned by the reviewer's test pair.offer_observed_payout_revisioncan be one bump behind the revision at the decision.Fdoes not depend on it, and a stale abandon failsrequire_revisionand retries.payout_divergenceline 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.Fis conservative (integrity fix-delta note). A block superseded only by a balance-neutral bump is still held toF. Follow-up: reserve as current when the as-issued digest equals the current digest.divergent_accountscounts 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.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)
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.RetainedJobs::permitorder-dependent with permit-less jobsfind_map. Pinned over 64 map orders.caphelper. 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)
ledger-confirmation-failedpermit.is_none()prism-rejections.mdand the metric text.Round 2, general: NO BLOCKERS (1 major, 6 minor)
ledger-confirmation-failed, feeding the share-append failure alertSaveOutcome::Superseded(cause)answersstale-jobwith 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.FOR SHAREread, 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.disabled, a separate counter label and report field.8fc94faf, with the census re-derived.Round 2, payout integrity: BLOCKERS 1 (1 blocker, 1 major, 3 minor; 1 pre-existing item)
Uwas not a bound when a later current block confirmed firstF, which bounds the realized debt in every order. The reviewer's real-policy test is adopted (realized 10,000 =F).record_capture_disabled. The reviewer's test is adopted.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.
offer_observed_payout_revisioncan lag the decision by one bumpabandoned_ceiling" are in the ops doc and above.divergent_accountsis not "overpaid accounts"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.
Frefuses balance-neutral supersessionsCodex
Not run.
🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.