Skip to content

feat: add --augmented-data and --tipset-lookup to forest-cli snapshot export#7376

Open
hanabi1224 wants to merge 11 commits into
mainfrom
hm/export-augmented-data
Open

feat: add --augmented-data and --tipset-lookup to forest-cli snapshot export#7376
hanabi1224 wants to merge 11 commits into
mainfrom
hm/export-augmented-data

Conversation

@hanabi1224

@hanabi1224 hanabi1224 commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Stats:

# calibnet (2000 state trees)
-rw-r--r--. 1 me me 8.1G Jul 16 17:37 forest_snapshot_calibnet_2026-07-16_height_3895600.forest.car.zst
-rw-r--r--. 1 me me 5.3M Jul 16 17:37 forest_snapshot_calibnet_2026-07-16_height_3895600_receipts_events.forest.car.zst
-rw-r--r--. 1 me me  22M Jul 16 17:37 forest_snapshot_calibnet_2026-07-16_height_3895600_tipset_lookup.forest.car.zst

❯ forest-tool snapshot validate-extended --base forest_snapshot_calibnet_2026-07-16_height_3895600.forest.car.zst --augmented forest_snapshot_calibnet_2026-07-16_height_3895600_receipts_events.forest.car.zst --tipset-lookup forest_snapshot_calibnet_2026-07-16_height_3895600_tipset_lookup.forest.car.zst
Importing augmented snapshot...
Verifying message receipts and events can be loaded...
Augmented snapshot is valid, 1993 tipsets validated
Importing tipset lookup snapshot...
Verifying lookup checkpoints can be loaded...
Tipset lookup snapshot is valid, 191843 checkpoints validated

# mainnet (2000 state trees)
-rw-r--r--. 1 me me 80G Jul 17 02:53 forest_snapshot_mainnet_2026-07-16_height_6196879.forest.car.zst
-rw-r--r--. 1 me me 13M Jul 17 02:54 forest_snapshot_mainnet_2026-07-16_height_6196879_receipts_events.forest.car.zst
-rw-r--r--. 1 me me 54M Jul 17 02:54 forest_snapshot_mainnet_2026-07-16_height_6196879_tipset_lookup.forest.car.zst

❯ forest-tool snapshot validate-extended --base forest_snapshot_mainnet_2026-07-16_height_6196879.forest.car.zst --augmented forest_snapshot_mainnet_2026-07-16_height_6196879_receipts_events.forest.car.zst --tipset-lookup forest_snapshot_mainnet_2026-07-16_height_6196879_tipset_lookup.forest.car.zst
Importing augmented snapshot...
Verifying message receipts and events can be loaded...
Augmented snapshot is valid, 1982 tipsets validated
Importing tipset lookup snapshot...
Verifying lookup checkpoints can be loaded...
Tipset lookup snapshot is valid, 307466 checkpoints validated

Summary of changes

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

  • New Features
    • Added optional augmented-data and tipset-lookup exports to snapshot commands.
    • Added extended snapshot validation for base, receipts/events, and tipset-lookup data.
    • Added validation results for referenced and null checkpoints.
  • Documentation
    • Added generated CLI documentation for extended snapshot validation.
  • Bug Fixes
    • Improved snapshot export verification, including file size, checksum, CAR validity, and extended validation checks.

@hanabi1224 hanabi1224 added the Snapshot Run snapshot tests label Jul 16, 2026
@hanabi1224
hanabi1224 marked this pull request as ready for review July 17, 2026 06:13
@hanabi1224
hanabi1224 requested a review from a team as a code owner July 17, 2026 06:13
@hanabi1224
hanabi1224 requested review from LesnyRumcajs and akaladarshi and removed request for a team July 17, 2026 06:13
@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Snapshot export gains optional augmented receipts/events and tipset-lookup CAR outputs. A new extended validation command checks these artifacts, while calibration checks and CLI documentation cover the new workflow.

Changes

Snapshot export and validation

