Skip to content

3.x.x: keep the refresh delta path across retargets and multi-page deltas (#275) - #501

Merged
djh58 merged 2 commits into
3.x.xfrom
djh58/prism-b275-delta-retarget
Sep 23, 2026
Merged

djh58 merged 2 commits into
3.x.xfrom
djh58/prism-b275-delta-retarget

Conversation

@djh58

@djh58 djh58 commented Sep 23, 2026 •

Copy link
Copy Markdown
Member

Why

RetainedShares::eligible refused any change in scaled network difficulty and any delta
over 4,096 sequence slots (ledger/window/snapshot_delta.rs). qbit retargets every block,
so every tip's refresh paid the serial fetch-then-decode full scan (about 100 pages at
400k); the harness hid it because the fake node served constant bits and the timed tip
added no shares.

Measure honestly

  • qbit_prism_refresh_window_acquisitions_total{outcome}: once per refresh snapshot, in the
    ledger: advanced, or the reason the full scan ran (no_prior, empty_prior,
    tail_mismatch, anchor_regressed, cutoff_regressed, delta_too_large, no_evidence,
    leaf_changed, margin_too_large, partial, witness_changed, count_mismatch,
    invariant).
  • qbit_prism_refresh_seconds{trigger,acquisition}: once per refresh that published rebuilt
    work, entry to publication. Trigger initial|tip|revision|balances|reanchor|shares|fee|template,
    by the label's own precedence when several inputs changed on one poll; acquisition
    delta|full|cached.
  • One INFO prism::refresh: refresh published line per published rebuild with trigger,
    acquisition, outcome, parent, height, share_seq, window/prior/delta/margin/retired rows,
    pages, snapshot_ms, refresh_ms and started_unix_ms.
  • Load harness, opt-in only (defaults unchanged): --retarget-bits (the fake node serves
    different bits on every tip: a deterministic 0.8%-per-block triangle walk within 6.7% of
    the stock bits, and a tenth more history is seeded below the window so a harder target
    has older rows to reach into, as production always has) and --background-shares-per-second
    (offered rate during warm-up, where the external tips are minted). time_to_usable_work
    tips gain min/p90 and a by_frontend[] breakdown so publish→first/p50/p90/last can be
    read per frontend against that frontend's own refresh line.

Implement

snapshot_delta::advance replays the full reader's newest-first saturating fold for the
fresh target over the delta above the retained cutoff (ascending keyset pages, up to
262,144 slots), the retained rows, and, for a heavier target, a margin below the retained
first row (descending pages, up to 16; a per-block retarget moves the crossing row by a
fraction of a percent of the window). A lighter target retires rows from the old end; a
heavier one pulls the margin in. Mandatory checks: post-merge crossing (the fold over the
window reaches zero and the fold without the first row does not; a walk that runs out of
history is refused as partial), strictly ascending no-duplicate order, the full reader's
saturating crossing-row rule, WindowRef over exactly the merged window, and the unchanged
leaf / partition / WAL-timeline witness, re-read over the merged range without the count
and then with it. Invariant failures are refused to the full scan and logged at error.
The reads are READ COMMITTED, as the full scan's are: rows never change, eligibility is
anchored, and the anchor is issued by an update of the singleton every append updates, so
every later append carries a clock above it; the final count catches the two ways a row
can still appear between statements. Memory at both bounds peaks at about 640 MB for a
400k window (720 MB at 500k), stated next to the constants.

Tests (real PostgreSQL, gated, registered in test/prism-gated-tests.txt): retargets up
and down with appended shares; multi-page delta and margin; both size bounds and one page
under; seeded random walks over target and inserts (every crossing window byte-equal to
the full reader's, every partial one refused); landing re-derivation accepts a
delta-assembled window and refuses its superset and its under-covering subset; the
independent review's adversarial differential (legacy-style fixture with gaps, rejected
rows and a partition boundary, retargets up to 8x either way, rows committed between the
anchor and the extension read, corrupted retained inputs) is adopted as a gated module;
and a coordinator-level test lands a found block, through the coordinator's own submit
loop, on a window the delta path built after a retarget. All pre-existing delta and
coordinator tests keep their assertions.

