lookup stamps spent.idx; write ensure skips archived parents - #246
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Below-milestone IBD write
ensure≈8.4ms/blkwas re-idx-batching ~230k archived parents whosespent.idxranges the stage table already said lookup should stamp. Loadthin=rebuilt parent need-vouts frompackedafter lookup had walked every input.This PR makes the stage table true and removes the duplicate walks.
fill_missing_parent_rangesbatchesspent.idxnext to body range. Archived parents carry spent(off,len)on the stamp. Same-batch creates still have nospent.idxuntil Class A.BatchParents(no idx IO). Write ensure only stamps holes.has_spender_relsdeleted (algo-review §6.20 — it was identical tohas_abs_layout).BatchParents::spend_abs_jobs(unique abs from pin arithmetic). 8-byte spender-meta batch is unchanged.Test plan
cargo test -p rbitcoin-query --libcargo test -p rbitcoin-consensus --lib write_idempotentDocs
docs/invariants.mdstage table: lookup stamps spent ranges; load copies; ensure is holes-only.docs/algo-review.md§11 closes §6.20.