Skip to content

fix(storage): register the block_index table on the redb backend - #24

Merged
secsovereign merged 3 commits into
mainfrom
fix/redb-block-index-table
Oct 15, 2026
Merged

secsovereign merged 3 commits into
mainfrom
fix/redb-block-index-table

Conversation

@secsovereign

Copy link
Copy Markdown
Member

Summary

Storage::with_backend(.., DatabaseBackend::Redb) fails on main:

Unknown table name: block_index. Redb requires pre-defined tables.

ChainState::new (src/storage/chainstate.rs:91) opens the block_index tree through BlockIndex::new, but the redb backend only opens tables listed in redb_impl::get_table_def, and block_index isn't there. So any redb-backed Storage fails to open. This is the same kind of gap as block_undo, fixed in de5dac8.

It surfaced in #23's new cargo test --features rocksdb CI step as test_storage_backend_interchangeability (tests/storage_rocksdb_integration_tests.rs:150). tests/storage_tidesdb_integration_tests.rs:122 has the same pattern under --features tidesdb.

Change

src/storage/database/mod.rs (redb only): adds BLOCK_INDEX_TABLE and registers it in both table-creation paths (new database and existing database) and in get_table_def. Opening an existing redb file creates the table if it's missing, so there's no migration. Other backends and consensus code are untouched.

Other missing tables

I compared KNOWN_TREE_NAMES against redb's table list. Besides block_index, redb is also missing:

  • ibd_utxos_ckpt_a / ibd_utxos_ckpt_b: these are the IBD engine's ping-pong checkpoint trees. On redb today, a checkpoint export logs "failed to open" and continues, and resume falls back. Registering them would turn on engine checkpoints/resume for redb nodes, which changes IBD behaviour, so it's left for a separate change.
  • test_tree, tree1, tree2, dynamic_tree_*: column families used only by the RocksDB tests.

Tests

New tests/storage_redb_tests.rs (#[cfg(feature = "redb")], and redb is a default feature):

  • storage_opens_and_reopens_on_redb: opens Storage on redb, stores a block, then reopens the same datadir, which takes the existing-database path.
  • redb_opens_every_known_tree: every KNOWN_TREE_NAMES entry opens on redb, except the explicit list above. A tree added later without a redb table fails this test.

Without the fix, both tests fail: redb storage must open: Unknown table name: block_index and redb has no table for: ["block_index"]. With the fix, both pass.

ChainState::new opens block_index via BlockIndex::new, but redb only opens
tables listed in get_table_def, so Storage::with_backend(.., Redb) failed
with "Unknown table name: block_index".

Adds tests/storage_redb_tests.rs: redb Storage opens and reopens, and every
KNOWN_TREE_NAMES entry opens on redb except the IBD engine ckpt trees and
rocksdb-test-only names. Both tests fail without the fix.
Bring #24 up to date with main while keeping block_index redb registration.
@secsovereign
secsovereign merged commit 6b95cbe into main Oct 15, 2026
12 checks passed
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