Benchmark

Two real frontends, 2,000 sessions, a 400k window at the stock bits, admission 128 (the
default), 8 runtime workers, pool 16, PostgreSQL 16 managed by the harness, 8 external
tips 45 s apart, --retarget-bits --background-shares-per-second 133 (every tip
retargets; about 6,000 shares, a two-page delta, per tip; a tenth more history seeded
below the window). Base is 3.x.x b61747e, which already carries the fan-out work of
#499; the candidate is this branch rebased onto it, so the gain is on top of the merged
fan-out. Every run exit 0, every session served on every tip. Medians over the 8 tips;
the candidate's server-side figures are medians over both frontends' refresh published
lines; the base has no such line.

Run tip→refresh start refresh publish→first / p50 / p90 / last client first / p50 / p90 / last from tip mean miner latency hashrate loss 60 s steady ack p99
AB base b61747e n/a n/a n/a 1652 / 1795 / 1847 / 1864 1785 2.93% 14.9
AB candidate 0 ms 803 ms (723–845) 38 / 164 / 211 / 220 832 / 972 / 1022 / 1035 962 1.59% 17.3
BA candidate 0 ms 798 ms (757–829) 41 / 172 / 216 / 226 809 / 967 / 1012 / 1033 952 1.57% 13.7
BA base b61747e n/a n/a n/a 1691 / 1846 / 1898 / 1919 1834 3.01% 14.9

