Skip to content

3.x.x: attribute 016's block solvers in statements of at most 128 blocks, so the migration transaction stays inside the default statement timeout on a cold cache (#672) - #680

Merged
RobertClarke merged 2 commits into
3.x.xfrom
prism-672-solver-attribution
Oct 5, 2026
Merged

RobertClarke merged 2 commits into
3.x.xfrom
prism-672-solver-attribution

Conversation

@RobertClarke

@RobertClarke RobertClarke commented Oct 5, 2026 •

Copy link
Copy Markdown
Member

Fixes #672.

Migration 016 fills qbit_pool_blocks.solver_* for the blocks a 2.x.x pool found before it. The lookup is one probe of qbit_share_ledger_accepted_block_suffix_idx per block (13,566 on mainnet), exactly what the dashboard queries made on every request. 016's file ran it as one UPDATE ... CROSS JOIN LATERAL statement inside the migration transaction, under PRISM_DATABASE_STATEMENT_TIMEOUT_MS. Each probe is two random reads (an index leaf and a heap page), so on a cold cache that single statement grows with the ledger. #582's measured rehearsal on a saturated disk saw it refused at the 15 s default.

Change

  • 016's file keeps everything except the backfill UPDATE: columns, landing trigger, catalog and functions.
  • Right after the file, inside the same transaction, the migrator makes the same probes in statements of at most 128 blocks. The batches are keyset-ordered by block_hash and skip blocks that already have a solver (ledger/migration/block_solvers.rs).
  • The attribution, the locks and the atomicity are the single statement's. Only the statements are short.
  • A block whose solving share isn't found keeps NULL columns, as before, and the keyset moves past it.
  • One log line reports the blocks attributed, the statement count, the slowest statement and the total.
  • It is the same code on both paths that apply 016: a 2.x.x source, and a native database without 16.
  • Nothing moves out of the transaction, so there are no readiness or gating changes. The work is bounded by the block count, which grows slowly.

Measurements

Setup:

Ledger Cache Before: 016's statement After: statements, longest, total Transaction before → after
8.25M warm 3.0 s 107, 406 ms, 9.1 s 4.2 s → 10.7 s
8.25M cold 6.7 s 107, 71 ms, 3.9 s 8.9 s → 4.9 s
16.5M warm 7.4 s 107, 592 ms, 5.6 s 8.7 s → 7.2 s
16.5M cold 11.2 s 107, 181 ms, 5.1 s 13.0 s → 6.3 s

With a concurrent direct-I/O writer saturating the same disk (cold, 8.25M, at the default 15 s timeout):

Tests

  • ledger_postgres::block_solvers::migration_016_attributes_a_2x_sources_blocks_as_its_single_statement_did, on a frozen 2.x.x source with 300 blocks (three statements' worth), in six cases:

    • one solving share;
    • an earlier and a later share, where the later wins, with its hash in upper case;
    • two at the same instant, where the higher share_seq wins;
    • a rejected share only;
    • no share;
    • a bare 64-digit share ID.

    The attribution must equal the old single statement's lookup, row for row, and every version must be recorded.

  • ledger_postgres::block_solvers::migration_016_attributes_a_native_ledgers_blocks_when_016_is_missing: the same attribution on the native path, for a native ledger without 16.

  • Unit: the batch makes exactly the lookup 016's landing trigger makes (read from the file), and keysets by block_hash.

  • ledger_postgres (the whole binary), share_partitions_postgres and migration_rollback's PR rehearsal: see the test run on this PR.

Docs

docs/prism-rust-migration.md's 016 section gives the cost model, the before table, and what the migrator does now. 016's file says where its backfill went.

🤖 Generated with Claude Code

…cks, so the migration transaction stays inside the default statement timeout on a cold cache (#672)

Migration 016 fills qbit_pool_blocks.solver_* for the blocks a 2.x.x pool
found before it, with one probe of qbit_share_ledger_accepted_block_suffix_idx
per block (13,566 on mainnet). Its file ran that as one UPDATE ... CROSS
JOIN LATERAL statement inside the migration transaction, under the
statement timeout. Each probe is two random reads, so on a cold cache the
statement grows with the ledger. On mainnet-shaped ledgers, from a quiet
disk, it took 6.7 s at 8.25M shares and 11.2 s at 16.5M; under a concurrent
writer it took 14.0 s at 8.25M; and #582's rehearsal on a saturated host
saw it refused at the 15 s default.

016's file keeps its columns, landing trigger, catalog and functions, and
loses the UPDATE. Right after the file, in the same transaction, the
migrator makes the same probes in statements of at most 128 blocks,
keyset-ordered by block_hash over the blocks without a solver
(ledger/migration/block_solvers.rs). The attribution, locks and atomicity
are unchanged, and a block whose solving share is not found keeps NULL
columns. The longest statement measured 71-592 ms across those runs, and
0.47 s under the concurrent writer.

Test: on a frozen 2.x.x source with 300 blocks (three statements), the
attribution equals the old single statement's lookup, row for row. That
covers the latest accepted share winning, the share_seq tie-break, case
folding, rejected shares, missing shares and bare 64-digit IDs. A unit
test pins the probe to 016's.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-05T21:41:16.818346Z 3cb2bb3 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

…e native path, and fix the statement count (#672)

From /code-review high on #680:

- The unit test reads the solver lookup from 016's landing trigger and
  requires the batch statement to make exactly that probe, rather than
  comparing the batch with a hand copy of itself. The trigger attributes
  every block landed after 016 and the batch the ones before it, so the
  two must not drift.
- A native ledger without 16, with blocks and shares, applies 016 on the
  native path with the same attribution as the old single statement.
- Every statement is counted, the final empty one too, so the logged
  count agrees with the slowest-statement figure: 107 for 13,566 blocks.
- 016's header comment points to the note after the landing trigger, and
  the docs no longer say the file itself backfills the columns.

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

Copy link
Copy Markdown
Member Author

/code-review high round (9 candidates), addressed in 3cb2bb3:

  • Fixed: the unit test compared the batch with a hand copy of itself. It now reads the solver lookup from 016's landing trigger and requires the batch to make exactly that probe. The trigger attributes blocks landed after 016 and the batch the ones before, so they must not drift.
  • Fixed: native path untested. A native ledger without 16, with blocks and shares, now applies 016 on the native path with the same attribution as the old single statement (migration_016_attributes_a_native_ledgers_blocks_when_016_is_missing).
  • Fixed: statement count. Every statement is counted, the final empty one too: 107 for 13,566 blocks.
  • Fixed: 016's header pointer and the docs' "added and backfilled here".
  • Kept: the work stays inside the transaction, so the lock hold isn't shortened and has no overall cap.
    • The old single statement held the same locks for its whole run. The batched work is bounded by the block count: 3.9–11.9 s for 13,566 blocks, including a saturated disk.
    • During the cutover, the transaction already holds the cutover locks.
    • Moving it after the commit would mean blank solvers until it finishes on a native upgrade, plus a new completion gate.
  • Kept: fixed 128 blocks, no timeout retry. A statement timeout small enough to cancel a 128-block batch (longest measured 0.6 s) would cancel other statements in the same transaction first: 001's file took up to 0.59 s in the same runs.
  • Kept: no shared SQL function for the lookup. Adding a function to 016 would change its object set on databases that already applied it. The test above now catches drift.
  • Kept: the quiesce checks for 018 and later run after 016. That ordering predates this change, and the work it can waste is bounded by the block count, as before.

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