Skip to content

Feat/graphman chain rebuild storage#6518

Open
dimitrovmaksim wants to merge 6 commits intomasterfrom
feat/graphman-chain-rebuild-storage
Open

Feat/graphman chain rebuild storage#6518
dimitrovmaksim wants to merge 6 commits intomasterfrom
feat/graphman-chain-rebuild-storage

Conversation

@dimitrovmaksim
Copy link
Copy Markdown
Member

@dimitrovmaksim dimitrovmaksim commented Apr 16, 2026

Problem

After manual DB operations or a DB failure it's possible to end up with a chain whose storage schema (e.g. chain123) has been dropped on the shard while its metadata row in public.chains still exists. graph-node cannot recover from this automatically and will fail with:

INFO Downloading latest blocks from Ethereum, this may take a few minutes..., provider: arbitrum-one, component:
ERRO Trying again after block polling failed: Ingestor error: store error: relation "chain123.blocks" does not exist, provider: arbitrum-one, component: EthereumPollingBlockIngestor

Currently the only way to fix is to manually re-create the schema, tables and ethereum_networks records on the shard.

What this PR does:

Adds a new graphman chain rebuild-storage <CHAIN_NAME> command. It recreates the schema, tables and inserts/updates the ethereum_networks table

Behaviour depends on current state:

  • Schema/namespace missing — silently skips drop and recreates the schema; no confirmation required.
  • Schema/namespace exists — prompts for confirmation before dropping and rebuilding. Use --force to skip the prompt.
  1. Drops the existing storage schema if present (DROP SCHEMA ... CASCADE), reusing Storage::drop_storage.
  2. Upserts the chain's row in ethereum_networks: insert if missing (seeding from the provided chain identity), or reset head_block_hash, head_block_number, head_block_cursor to NULL and repair identity columns if the row exists.
  3. Recreates the schema with empty blocks, call_cache, and call_meta tables.

After this, graph-node treats the chain as a freshly added chain.

Adds ChainStore::rebuild_storage, which drops the chain's schema (if
present), upserts the ethereum_networks row to reset head tracking
columns, and recreates the schema with empty tables — all in a single
transaction.

Adds BlockStore::has_namespace and BlockStore::rebuild_chain_storage as
the public entry points used by the graphman command.
Adds the rebuild-storage subcommand to graphman chain. Looks up the
chain in public.chains, rejects shared-storage chains, prompts for
confirmation when storage already exists (--force skips the prompt),
then delegates to BlockStore::rebuild_chain_storage.
Covers four scenarios: existing namespace (drop + rebuild), missing
namespace, missing ethereum_networks row (full upsert path), and
has_namespace returning false after a manual schema drop.
Adds synopsis, description, constraints, and examples for the new
chain rebuild-storage subcommand.
@dimitrovmaksim dimitrovmaksim self-assigned this Apr 16, 2026
Rather than always running DROP SCHEMA IF EXISTS unconditionally,
the command layer passes the result of has_namespace as a drop_schema
bool down through BlockStore::rebuild_chain_storage into
ChainStore::rebuild_storage. When true, the existing
Storage::drop_storage is reused; when false, the drop is skipped
entirely.
Note that graph-node must be stopped before running the command, making
explicit the single-operator assumption baked into the check-then-act
flow. Also correct the DROP SCHEMA step description to remove the
stale IF EXISTS qualifier.
@dimitrovmaksim dimitrovmaksim force-pushed the feat/graphman-chain-rebuild-storage branch from f68bee0 to cc90bd2 Compare April 16, 2026 19:06
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