Milliseconds. The candidate advanced by the delta path on every tip of both runs (16 of
16 across both frontends, tip/delta/advanced; the reanchor refreshes between tips
advanced too). Saving on the endpoint (last session's fresh work): 829 ms (44%) in the AB
pair and 886 ms (46%) in the BA pair; the two base runs are 55 ms apart. Mean miner
latency 1.78–1.83 s to 0.95–0.96 s; hashrate loss at 60 s, 1-exp(-mean/60), 2.9–3.0%
to 1.6%. Steady-state share-ack p99 13.7–17.3 ms across all four runs; last/p99 per tip
did not regress on either arm.

Before the rebase, on 7b78ea6 (four base runs 2,056–2,095 ms, an A/A pair 3 ms apart,
two candidate runs 1,208 and 1,227 ms): saving 887 ms (AB) and 830 ms (BA), the same
size as above, with default mode (constant bits, 1 share/s) at about 1.2 s for both
binaries, which is where the base's delta path already advanced: the cost the default
harness hid.

Fault injection (candidate on 7b78ea6, realistic mode, two scheduled blocks each): every
frontend backend terminated mid-fan-out at three tips; the payout revision bumped between
build and persist at four tips; the primary restarted during two tips. In all three,
every session got fresh work on every tip, the harness's receipt-versus-PostgreSQL
reconciliation was exact (0 missing, 0 unexpected, 0 unknown-outcome, 0 ack/commit
divergence, no durability findings), both blocks were accepted and landed, and each
landing's revision bump refreshed both frontends by the delta path.

Method, per-tip tables, caveats and the environment are in the lane report (kept with the
run artifacts, not in the repository).

Verification

cargo fmt --check clean; cargo clippy --locked --all-targets -p qbit-prism-server -p qbit-prism-load -- -D warnings clean; scripts/check_prism_settings.py agrees;
cargo test --locked --workspace --all-targets --no-fail-fast plus the four explicit
#[ignore] database selections against a disposable PostgreSQL 16 with the CI auth rules
and the pinned qbitd, in required integration mode, on the tree rebased onto b61747e:
every target ok, and scripts/check_gate_manifest.py confirms all 692 expected gated
tests executed (the list gains the five new delta tests, the two adopted adversarial tests
and the coordinator-level landing test). Environmental exceptions on the shared host, all
re-run green: a port collision in live_regtest, and share_archive and
share_partitions_postgres lock timeouts at 22-thread parallelism that the unchanged base
tree reproduces and that disappear at CI's --test-threads=2 (32/32 and 8/8).

Refs #275

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

djh58 and others added 2 commits September 23, 2026 14:08
…ltas (#275)

RetainedShares::eligible refused any change in scaled network difficulty
and any delta over 4,096 sequence slots, so with a per-block retarget every
tip's refresh paid the serial full scan (about 100 pages at 400k). The
harness hid it: constant bits and a timed tip with no new shares.

snapshot_delta::advance now replays the full reader's newest-first
saturating fold for the fresh target over the delta above the retained
cutoff (ascending pages, up to 262,144 slots), the retained rows, and, for
a heavier target, a bounded margin below the retained first row (up to 16
pages; a per-block retarget moves the crossing row by a fraction of a
percent of the window). The merged window must be strictly ascending and
cross exactly at its first row (the fold reaches zero and the fold without
the first row does not); a walk that runs out of history is refused as
partial, because the count proof cannot vouch for rows older than the
first row. WindowRef is the digest of exactly the merged window, and the
leaf, partition and WAL-timeline witness is unchanged: re-read over the
merged range without the count, then with it. The reads are READ
COMMITTED like the full scan's; consistency comes from immutable rows, the
anchored predicate and the anchor's update of the singleton every append
updates, and the final count catches what can still appear between
statements. Memory at both bounds is stated next to the constants (about
640 MB at 400k, 720 MB at 500k).

Measure it: qbit_prism_refresh_window_acquisitions_total{outcome} counts
every snapshot's acquisition decision, qbit_prism_refresh_seconds
{trigger,acquisition} times every published rebuild, and one "refresh
published" line per rebuild carries the row and page counts. The load
harness gains opt-in --retarget-bits (different bits on every tip, and a
tenth more seeded history below the window) and
--background-shares-per-second; per-tip client latency gains min, p90 and
a per-frontend breakdown. Defaults are unchanged.

Differential tests against the full reader cover retargets in both
directions, multi-page deltas and margins, both size bounds, seeded random
walks over target and inserts, and landing re-derivation of a
delta-assembled window with its superset and subset refused; the
independent review's adversarial differential over a legacy-style fixture
is adopted, and a coordinator-level test lands a found block, through the
coordinator's own submit loop, on a window the delta path built after a
retarget.

Two real frontends, 2,000 sessions, 400k window, admission 128, every tip
retargeting with 133 shares/s, base b61747e (with #499's fan-out cut)
against this branch rebased onto it: the candidate advances by the delta
path on every tip (refresh 0.80 s) where the base full-scans (about
1.7 s); the last session holds fresh work 1.03-1.04 s after the tip
instead of 1.86-1.92 s (829 and 886 ms in the AB and BA pairs, the two
base runs 55 ms apart), and hashrate loss at 60 s drops from 3.0% to
1.6%. On 7b78ea6 the same pair saved 887 and 830 ms against an A/A
noise of 3 ms. Backend kills mid-fan-out, revision bumps between build
and persist, and primary restarts during a tip all keep every session's
work correct with exact receipt reconciliation and landed blocks.

Refs #275

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…us (#275)

The delta path's advance call dropped its network_difficulty argument in
3f75d27, and scripts/prism_pool_acquires.json still keyed the old call
text, so the pool-acquire guard reported the new call unclassified and the
old key stale. Rekey the entry to the new text with the same
classification (one transaction-scoped checkout); no code changes.

Refs #275

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@djh58

djh58 commented Sep 23, 2026

Copy link
Copy Markdown
Member Author

Review ledger (final)

Lanes

  • Independent adversarial review (Claude Fable, separate session, read-only, on the pre-rebase candidate 7b78ea6 plus this branch's patch): NO BLOCKERS, 0 blocker / 0 major / 5 minor. The reviewer's own differential over 360 random steps of a legacy-style fixture (sequence gaps, rejected rows, a partition boundary, retargets of up to 8x either way, rows committed between the anchor and the extension read, retained partial windows) found every one of its 330 advanced windows byte-equal to the full reader's and re-derivable by landing, every refusal predicted and named, and two mutations of the candidate (a superset window with one extra older row; the same off-by-one with the checks intact) each caught by the candidate's tests and by the reviewer's. All five minors addressed in 3f75d27.
  • Coordinator delta check of the post-review changes (bounds, isolation note, labels, adopted module, coordinator-level landing test): clean.
  • Codex adversarial lane: NOT RUN (capacity unavailable).
  • CI: 20/20 green on b0c9698.

Findings and dispositions

# source finding disposition
1 independent review, minor the memory bound at the delta and margin limits was no longer stated; the retained window, the whole delta and the whole margin are alive together until the merge fixed in 3f75d27: the transient peak is stated next to the two constants and in the design doc (about 640 MB at 400k and 720 MB at 500k with both at their bounds, against the full scan's own 108 MB doubling slack); MAX_MARGIN_PAGES cut from 64 to 16 pages, since a per-block retarget moves the crossing row by a fraction of a percent of the window (the measured margins were a few thousand rows); the 64-page delta bound is kept (about half an hour of production shares)
2 independent review, minor "one transaction" read as if the fold ran under one snapshot; the reads are READ COMMITTED fixed in 3f75d27: the advance doc comment and the design doc say why that is sound (immutable rows, the anchored predicate, the anchor's update of the singleton every append updates so every later append carries a clock above it, and the final count catching a retroactive insert or a newly eligible row)
3 independent review, minor refresh_seconds{trigger} was documented as "the order the reuse test refuses it"; the label ranks inputs by its own precedence, and a missing cached window with published work labels reanchor fixed in 3f75d27: the metric metadata, inventory and the function's doc comment state the label's own precedence (tip, revision, balances, reanchor, shares, fee, template) and the missing-cached-window case
4 independent review, minor two refusal labels were less precise than their descriptions: a retained tail that is not the cutoff counted as empty_prior, and a witness that changed during the count statement counted as count_mismatch fixed in 3f75d27: tail_mismatch and witness_changed added (fourteen outcomes); the merged range is always re-witnessed without the count before the count statement, so count_mismatch now means a changed count; contract, cardinality and inventory tests and docs follow
5 independent review, minor (coverage) landing of a delta-built window was proven at the audit-function level, not through the coordinator fixed in 3f75d27: the reviewer's adversarial module is adopted as a gated test module (two tests, the 330-window differential above), and a coordinator-level gated test drives a real coordinator through a full-scan refresh, a node retarget plus new shares, a delta-path refresh (margin below, delta above, retargeted bits in the published work) and a found block claimed, offered, rebuilt and landed by the coordinator's own submit loop, with the landed audit snapshot equal to the published window's reference
6 CI (first push, Python shard 1) the pool-acquire census guard reported the delta path's advance(...) call unclassified and its old key stale, because the call dropped its network_difficulty argument fixed in b0c9698: the entry rekeyed to the new call text with the same classification (one transaction-scoped checkout); guard clean, its unit tests 14/14

Verification behind the PR: on the tree rebased onto b61747e (#498, #499), fmt and clippy -D warnings clean, the settings check agrees, the whole workspace and the four explicit database selections green in required integration mode, and the gate manifest check confirms all 692 expected gated tests executed. Two partition-heavy binaries hit lock timeouts at the shared host's 22-thread test parallelism, the unchanged base reproduces them, and both pass at CI's parallelism.

CI: 20 checks green on b0c9698 (formatting, lints, Rust tests, PostgreSQL contract shards, Python shards, Compose validation, image builds and smoke, dependency audit, Dockerfile lint, ckpool live suite, deleted-test map). The first push, 3f75d27, failed only Python shard 1 on finding 6.

Not merging from this session.

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