Conversation
WalkthroughAdds a developer-focused state CLI under Changes
Sequence Diagram(s)mermaid Estimated code review effort🎯 3 (Moderate) | ⏱️ ~35 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@src/dev/subcommands/state_cmd.rs`:
- Around line 256-258: Update the doc comment on the ReplayValidateCommand's
snapshot field to correctly reference the producing command; replace "generated
by `forest-tool state compute`" with the correct generator "produced by
`forest-dev state validate`" (or an accurate description like "snapshot produced
by the forest-dev state validate command") so the comment on the snapshot:
PathBuf field correctly documents expected input for ReplayValidateCommand.
- Around line 127-129: Update the doc comment on the snapshot field of the
ReplayComputeCommand struct to reference the new command name; change the text
that currently says "forest-tool state compute" to "forest-dev state compute"
(or the correct new command name) so the doc comment for
ReplayComputeCommand::snapshot accurately reflects the moved compute command.
🧹 Nitpick comments (2)
src/state_manager/utils.rs (1)
213-231: Add rustdoc for the new public snapshot helpers.These new
pubfunctions should have brief///docs describing purpose, inputs, and outputs to satisfy the public-API documentation rule. As per coding guidelines, document all public functions and structs with rustdoc comments.Also applies to: 253-260
src/dev/subcommands/state_cmd.rs (1)
300-301: Consider adding a safety comment for theunsafeblock.The use of
unsafe { std::env::set_var(...) }is necessary since Rust 1.80+ deprecated safeset_vardue to thread-safety concerns. However, a brief safety comment explaining why this is acceptable here would improve maintainability.💡 Suggested improvement
fn disable_tipset_cache() { + // SAFETY: This is called at the start of single-threaded CLI commands before + // any concurrent work begins, so there are no data races with other threads + // reading environment variables. unsafe { std::env::set_var("FOREST_TIPSET_CACHE_DISABLED", "1") }; }
87ca542 to
459fa98
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/dev/subcommands/state_cmd.rs`:
- Around line 300-302: The unsafe call to std::env::set_var inside
disable_tipset_cache needs an explanatory safety comment: describe why using
unsafe here is safe (e.g., this function is invoked only during single-threaded
startup before any threads are spawned, the environment variable is
process-local and race is acceptable in our usage, or we ensure synchronization
elsewhere), and document any preconditions or alternatives (like moving the call
to early initialization or guarding with a Once). Add this comment immediately
above or inside the unsafe block in disable_tipset_cache so reviewers can verify
the assumptions and consider using synchronization (std::sync::Once) if those
preconditions cannot be guaranteed.
🧹 Nitpick comments (4)
src/tool/subcommands/api_cmd/generate_test_snapshot.rs (1)
161-173: Missing rustdoc comments for public methods.The
resume_trackingandpause_trackingmethods are public but lack documentation. As per coding guidelines, all public functions should have rustdoc comments explaining their purpose.📝 Suggested documentation
impl<T> ReadOpsTrackingStore<T> { + /// Resumes recording of read operations to the in-memory tracker. + /// + /// After calling this method, subsequent read operations will be + /// written to the tracker for snapshot export. pub fn resume_tracking(&self) { self.tracking.store(true, Ordering::Relaxed); } + /// Pauses recording of read operations to the in-memory tracker. + /// + /// While paused, read operations will still be performed on the + /// inner store but will not be recorded for snapshot export. pub fn pause_tracking(&self) { self.tracking.store(false, Ordering::Relaxed); } fn tracking(&self) -> bool { self.tracking.load(Ordering::Relaxed) } }src/state_manager/utils.rs (1)
228-252: Consider adding validation for thebucketparameter.The
bucketparameter is interpolated directly into the URL without validation. While currently only called with known values ("state_compute","state_validate"), a malformed bucket string could produce invalid URLs.💡 Optional: Add bucket validation
pub async fn get_state_snapshot( chain: &NetworkChain, bucket: &str, epoch: i64, ) -> anyhow::Result<PathBuf> { + anyhow::ensure!( + bucket.chars().all(|c| c.is_ascii_alphanumeric() || c == '_'), + "Invalid bucket name: {bucket}" + ); let url = Url::parse(&format!( "https://forest-snapshots.fra1.cdn.digitaloceanspaces.com/{bucket}/{chain}_{epoch}.forest.car.zst" ))?;src/dev/subcommands/state_cmd.rs (2)
61-121: Significant code duplication betweenComputeCommand::runandValidateCommand::run.Both methods share nearly identical setup logic (lines 69-102 vs 204-238):
- Disable tipset cache
- Resolve DB root path
- Load DB and chain config
- Create genesis header
- Create chain store
- Pause/resume tracking and load tipset
- Export snapshot
Consider extracting shared logic into a helper function.
♻️ Suggested refactor approach
Extract common setup into a helper:
struct StateCommandSetup { db: Arc<ReadOpsTrackingStore<ManyCar<ParityDb>>>, chain_store: Arc<ChainStore<...>>, ts: Tipset, } async fn setup_state_command( epoch: ChainEpoch, chain: &NetworkChain, db_path: Option<PathBuf>, ) -> anyhow::Result<StateCommandSetup> { disable_tipset_cache(); let db_root_path = if let Some(db) = db_path { db } else { let (_, config) = read_config(None, Some(chain.clone()))?; db_root(&chain_path(&config))? }; // ... shared setup logic }Also applies to: 196-250
138-176: Similar duplication pattern in replay commands.
ReplayComputeCommand::runandReplayValidateCommand::runalso share substantial setup logic for loading snapshots and initializing the chain store. The same refactoring opportunity applies here.Also applies to: 267-297
Codecov Report❌ Patch coverage is Additional details and impacted files
... and 27 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
459fa98 to
13d2c00
Compare
LesnyRumcajs
left a comment
There was a problem hiding this comment.
LGTM. Let's have a changelog entry for this breaking change. I don't think anyone was actively using forest-tool state compute but in case they were, it'd be helpful to put an info.
@LesnyRumcajs changelog added. |
Summary of changes
(Part of codecov improvement effort)
Changes introduced in this pull request:
validate_tipsetforest-tool state computetoforest-devforest-dev state validateReference issue to close (if applicable)
Closes
Other information and links
Change checklist
Summary by CodeRabbit
New Features
Documentation
Refactor
Chores
Tests
✏️ Tip: You can customize this high-level summary in your review settings.