Skip to content

lookup stamps spent.idx; write ensure skips archived parents - #246

Merged
reardencode merged 6 commits into
masterfrom
confirm/stamp-spent-reuse-thin
Aug 25, 2026
Merged

lookup stamps spent.idx; write ensure skips archived parents#246
reardencode merged 6 commits into
masterfrom
confirm/stamp-spent-reuse-thin

Conversation

@rearden-grok

@rearden-grok rearden-grok Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Summary

Below-milestone IBD write ensure≈8.4ms/blk was re-idx-batching ~230k archived parents whose spent.idx ranges the stage table already said lookup should stamp. Load thin= rebuilt parent need-vouts from packed after lookup had walked every input.

This PR makes the stage table true and removes the duplicate walks.

  • Lookup fill_missing_parent_ranges batches spent.idx next to body range. Archived parents carry spent (off,len) on the stamp. Same-batch creates still have no spent.idx until Class A.
  • Load pin copies those ranges onto BatchParents (no idx IO). Write ensure only stamps holes.
  • has_spender_rels deleted (algo-review §6.20 — it was identical to has_abs_layout).
  • Structural uses BatchParents::spend_abs_jobs (unique abs from pin arithmetic). 8-byte spender-meta batch is unchanged.
  • plan_batch publishes sorted parent need-vouts; pin reuses them instead of HashMap-rebuilding from packed.

Test plan

  • cargo test -p rbitcoin-query --lib
  • cargo test -p rbitcoin-consensus --lib write_idempotent

Docs

docs/invariants.md stage table: lookup stamps spent ranges; load copies; ensure is holes-only. docs/algo-review.md §11 closes §6.20.

rbitcoin-grok added 6 commits August 25, 2026 13:04
The Direct IBD stage table already said lookup fills parent
txout/spent ranges. fill_missing_parent_ranges only did body.
Write ensure then re-idx-batched ~230k archived parents on the
confirm pole.

Carry spent.body (off, len) on ExternalParentStamp /
ArchiveWritePlan / ParentPinStamp. Same idx-fill helper now
batches spent.idx for stamped fks with no in-flight outs.
Store body fill without spent.idx is Corrupt; RAM-only identity
(no spent row) stays unset for write ensure.

Same-batch creates still have no spent.idx until Class A.
Lookup already carries spent.body ranges. Load pin copies them
onto BatchParents so write ensure skips archived parents (same-
batch still waits for Class A).

has_spender_rels was identical to has_abs_layout (algo-review
§6.20). Keep has_abs_layout; delete the dead ensure branch that
re-idx-batched when they diverged in name only.
structural_validate_spends regrouped spends into vouts_by_create
then probed get_spender_abs per vout. After lookup-stamped
spent.idx on the pin, abs is off+slot*vout.

BatchParents::spend_abs_jobs walks edges once, dedups by abs,
and Corrupt-fails a missing pin. Structural uses that list;
8-byte spender-meta batch is unchanged (consensus authority).
plan_batch already walks every input to stamp create_fk. Publish
sorted unique parent vouts on the plan/stamp so pin_for_wire_batch
does not rebuild that HashMap from packed. Thin edges still zip
packed InputRecords. plan=None and tests with empty stamp vouts
keep the packed/wire walk.
Match the Direct IBD stage table to shipped code: lookup fills
archived-parent spent.idx ranges, load pin copies them (no idx
IO), write ensure only stamps holes. has_spender_rels is gone.
§6.20 and the lookup spent.idx stamp gap close on this PR.
@reardencode
reardencode merged commit 0f1f43e into master Aug 25, 2026
13 checks passed
rearden-grok Bot added a commit that referenced this pull request Aug 25, 2026
PR #247 is dirty against master (#244#246). Take the spent.idx pin
path and other algo-review closures; keep this branch's consensus
fixes.

Co-authored-by: Cursor <cursoragent@cursor.com>

# Conflicts:
#	docs/algo-review.md
@rearden-grok
rearden-grok Bot deleted the confirm/stamp-spent-reuse-thin branch August 25, 2026 23:15
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