Repository navigation
3.x.x: keep the refresh delta path across retargets and multi-page deltas (#275) - #501
Conversation
…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]>
Review ledger (final)Lanes
Findings and dispositions
Verification behind the PR: on the tree rebased onto b61747e (#498, #499), fmt and clippy 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. |
Why
RetainedShares::eligiblerefused any change in scaled network difficulty and any deltaover 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 theledger:
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 rebuiltwork, 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.INFO prism::refresh: refresh publishedline 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.
--retarget-bits(the fake node servesdifferent 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_worktips gain
min/p90and aby_frontend[]breakdown so publish→first/p50/p90/last can beread per frontend against that frontend's own refresh line.
Implement
snapshot_delta::advancereplays the full reader's newest-first saturating fold for thefresh 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'ssaturating crossing-row rule,
WindowRefover exactly the merged window, and the unchangedleaf / 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 upand 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 tipretargets; 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 publishedlines; the base has no such line.
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 tipsadvanced 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 --checkclean;cargo clippy --locked --all-targets -p qbit-prism-server -p qbit-prism-load -- -D warningsclean;scripts/check_prism_settings.pyagrees;cargo test --locked --workspace --all-targets --no-fail-fastplus the four explicit#[ignore]database selections against a disposable PostgreSQL 16 with the CI auth rulesand the pinned qbitd, in required integration mode, on the tree rebased onto b61747e:
every target
ok, andscripts/check_gate_manifest.pyconfirms all 692 expected gatedtests 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, andshare_archiveandshare_partitions_postgreslock timeouts at 22-thread parallelism that the unchanged basetree reproduces and that disappear at CI's
--test-threads=2(32/32 and 8/8).Refs #275
🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.