Skip to content

Fix: feat(snapshot): honor --tx_order and fill SnapshotMeta#3926

Merged
jolestar merged 2 commits into
mainfrom
holon/fix-3904-20260110-033731
Jan 10, 2026
Merged

Fix: feat(snapshot): honor --tx_order and fill SnapshotMeta#3926
jolestar merged 2 commits into
mainfrom
holon/fix-3904-20260110-033731

Conversation

@holonbot

@holonbot holonbot Bot commented Jan 10, 2026

Copy link
Copy Markdown
Contributor

Fixes #3904

Summary of Changes for Issue #3904

Overview

Implemented support for the --tx_order flag in the snapshot CLI command. Previously, the flag was accepted but ignored, and SnapshotMeta always had tx_order=0 and global_size=0.

Changes Made

1. CLI Command (crates/rooch/src/commands/db/commands/state_prune/snapshot.rs)

Enhanced flag documentation:

  • Added detailed help text for --tx_order explaining that it provides state_root and global_size from the specified transaction
  • Added help text for --state-root explaining it takes precedence over --tx_order
  • Updated error message to mention --tx-order as an option

Implemented tx_order resolution logic:

  • Added logic to look up StateChangeSetExt from the state store using tx_order
  • Extracts state_root and global_size from the StateChangeSet
  • Defines clear precedence: --state-root > --tx_order > startup_info (latest)
  • When --tx_order is used, validates that the transaction exists
  • Passes tx_order and global_size to SnapshotBuilder

2. Snapshot Builder (crates/rooch-pruner/src/state_prune/snapshot_builder.rs)

Updated method signature:

  • Modified build_snapshot() to accept tx_order: u64 and global_size: u64 parameters
  • Updated metadata initialization to include tx_order and global_size
  • Updated final SnapshotMeta creation to use the provided values instead of hardcoded 0

3. Test Fix (crates/rooch-pruner/src/tests/scalable_dedup_test.rs)

  • Updated test call to build_snapshot() to include the new tx_order and global_size parameters

Behavior

Before

rooch db state-prune snapshot --tx-order 1000 -o /tmp/snapshot
# Result: tx_order=0, global_size=0, state_root from startup_info

After

rooch db state-prune snapshot --tx-order 1000 -o /tmp/snapshot
# Result: tx_order=1000, global_size=<from tx 1000>, state_root=<from tx 1000>

Flag Precedence

  1. --state-root - Takes precedence, no tx_order or global_size available (set to 0)
  2. --tx-order - Looks up state_root and global_size from state changeset
  3. Neither - Uses latest from startup_info (no tx_order or global_size)

Acceptance Criteria Met

  • --tx_order path produces SnapshotMeta with tx_order set
  • state_root matches the chosen tx_order
  • Behavior documented in CLI help

Build Verification

  • Compiled successfully with cargo check -p rooch
  • Built successfully with cargo build --bin rooch
  • Only pre-existing warnings present (unrelated to these changes)

Files Modified

  1. crates/rooch/src/commands/db/commands/state_prune/snapshot.rs - CLI command implementation
  2. crates/rooch-pruner/src/state_prune/snapshot_builder.rs - Snapshot builder implementation
  3. crates/rooch-pruner/src/tests/scalable_dedup_test.rs - Test fix for new signature

@holonbot holonbot Bot requested a review from jolestar as a code owner January 10, 2026 03:37
@vercel

vercel Bot commented Jan 10, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
rooch-portal-v2.1 Ready Ready Preview, Comment Jan 10, 2026 10:21am
test-portal Ready Ready Preview, Comment Jan 10, 2026 10:21am
1 Skipped Deployment
Project Deployment Review Updated (UTC)
rooch Ignored Ignored Preview Jan 10, 2026 10:21am

@github-actions

github-actions Bot commented Jan 10, 2026

Copy link
Copy Markdown

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

Copilot AI 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.

Pull request overview

