Repository navigation
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) - #674
Merged
Conversation
…hare'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]>
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. |
…ce-capture # Conflicts: # docs/prism-native-metrics.md
This comment has been minimized.
This comment has been minimized.
…e 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]>
…ce-capture Co-Authored-By: Claude Opus 5.5 <[email protected]>
Member
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. Delightful! 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". |
RobertClarke
added a commit
that referenced
this pull request
Oct 5, 2026
Brings in #674 and #680; neither adds a migration, so 023 keeps its number. Co-Authored-By: Claude Opus 5.5 <[email protected]>
RobertClarke
added a commit
that referenced
this pull request
Oct 6, 2026
… not ledger-confirmation-failed (#675) (#698) A share whose payout revision moves between its submit check and the append's read under ORDER_LOCK is refused by the append's fence before any write. Since #674 the refusal is a typed PayoutRevisionChanged, but it still reached the generic Failed arm and was answered ledger-confirmation-failed ("share was not confirmed by the database"), with a "share persistence failed" WARN. Its work was superseded, which the submit check itself answers stale-job a moment later; the ledger is healthy. persist_share_pass now maps that refusal to Superseded(PayoutRevision), beside the existing stale-authority gate mapping. The miner is answered stale-job (code 21, "stale job"), still never credited, and the payout_revision stale-job cause is counted once. A plain share's refusal is counted, not logged, like the submit check's. With capture off, a block-bearing share is refused the same way, and its found block is never offered, so a WARN names the lost block. The refusal no longer feeds PrismShareAppendFailures, which fired around every revision bump at production share rates. The load harness classes these refusals as expected landing races instead of backend refusals. The tests that pinned the old answer now pin stale-job, the cause count, and the absence of a persistence WARN. The rejection, metric and PayoutRevisionChanged docs say where the refusal is counted. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #657. Refs #478, #504, #574, #632, #656.
The bug
submit_shareadmits a block-bearing share on the credit path at payout revision R, and the candidate rides in the share's append.append_preparedre-reads the revision underORDER_LOCK. If a same-parent settlement committed in between, it bailed withpayout revision changed before share commitbeforeappend_inand before the candidate insert. The transaction rolled back with the candidate inside it, and the miner gotledger-confirmation-failed. Nothing enqueued the block, so a valid found block was never offered.#504 (#478) captures a block found on same-parent superseded work, but only when the supersession is already visible at the submit check (
capture_stale).The fix: capture inside the same transaction
I chose the in-attempt option over handing the candidate back to
submit_share. It is the simpler of the two that is provably atomic, for two reasons:ORDER_LOCKand the sameFOR SHAREread, so an attempt commits either the credited share with its candidate or the capture, never both.submit_sharewould only run if the append finished in time. Here the capture is the append's own work, so an append that finishes after its answer still captures its block.The changes:
ledger/candidates.rs). When the append may capture, its candidate is prepared in two forms before the transaction opens. One is the credited form. The other is its capture: the same document with the solver share asdeferred_share, its digest, and the deferred-share row. The block and the as-issued balances are#[serde(skip)]fields, so the capture costs one more O(1) serialization, and the transaction still inserts only prepared bytes.persist_prepared_candidateandpersist_prepared_captureboth write throughpersist_candidate_row, behind the same writer fence, as-issued snapshot and 3.x.x: after an async promotion, a block on a job issued in the replication gap is offered and lands on chain but can never be landed in the pool (window range incomplete) #619 window probe.ledger/window.rs). The caller says what a moved revision means for a block,MovedRevision::{Capture, Refuse}:append_preparedwrites the capture (outbox rowshare_idNULL, plus the deferred share), runs the same commit-gate tail as a credited append, commits, and logs a WARN.persist_block_onlyuses. A proof already credited with its candidate, then resubmitted as the revision moves, is answeredduplicate-shareand writes nothing. Without the probe it would fail oncandidate identity conflictand be answeredledger-confirmation-failed.PayoutRevisionChanged { expected, observed }, and still answeredledger-confirmation-failed.AppendResult.capturedreports the capture.coordinator/submit_ledger.rs,coordinator/miner_submit.rs).persist_share_passpassesCapturewhenPRISM_CAPTURE_OVERPAY_CEILING_BPS> 0, otherwiseRefuse, the same switch the submit check'sblock_captureuses.SubmitLedgernow returnsAppended::{Inserted, Recorded, Captured}.share_commit_timeoutfor the block's disposition (deferred_share_disposition, extracted frompersist_block_only), then is answered:stale-job, if the capture is abandoned;sync_rep_unknown) applies to a captured COMMIT as it does to a credited one. The follow logger reportsoutcome="captured".PRISM_CAPTURE_OVERPAY_CEILING_BPSat its offer by the existing reservation, exactly as a capture at the submit check is (offered/abandoned). It lands as issued, and its share is credited once on confirmation. With the ceiling at 0, capture is off: the fence refuses as before 3.x.x: a block found on the current tip is dropped when the payout revision moves between its submit check and its append's revision fence (#478 capture gap) #657, as the submit check refusesstale-jobas before 3.x.x: An own block found 9 s after the previous landing was refusedunknown-joband never reached the node #478.Invariants and their tests
Same rows as a capture at the submit check.
ledger::candidates::capture_form_tests(no database) pins that the fence's capture form is byte-identical to preparing the candidate with its share deferred, which is whatcapture_staleenqueues: same document, digest, deferred row and snapshot. Preparing it leaves the credited form unchanged.One offer, one credit, audit and reconciliation intact (PostgreSQL, real
Coordinator, scripted node). New tests incoordinator::commit_reconcile_tests. The race is driven deterministically: the test session holdsORDER_LOCK, waits until the submit's append queues behind it, then bumps the revision and releases the lock. That is a settlement committing behind a share already past its submit check.…block_whose_revision_moves_before_its_commit_is_captured_and_lands_once. The outbox row is a capture: no crediting share, the share deferred, the block at its issued revision. The share is not credited before confirmation, and is not answered before its block's disposition. After the drive:submitted, offer decisionofferedwith both revisions;submitblock, exactly 1 ledger row;confirmedwith 1 audit bundle;Resubmitting the same proof credits and offers nothing more.
…credited_block_resubmitted_as_its_revision_moves_is_a_duplicate. A proof credited with its candidate, resubmitted into a moving revision:duplicate-share;With the probe disabled, this test fails on
candidate identity conflict.…block_append_queued_past_its_deadline_still_captures_its_block. Answeredledger-outcome-unknownat its deadline while still queued. When the lock frees, it still captures, lands once and credits once.…block_whose_revision_moves_with_capture_off_is_refused_as_before. With ceiling 0:ledger-confirmation-failed, with the typed reason logged;…plain_share_whose_revision_moves_before_its_commit_writes_nothing. Answeredledger-confirmation-failedwith the typed reason logged, no row, and no INSERT reached.Coordinator unit tests (no database).
coordinator::miner_tests::fence_capturecovers:MemoryLedgerreproduction: captured, not dropped;MemoryLedgernow models the fence the way production does.Evidence
Setup: local PostgreSQL 16.15, debug build.
The new database tests against the base product code (bd1ddeb, with only the test file applied, before review added the capture-off and duplicate tests):
The same tests on this branch: all pass, as do all 21
commit_reconcile_tests.Unit and equivalence tests: 5 of 5 pass.
The rest, before merging the latest
3.x.x: all pass:qbit-prism-serverlib suite against PostgreSQL: 652 passed, 2 ignored;append_admission25,b478_capture_overpay29,b478_payout_integrity21,b478_stale_revision_block20,b574_ack_cap22,b602_order_lock_hold22,b619_gap_work_after_promotion6,candidate_storm20,cluster_row_fences1,ledger_cancelled_begin18,ledger_deadline_atomicity7,ledger_postgres194,ledger_single_execution22,ledger_wait_metrics3,lost_race_pin8,offer_lifecycle22,stratum_admission_postgres17.After merging
3.x.x(07da6a7): all pass again:append_admission25,b478_capture_overpay29,b478_payout_integrity21,b478_stale_revision_block20,b574_ack_cap22,ctv_fanout_bookkeeping24,ledger_postgres199,ledger_single_execution22,offer_lifecycle22,stratum_admission_postgres17.The lib suite ran on a fresh database. The reused local one had been migrated to 021 by the pre-merge runs and still held a running test instance, so 3.x.x: time CTV fanout claim leases on the taker's monotonic clock, and label session timeouts and hung refreshes by the dependency they wait on (#654, #655) #667's migration 022 refused it.
Python:
scripts/check_prism_pool_acquires.py,tests.test_check_prism_pool_acquiresandscripts/generate_prism_metrics.py --checkpass. Locally, shard 2's tests all pass; four parity citations were skipped here for lack of docker and credential images.Lint:
cargo fmt --all --checkandcargo clippy --workspace --all-targets -- -D warningsare clean.Code review (
/code-review high) and what changedMovedRevision.block-only→ it now names its path.duplicate-share. Same aspersist_block_only.ORDER_LOCK.Also
test/prism-gated-tests.txt.scripts/prism_pool_acquires.jsonclassifies the acquire that moved intodeferred_share_disposition.docs/prism-rejections.mdanddocs/prism-native-metrics.mdsay what happens to a block-bearing share-pass proof whose revision moved. Theblock_proof_ack_capped_totalmetadata covers the captured share path, and the inventory was regenerated withscripts/generate_prism_metrics.py.ledger-confirmation-failedanswer, now from a typed error. Answering themstale-job(causepayout_revision), as 3.x.x: transcript replay fails when a payout-revision change refuses a share mid-commit (ledger-confirmation-failed) #632 suggested, is left as a separate decision: 3.x.x: answer a plain share refused by the payout-revision fence stale-job, not ledger-confirmation-failed (#674 follow-up) #675.🤖 Generated with Claude Code