Skip to content

3.x.x: deliver a job build that a same-tip republication overtakes, so publications faster than one fan-out no longer starve job delivery (#598) - #616

Merged
djh58 merged 1 commit into
3.x.xfrom
djh58/prism-b598-fanout
Sep 30, 2026
Merged

djh58 merged 1 commit into
3.x.xfrom
djh58/prism-b598-fanout

Conversation

@djh58

@djh58 djh58 commented Sep 30, 2026 •

Copy link
Copy Markdown
Member

Closes #598. Workstream A (#261).

Problem

Each Stratum session builds and saves its own job (build_job, then persist_issued_job). The build's issuance proof held the published tip's publication stamp, (tip hash, publication generation), and compared it by equality after the build and before and after the save. Every publication bumps that generation, including a same-tip reanchor, new shares or a template change that keeps the parent, the payout revision and the fee. With 2,000 sessions on one frontend and a 1 s reanchor, a full fan-out takes longer than one publication interval, so almost every build was overtaken and thrown away (job persistence deferred / job preparation deferred: payout snapshot stale), and a new tip, or a first job, reached no session.

Change

  • TipState carries a tip_generation that changes only when a publication changes the published tip hash, so A -> B -> A still differs.
  • Freshly built work takes its admission from the view its prepared work was read with (IssuanceAuthority::fresh) and keeps it across a later publication on the same published tip that kept its parent, payout revision, prior-balances digest and fee. Such a job is delivered as its own publication, and the session's next pass (the refresh watch has already fired) brings it up to date.
  • Nothing else is relaxed: readiness epoch, the database payout revision (re-read at admission, after the build, before the save, inside the save transaction under the cluster row's KEY SHARE fence, and after the save), the job's fee against the live relay floor, and tip authority are all still checked. Resumed work and replacement leases keep the exact publication stamp (fix: fence compact publication and replacement lease authority #377's lease rule).

Payout safety

A delivered overtaken job is same-parent, same-revision, same-balances, same-fee work from the publication just before the current one: the class every session already holds live after such a republication (bury_superseded_same_parent retires only on a revision change). No job is created or saved under a revision other than the current database revision, so #478's block-only capture and the stale-grace ceiling see no new case. The new gated test proves the class claim byte for byte instead of assuming it.

Contract change to #377's tests

#377 kept "a real same-parent/revision replacement refuses ordinary issue and persist" as a control. This PR deliberately changes that for fresh issue and persist when balances and fee are also unchanged. authority_lease.rs's two tests now expect: reanchor republication -> issue and persist admitted, resume refused; balances republication -> all refused.

Tests

New gated test module coordinator::same_tip_republish_tests, a real coordinator on a private PostgreSQL schema and a fake node, holding build_job after the build (a #[cfg(test)] seam) while it publishes:

Case Expected Mutant that fails it
reanchor, new shares (second miner), template change delivered, saved, payout outputs byte-identical to the live job of its publication; the republication itself pays differently same-tip rule disabled (pre-fix behaviour)
build before, save after a reanchor saved same
A -> B -> A on the published tip discarded tip generation not bumped on a hash change
new tip discarded —
revision bump, with and without a republication discarded —
fee change on the same tip (old fee still above the relay floor) discarded fee not compared

Balances republication: authority_lease tests (above); fails with the digest comparison removed.

Per-PR CI cost: three gated tests, about 3 s together on PostgreSQL 16.

Measurements

Local runs, debug build (the L4 cases) or release build (the preset), on one shared host, so absolute seconds are noisy; base and fix ran back to back under the same conditions.

Case Base (3.x.x) This PR
#553 weekly: 1 frontend, 2,000 sessions, 1 s reanchor, 100 shares/s, 3 tips reproduces #598 in 2/2 runs: tips left 63–1,809 of ~2,000 sessions without work flips in 3/3 runs ("#598 looks fixed"): every tip reached every session; p50 2.3–4.7 s, worst session 3.1–6.4 s
same case, job saves per second (mean / p95) 920–1,130 / 1,330–1,670, but 62,000–84,000 saved jobs then discarded by the post-save check 920–980 / 1,340–1,460, delivered; no pool timeouts
#553 weekly: 2,000 wallets, share-to-spend reproduces #598 (first-job starvation) at 334–447 s still fails, later (after ~27 min) and for a different reason: #604
rental-churn preset (#521), new-session first job p99 12 ms over 3,581 connections 11 ms over 3,581 connections
rental-churn preset, churn tip-to-last-notify p99 851 ms 794 ms

The 2,000-wallet case opens its ~3,000 sessions one at a time; with this PR each first job now queues behind the whole same-tip rebuild fan-out a 1 s reanchor causes, so opening grows with the square of the sessions and the run crosses the fixture's clock horizon. That is #604 (a first-job admission lane is the proposed fix). #553's expected failure for that case should point at #604 instead of #598, and its 1 s-reanchor expected failure becomes an ordinary weekly case once this lands.

Follow-up (not in this PR)

#604: first jobs queue behind same-tip rebuild storms. Coalescing same-tip publications (at the session or the publisher) would also cut the redundant rebuilds a fast reanchor still causes; not needed for correctness.

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

…o publications faster than one fan-out no longer starve job delivery (#598)

Each Stratum session builds and saves its own job. The build's admission
proof compared the published tip's publication stamp, (tip hash,
publication generation), by equality after the build and before and after
the save, and every publication bumps that generation, including a
reanchor, new shares or a template change on the same tip with the same
payout revision. With 2,000 sessions on one frontend and a 1 s reanchor,
almost every build was overtaken before it was saved and was thrown away
("payout snapshot stale"), so a new tip, and some first jobs, reached no
session.

Fresh work now keeps its admission across a later publication that kept
the same published tip, parent, payout revision, prior balances and fee,
and is delivered exactly as the jobs other sessions already hold from its
publication; the session's next pass brings it up to date. The published
tip now carries a tip generation that changes only when the published hash
does, so a tip change, including A -> B -> A, still revokes the build, as
do a payout revision change (still re-proved against the database at every
step and inside the save transaction), a prior-balances change and a fee
change. Resumed work and replacement leases keep the exact publication
stamp. #377's authority tests now expect a reanchor republication to admit
issue and persist, and a balances republication to refuse them.

A gated test holds a real coordinator's build between build and
revalidation while it republishes: a reanchor, new shares or a template
change delivers and saves the build, byte-identical in its payout outputs
to the live job of its publication; a new tip, A -> B -> A, a revision
change with or without a republication, and a fee change discard it.

Closes #598

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

djh58 commented Sep 30, 2026

Copy link
Copy Markdown
Member Author

@cursor review

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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 24bb8c2. Configure here.

@djh58

djh58 commented Sep 30, 2026

Copy link
Copy Markdown
Member Author

Review ledger at 24bb8c2f

CI green (22 pass, 9 skipped). No open findings: 0 fixed, 0 deferred, 2 rejected.

Stakes: high (job issuance authority and payout-revision fencing), so Bugbot was summoned.

Lane Result
/code-review medium No findings.
Adversarial review (Claude) No refutation; one minor candidate (R1).
Maintainability review (Claude) No structural findings; same minor candidate as R1.
Bugbot No new issues at 24bb8c2f.
Cross-provider adversarial lane Not run: this change's review is limited to Claude models.
ID Claim Disposition
R1 IssuanceAuthority::fresh errors when no tip is published, where the old admission allowed it. Rejected. Unreachable: the only install path, CompactPublicationGuard::publish, publishes the tip before installing prepared work under the same locks, so a fresh build that read prepared work always has a published tip.
R2 Delivering an overtaken build updates the session's delivery-progress stats while publications outpace fan-out. Rejected. SessionObservation::delivered records the job's own refresh_generation, so an overtaken job counts toward its older generation, never the current one; coverage of current work is not overstated.

Evidence beyond the tests in the PR body: in #553's 1 s-reanchor case, stale-job refusals fell from 1,296–2,575 (3.x.x) to 750–818 with this change and accepted shares rose, so shares on overtaken jobs are credited.

@djh58
djh58 merged commit 6572613 into 3.x.x Sep 30, 2026
31 checks passed
djh58 added a commit that referenced this pull request Sep 30, 2026
… of expecting its failure weekly (#553)

Review of the first commit found checks weaker than the manifest claims,
and #616 has since fixed #598.

- Scenarios 1, 2 and 4 now reach their first event under the whole
  load. #521's server_ready waits on a ready gate that the load
  installs (99% of sessions holding work), and scenario 4's case takes
  a `ready` hook before its first block. Before this, scenario 1's
  race came with 42 of 2,000 sessions connected and scenario 4's fault
  with about 1,350.
- Sessions spread their first connections from the first ready
  frontend, not from the load's start.
- The load records every notify, so work on a parent a session held
  before still serves that tip after a reorg back.
- Refusals are an allow-list (the harness's expected and backend
  classes). An impossible or unclassified refusal fails, and
  ledger-outcome-unknown counts as unanswered, since its share may
  land.
- External tips and the weekly soak hold at least one tip per frontend
  to the bound. The peer-loss case holds the isolated block itself to
  it on every session.
- The 1 s-reanchor case becomes #598's nightly guard at 5 shares/s,
  #598's reproducer rate: each of three tips must reach all 2,000
  sessions on the one frontend within 15 s. It fails before #616 and
  passes after it. It runs nightly because live-nightly builds debug;
  in release the fan-out outruns a 1 s reanchor even without the fix.
- The 2,000-wallet case leaves the weekly list, since in release (the
  weekly job's build) it fails on #622 rather than #604. It stays an
  ignored case for running by hand, counting as #604 only once at
  least 100 sessions opened; the wallet fixture's error now says how
  many had. wallets-2000-cap stays unexercised, naming #604 and #622,
  and the expected-failure scenarios go.
- The load soak validates its duration and budget as #521's does, and
  the load settings reuse the soak's env reader.
- live-nightly's and live-weekly's comments name the jobs they run.

Refs #553

Co-Authored-By: Claude Opus 5.5 <[email protected]>
djh58 added a commit that referenced this pull request Sep 30, 2026
… and add tip-disagreement, peer-loss and external-tip scenarios (#553) (#618)

* 3.x.x: run #521's chain-event scenarios under 2,000 Stratum sessions, and add tip-disagreement, peer-loss and external-tip scenarios (#553)

#487 S15 (L4). #521's fixtures run unchanged under load: each case
opens the fixture as its own test does, starts a session load against
its frontends, and calls the scenario's own function (decision 12).

- live_session_load.rs: 2,000 Stratum sessions that fail over between
  frontends and submit share-only proofs at a fixed rate, so the load
  never finds a block. It stamps every node tip with a waitfornewblock
  long-poll and checks three things: every acknowledged share is a
  durable row and no refused share is; no refusal a correct miner
  cannot earn; every session gets work on every lasting tip within
  15 s while its node answers and its frontend is ready. It reports
  #481's time to usable work per frontend and per tip.
- live_chain_events_load.rs, nightly: scenarios 1 and 2, scenario 4's
  crash after acceptance, and three new scenarios with their criteria.
  Two frontends on two nodes disagree about the tip: the ledger takes
  one side, and the other frontend stands down with no work on its
  node's tip. The pool's node loses its only peer: regtest exempts the
  peer floor, so the isolated own block is deactivated and credited
  once. External tips come at the 60 s target spacing. Weekly: the
  other scenario-4 cases, the soak, 45 minutes of external tips at
  400 shares/s, and two expected failures: 2,000 sessions on one
  frontend at a 1 s reanchor (#598) and scenario 7 at 2,000 wallets
  (#604).
- Load frontends use the production 60 s reanchor. At the fixture's
  1 s, 2,000 sessions on one frontend get no work (#598).
- check_e2e_scenarios.py: ids in test/prism-weekly-gated-tests.txt run
  in the weekly lane, which now also needs the live-weekly job's
  schedule and gate-manifest step, and every weekly id must be named by
  a running scenario, as for the nightly list. The manifest cites every
  weekly id, #545's and #575's included, and each expected failure has
  its own scenario owned by its issue.
- live-weekly's timeout goes from 120 to 180 min for the long set,
  about 85 minutes.
- Shared support changes: pub(super) on scenario functions,
  outage_case_on, solve_share, the 2,000-wallet connection limit, and
  assert_no_duplicate_headers reading its two counts in one statement
  (under load, shares landed between them).

Refs #553

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

* 3.x.x: hold #553's load to its claims, and guard #598 nightly instead of expecting its failure weekly (#553)

Review of the first commit found checks weaker than the manifest claims,
and #616 has since fixed #598.

- Scenarios 1, 2 and 4 now reach their first event under the whole
  load. #521's server_ready waits on a ready gate that the load
  installs (99% of sessions holding work), and scenario 4's case takes
  a `ready` hook before its first block. Before this, scenario 1's
  race came with 42 of 2,000 sessions connected and scenario 4's fault
  with about 1,350.
- Sessions spread their first connections from the first ready
  frontend, not from the load's start.
- The load records every notify, so work on a parent a session held
  before still serves that tip after a reorg back.
- Refusals are an allow-list (the harness's expected and backend
  classes). An impossible or unclassified refusal fails, and
  ledger-outcome-unknown counts as unanswered, since its share may
  land.
- External tips and the weekly soak hold at least one tip per frontend
  to the bound. The peer-loss case holds the isolated block itself to
  it on every session.
- The 1 s-reanchor case becomes #598's nightly guard at 5 shares/s,
  #598's reproducer rate: each of three tips must reach all 2,000
  sessions on the one frontend within 15 s. It fails before #616 and
  passes after it. It runs nightly because live-nightly builds debug;
  in release the fan-out outruns a 1 s reanchor even without the fix.
- The 2,000-wallet case leaves the weekly list, since in release (the
  weekly job's build) it fails on #622 rather than #604. It stays an
  ignored case for running by hand, counting as #604 only once at
  least 100 sessions opened; the wallet fixture's error now says how
  many had. wallets-2000-cap stays unexercised, naming #604 and #622,
  and the expected-failure scenarios go.
- The load soak validates its duration and budget as #521's does, and
  the load settings reuse the soak's env reader.
- live-nightly's and live-weekly's comments name the jobs they run.

Refs #553

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

* 3.x.x: count work a session held at the stamp, hold lasting tips to the bound, and match the untyped refusal exactly (#553)

Review of the second commit found two checks that could pass without
holding what they claim.

- Since the load records every notify, a republication on a parent
  after the next tip's stamp could count as work on that parent when
  the node returned to it, although the session had moved to the next
  tip's work in between. Work before a stamp now counts only while the
  session still held it at the stamp: its last run of notifies on the
  tip, from after the node's previous tip. A new unit test fails on
  the old lookup.
- "At least one tip held to the bound" counted gated tips, and a gated
  tip replaced within 15 s can only count sessions as replaced. The
  report adds held_tips (gated and lasting the bound), which the
  external-tips, soak, scenario 1, 2 and 4 checks and #598's guard now
  use; the soak ends on a closing tip, since its own blocks come seconds
  apart.
- The one refusal without a reason_id a correct load can earn is the
  unknown-job budget, now matched on its code and exact message as the
  harness does. "too many connections" is an authorize-time error and
  never reaches the submit counts.
- The manifest's criteria say what the load checks: the refusal
  allow-list, and every session holding work in #598's guard. Stale
  comments are fixed, and until_connected reuses holding.

Refs #553

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

* 3.x.x: document #553's chain events under session load in the CI lane guide (#553)

#612's lane guide still listed #553's scenarios as not yet running. L4
now names the nightly and weekly sets, the load's own checks and #598's
guard, and keeps only the 2,000-wallet case, on #604 and #622, as not
proven.

Refs #553

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

---------

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