Layer / File(s) Summary
Export contracts and CLI wiring
src/cli/subcommands/snapshot_cmd.rs, src/rpc/methods/chain.rs, src/db/car/forest.rs
Adds export flags and RPC parameters for augmented data and tipset lookup, plus deterministic suffix-based CAR filenames.
Receipts/events and tipset-lookup generation
src/chain/mod.rs, src/ipld/util.rs, src/rpc/methods/chain.rs
Generates receipts/events CAR data and conditionally writes tipset-lookup and augmented CAR artifacts.
Extended validation and integration checks
src/tool/subcommands/snapshot_cmd.rs, scripts/tests/calibnet_export_check.sh, docs/docs/users/reference/cli.sh
Adds extended CAR validation, calibration checks, and generated CLI documentation for the new command.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant SnapshotCLI
  participant ForestChainExport
  participant ValidateExtended
  participant ManyCar
  SnapshotCLI->>ForestChainExport: request augmented_data and tipset_lookup
  ForestChainExport->>ManyCar: write base and optional CAR artifacts
  SnapshotCLI->>ValidateExtended: validate base, augmented, and tipset-lookup CARs
  ValidateExtended->>ManyCar: import CAR blocks
  ValidateExtended->>ManyCar: load receipts, events, and HAMT checkpoints
Loading

Possibly related PRs

Suggested labels: RPC

Suggested reviewers: akaladarshi, lesnyrumcajs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title accurately describes the main change: adding augmented-data and tipset-lookup options to snapshot export.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch hm/export-augmented-data
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch hm/export-augmented-data

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: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/rpc/methods/chain.rs (1)

445-519: 🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift

Stage every requested CAR before publishing final paths.

The base snapshot is persisted first, while auxiliary CARs are written directly to their final paths. A later error or cancellation therefore leaves a completed base file and potentially truncated auxiliary files even though the RPC reports failure. Write all outputs to temporary paths, then persist them only after every export succeeds.

🤖 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/rpc/methods/chain.rs` around lines 445 - 519, Update the export flow
around the base snapshot persistence, tipset lookup export, and augmented-data
export so every requested CAR is written to a temporary path first. Defer
persisting or publishing the base and auxiliary outputs until all exports
complete successfully, then atomically persist each temporary file to its final
path; ensure errors or cancellation leave no completed or truncated final
auxiliary files.
🧹 Nitpick comments (1)
src/chain/mod.rs (1)

265-270: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Document the new public snapshot APIs.

Add rustdoc describing their purpose and important semantics.

  • src/chain/mod.rs#L265-L270: document depth boundaries, output contents, and placeholder CAR root.
  • src/rpc/methods/chain.rs#L1634-L1643: document the receipts/events export parameter schema.
  • src/ipld/util.rs#L580-L586: document the stream’s role and expected generic parameters.

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/chain/mod.rs` around lines 265 - 270, Document the public snapshot APIs
with rustdoc: in src/chain/mod.rs lines 265-270, describe export depth
boundaries, output contents, and the placeholder CAR root; in
src/rpc/methods/chain.rs lines 1634-1643, document the receipts/events export
parameter schema; and in src/ipld/util.rs lines 580-586, describe the stream’s
role and expected generic parameters.

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 `@scripts/tests/calibnet_export_check.sh`:
- Around line 94-101: Update the snapshot validation command in the calibration
check to invoke the harness-configured FOREST_TOOL_PATH instead of the literal
forest-tool executable, preserving the existing validate-extended arguments and
flow.

In `@src/rpc/mod.rs`:
- Line 101: Prevent the internal testing RPC from being available in production:
update the ForestChainExportReceiptsEvents registration in src/rpc/mod.rs lines
101-101 to gate or remove it, and restrict the corresponding method in
src/rpc/methods/chain.rs lines 276-282 to test/feature builds rather than
production API paths.

