Skip to content

confirm: cut stamp/write CPU copies - #249

Merged
reardencode merged 8 commits into
masterfrom
confirm/one-spend-edge
Aug 25, 2026
Merged

confirm: cut stamp/write CPU copies#249
reardencode merged 8 commits into
masterfrom
confirm/one-spend-edge

Conversation

@rearden-grok

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

Copy link
Copy Markdown
Contributor

Why

Below-milestone IBD still spends CPU re-encoding parent/spend facts and cloning pin/pres Arcs that lookup already built. After #245/#246, ensure=/thin= dropped; remaining waste is structure, not missing idx.

What

Phase A of the confirm-pipeline CPU plan (same-thread occupancy and encode-at-write stay later PRs).

  • Optimistic assemble: unstamped parent is invariant: lookup stage miss, not tx_fk_by_txid_tip recover. Full mode still uses tip fk + has_parent_out.
  • Script jobs attach Arc<[TxPrecompute]> + idx (no Arc::new(p.clone())). take_from_plan does not SipHash-invert create_by_txid (plan=None still does).
  • S0 plan_batch: one fill_missing_parent_ranges unless packed adds pre-stamped fks.
  • Direct write skips unused write_create_pins FkMap. One tx_body_range_batch(planned_fks) feeds layout holes and RecentCreates; spent.idx stays holes-only.
  • Pin takes stamp parent_vouts (no clone+re-sort). Same-header creates stay off the pin (wire TxOut); cross-height same-pack still pins. Pin-covered contract walk is debug_assert only.

Follow-ups on this branch if needed

CreatePin-backed pin (no script clone on plan hit), one spend-edge list (drop IBD BatchThin), structural/annotate consume that list once.

Not this PR: stamp-on-lookup occupancy, encode packed at write, class_c_join / OA seal / pin_hit.

Test

cargo test -p rbitcoin-query --lib plan_batch
cargo test -p rbitcoin-consensus --lib pin_
cargo test -p rbitcoin-consensus --lib structure_rule

No workflow YAML. Do not merge unless asked.

rearden-grok Bot pushed a commit that referenced this pull request Aug 25, 2026
rbitcoin-grok added 7 commits August 25, 2026 15:34
Direct IBD already stamps create_fk. tx_fk_by_txid_tip on the
optimistic walk was a dual path that IBD never needed (cold=0)
and re-probed pin via has_parent_out before get_parent_txout_parts.

Unstamped parents are Corrupt("invariant: lookup stage miss").
Full mode still uses tip fk + has_parent_out for durable spentness.
input_create_heights is allocated only in Full (BIP68 at assemble).
take_from_plan pins from packed create_fk, so rebuilding
create_by_txid with SipHash on S0 was wasted. plan=None still
fills it for thin edges.

Script jobs attach Arc<[TxPrecompute]> + idx instead of
Arc::new(p.clone()) so assemble does not copy midstates.
stamp_external_parents already idx-fills resolved parents. A second
packed rewalk + fill_missing was a no-op idx batch on Direct IBD.
Pre-stamped reconstruct create_fk still joins txids in the stamp
loop and fill_missing runs only when that set grew.
SH collect is a no-op under IndexMode::Direct, so write_create_pins
was an unused FkMap of Arc clones. Tip still fills it.

One tx_body_range_batch(planned_fks) now feeds both layout holes and
RecentCreates. Spent.idx batch stays holes-only. Rows take &[CreatePin]
instead of a third Option-wrapped clone vec.
Lookup already sorts need-vouts. Load now moves that map instead of
cloning and re-sorting. Same-header spends stay off parent_vouts —
assemble values them from the wire TxOut. Cross-height creates in the
same write pack still pin.

The pin-covered contract walk is debug_assert only (still_need empty
is the release check).
Load copies spent_range; write ensure is holes-only. Invariants
regression table covers the new stamp/pin/write pins.
Assemble attaches Arc<[TxPrecompute]> via with_pre_slice. The Owned
with_pre helper was only used from tests and failed lib dead_code
on CI (test/windows/macos).
@rearden-grok
rearden-grok Bot force-pushed the confirm/one-spend-edge branch from f57b0ed to eeddd33 Compare August 25, 2026 22:36
validate_block_connect is Optimistic: an unstamped parent is
Corrupt(\"invariant: lookup stage miss\"), not MissingPrevout via
head recover. The analog still requires the connect to fail.
@reardencode
reardencode merged commit ad9c2af into master Aug 25, 2026
13 checks passed
@rearden-grok
rearden-grok Bot deleted the confirm/one-spend-edge 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