Skip to content

feat(data-api): retire D1 chain-data write path (#4772)#4908

Merged
JSONbored merged 2 commits into
mainfrom
feat/d1-chain-data-retirement
Jul 11, 2026
Merged

feat(data-api): retire D1 chain-data write path (#4772)#4908
JSONbored merged 2 commits into
mainfrom
feat/d1-chain-data-retirement

Conversation

@JSONbored

Copy link
Copy Markdown
Owner

Summary

  • Retires the D1-side write/prune/rollup infrastructure for blocks, extrinsics, account_events, neurons, and neuron_daily now that Build the metagraph/neuron pipeline's missing Postgres write path (neurons + neuron_daily) #4771's Postgres write path (neurons-sync) and the Postgres-native indexer-rs pipeline (blocks/extrinsics/account_events/chain_events) are the real serving tiers, with tryPostgresTier(...) ?? d1Fallback() already wired across every read route.
  • Deletes the realtime streamer scripts (fetch-events.py, stream-events.py, backfill-events.py) and their workflow/docs, the internal ingest handlers (handleEventIngest/handleBlockIngest/handleNeuronBackfill), the D1 staged-batch loaders for those four tables, and each table's prune/rollup/archive cron logic.
  • Restructures EVENTS_LOAD_CRON, HEALTH_PRUNE_CRON, and NEURON_HISTORY_ROLLUP_CRON to drop only what they retired, keeping subnet_hyperparams/account_identity staging and account_position_daily's rollup/prune untouched.
  • Fixes a latent bug the restructuring surfaced: HEALTH_PRUNE_CRON's unrelated pruneHealthHistory prune was gated on the now-removed rollupAccountEventsDaily succeeding, which would have silently wedged it forever once D1's account_events table is gone.
  • Fixed a related bug in the private metagraphed-indexer-rs repo (already merged/deployed separately): the backfill flush() used ON CONFLICT DO NOTHING for extrinsics/account_events/chain_events instead of DO UPDATE, which would have silently preserved stale rows on the eventual archive-gated backfill re-run.

Explicitly out of scope, left as-is: account_position_daily (has a Postgres write mirror but no read route yet), account_events_daily's independent Postgres-side rollup (already had its own GitHub Actions workflow, never depended on the removed D1 rollup), and the ~40 dead D1-fallback branches in workers/request-handlers/entities.mjs (cosmetic, provably safe via d1All's graceful degradation — tracked as follow-up).

Closes #4772

Test plan

  • npx vitest run — 255 files / 7517 tests passing
  • npm run lint — clean
  • npx prettier --check on all touched files — clean
  • git diff --check — clean
  • npm run test:coverage (unsharded) — 99.5% stmts / 97.92% branch overall; manually verified zero uncovered lines within this diff's actual added/changed lines (the diff is almost entirely deletions)
  • npm run scan:public-safety — clean
  • npm run validate — clean (129 subnets, 1553 surfaces)
  • node scripts/validate-workflows.mjs — 24 workflows validated

Drops the D1-side write/prune/rollup infrastructure for blocks,
extrinsics, account_events, neurons, and neuron_daily now that #4771's
Postgres write path (neurons-sync) and the Postgres-native indexer-rs
pipeline (blocks/extrinsics/account_events/chain_events) are the real
serving tiers, with tryPostgresTier(...) ?? d1Fallback() already wired
across every read route. Deletes the realtime streamer scripts
(fetch/stream/backfill-events.py) and their workflow/docs, the
internal ingest handlers (handleEventIngest/handleBlockIngest/
handleNeuronBackfill), the D1 staged-batch loaders for those four
tables, and each table's prune/rollup/archive cron logic --
restructuring EVENTS_LOAD_CRON, HEALTH_PRUNE_CRON, and
NEURON_HISTORY_ROLLUP_CRON to drop only what they retired. Fixes a
latent bug the restructuring surfaced: HEALTH_PRUNE_CRON's unrelated
pruneHealthHistory prune was gated on the now-removed
rollupAccountEventsDaily succeeding, which would have silently wedged
it forever once D1's account_events table is gone.

account_position_daily, account_events_daily's independent Postgres
rollup, and the ~40 dead D1-fallback branches in entities.mjs are
explicitly out of scope and left as-is.
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
metagraphed-data-api a6197b6 Jul 11 2026, 05:03 PM

Checks off sequencing item 8 (D1 write/prune/ingest code retired,
PR #4908) and adds item 11 documenting the indexer-rs backfill
DO NOTHING -> DO UPDATE conflict-resolution fix found while auditing
the eventual archive-gated backfill for correctness. Updates
Links/resources for the files this PR deleted.
@superagent-security

Copy link
Copy Markdown

Superagent didn't find any vulnerabilities or security issues in this PR.

@codecov

codecov Bot commented Jul 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.94%. Comparing base (bcf7de0) to head (a054c4b).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4908      +/-   ##
==========================================
+ Coverage   97.88%   97.94%   +0.05%     
==========================================
  Files         162      162              
  Lines       20030    19425     -605     
  Branches     7527     7349     -178     
==========================================
- Hits        19606    19025     -581     
+ Misses         59       53       -6     
+ Partials      365      347      -18     
Files with missing lines Coverage Δ
src/account-events.mjs 100.00% <ø> (ø)
src/blocks.mjs 100.00% <ø> (ø)
src/extrinsics.mjs 93.75% <ø> (-0.27%) ⬇️
src/neuron-history.mjs 96.62% <ø> (-0.70%) ⬇️
workers/api.mjs 95.29% <100.00%> (+0.04%) ⬆️
workers/config.mjs 100.00% <ø> (ø)
workers/request-handlers/staging.mjs 97.93% <ø> (+2.03%) ⬆️
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@gittensory-orb gittensory-orb Bot added the gittensor:bug Gittensor-scored bug fix or unsolicited PR — scores a 0.05x multiplier. label Jul 11, 2026
@JSONbored JSONbored merged commit 4c3dbbf into main Jul 11, 2026
14 checks passed
@JSONbored JSONbored deleted the feat/d1-chain-data-retirement branch July 11, 2026 17:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gittensor:bug Gittensor-scored bug fix or unsolicited PR — scores a 0.05x multiplier.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fully retire D1 for chain data — delete tables, prune logic, ingest endpoints, and the D1 fallback (gated on #4771)

1 participant