Skip to content

refactor: replace generic db with enum in ChainIndex#7044

Closed
hanabi1224 wants to merge 4 commits into
mainfrom
hm/db-enum
Closed

refactor: replace generic db with enum in ChainIndex#7044
hanabi1224 wants to merge 4 commits into
mainfrom
hm/db-enum

Conversation

@hanabi1224
Copy link
Copy Markdown
Contributor

@hanabi1224 hanabi1224 commented May 13, 2026

Summary of changes

(ChainStore, StateManager, etc. are updated in #7051 we could either review and merge this one first, or discard this one)

Changes introduced in this pull request:

Reference issue to close (if applicable)

Closes

Other information and links

Change checklist

  • I have performed a self-review of my own code,
  • I have made corresponding changes to the documentation. All new code adheres to the team's documentation standards,
  • I have added tests that prove my fix is effective or that my feature works (if possible),
  • I have made sure the CHANGELOG is up-to-date. All user-facing changes should be reflected in this document.

Outside contributions

  • I have read and agree to the CONTRIBUTING document.
  • I have read and agree to the AI Policy document. I understand that failure to comply with the guidelines will lead to rejection of the pull request.

Summary by CodeRabbit

  • Refactor

    • Simplified and consolidated database abstraction and backends for more consistent runtime behavior.
    • Removed pervasive generic DB parameters across VM, state tree, chain/index, and execution paths to simplify APIs.
    • Unified state-loading and migration paths to use shared/owned state-tree representations.
  • Chores

    • Updated trait/macro annotations and helper signatures to align with the new concrete DB/type usage.

Review Change Stack

@hanabi1224 hanabi1224 added the RPC requires calibnet RPC checks to run on CI label May 13, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 13, 2026

Walkthrough

Refactors the codebase to introduce a concrete DbImpl delegating enum, remove DB generics from core types (ChainIndex, VM/FVM externs, StateManager), change StateTree to accept stores directly with ShallowClone, and update tooling, RPC, and migration APIs and trait delegations.

Changes

Database Abstraction and Type System Refactoring

Layer / File(s) Summary
Full refactor checkpoint
src/db/db_impl.rs, src/db/either.rs, src/db/mod.rs, src/chain/store/index.rs, src/chain/store/chain_store.rs, src/shim/state_tree.rs, src/interpreter/vm.rs, src/interpreter/fvm2.rs, src/interpreter/fvm3.rs, src/interpreter/fvm4.rs, src/state_manager/*, src/rpc/*, src/tool/subcommands/*, src/state_migration/*, src/blocks/chain4u.rs, src/libp2p_bitswap/store.rs
Introduces DbImpl enum and delegates Blockstore/ShallowClone; removes many DB generics by switching ChainIndex/ChainStore/TipsetTracker/ChainRand/VM/ForestExterns to use concrete DbImpl/non-generic ChainIndex; refactors StateTree<S> to accept S with ShallowClone; updates StateManager, state computation, FVM/VM wiring, RPC handlers, archive/snapshot tooling, migration APIs, and adds delegating trait impls for Chain4U and Bitswap traits.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • LesnyRumcajs
  • sudo-shashank
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main refactoring objective: replacing a generic database type with an enum in ChainIndex, which is the core change across the codebase.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch hm/db-enum
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch hm/db-enum

Comment @coderabbitai help to get the list of available commands and usage tips.

@hanabi1224 hanabi1224 marked this pull request as ready for review May 13, 2026 13:35
@hanabi1224 hanabi1224 requested a review from a team as a code owner May 13, 2026 13:35
@hanabi1224 hanabi1224 requested review from LesnyRumcajs and sudo-shashank and removed request for a team May 13, 2026 13:35
@codecov
Copy link
Copy Markdown

codecov Bot commented May 13, 2026

Codecov Report

❌ Patch coverage is 49.44649% with 137 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.13%. Comparing base (ff926a4) to head (343d44b).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/blocks/chain4u.rs 0.00% 42 Missing ⚠️
src/tool/subcommands/archive_cmd.rs 45.16% 16 Missing and 1 partial ⚠️
src/db/db_impl.rs 58.33% 10 Missing and 5 partials ⚠️
src/db/either.rs 0.00% 10 Missing ⚠️
src/interpreter/fvm2.rs 12.50% 7 Missing ⚠️
src/interpreter/fvm3.rs 14.28% 6 Missing ⚠️
src/interpreter/fvm4.rs 14.28% 6 Missing ⚠️
src/state_migration/nv21fix/migration.rs 0.00% 5 Missing ⚠️
src/state_migration/nv21fix2/migration.rs 0.00% 5 Missing ⚠️
src/state_migration/nv22fix/migration.rs 0.00% 5 Missing ⚠️
... and 10 more
Additional details and impacted files
Files with missing lines Coverage Δ
src/chain/store/chain_store.rs 69.01% <100.00%> (+1.43%) ⬆️
src/chain/store/index.rs 89.47% <100.00%> (ø)
src/chain/store/tipset_tracker.rs 66.26% <100.00%> (ø)
src/chain_sync/tipset_syncer.rs 63.19% <100.00%> (ø)
src/db/mod.rs 33.33% <ø> (ø)
src/fil_cns/validation.rs 78.89% <100.00%> (ø)
src/libp2p_bitswap/store.rs 70.00% <ø> (ø)
src/rpc/methods/eth.rs 65.30% <100.00%> (ø)
src/rpc/methods/eth/trace/mod.rs 81.81% <100.00%> (ø)
src/rpc/methods/eth/trace/parity.rs 50.14% <100.00%> (ø)
... and 38 more

... and 9 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ff926a4...343d44b. Read the comment docs.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/db/db_impl.rs (1)

17-31: ⚡ Quick win

Add documentation for the public DbImpl enum.

The DbImpl enum is a central public type in this refactor but lacks doc comments. As per coding guidelines, public structs and enums should be documented.

📝 Suggested documentation
+/// Concrete database implementation enum that delegates operations to underlying backends.
+///
+/// This type replaces generic database parameters throughout the codebase, providing
+/// a unified interface to various storage backends including ManyCar, ParityDb, MemoryDB,
+/// and specialized wrappers like ReadOpsTrackingStore.
 #[derive(Delegate)]
 #[delegate(SettingsStore)]

As per coding guidelines: Document public functions and structs with doc comments.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/db/db_impl.rs` around lines 17 - 31, Add a doc comment for the public
enum DbImpl describing its role as the central database implementation selector
used throughout the crate, explain that each variant wraps a concrete store type
(ManyCarWithGarbageCollectableParityDb, ManyCarWithMemoryDB, ManyCarParityDb,
Memory, ReadOpsTrackingManyCarParityDb and the test-only Chain4U) and note any
important behavior (e.g., which variants are used for testing or track read
ops). Place the comment immediately above the pub enum DbImpl declaration and
keep it concise but informative for users and maintainers.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/db/db_impl.rs`:
- Around line 17-31: Add a doc comment for the public enum DbImpl describing its
role as the central database implementation selector used throughout the crate,
explain that each variant wraps a concrete store type
(ManyCarWithGarbageCollectableParityDb, ManyCarWithMemoryDB, ManyCarParityDb,
Memory, ReadOpsTrackingManyCarParityDb and the test-only Chain4U) and note any
important behavior (e.g., which variants are used for testing or track read
ops). Place the comment immediately above the pub enum DbImpl declaration and
keep it concise but informative for users and maintainers.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 7f4efb01-0274-4742-8203-4beb77353225

📥 Commits

Reviewing files that changed from the base of the PR and between 6a41f04 and 343d44b.

📒 Files selected for processing (6)
  • src/blocks/chain4u.rs
  • src/chain/store/chain_store.rs
  • src/chain/store/tipset_tracker.rs
  • src/db/db_impl.rs
  • src/libp2p/service.rs
  • src/libp2p_bitswap/store.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/blocks/chain4u.rs

@hanabi1224
Copy link
Copy Markdown
Contributor Author

Superseded by #7051

@hanabi1224 hanabi1224 closed this May 14, 2026
@hanabi1224 hanabi1224 deleted the hm/db-enum branch May 14, 2026 10:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

RPC requires calibnet RPC checks to run on CI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant