Skip to content

3.x.x: pause the session load's shares around scenario 2's own blocks, and start each replayed transcript after earlier blocks land (#631, #632) - #640

Merged
djh58 merged 3 commits into
3.x.xfrom
djh58/prism-flakes-1001
Oct 1, 2026
Merged

djh58 merged 3 commits into
3.x.xfrom
djh58/prism-flakes-1001

Conversation

@djh58

@djh58 djh58 commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

Closes #631. Closes #632. Refs #553, #586.

Test-only: no server code changes. Both failures were test bugs; the diagnoses are on #631 and #632.

#631: scenario 2 under load paid its own blocks by timing

Cause. On regtest a load share weighs about half an own block:

  • The load's share difficulty, 2^-32, is already the easiest share target there is.
  • An own block's block-only proof is credited at regtest's ~2^-31 network difficulty.

So ~15 load shares fill the 8× window. Every own block paid most of its reward to the load's address, plus at most one earlier own share, and which one survived was a race. The nightly hit the case where branch B paid both miners exactly what branch A did.

Change.

  • live_session_load.rs: SessionLoad::share_pause pauses or resumes every session's share offers, and SessionLoad::answered reports when none is still waiting for an answer.
    • Paused sessions stay connected and keep taking work, so the delivery check still applies to every tip.
    • The report's seconds and offered now exclude pauses, and a new paused_seconds field records them.
    • The module doc's claim that a load share "weighs about 2^-32 … economics unchanged" is corrected.
  • live_two_node.rs: LOAD_SHARES, a hook in the style of READY_GATE. deep_reorg pauses the load's shares from its seed blocks until branch B's own blocks are paid. It resumes them for the partition depth, the heal, the reorg reconciliation and fanout maturity, so the reorg itself still runs under the whole load. Without a load the hook does nothing, so the per-PR case is unchanged. The precondition's message now prints branch A's balances.
  • live_chain_events_load.rs: the scenario-2 load case installs the hook.

#632: transcript replay started before the previous block landed

Cause. esp-miner-suggest-difficulty finds a block, and the block lands after its submit is answered. current() waited only for observed_tip to equal the node's tip, which still held the old tip. The next transcript's share could pass its revision check before the landing and commit after it, and was then refused as ledger-confirmation-failed. #625 changes only admission order, so this is not a regression from it.

Change. current() also waits until no candidate is unfinished (CandidateState::UNFINISHED_SQL) and /healthz payout_state_generation equals qbit_prism_cluster.payout_revision.

Evidence (local: private PostgreSQL 16 with fsync on, pinned qbit, debug)

  • 3.x.x: transcript replay fails when a payout-revision change refuses a share mid-commit (ledger-confirmation-failed) #632 mutant. A scratch server patch (not committed) sleeps 1.5 s between a submit's revision check and its append, as a slow host would. With it, the unchanged replay failed 2 of 2 with CI's exact error ("payout revision changed before share commit", ledger-confirmation-failed on nicehash-extranonce-subscribe id 5). The fixed replay passed 2 of 2.
  • 3.x.x: nightly chain-event case under load fails the deep-reorg precondition ('branch B's own blocks left the balances at branch A's') #631 mechanism. Unchanged code with a per-block allocation diagnostic, 5 runs, all passing by the same race: each own block paid 87.5–100% to the load address and at most 1/8 to a scenario miner. With the pause, the scenario miners' part grew from 1/8 to 5/8 between seed 2 and B2. Branch A's balances were identical across runs (21.0e9 / 5.25e9), and branch B's differ by construction.
  • Passing:
    • replay: 6 of 6 (3 before and 3 after a final refactor of the outbox query)
    • per-PR real_deep_reorg_…: 2 of 2
    • nightly scenario 2 under 2,000 sessions: 6 of 6 (about 91 s each)
    • nightly peer-loss under load: 1 of 1
    • session_load unit tests: 8 of 8
    • cargo fmt --check and clippy -D warnings on live_regtest: clean
  • Per-PR CI cost: about +2 s in the shard that runs the transcript replay (3.5 s → 5.35 s locally, 3 runs each), which is the wait for the landed block and the revision. The nightly lane is unchanged at about 90 s for scenario 2.

No new tests, so test/prism-gated-tests.txt is unchanged.

Follow-up suggestion (#621's thread): the pre-insert revision refusal writes nothing and could answer stale-job instead of ledger-confirmation-failed.

🤖 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.

Coverage note: frontend 0's stop and the failover to frontend 1 now happen while load shares are paused, so scenario 2 no longer exercises load share appends during that failover. The other nightly cases still do.

…, and start each replayed transcript after earlier blocks land (#631, #632)

#631: on regtest a load share weighs about half an own block. The
share-only settings' 2^-32 is the easiest share target there is, and an
own block's block-only proof is credited at regtest's ~2^-31 network
difficulty. So ~15 load shares fill the 8x window, and which earlier
own share survives in each own block's window is a timing race. The
nightly deep reorg under 2,000 sessions hit the case where branch B paid
both miners exactly what branch A did. The load can now pause its share
offers (sessions stay connected and keep taking work), and deep_reorg
pauses them from its seed blocks until branch B's own blocks are paid,
then resumes them for the heal and the reorg. Without a load the hook
does nothing.

#632: esp-miner-suggest-difficulty finds a block, which lands after its
submit is answered. The next transcript's first share could pass its
revision check before the landing and commit after it, and was refused
as ledger-confirmation-failed. current() now also waits until no
candidate is unfinished and /healthz payout_state_generation is the
cluster's payout_revision.

Closes #631, closes #632. Refs #553, #586.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@djh58
djh58 requested a review from kiwidream October 1, 2026 15:49
@djh58

djh58 commented Oct 1, 2026

Copy link
Copy Markdown
Member Author

Handover

@kiwidream now owns this PR. It is a test-only flake fix. Head is d6c1b9f. CI is still running on the head commit. A review ledger will be posted here once CI is green. Any findings from that review will be listed in the ledger as open items with a proposed fix. No new commits will be pushed by the current owner. Left to do: green CI, the ledger, then owner review and merge. This closes #631 and #632.

@djh58

djh58 commented Oct 1, 2026

Copy link
Copy Markdown
Member Author

Review ledger (d6c1b9f)

Two reviews ran: /code-review at medium, and one adversarial review. Neither found a blocker.

Confirmed sound:

  • Economics claim. deactivate_pool_block changes only the block's state and its fanouts, and the window doesn't filter shares by chain_state. So A1's and A2's credited deferred shares stay in branch B's windows, and with the pause B's balances differ from A's every time.
  • Replay gate (3.x.x: transcript replay fails when a payout-revision change refuses a share mid-commit (ledger-confirmation-failed) #632). /healthz ok already requires the prepared parent to equal observed_tip and the prepared revision to equal the ledger's. payout_state_generation is null only while ok is false, so the gate can't pass on stale work and can't hang on the first transcript. The outbox check carries the fix; the revision clause is redundant but harmless.
  • unanswered accounting. Each loop pass applies only the before/after change in its session's outstanding. That covers submit success and failure, timeouts, close() and reconnects. The counter never underflows, and paused sessions don't affect stop()'s drain.
  • Load checks while paused. Paused sessions keep taking work, so delivery, held tips and every-session-held-work still apply.

Open items: three leaks in the pause barrier (low severity; each can let a stray load share into scenario 2's window on rare timing):

  • (a) A share being written isn't counted. In run_session, unanswered only goes up after submit()'s write_all returns. A session that passed the !paused check just before the pause, and is still writing, is invisible to answered(), which can return at once.
    • Proposed fix: on a tick, when nothing is outstanding, increment unanswered before reading paused, both SeqCst, and mark the session as counted. At the bottom of the loop, reconcile "counted" against outstanding.is_some(): decrement if the session counted itself but has nothing outstanding, increment if it didn't but has. Then either the session sees the pause or the pauser sees the count.
  • (b) A share can commit after its answer. A share whose connection closed in flight (Answer::Lost), or that was answered ledger-outcome-unknown, may still commit after answered() is true.
    • Proposed fix: after the drain, have pause_load_shares (which takes the fixture) poll SELECT count(*) FROM qbit_share_ledger every 2 s. Return once two consecutive reads match, and fail after 60 s.
  • (c) The drain bound is too short. A stuck share is cleared only on the session's first tick past ANSWER_BOUND (70 s). Ticks are sessions/rate apart, which is 20 s in the nightly. So the 60 s drain can never wait out a hung share and fails falsely.
    • Proposed fix: set the drain bound to 2 * ANSWER, which covers any tick interval up to the bound.

A tested patch implementing (a)–(c) exists (+45/−14 across live_session_load.rs and live_two_node.rs) and is available on request.

Coverage note. Frontend 0's stop and the failover to frontend 1 now happen while shares are paused, so scenario 2 no longer exercises load share appends during that failover. The other nightly load cases still do.

Revalidation of the patch: private PostgreSQL 16 with fsync on, pinned qbit, debug build.

Test Result
Transcript replay 3/3
Per-PR real_deep_reorg_… 1/1
Nightly scenario 2 under 2,000 sessions 3/3, about 91 s each, about 17 s paused
session_load unit tests 8/8
cargo fmt --check, clippy -D warnings on live_regtest clean

Low risk, noted only:

  • LOAD_SHARES is process-wide, like READY_GATE. The nightly runs --test-threads=1.
  • A block whose submit outcome is unknown can hold the replay gate past its 30 s limit through reconciliation backoff. That fails loudly; it never hangs.

@djh58

djh58 commented Oct 1, 2026

Copy link
Copy Markdown
Member Author

Ledger addendum: CI on d6c1b9f is green (21 pass, 12 skipped, 0 fail). The open items (a)–(c) in the ledger above are handed to @kiwidream; no further commits from this lane.

… sent, and on shares that commit after their answer (#631)

Review follow-ups:
- A session now counts itself as unanswered before it reads the pause
  flag. Before, a share could be mid-write when the pauser read zero.
- After the answers drain, the pause also waits until the share ledger
  holds still for 2 s. A lost or ledger-outcome-unknown answer may
  still commit.
- The drain allows twice the answer bound. A stuck share is cleared on
  the first tick past the bound, and ticks can be up to the bound apart.

Refs #631, #553.

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

djh58 commented Oct 1, 2026

Copy link
Copy Markdown
Member Author

Ledger update

8dde4dc fixes all three open items in the review ledger above:

  • A session counts itself as unanswered before it reads the pause flag (SeqCst on both sides), so a share already being sent is counted.
  • After the drain, the pause also waits until the share ledger holds still for 2 s. A share that commits after its answer is caught.
  • The drain bound is now 2x the answer bound (it was 60 s against a 70 s answer bound).

Revalidated before push: replay 3/3, per-PR deep reorg 1/1, nightly scenario 2 3/3, unit tests 8/8, fmt and clippy clean. Test-only change, two support files. Left to do: green CI on 8dde4dc, then owner review and merge.

@djh58
djh58 merged commit 7dee205 into 3.x.x Oct 1, 2026
33 checks passed
RobertClarke added a commit that referenced this pull request Oct 5, 2026
…landing cannot race the phase's first share (#656) (#659)

* 3.x.x: mine each clock-jump phase on settled work, so a held block's landing cannot race the phase's first share (#656)

The 10-04 nightly failed phase 3 of the wall-clock jump test. Server 0
refused the phase's first share as ledger-confirmation-failed and logged
"payout revision changed before share commit" in the same second the
node took the held block. held_landing returned as soon as the held
block was the node's tip, and the phase mined at once, on work from
before two payout-revision moves: the landing's and the servers'
observation of the new tip. The share passed its submit check and met
the moved revision at the append's fence (#632).

Since #581 the holder lands its held block itself as soon as it is
released, so phase 3 now has phase 4's shape. Phase 4's refusals were
the same race (10-02 and 10-05 nightlies). The test allowed them as
REFUSED_AFTER_STEP_BACK and blamed the clock stepping back.

Fixture::settled is #640's wait from the transcript replay's current(),
now shared. It waits until no candidate is unfinished and the server's
/healthz shows the node's tip with payout_state_generation at
qbit_prism_cluster.payout_revision. The replay calls it with the same
conditions as before. The clock-jump test waits on it before every
serving mine and before each held block, and REFUSED_AFTER_STEP_BACK is
removed: phases 3 and 4 must accept every share, like every other phase.

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

* 3.x.x: count a clock-jump phase's settling against its WORK_SECONDS, so waiting for settled work does not double a server's serving budget (#656)

The settle wait added before each mine had its own 30 s, ahead of the
30 s work_on still gave a miner. A corrected server therefore had up to
60 s to serve again, where the test's WORK_SECONDS documents 30 s. Run::mine
and held_landing now set one WORK_SECONDS deadline, settle within it and
give work_on what remains. The ahead phase's no-work check keeps its own
WORK_SECONDS. Fixture::settled takes its time limit, and the transcript
replay passes its 30 s as before.

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

* 3.x.x: retrigger CI after an unrelated authorization_rpc statement-timeout failure (#656)

Shard 2 failed authorization_rpc's
authorization_fallback_requires_a_definitive_address_result with
"canceling statement due to statement timeout". That test is outside
this change, and the same shard passed on 26a866f. The token cannot
rerun a job, so this empty commit runs CI again.

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

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
RobertClarke added a commit that referenced this pull request Oct 6, 2026
…ettlement-lock hold cannot start ahead of the landing's revision bump (#686) (#691)

faults_under_load_drain_an_offer_in_flight_and_outlast_a_settlement_lock_holder
failed three times, on two PRs and one 3.x.x push. Each time every
retained-work share in the first 3 s of the settlement-lock hold was
refused stale-job. The sigterm-drain fault leaves its found block for
the relaunched frontend to land. The landing confirms the block and
bumps the payout revision, and until work at the new revision is
published every share on the old work is refused stale-job. The harness
started the next fault as soon as the frontend answered /healthz. When
the bump came just before settlement-lock took SETTLEMENT_LOCK, the
holder also blocked the republication.

SigtermDrain now settles before the next fault, like the SIGKILL's
landing wait and #640's gate. Once the frontend serves again, it polls
the block's row until it is submitted. Then it reads
qbit_prism_cluster.payout_revision and every frontend's /healthz until
each one is ok, publishes payout_state_generation equal to that
revision, and has delivered that work to every authorized session. The
recovery window waits for the settle, bounded at 60 s, and the phase's
time bound includes that wait. A new check fails the drain when it did
not settle. A row that goes terminal without landing ends the wait at
once, and a block the shutdown itself landed counts as landed. The
evidence reports the landing and settle times and the last reading.

Locally, pinned to two CPUs, the per-PR test passed 20 of 20 before and
after. With the hold started 3 s earlier (baseline=0), 12 of 20 passed
before, every failure with CI's message, and 20 of 20 after, with no
refusal in any hold. The block landed 0.5 to 3.3 s, and every
frontend's work was current 2 to 6 s, after the frontend served again.
#692 tracks the same guard for the other faults that land a block.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
RobertClarke added a commit that referenced this pull request Oct 6, 2026
… CI on the tag by dispatch, and the issue list at the cut

From the review of #703:
- A rehearsal uses both holds, as the rehearsal procedure requires: the
  ledger's `submission-hold set` before any frontend starts, and
  PRISM_BLOCK_SUBMIT_ENABLED=0 on every frontend. The notes offered them as
  alternatives.
- ci.yml has no tag trigger, so CI on the tag is dispatched by hand. The
  nightly set runs on the version-bump PR and on the tag. The soak and
  faults-long-real-node are described as runs whose verdicts are in the
  bundle.
- #632 is closed (fixed by #640) and leaves the known issues. #582 and #604
  are added: fixed in code, open for #291's go/no-go sweep.
- The production line is 2.x.x, without naming a version the 2.0.2 tip
  contradicts.
- The development-line note gives the tree's identity as 3.0.0-rc.1 and no
  longer lists the closed #268 as outstanding.

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