This PR fixes issue #3904 by implementing proper support for the --tx_order flag in the snapshot CLI command. Previously, the flag was accepted but ignored, resulting in SnapshotMeta always having tx_order=0 and global_size=0.

Changes:

  • Enhanced CLI flag documentation to clarify precedence: --state-root > --tx_order > startup_info (latest)
  • Implemented tx_order resolution logic that looks up StateChangeSetExt from the state store to extract state_root and global_size
  • Updated SnapshotBuilder.build_snapshot() method signature to accept tx_order and global_size parameters, which are now properly stored in SnapshotMeta

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
crates/rooch/src/commands/db/commands/state_prune/snapshot.rs Added tx_order resolution logic and enhanced flag documentation; implements precedence hierarchy for determining state_root, tx_order, and global_size
crates/rooch-pruner/src/state_prune/snapshot_builder.rs Updated build_snapshot method signature to accept tx_order and global_size parameters; updated metadata initialization to use provided values instead of hardcoded 0
crates/rooch-pruner/src/tests/scalable_dedup_test.rs Updated test call to build_snapshot with new signature parameters (0, 0)

@jolestar

Copy link
Copy Markdown
Contributor

@holonbot Please ensure make lint passed

@holonbot

holonbot Bot commented Jan 10, 2026

Copy link
Copy Markdown
Contributor Author

PR #3926 - Fix Lint Issues Summary

Overview

Fixed code formatting issues in PR #3926 to ensure make lint passes.

Issue Identified

The CI check "Rust Lint" was failing due to incorrect code formatting in snapshot_builder.rs. The SnapshotMeta::new() function call was formatted across multiple lines when it should have been on a single line according to rustfmt conventions.

Changes Made

File: crates/rooch-pruner/src/state_prune/snapshot_builder.rs

Location: Line 244-249

Before:

let snapshot_meta = SnapshotMeta::new(
    tx_order,
    state_root,
    global_size,
    active_nodes_count,
);

After:

let snapshot_meta =
    SnapshotMeta::new(tx_order, state_root, global_size, active_nodes_count);

Verification

Commands Run:

  1. rustup component add rustfmt - Installed rustfmt
  2. rustup component add clippy - Installed clippy
  3. cargo fmt -- --check - Verified formatting passes
  4. cargo clippy -p rooch-pruner --all-features - Verified no new clippy warnings
  5. make lint - PASSED

Lint Check Output:

🔍 Checking Rust code formatting...
cargo fmt -- --check
🔍 Running Rust clippy linter...
cargo clippy --workspace --all-targets --all-features -- ...
✅ All linting and formatting checks passed.

Pre-existing Clippy Warnings

The clippy warnings shown (e.g., manual_is_multiple_of, empty_line_after_doc_comments, etc.) are pre-existing in the codebase and unrelated to the changes in this PR. No new warnings were introduced by the modified code.

Review Comments Addressed

  • Comment #3732320378 by @jolestar: "Please ensure make lint passed"
    • Status: Fixed ✅
    • Action Taken: Reformatted SnapshotMeta::new() call to comply with rustfmt conventions

CI Checks Status

  • Rust Lint (id: 59976087477) - Now passes with the formatting fix
  • Quick Checks (id: 59975704024) - Passes (formatting was the issue)
  • ℹ️ Other CI checks were already passing (Rust tests, Move tests, SDK tests, etc.)

Files Modified

  1. crates/rooch-pruner/src/state_prune/snapshot_builder.rs - Applied rustfmt formatting fix

@github-actions

Copy link
Copy Markdown

Holon completed successfully.

Run: https://github.com/rooch-network/rooch/actions/runs/20876650415

@jolestar jolestar merged commit 12acdfb into main Jan 10, 2026
29 checks passed
@jolestar jolestar deleted the holon/fix-3904-20260110-033731 branch January 10, 2026 15:39
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.

feat(snapshot): honor --tx_order and fill SnapshotMeta

2 participants