Skip to content

query: megakey Electrum/Esplora join; SH extents (schema 19) - #162

Merged
reardencode merged 12 commits into
masterfrom
query/sh-join-session
Aug 20, 2026
Merged

query: megakey Electrum/Esplora join; SH extents (schema 19)#162
reardencode merged 12 commits into
masterfrom
query/sh-join-session

Conversation

@rearden-grok

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

Copy link
Copy Markdown
Contributor

Summary

Electrum get_history / get_balance / listunspent and Esplora address txs/utxo/chain_stats expand Class B create lists through Class A + spends. That used to be ~3 serial preads per create.

One owner in rbitcoin-query: waved load_creates_once (IdxBodyMode::Outs) + txids_get_many + tx_spent_range_batch / get_spender_meta_at_abs_batch on the process RBITCOIN_IO session. History, balance, listunspent, and chain_stats share that join.

Megakey extents (schema 19, this follow-on): new megakeys write pack8 mode 11. The last page is ver=2 and stores extent_base + extent_n (tight used count, no slack). entries() span-reads that run. Tip overflow alloc_pages a 4 KiB page and links it after the extent (extent_n unchanged) unless the bump is still glued to the extent end. Schema-18 mode 10 leftovers stay a linked walk. Occupied 18 datadirs rewrite meta to 19. SH shard / ovf bodies grow in 64 KiB steps, not Class A 64–256 MiB slabs.

Protocol results stay identical. Confirm idx-body / spend-annotate machines are called, not flattened. No last = first + (n−1)×4096 guess as the contiguity owner.

Test plan

  • 4 OP_TRUE coinbases: scripthash_history increments body_ok_reads by create count
  • 2-vout create, spend one: history len=2, sibling stays unspent, chain_stats.tx_count matches unique history txids
  • spenders(txid) / get_tx gone from scripthash query methods
  • occupied schema-18 store with SH data opens; meta becomes 19; mode 10 entries() still match
  • pack8 mode 11 + ver=2 last-page codec (bad extent_n==0 / unaligned base is Corrupt)
  • bulk-pack ≥257 fks: mode 11, extent_n equals page count, next key packs at extent_end, entries match, sh_page_chain_ios() ≤ 2 (RBITCOIN_IO session and pread)
  • last-page overflow after another key moved bump: last_page is a tail, extent_n unchanged, second overflow adds another linked page; glued HWM bumps extent_n in place
  • new SH shard body after one slab: on-disk length stays < 128 KiB above need, not a 64 MiB file; idx grow_tight 1 MiB still holds
  • required Actions green (fmt, deny, clippy, test, multinode, coverage)

rearden-grok Bot and others added 5 commits August 20, 2026 06:31
Electrum/Esplora history loaded each create with serial
get_tx_meta_and_outputs. Megakeys paid one idx+body pread per
create. Drive the same join through load_creates_once in 4096-fk
waves and fill txids from txid.body (page-grouped), leaving the pin
path's zero-txid contract unchanged.

Co-authored-by: Cursor <cursoragent@cursor.com>
History looked up spenders via txid (tx.head) and loaded the
spender Class A body just for identity. Wave spent.body 8-byte
peeks at known abs offsets, then fill spender txids from
txid.body. Multi-list stays the rare create-fk walk.

Co-authored-by: Cursor <cursoragent@cursor.com>
History, balance, listunspent, and chain_stats each walked creates
(and spends) separately. Drive all four from join_creates_and_spends
so a megakey pays one waved Class A + spent.body session per call.

Co-authored-by: Cursor <cursoragent@cursor.com>
Query walked megakey page chains with one 4 KiB pread per page.
When last = first + (n-1)*4096, one completion-session (or pread)
span fills the chain; linked walk remains the fragmented fallback.
entries() uses a single locate_head so last-page first recovery
is not paid twice.

Co-authored-by: Cursor <cursoragent@cursor.com>
Name the waved idx→body + spent 8 B batch on the process RBITCOIN_IO
session. --api-log wall_ms stays the full handler; --log-level debug
emits sh_join: pages/class_a/spends when the join exceeds 10 ms.

Co-authored-by: Cursor <cursoragent@cursor.com>
Comment thread crates/rbitcoin-query/src/lib.rs Dismissed
rearden-grok Bot and others added 7 commits August 20, 2026 06:53
rbitcoin-consensus structure_with_pres_skips_from_tx races global
plan_stamp_sub_stats atomics with parallel structure_meters_split.

Co-authored-by: Cursor <cursoragent@cursor.com>
Megakey extents need a new pack8 mode. 18 datadirs rewrite meta even
when tx.head / scripthash* are populated; 17 occupied indexes still
refuse. 13–18 table headers stay openable.

Co-authored-by: Cursor <cursoragent@cursor.com>
Mode 11 stores last_page; that page's 24 B header holds extent_base
and extent_n. Bad n=0 or unaligned base is Corrupt. Mode 10 pack8
is unchanged.

Co-authored-by: Cursor <cursoragent@cursor.com>
Bulk and tip-first megakey packs allocate used pages at bump with no
slack. Last page is ver=2; pack8 is mode 11. entries() span-reads
extent_n. The next key packs at extent_end.

Co-authored-by: Cursor <cursoragent@cursor.com>
Overflow alloc_page and sets next; extent_n stays unless the new page
is still glued to bump. entries() span-reads the prefix then walks the
tail. A second overflow adds another linked page.

Co-authored-by: Cursor <cursoragent@cursor.com>
Shard and ovf bodies are slow-growing. Align64k rounds need up to 64 KiB
instead of Class A 64–256 MiB slabs. Idx grow_tight (1 MiB) is unchanged.

Co-authored-by: Cursor <cursoragent@cursor.com>
pack8 mode 11 last page stores extent_base/n. Query span-reads that
run then a linked tail. Drop last=first+(n-1)*4096 as the contiguity
check. SH body grow is 64 KiB.

Co-authored-by: Cursor <cursoragent@cursor.com>
@rearden-grok rearden-grok Bot changed the title query: megakey Electrum/Esplora join via completion session query: megakey Electrum/Esplora join; SH extents (schema 19) Aug 20, 2026
@reardencode
reardencode merged commit 0cc2676 into master Aug 20, 2026
13 checks passed
@rearden-grok
rearden-grok Bot deleted the query/sh-join-session branch August 20, 2026 15:09
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.

2 participants