Skip to content

fix(store): re-verify stored sections once on first start after the receive-path binding - #24

Open
cafebedouin wants to merge 1 commit into
mwaddip:mainfrom
cafebedouin:ergo-logic/rebind-stored-sections
Open

cafebedouin wants to merge 1 commit into
mwaddip:mainfrom
cafebedouin:ergo-logic/rebind-stored-sections

Conversation

@cafebedouin

Copy link
Copy Markdown

Branch: ergo-logic/rebind-stored-sections. Files: store/src/redb.rs, src/main.rs,
facts/store.md.

Why

v0.8.2's binding applies to writes. A body stored under a derived id by v0.8.1 — including one a peer
wrote while v0.8.1 accepted unbound deliveries — is read back by v0.8.2, passes the sweep's
has_modifier gate, and is applied; nothing recomputes its id (section_id_from_body has one
production call site, the pipeline write). Executed across two clones sharing one store file:
poison: read_back=true contains=true would_bind=Some(false); honest control binds.

What

RedbModifierStore::rebind_sections(type_ids, bound): one read pass over PRIMARY for 102/104/108,
one write pass deleting rows that fail the predicate and the HEIGHT_INDEX rows pointing at them;
returns (kept, dropped). main.rs runs it once after the scores migration, predicate
section_id_from_body(t, bytes).id == id, and records chain_meta["sections_rebound_v1"], mirroring
scores_migrated_v1.

Tests

New: rebind_sections_drops_unbound_rows_and_their_index_entries (kept/dropped counts, index rows,
idempotence). cargo test -p enr-store: 54 passed; cargo check -p ergo-node-rust: clean.

Contract

facts/store.md § "One-shot rebind of stored sections".

Cost, and what a dropped row means

The pass hashes every stored body of types 102/104/108 in one read pass and removes the unbound rows
in one write transaction, before the chain restores. The scores migration just above it chunks its
writes at 50,000 entries to bound unclean-restart work (src/main.rs:2217-2255); this pass is not
chunked. On a pruned node the walk is blocks_to_keep bodies and short. On an archival node it hashes
every body on the chain once; if you would rather have it chunked with a progress line, say so and
the patch gets that shape. A dropped row was never a body the node had validated against its header:
its bytes did not hash to its key. Below the applied tip nothing re-requests it (the sweep resumes at
applied_tip + 1, sync/src/state.rs), so an archival node that was poisoned on v0.8.1 serves
nothing for that height's section after the pass, where before it served the poison; a resync
restores it. Above the applied tip the sweep's existence gate sees the gap and downloads the body.

Changelog entry

Not in the patch (your repo instructions reserve CHANGELOG.md for the main session, and four PRs
inserting an Unreleased block at the same spot conflict with each other). Text, if useful:

#### Sections stored before v0.8.2 are re-verified once on startup

The receive-path binding applied to writes only. A body stored under a
derived id by an earlier version — including one written by a peer while
v0.8.1 accepted unbound deliveries — was read back, passed the sweep's
existence gate, and applied; nothing recomputed its id. On first start the
node now walks stored non-header sections once, drops every row whose bytes
do not hash to their key (and its height-index row), and records the pass
in `chain_meta` (`sections_rebound_v1`).

🤖 Generated with Claude Code

…eceive-path binding

v0.8.2 binds sections at the network write. A body stored under a derived
id by an earlier version — including one a peer wrote while v0.8.1 accepted
unbound deliveries — is read back by v0.8.2, passes the sweep's has_modifier
gate, and is applied; section_id_from_body has one production call site,
the pipeline write, so nothing re-checks stored bytes. Witnessed across two
versions sharing one store file.

RedbModifierStore::rebind_sections(type_ids, bound): one read pass over
PRIMARY for 102/104/108, one write pass deleting rows that fail the
predicate and the HEIGHT_INDEX rows that pointed at them; returns
(kept, dropped). main.rs runs it once after the scores migration with
section_id_from_body(t, bytes).id == id and records chain_meta
"sections_rebound_v1", mirroring scores_migrated_v1.

Test: rebind_sections_drops_unbound_rows_and_their_index_entries.
Contract: facts/store.md § One-shot rebind of stored sections.
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