In `@src/tool/subcommands/snapshot_cmd.rs`:
- Around line 282-293: Update the checkpoint validation loop around
heaviest_tipset and hamt.get to derive each expected checkpoint tipset from the
base chain, require a HAMT entry for every checkpoint, and compare the stored
TipsetKey with the base tipset’s key. Reject missing entries or mismatches
before counting the checkpoint as validated, while preserving the existing load
validation and error context.

---

Outside diff comments:
In `@src/rpc/methods/chain.rs`:
- Around line 445-519: Update the export flow around the base snapshot
persistence, tipset lookup export, and augmented-data export so every requested
CAR is written to a temporary path first. Defer persisting or publishing the
base and auxiliary outputs until all exports complete successfully, then
atomically persist each temporary file to its final path; ensure errors or
cancellation leave no completed or truncated final auxiliary files.

---

Nitpick comments:
In `@src/chain/mod.rs`:
- Around line 265-270: Document the public snapshot APIs with rustdoc: in
src/chain/mod.rs lines 265-270, describe export depth boundaries, output
contents, and the placeholder CAR root; in src/rpc/methods/chain.rs lines
1634-1643, document the receipts/events export parameter schema; and in
src/ipld/util.rs lines 580-586, describe the stream’s role and expected generic
parameters.
🪄 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: f0b8604c-8331-4b98-bdbf-d67800bf11be

📥 Commits

Reviewing files that changed from the base of the PR and between 516fe70 and f5acf16.

📒 Files selected for processing (8)
  • scripts/tests/calibnet_export_check.sh
  • src/chain/mod.rs
  • src/cli/subcommands/snapshot_cmd.rs
  • src/db/car/forest.rs
  • src/ipld/util.rs
  • src/rpc/methods/chain.rs
  • src/rpc/mod.rs
  • src/tool/subcommands/snapshot_cmd.rs
🔗 Linked repositories identified

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

  • filecoin-project/lotus (manual)

Comment thread scripts/tests/calibnet_export_check.sh
Comment thread src/rpc/mod.rs Outdated
Comment thread src/tool/subcommands/snapshot_cmd.rs Outdated
@codecov

codecov Bot commented Jul 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 6.34921% with 177 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.93%. Comparing base (a6f303b) to head (31ee9c1).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/tool/subcommands/snapshot_cmd.rs 0.00% 75 Missing ⚠️
src/rpc/methods/chain.rs 0.00% 55 Missing ⚠️
src/chain/mod.rs 0.00% 41 Missing ⚠️
src/cli/subcommands/snapshot_cmd.rs 0.00% 4 Missing ⚠️
src/db/memory.rs 33.33% 0 Missing and 2 partials ⚠️
Additional details and impacted files
Files with missing lines Coverage Δ
src/db/car/forest.rs 84.45% <100.00%> (+0.45%) ⬆️
src/db/memory.rs 93.68% <33.33%> (-0.67%) ⬇️
src/cli/subcommands/snapshot_cmd.rs 0.00% <0.00%> (ø)
src/chain/mod.rs 66.84% <0.00%> (-18.40%) ⬇️
src/rpc/methods/chain.rs 54.60% <0.00%> (-2.72%) ⬇️
src/tool/subcommands/snapshot_cmd.rs 0.00% <0.00%> (ø)

... and 8 files with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d44ecc7...31ee9c1. 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.

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
scripts/tests/calibnet_export_check.sh (1)

64-66: 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Wait for export status instead of sleeping for a fixed five seconds.

On fast nodes, the export can finish before the second export attempt, causing this test to fail even though the implementation is correct. Poll snapshot export-status with the existing retry/timeout pattern before asserting that concurrent exports are rejected.

🤖 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 `@scripts/tests/calibnet_export_check.sh` around lines 64 - 66, Replace the
fixed sleep after launching the first export in the snapshot export test with
polling via snapshot export-status, using the script’s existing retry and
timeout pattern. Continue only once the export is confirmed active, then
preserve the concurrent-export rejection assertion.
🤖 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.

