Repository navigation
Fix stale abandon of accepted PRISM blocks - #89
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f80f9877de
ℹ️ 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".
|
@codex review |
|
Codex Review: Didn't find any major issues. Can't wait for the next one! 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". |
* Close the accepted-block blind spot behind lost submitblock acks qbitd can accept a submitted PRISM block while the submitblock ack is lost in transport: acceptance then arrives only as a blockwait tip observation of the pool's own candidate hash, the accepted success tail never runs, and #89's protections both miss -- the accounted registry is only written in the direct-accept tail, and the retry disposition trusts one instantaneous chain snapshot in which the tip has already raced past the candidate and the header probe cannot prove it active. The stale-job abandon then terminally discards the pool's own on-chain block, withdraws its landed payout preview, fences payout publication, and leaves template refreshes coordination-blocked until the #90 watchdog restart (observed three times on mainnet 2026-07-25). Every tip-observation channel now registers an outstanding candidate hash seen as the chain tip as acceptance evidence, and every disposition/abandon-capable path re-checks fresh chain state plus that evidence before committing a terminal abandonment: candidates that are (or were recently observed as) active defer and retry until the accepted tail finalizes them as submitted; hashes provably absent from the active chain past the observation window stay terminally stale. Co-Authored-By: Claude Fable 5 <[email protected]> * Address Codex/Bugbot round 1: order acceptance checks before durable rejection - check acceptance evidence BEFORE reject_prepared_block on the post-persist stale-chain path, and commit that abandon terminally (recheck_acceptance=False) once prepared rows are rejected -- a rejected row cannot be confirmed by a later settled view - consult tip-observation evidence again after the blocking payout-preview withdrawal, atomically with the terminal counts, so evidence arriving during the withdrawal window still defers - require a probe-proven active block (not observation evidence alone) to open the pool-closed gate, so a closed pool can never fall through to submitblock on stale evidence; unprovable views defer via the abandon path instead Co-Authored-By: Claude Fable 5 <[email protected]> * Address Codex round 2: seal the terminal decision before rejecting prepared rows Reorder the post-persist stale-chain path to decide-then-reject: the abandon runs first (its terminal commit reads tip-observation evidence atomically with the counts under the coordinator lock, so no observation can land between the decision and the rejection unseen) and the prepared payout rows are rejected only after a sealed terminal outcome. Live evidence defers with the rows untouched; a crash between the sealed decision and the rejection leaves the outbox row pending for restart replay. The recheck_acceptance escape hatch is gone -- every abandon path now takes the full evidence check unconditionally. Co-Authored-By: Claude Fable 5 <[email protected]> * Address Codex round 3: seal terminal dispositions against late observations The terminal commit in _abandon_block_candidate now drops the hash from the outstanding-candidate set inside the same critical section that commits the abandonment counts. Observation registration takes the same lock and only matches outstanding hashes, so acceptance evidence is structurally excluded from the gap between a sealed terminal decision and the follow-up durable rejection of prepared payout rows -- no evidence can register mid-rejection and contradict the sealed disposition. A crash before the durable outbox update still replays the candidate, which re-registers the hash and re-evaluates from live chain state before rejecting. Co-Authored-By: Claude Fable 5 <[email protected]> * Address round 4: independent acceptance probes; restore barrier on late defer - probe getbestblockhash and the active header independently so a best-tip lookup failure no longer suppresses the header check, which subsumes it and can prove acceptance (or wrong-height staleness) alone (Codex) - when acceptance evidence arrives during the payout-preview withdrawal, re-begin and re-land the preview before deferring: the restored barrier pops the fail-closed tombstone so descendant builders wait on the preview instead of fencing template refreshes while retries defer on observation evidence (Cursor) Co-Authored-By: Claude Fable 5 <[email protected]> * Address round 5: restore replay acceptance evidence; heal fenced withdrawal - startup replay restores acceptance evidence for durable candidates whose prepared/confirmed pool-block row proves a prior process's submitblock succeeded, so a replay disposition racing a transient fork view cannot terminally abandon the accepted block after a restart dropped the in-memory observation registry (Codex) - the late-acceptance defer republishes the withdrawn preview after restoring the landed barrier: a withdrawal whose own publication lost its race had fenced delivery, and the deferral cycles must not leave template refreshes coordination-blocked until the accepted tail republishes (Cursor) Co-Authored-By: Claude Fable 5 <[email protected]> * Address Bugbot round 6: probe verdict wins both directions in the late check The late-acceptance gate now reuses the pre-check chain-probe verdict: a candidate the probe proved active at the wrong height stays terminally abandonable even when a tip observation registers during the payout-preview withdrawal. Header heights are immutable, so the wrong-height verdict cannot be overtaken by later evidence, and a corrupt-height candidate no longer defers until window expiry. Co-Authored-By: Claude Fable 5 <[email protected]> --------- Co-authored-by: admin <[email protected]> Co-authored-by: Claude Fable 5 <[email protected]>
Summary
Root cause
The moved-tip path could classify a duplicate candidate as stale after the same hash had already completed the accepted success tail. Payout-preview cleanup was also distributed across callers, so a raced or omitted cleanup could leave a
landed=Truetransition behind after the candidate became terminal. That transition blocked payout reconciliation until restart.Impact
Accepted candidates now finalize their durable outbox row as submitted even when the tip advances before a duplicate submit check completes. Every actual terminal abandonment withdraws its live payout-preview transition before recording the terminal outcome, preventing reconciliation stalls and preserving downstream audit finalization.
Validation
python3 -m unittest tests.test_prism_coordinator_vardiff— 278 tests passedpython3 -m unittest discover -s tests -p 'test_*.py'— 1,237 tests passedgit diff --checkNeed help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Note
High Risk
Changes block-candidate submission, abandonment, and payout-preview lifecycle on critical mining/payout paths; incorrect ordering could mis-finalize outbox rows or stall reconciliation.
Overview
Fixes a race where a moved-tip duplicate submit could abandon a PRISM block hash that had already finished the accepted success tail, leaving the durable outbox wrongly terminal and payout previews stuck as
landed.Adds a per-hash disposition guard (
_block_candidate_disposition) so synchronous below-target submits and outbox replay for the same hash serialize._abandon_block_candidatenow takesblock_hash, always withdraws payout-preview state on terminal abandon, and withpreserve_if_acceptedyields to_accounted_accepted_block_hashesso the outbox can still finalize as submitted.submit_block_candidatewraps the real work in that guard and treats tip-moved / duplicate wakeups as success when acceptance is already recorded.Regression tests cover accepted-then-tip-moved finalization, acceptance winning during cleanup, immediate preview invalidation, and replay blocking behind the accepted tail.
Reviewed by Cursor Bugbot for commit 6e56d82. Bugbot is set up for automated code reviews on this repo. Configure here.