Repository navigation
3.x.x: release a CTV fanout claim whose completion is refused after a successful attempt, instead of holding it for 120 s (#569) - #571
Merged
Conversation
… successful attempt, instead of holding it for 120 s (#569) When a block landed between a successful fanout attempt and its completion, the payout revision bump made finish_fanout fail with "payout revision changed while observing chain state". The error left run_once with the claim still held, so the fanout stayed claimed, with no attempt recorded, until its 120 s lease expired, and no server could check it again. The attempt-failure branch already released its claim through finish(..., 'failed'); only success followed by a refused completion leaked. run_once now hands such a claim back through the new Ledger::release_fanout_claim, then ends the pass with the same error as before. The release is an early expiry: it clears the claim fenced by the holder's token, records no attempt and leaves the recheck schedule alone. A completion that did commit, or a claim another frontend has taken over, is not touched. The next claim re-verifies the chain from scratch, as after an expiry, so broadcasts stay exactly as idempotent as before and every revision check is unchanged. A completion that loses its connection is also a refused completion, so refresh_liveness's lost-completion case now expects the claim back and every row finished by the next pass. Tests: a gated PostgreSQL case holds a real attempt at its tip re-check, bumps the payout revision, and asserts the refused completion leaves the fanout unclaimed with no attempt recorded, that the next pass settles every row, and that a stale token cannot release another frontend's claim. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Member
Author
Deep-review ledger (head
|
| # | Lane | Finding | Disposition |
|---|---|---|---|
| 1 | code-review | No bugs found. It checked a completion that committed but reported an error (the token is already cleared, so the release is a no-op), a takeover after expiry (the token does not match, so it is a no-op), an unwritable database (the release fails and the claim falls back to expiry), and an immediate retry after a broadcast (getmempoolentry turns it into a check-only observation, and a persisted CPFP child is replayed). |
No action. |
| 2 | code-review (note) | A released row keeps its old next_broadcast_attempt_at, so the next pass claims it first. If its completion were refused on every attempt (the revision moving during each one), each pass would stop at that row. The old 120 s hold let other rows go ahead meanwhile. |
Deferred to #562. It needs a revision change inside nearly every attempt of the same row, which does not happen at normal block rates. The old hold was an accidental backoff, not a designed one. If it is wanted, the cheap follow-up is to release with next_broadcast_attempt_at = clock_timestamp(), which keeps the row claimable at once but orders it behind rows already due. That would be a separate settlement-path change with its own test. |
| 3 | thermo | Put the release inside finish_fanout (the canonical ledger layer) instead of the call site. |
Rejected. The failed completion's transaction has aborted, so the release must be a separate transaction. A lost connection cannot be recovered inside it either. run_once owns the claim's lifetime, and the failure branch already completes at the same call site. A combined "finish or release" would hide a second write behind one call. |
| 4 | thermo | release_fanout_claim returns a bool that production ignores. |
Rejected. The bool is the observable contract of the token fence (a stale token releases nothing), and the test pins it. The caller logs only the release failures that matter. |
| 5 | thermo | The new test covers two scenarios: the refused completion, and the token fence. | Rejected. Both need the same mature-fanout fixture. Sharing it saves about 1.5 s of per-PR CI, and the fence part is commented as its own step. Mutant B fails only that step. |
| 6 | thermo | broadcaster.rs is over 1k lines. |
No action. It was 1019 lines before this PR (1030 after), so the PR does not cross the line, and the change is 11 lines in run_once. |
| 7 | adversarial | No refutation found. It attacked a committed but unacknowledged completion (the token is already cleared), a takeover between expiry and release (the token fence), and a re-send by the next claimer (the mempool, confirmation and CPFP-package checks run before any send, as after an expiry). All three held. | No action. |
| 8 | adversarial (note) | A real sendrawtransaction attempt whose completion is refused leaves no row in qbit_ctv_fanout_broadcast_attempts, because the next claim sees the transaction in the mempool and records only a check-only observation. |
Deferred. It predates this PR: expiry lost the same row. It affects the attempt history only, and nothing is sent twice. Noted for #562. |
Totals: 0 fixed, 3 rejected, 2 deferred, 3 with no action needed.
Follow-ups already listed in the PR body (not fixed here): a failure-branch completion that itself fails still holds the claim until it expires (releasing there would drop the backoff), and a candidate claim dropped at shutdown is held until its lease expires.
This was referenced Sep 29, 2026
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 #569 (split out of #562)
Problem
broadcaster::run_onceclaims a CTV fanout for 120 s, runsprocess(), then records the result withfinish_fanout(). The completion goes throughapply_progress, which requires thepayout_revisionthatprocess()observed. When a block lands in between, the revision moves andfinish_fanoutfails withpayout revision changed while observing chain state.In the success branch that error left
run_oncewith the claim still held. Nothing finished the row and nothing cleared the claim. The fanout stayed claimed, withattempt_count0, untilclaim_expires_at, up to 120 s, and no server could check it again. Theprocess()-error branch never had this problem, because it releases throughfinish(…, 'failed'). This is theweighted_recipients … timed out waiting for every fanout confirmedfailure: that wait is 60 s, shorter than the lease.Fix
When
finish_fanoutfails after a successfulprocess(),run_oncehands the claim back through the newLedger::release_fanout_claim, then ends the pass with the same error as before. The release is an early expiry and nothing more:claim_token,claim_instance_idandclaim_expires_atfenced by the holder's token, in one statement behind the usualwritable()check. A completion that actually committed (for example one whose COMMIT reply was lost) has already cleared the token. A claim another frontend has since taken over has a different token. Neither is touched, and the method reports whether it released anything.settlement_status,next_broadcast_attempt_at, the attempt counters, the scan cursor and the CPFP reservations as they were. So the row ends up exactly as an expired claim would, only without the 120 s wait.process()from scratch: it renews the claim, observes the chain and revision again, re-verifies the covenant and parent maturity, and checks the mempool and confirmations before any send. That is the same path a claim takes after expiry today, so no new broadcast is possible that expiry could not already cause, and whatever this attempt sent is already known to the node.require_revisionandrequire_fanoutare unchanged.process()builds the status and the evidence itself. The revision moved, the claim was lost, or a database or connection error occurred: all transient. Or the parent left the active chain, which also takes the row out ofclaim_fanout. So a quicker retry replaces a 120 s stall rather than a backoff.CTV claim release deferredand the claim falls back to expiry, as it does today.A completion that loses its database connection is also a failed completion after a good attempt, so it now releases too.
refresh_liveness::ctv_chunk_metrics_count_an_attempt_whose_completion_failed_to_persistasserted the old fenced-until-expiry outcome, and now expects the claim back and every row finished by the next pass. Its metric assertions are otherwise unchanged.No migration and no new metric.
scripts/prism_pool_acquires.jsonregisters the newbegin()site.Other claim/lease paths audited (same "success, then the completion fails, claim held" shape)
run_once)process()error or 90 s deadline branchfinish(…, 'failed')releases the claim with backoff. If that write fails (claim lost, parent no longer confirmed and mature, cluster halted, database error), the claim is held until expiry. That completion carries nopayout_revision, so a landing cannot refuse it.claim_candidate→process_candidate)finish_candidate*failing after a successfulsubmitblock, goes toretry_candidate, which clears the claim withmin(60, attempt_count)s backoff (reconciliation rowsmin(3600, 10·attempts))with_candidate_heartbeat)claim_candidate_for_recovery,recover_candidate)release_recovery_tokenorrelease_recovery_claim, token-fenced and boundedreserve_in→record_offer,release_unsent_offer)retry_candidateas aboveselect!drops the in-flight work, and the claim is held until expiryFollow-ups, not fixed here (for #562):
finish(…, 'failed')itself fails, the claim is held until it expires. Releasing it there would drop the backoff that a failed attempt should record, so it needs its own design (for example a token-fenced "retry at backoff" write) rather than this release.Tests
refresh_liveness::ctv_releases_the_claim_when_a_revision_bump_refuses_a_successful_attempt(new)run_onceattempt is held at its tip re-check, after it has read its chain view and payout revision. The revision is bumped, as a landing does, and the attempt is released. The pass fails withpayout revision changed, and the fanout is unclaimed at once: no token, no instance, no expiry,broadcast_attempt_count0, recheck still due. The next pass settles every row: all confirmed, unclaimed, recheck scheduled. A stale token cannot release a claim another frontend took over after expiry; the holder can release its own.refresh_liveness::ctv_chunk_metrics_count_an_attempt_whose_completion_failed_to_persist(updated)The new test is listed, sorted, in
test/prism-gated-tests.txt. Net per-PR CI time: about +2 s, in the shard that runsrefresh_liveness.Mutants (each run, then reverted):
if finished.is_err() && false): the new test fails withthe refused completion left its claim held, and the updated test fails withaborted completion left 1 fenced claims. The other 4 CTV cases pass.… AND claim_token IS NOT NULL): the new test fails witha stale token released another frontend's claim.Also run: all 38
refresh_livenesstests against a private PostgreSQL 16 (fsync on, integration required);cargo fmt --check;cargo clippy -p qbit-prism-server --all-targets -D warnings;scripts/check_prism_pool_acquires.py.Live
weighted_recipientsunder 2 pinned CPU burners (two busy loops and the test sharing two cores, 5 runs each):generatetoaddressbatch during the difficulty ramp, before any fanout existed. #563, merged after this branch point, gives that call a 600 s deadline.On this host the race never fired in 10 runs, with either build, so these reruns show no regression but do not exercise the fix. The 2-of-4 base failures reported while investigating #562 were seen on a differently loaded host. The fix is proven by the deterministic gated test above, which forces the race.
Live CTV and CPFP cases (
cpfp_tests×3,real_ctv_maturity_broadcast_and_confirmation,two_node_tests::real_deep_reorg…): all pass on this branch. On a saturated host (load average 22–32 on 22 cores) the deep-reorg case sometimes failed with the same fixture RPC timeout, because qbitd went silent for 45 s in the middle ofgeneratetoaddress. In an interleaved comparison the release never ran in any of those runs: the only broadcaster errors were the pre-claimqbit is not caught upchecks. With this branch's server the case passed 6 of 10 (the 4 failures were all at load ≥ 22), and with the release disabled it passed 8 of 8 (loads up to 23). Once the load fell, both builds passed every run. This is a load-sensitive fixture timeout, and not this change. #563 lengthened the equivalent call in the weighted-recipients file only, so the two-node file'sgeneratetoaddressstill uses the 45 s client. Noted for #562.🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.