Skip to content

refactor(tool): extract snapshot export into a shared module#7319

Open
0xDevNinja wants to merge 1 commit into
ChainSafe:mainfrom
0xDevNinja:0xdevninja/issue-6096-extract-export-module
Open

refactor(tool): extract snapshot export into a shared module#7319
0xDevNinja wants to merge 1 commit into
ChainSafe:mainfrom
0xDevNinja:0xdevninja/issue-6096-extract-export-module

Conversation

@0xDevNinja

@0xDevNinja 0xDevNinja commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Summary of changes

The Filecoin.ChainExportDiff RPC method called do_export directly from the archive_cmd CLI subcommand module, coupling the RPC layer to a CLI subcommand (flagged during review of #6074).

Changes introduced in this pull request:

  • Moved do_export and its build_output_path helper out of tool::subcommands::archive_cmd into a dedicated crate::tool::export module.
  • Both the forest-tool archive/snapshot CLI subcommands and the ChainExportDiff RPC method now import the export logic from that shared module.
  • Trimmed the imports that were only used by the moved functions.

This is a pure move with no behaviour change.

Reference issue to close (if applicable)

Closes #6096

Other information and links

Identified during review of #6074 (#6074 (comment)).

I kept the module under crate::tool since the export path still uses CLI-oriented helpers (progress bar, interactive overwrite prompt guarded by force). Happy to move it deeper (e.g. under crate::chain) if you'd prefer to fully separate it from the tooling layer.

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

  • Bug Fixes

    • Improved differential chain export so the RPC path matches the CLI’s behavior, including finality/depth validation, diff handling, overwrite confirmation, and progress feedback.
    • Export output paths are handled consistently, including when a directory is provided (including CARZST naming).
  • Refactor

    • Centralized snapshot/diff export logic into a shared export utility used by both the CLI and RPC flows.
  • Tests

    • Updated export tests to use the shared path helper.

@0xDevNinja 0xDevNinja requested a review from a team as a code owner July 8, 2026 12:49
@0xDevNinja 0xDevNinja requested review from hanabi1224 and sudo-shashank and removed request for a team July 8, 2026 12:49
@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 8cf8ab6b-2762-4d5a-bb4d-48d943a09177

📥 Commits

Reviewing files that changed from the base of the PR and between 8e863a5 and 5363567.

📒 Files selected for processing (4)
  • src/rpc/methods/chain.rs
  • src/tool/export.rs
  • src/tool/mod.rs
  • src/tool/subcommands/archive_cmd.rs
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • filecoin-project/lotus (manual)
✅ Files skipped from review due to trivial changes (1)
  • src/tool/mod.rs
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/rpc/methods/chain.rs
  • src/tool/subcommands/archive_cmd.rs
  • src/tool/export.rs

Walkthrough

Snapshot export logic is moved into src/tool/export.rs, and both the RPC diff-export path and the CLI archive command now call the shared exporter. The old local implementation in archive_cmd.rs is removed, and the module tree is updated to expose the new code.

Changes

Export logic relocation

Layer / File(s) Summary
Path building and export validation
src/tool/export.rs
Adds build_output_path and the early do_export logic for genesis resolution, network/epoch derivation, and depth/finality validation.
Tipset loading and export execution
src/tool/export.rs
Loads the target and diff tipsets, computes the seen set, handles overwrite prompting and file creation, and calls crate::chain::export with the computed state.
Module wiring and caller updates
src/tool/mod.rs, src/rpc/methods/chain.rs, src/tool/subcommands/archive_cmd.rs
Registers the new module, retargets the RPC and CLI callers to crate::tool::export::do_export, removes the old local exporter and related imports, and updates the test import.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant RPC as ForestChainExportDiff
  participant CLI as archive_cmd
  participant Export as tool::export::do_export
  participant Chain as crate::chain::export

  RPC->>Export: do_export(...)
  CLI->>Export: do_export(...)
  Export->>Export: resolve genesis, validate depth, build seen set
  Export->>Chain: export(writer, seen, options)
  Chain-->>Export: completion
  Export-->>RPC: Ok(())
  Export-->>CLI: Ok(())
Loading

Possibly related PRs

Suggested labels: RPC, Snapshot

Suggested reviewers: LesnyRumcajs, akaladarshi

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main refactor: extracting snapshot export into a shared module.
Linked Issues check ✅ Passed The PR extracts export logic into src/tool/export.rs and updates CLI/RPC callers to use it, matching #6096.
Out of Scope Changes check ✅ Passed The changes stay focused on shared export refactoring and caller updates, with no obvious unrelated additions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
✨ Simplify code
  • Create PR with simplified code

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/tool/export.rs (1)

52-66: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add a doc comment for the public do_export API.

do_export is now a shared entrypoint with 9 positional parameters (epoch_option, depth, diff, diff_depth, force, …) whose meaning is not obvious from the name alone. A brief /// doc describing the parameters and the diff/full export semantics would help both the CLI and RPC callers. build_output_path is self-explanatory and can keep its existing comment.

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/tool/export.rs` around lines 52 - 66, The public do_export API is missing
a doc comment, making its many positional parameters and full-vs-diff export
behavior hard to understand. Add a brief /// comment above do_export that
explains what the function does, summarizes the roles of the key parameters like
epoch_option, depth, diff, diff_depth, and force, and clarifies the semantics of
full versus diff exports. Leave build_output_path as-is since it already has a
clear comment.

Source: Coding guidelines

🤖 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.

Inline comments:
In `@src/tool/export.rs`:
- Around line 4-5: Update the module doc in export.rs to use the correct RPC
method name: the shared snapshot export logic comment currently references
Filecoin.ChainExportDiff, but it should say Forest.ChainExportDiff. Make this
change in the top-level documentation comment so the symbol description matches
the actual RPC method name used by the export flow.

---

Nitpick comments:
In `@src/tool/export.rs`:
- Around line 52-66: The public do_export API is missing a doc comment, making
its many positional parameters and full-vs-diff export behavior hard to
understand. Add a brief /// comment above do_export that explains what the
function does, summarizes the roles of the key parameters like epoch_option,
depth, diff, diff_depth, and force, and clarifies the semantics of full versus
diff exports. Leave build_output_path as-is since it already has a clear
comment.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 50878905-b51d-46b0-980e-4b1562bfaf6c

📥 Commits

Reviewing files that changed from the base of the PR and between 7e7adc2 and 8e863a5.

📒 Files selected for processing (4)
  • src/rpc/methods/chain.rs
  • src/tool/export.rs
  • src/tool/mod.rs
  • src/tool/subcommands/archive_cmd.rs
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • filecoin-project/lotus (manual)

Comment thread src/tool/export.rs Outdated
`Filecoin.ChainExportDiff` (in the RPC layer) called `do_export` directly
from the `archive_cmd` CLI subcommand module, coupling the RPC layer to a
CLI subcommand. Move `do_export` and its `build_output_path` helper into a
dedicated `crate::tool::export` module that both the CLI subcommands and
the RPC method import. No behaviour change.

Closes ChainSafe#6096
@0xDevNinja 0xDevNinja force-pushed the 0xdevninja/issue-6096-extract-export-module branch from 8e863a5 to 5363567 Compare July 9, 2026 07:05
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.

Refactor export logic to separate module for better separation of concerns

1 participant