Skip to content

[hold until #573 cutover] feat(subgraph): index_scheme gate (field 14) for keyed blind indices - #846

Open
p-diogo wants to merge 3 commits into
mainfrom
feat/subgraph-index-scheme-573
Open

p-diogo wants to merge 3 commits into
mainfrom
feat/subgraph-index-scheme-573

Conversation

@p-diogo

@p-diogo p-diogo commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

What

Subgraph side of keyed blind indices (design v2.1, section 6 "On-chain scheme marker" and "New mapping"). Core side (field 14, keyed encoders, keyed tombstones) is already on main (#836).

Refs p-diogo/totalreclaw-internal#573

This subgraph must not replace the production subgraph until the cutover (release order step 7). It drops every legacy (unmarked) fact by design, so pointing the live relay at it early would show empty vaults.

Changes

  • schema.graphql: Fact.indexScheme: Int!. Always 1 on this subgraph, since unmarked payloads never create a row. Adding a field is additive, so no existing query on the old schema changes validity; I chose non-null over nullable/0-default because no legacy row can exist here.
  • src/protobuf.ts: decodes outer field 14 as a varint (kept as i64, only == 1 counts). A field 14 with another wire type is skipped, so it reads as unmarked. Unknown fields are still skipped. Hardening found while writing the vectors:
    • a truncated varint no longer yields a value (a cut 0x81 used to read as 1);
    • varints over 10 bytes are rejected;
    • field numbers and lengths are compared as i64 (an oversized key could alias field 14; a wrapped length could pass the bounds check).
  • src/mapping.ts: the rule is total. Not field 14 = 1 means return before any store access, with no liveness exception (isActive = decayScore >= 0.3 is unchanged but unmarked payloads never reach it). A marked tombstone (empty blob, decay 0) for an id never seen is ignored instead of creating an empty Fact.
  • Manifests: untouched (network, startBlock, address unchanged).

Shared protobuf vectors

tests/parity/fixtures/protobuf-index-scheme-vectors.json, generated from the core encoder by rust/totalreclaw-core/examples/generate_index_scheme_vectors.rs (cargo run --example generate_index_scheme_vectors, -- --check verifies it is current). Nine vectors: marked fact, marked tombstone, legacy fact, legacy low-decay fact, legacy tombstone, field 14 = 2, field 14 wrong wire type, truncated mid-field, truncated inside the field-14 varint. Each has payloadHex, expected decoded fields, and counts. The relay decoder should load the same file.

Tests

Matchstick, 18 passing: decoder against every shared vector plus hardening cases; mapping tests for marked fact indexed, unmarked fact (and low-decay) ignored entirely, marked tombstone for a known id deactivates, marked tombstone for an unknown id ignored, unmarked tombstone ignored, field 14 = 2 ignored, wrong wire type and truncated ignored, mixed batch.

  • matchstick-as added; top-level assemblyscript devDep pinned to 0.19.23 (matchstick 0.6.0 needs the 0.19 bin/asc; graph-cli already bundles that version for builds).
  • graph-cli 0.80 rejects Ubuntu 24.04 for the native binary, so tests run via graph test -d (Docker). New subgraph-tests CI job runs the vector --check, builds all three manifests and runs matchstick.

What a vNext deploy needs (not done here)

  • A separate subgraph name/version, deployed alongside prod (no replace). No graph deploy was run.
  • startBlock: per design section 6, unmarked payloads never count after cutover, so startBlock only affects sync speed; it can stay at the current contract startBlock or be raised, and needs a decision at deploy time.
  • Relay SUBGRAPH_ENDPOINT / fallback switch together with the gate flag (steps 7-8). Pedro-approved step.

🤖 Generated with Claude Code

@p-diogo p-diogo changed the title feat(subgraph): index_scheme gate (field 14) for keyed blind indices [hold until #573 cutover] feat(subgraph): index_scheme gate (field 14) for keyed blind indices Nov 26, 2026
@p-diogo

p-diogo commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator Author

🤖 Hold: merge this at the #573 cutover (release order step 7), not before. No workflow deploys the subgraph, but npm run deploy:prod / deploy:staging from main would ship this mapping, which drops every legacy (unmarked) fact, so live vaults would look empty until clients write scheme-1 facts. Review now so it is ready; merge together with the vNext deploy.

p-diogo added a commit that referenced this pull request Nov 26, 2026
…ailure grep); npm test uses Docker; fix a comment

Review nits on #846.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
p-diogo and others added 3 commits December 4, 2026 18:32
The mapping now counts a payload only when outer protobuf field 14
(index_scheme) is a varint equal to 1. Anything else creates no Fact, no
BlindIndex rows and has no tombstone effect. A marked tombstone for an
unknown id is ignored instead of creating an empty Fact. Adds
Fact.indexScheme, hardens the varint/length handling in the decoder,
shared protobuf vectors generated from the core encoder, matchstick
tests and a CI job.

Refs p-diogo/totalreclaw-internal#573

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ailure grep); npm test uses Docker; fix a comment

Review nits on #846.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@p-diogo
p-diogo force-pushed the feat/subgraph-index-scheme-573 branch from d7d1818 to 1d204ab Compare December 4, 2026 22:01
@p-diogo

p-diogo commented Dec 4, 2026

Copy link
Copy Markdown
Collaborator Author

Rebased onto main 77a3daaa (4 Dec): the gate now sits in main's DataEdge V2 mapping (<sender>:<id> fact ids), and the tests use V2 events. Subgraph builds and matchstick (18/18) pass locally. The audited commit stays at tag audit-halborn-2026-12-04-846 (d7d18181), so this rebase is part of the delta for Halborn. Still on hold until the cutover.

This branch has not been deployed

No deployments
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