Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a new option --validate-tipsets in forest-cli validate command #3167

Merged
merged 43 commits into from
Jul 14, 2023

Conversation

sudo-shashank
Copy link
Contributor

@sudo-shashank sudo-shashank commented Jul 11, 2023

Summary of changes

Changes introduced in this pull request:

  • Added a new option --validate-tipsets in forest-cli snapshot validate to validate already computed tipsets.
Validates the snapshot

Usage: forest-cli snapshot validate [OPTIONS] <SNAPSHOT>

Arguments:
  <SNAPSHOT>  Path to an uncompressed snapshot (CAR)

Options:
      --recent-stateroots <RECENT_STATEROOTS>
          Number of block headers to validate from the tip [default: 2000]
      --validate-tipsets <VALIDATE_TIPSETS>
          Validate already computed tipsets at given EPOCH, use a negative value -N to validate the last N EPOCH(s) starting at HEAD
  -h, --help
          Print help

Reference issue to close (if applicable)

Closes #3071

Other information and links

Change checklist

  • I have performed a self-review of my own code,
  • I have made corresponding changes to the documentation,
  • 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.

@sudo-shashank sudo-shashank changed the title Added the tipset re-validator into forest-cli snapshot validate Added the tipset re-validator into forest-cli snapshot re-validate Jul 11, 2023
@sudo-shashank sudo-shashank changed the title Added the tipset re-validator into forest-cli snapshot re-validate Added the tipset re-validator into a new sub-command forest-cli snapshot re-validate Jul 11, 2023
@sudo-shashank sudo-shashank changed the title Added the tipset re-validator into a new sub-command forest-cli snapshot re-validate Added the tipset re-validator into a new sub-command forest-cli snapshot re-validate Jul 11, 2023
@sudo-shashank sudo-shashank changed the title Added the tipset re-validator into a new sub-command forest-cli snapshot re-validate Added a new sub-command forest-cli snapshot re-validate Jul 11, 2023
@sudo-shashank sudo-shashank marked this pull request as ready for review July 11, 2023 11:29
Copy link
Contributor

@lemmih lemmih left a comment

Choose a reason for hiding this comment

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

I would prefer it if it were part of the validate command.

@sudo-shashank sudo-shashank marked this pull request as draft July 12, 2023 06:34
@sudo-shashank sudo-shashank marked this pull request as ready for review July 12, 2023 07:42
@sudo-shashank sudo-shashank marked this pull request as draft July 12, 2023 08:05
Comment on lines 1277 to 1278
epochs: RangeInclusive<i64>,
tipsets: itertools::Unfold<Option<Arc<Tipset>>, F>,
Copy link
Contributor

Choose a reason for hiding this comment

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

The range is not needed if we take a stream. Also, tipsets should be anything that implements stream.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

src/state_manager/mod.rs Outdated Show resolved Hide resolved
let pb = crate::utils::io::ProgressBar::new((epochs.end() - epochs.start()) as u64);
pb.message("Compute parent state: ");
pb.set_max_refresh_rate(Some(std::time::Duration::from_millis(500)));

tipsets
.take_while(|tipset| tipset.epoch() >= *epochs.start())
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to trim the stream. The caller can do that if they want it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@sudo-shashank
Copy link
Contributor Author

@lemmih I am also thinking of using --validate-tipsets=-1999 as default for snapshot validate
or should we leave it upto the user to decide always?

Comment on lines 213 to 219
let tipsets = itertools::unfold(Some(end_tipset), |tipset| {
let child = tipset.take()?;
*tipset = state_manager
.chain_store()
.tipset_from_keys(child.parents())
.ok();
Some(child)
Copy link
Contributor

Choose a reason for hiding this comment

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

this is copy-pasted - can you refactor to a common get_all_ancestors function please

self.validate_stream(epochs, tipsets)
}

pub fn validate_stream<F>(
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand why this new function is necessary - could you help me understand?

Copy link
Contributor

Choose a reason for hiding this comment

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

It's to avoid heaviest_tipset, which is undefined outside of the daemon.

ensure_params_downloaded().await?;
// Prepare tipset stream to validate
let heaviest_epoch = ts.epoch();
let end_tipset = state_manager
Copy link
Contributor

@lemmih lemmih Jul 13, 2023

Choose a reason for hiding this comment

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

Aren't ts and end_tipset the same tipset?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes fixed

ensure_params_downloaded().await?;
// Prepare tipset stream to validate
let tipsets = ts
.chain(Arc::clone(&store))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
.chain(Arc::clone(&store))
.chain(&store)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed

@@ -1251,8 +1251,6 @@ where
/// This is suspected to be due something in the VM or its `WASM` runtime.
#[tracing::instrument(skip(self))]
pub fn validate(self: &Arc<Self>, epochs: RangeInclusive<i64>) -> anyhow::Result<()> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
pub fn validate(self: &Arc<Self>, epochs: RangeInclusive<i64>) -> anyhow::Result<()> {
pub fn validate_range(self: &Arc<Self>, epochs: RangeInclusive<i64>) -> anyhow::Result<()> {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed

self.validate_stream(tipsets)
}

pub fn validate_stream<T>(self: &Arc<Self>, tipsets: T) -> anyhow::Result<()>
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
pub fn validate_stream<T>(self: &Arc<Self>, tipsets: T) -> anyhow::Result<()>
pub fn validate_tipsets<T>(self: &Arc<Self>, tipsets: T) -> anyhow::Result<()>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed

@sudo-shashank
Copy link
Contributor Author

@aatifsyed @lemmih PR ready for review again

@@ -240,42 +249,71 @@ async fn validate_with_blockstore<BlockstoreT>(
roots: Vec<Cid>,
store: Arc<BlockstoreT>,
recent_stateroots: &i64,
) -> Result<(), anyhow::Error>
validate_tipsets: &Option<i64>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Not a blocker:

Suggested change
validate_tipsets: &Option<i64>,
validate_tipsets: Option<i64>,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed

@@ -282,6 +282,15 @@ impl Tipset {
}
broken
}
/// Returns an iterator of all tipsets
Copy link
Contributor

Choose a reason for hiding this comment

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

Of all ancestor tipsets

Copy link
Contributor Author

Choose a reason for hiding this comment

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

since it includes itself also, @lemmih suggested we keep it to Returns an iterator of all tipsets

@sudo-shashank sudo-shashank added this pull request to the merge queue Jul 14, 2023
Merged via the queue into main with commit c00871a Jul 14, 2023
20 checks passed
@sudo-shashank sudo-shashank deleted the shashank/cli-validate branch July 14, 2023 14:09
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.

Hoist the tipset re-validator into forest-cli snapshot validate
3 participants