Outside diff comments:
In `@scripts/tests/calibnet_export_check.sh`:
- Around line 64-66: Replace the fixed sleep after launching the first export in
the snapshot export test with polling via snapshot export-status, using the
script’s existing retry and timeout pattern. Continue only once the export is
confirmed active, then preserve the concurrent-export rejection assertion.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 868017cd-d7a4-4034-90b5-17feb4768ca3

📥 Commits

Reviewing files that changed from the base of the PR and between f5acf16 and 492ae16.

⛔ Files ignored due to path filters (3)
  • src/rpc/snapshots/forest__rpc__tests__rpc__v0.snap is excluded by !**/*.snap
  • src/rpc/snapshots/forest__rpc__tests__rpc__v1.snap is excluded by !**/*.snap
  • src/rpc/snapshots/forest__rpc__tests__rpc__v2.snap is excluded by !**/*.snap
📒 Files selected for processing (2)
  • scripts/tests/calibnet_export_check.sh
  • src/tool/subcommands/snapshot_cmd.rs
🔗 Linked repositories identified

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

  • filecoin-project/lotus (manual)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/tool/subcommands/snapshot_cmd.rs

@hanabi1224
hanabi1224 force-pushed the hm/export-augmented-data branch from 220b4a0 to 042f4c0 Compare July 17, 2026 07:55
@LesnyRumcajs

Copy link
Copy Markdown
Member

no green checkmark, no review!

Comment thread src/rpc/mod.rs Outdated
$callback!($crate::rpc::chain::ForestChainExportDiff);
$callback!($crate::rpc::chain::ForestChainExportStatus);
$callback!($crate::rpc::chain::ForestChainExportCancel);
// $callback!($crate::rpc::chain::ForestChainExportReceiptsEvents);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is to address #7376 (comment) I used it to get perf stats we could 1. enable it 2. remove it 3. keep it commented out, what's your preference?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Commented out code is a pretty bad smell. The logic is trivial, so IMO it's fine to just remove it. If it later turns out to be needed, we can revive it and maybe gate it with some env variables.

Comment thread src/rpc/methods/chain.rs Outdated
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
pub struct ForestChainExportReceiptsEventsParams {
pub epoch: ChainEpoch,
pub recent_roots: i64,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

unsigned? I guess it can't be negative?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Changed to u32

Comment thread src/tool/subcommands/snapshot_cmd.rs Outdated
Comment on lines +223 to +226
anyhow::ensure!(
augmented.is_some() || tipset_lookup.is_some(),
"either `--augmented` or `--tipset-lookup` needs to be specified"
);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not a huge deal, but AFAIK this could be specified via clap derive sorcery.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

Comment on lines +241 to +242
if !store.has(ts.parent_state())? {
break;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't get it. If it can't find the parent state, then it will break... but the command itself will succeed, no?

@hanabi1224 hanabi1224 Jul 20, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

A lite snapshot only contains the state trees of the latest N epochs, thus we cannot find all state trees back to genesis. This command is to assert that, when the state tree presents for an epoch, the message receipts and events present for the same epoch

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Perhaps worth adding a comment in the code.


$FOREST_CLI_PATH shutdown --force

# Check file sizes

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@hanabi1224 I don't see any tests exercising the import of those snapshots. Do you intend to do it in a follow-up?

@hanabi1224 hanabi1224 Jul 20, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

forest-tool snapshot validate-extended imports and tests the snapshots. Hooking those into --auto-download really depends on how the snapshots are hosted and is beyond the scope of this PR.
Importing an augment-data snapshot into an existing node can be done via forest-tool db import.
Import a tipset lookup hamt can be implemented later similarly

@hanabi1224 hanabi1224 changed the title feat: add --augmented-data and --tipset-lookup to forestcli snapshot export feat: add --augmented-data and --tipset-lookup to forest-cli snapshot export Jul 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Snapshot Run snapshot tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants