Skip to content

Commit

Permalink
fixup! feat(advance-runner)!: validate snapshot hash
Browse files Browse the repository at this point in the history
  • Loading branch information
torives committed Aug 23, 2023
1 parent bcd7364 commit e352a35
Showing 1 changed file with 11 additions and 19 deletions.
30 changes: 11 additions & 19 deletions offchain/advance-runner/src/snapshot/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use clap::Parser;
use rollups_events::Address;
use snafu::{ensure, ResultExt, Snafu};
use snafu::{ensure, Snafu};
use std::path::PathBuf;
use url::Url;

Expand Down Expand Up @@ -35,19 +35,14 @@ impl SnapshotConfig {
ensure!(snapshot_latest.is_symlink(), SymlinkSnafu);

let validation_enabled = cli_config.snapshot_validation_enabled;
let provider_http_endpoint = if validation_enabled {
if let Some(endpoint) = &cli_config.provider_http_endpoint {
let url =
Url::parse(&endpoint).context(EndpointParseSnafu)?;
Some(url)
} else {
return Err(
SnapshotConfigError::NoProviderEndpointError {},
);
}
} else {
None
};
if validation_enabled {
ensure!(
cli_config.provider_http_endpoint.is_some(),
NoProviderEndpointSnafu,
);
}

let provider_http_endpoint = cli_config.provider_http_endpoint;

Ok(SnapshotConfig::FileSystem(FSManagerConfig {
snapshot_dir,
Expand All @@ -73,9 +68,6 @@ pub enum SnapshotConfigError {

#[snafu(display("A provider http endpoint is required"))]
NoProviderEndpointError {},

#[snafu(display("provider_http_endpoint isn't a valid URL"))]
EndpointParseError { source: url::ParseError },
}

#[derive(Parser, Debug)]
Expand All @@ -99,6 +91,6 @@ pub struct SnapshotCLIConfig {

/// The endpoint for a JSON-RPC provider.
/// Required if SNAPSHOT_VALIDATION_ENABLED is `true`
#[arg(long, env)]
provider_http_endpoint: Option<String>,
#[arg(long, env, value_parser = Url::parse)]
provider_http_endpoint: Option<Url>,
}

0 comments on commit e352a35

Please sign in to comment.