Skip to content

Commit

Permalink
add MESC (#165)
Browse files Browse the repository at this point in the history
* add MESC

* fix timestamp tests
  • Loading branch information
sslivkoff authored Jan 3, 2024
1 parent c5ed901 commit 5a1a3bf
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 15 deletions.
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ heck = "0.4.1"
indexmap = "2.1.0"
indicatif = "0.17.7"
lazy_static = "1.4.0"
mesc = "0.1.0"
polars = { version = "0.35.4", features = [
"parquet",
"string_encoding",
Expand Down
1 change: 1 addition & 0 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ ethers = { workspace = true }
eyre = { workspace = true }
governor = { workspace = true }
hex = { workspace = true }
mesc = { workspace = true }
polars = { workspace = true }
rand = { workspace = true }
serde = { workspace = true }
Expand Down
4 changes: 2 additions & 2 deletions crates/cli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ pub struct Args {
#[arg(long, help_heading = "Content Options")]
pub exclude_failed: bool,

/// RPC url [default: ETH_RPC_URL env var]
/// RPC url [default: 1. MESC 2. ETH_RPC_URL]
#[arg(short, long, help_heading = "Source Options")]
pub rpc: Option<String>,

Expand Down Expand Up @@ -114,7 +114,7 @@ pub struct Args {
#[arg(long, value_name = "M", help_heading = "Acquisition Options")]
pub max_concurrent_chunks: Option<u64>,

/// Chunk collection order (normal, reverse, or random)
/// Chunk collection order (normal, reverse, random)
#[arg(long, help_heading = "Acquisition Options")]
pub chunk_order: Option<String>,

Expand Down
39 changes: 27 additions & 12 deletions crates/cli/src/parse/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,33 @@ pub(crate) async fn parse_source(args: &Args) -> Result<Source, ParseError> {
}

pub(crate) fn parse_rpc_url(args: &Args) -> Result<String, ParseError> {
let mut url = match &args.rpc {
Some(url) => url.clone(),
_ => match env::var("ETH_RPC_URL") {
Ok(url) => url,
Err(_e) => {
println!("must provide --rpc or set ETH_RPC_URL");
std::process::exit(0);
}
},
// get MESC url
let mesc_url = if mesc::is_mesc_enabled() {
let endpoint = match &args.rpc {
Some(url) => mesc::get_endpoint_by_query(url, Some("cryo"))?,
None => mesc::get_default_endpoint(Some("cryo"))?,
};
endpoint.map(|endpoint| endpoint.url)
} else {
None
};
if !url.starts_with("http") & !url.starts_with("ws") & !url.ends_with(".ipc") {
url = "http://".to_string() + url.as_str();

// use ETH_RPC_URL if no MESC url found
let url = if let Some(url) = mesc_url {
url
} else if let Some(url) = &args.rpc {
url.clone()
} else if let Ok(url) = env::var("ETH_RPC_URL") {
url
} else {
let message = "must provide --rpc or setup MESC or set ETH_RPC_URL";
return Err(ParseError::ParseError(message.to_string()))
};
Ok(url)

// prepend http or https if need be
if !url.starts_with("http") & !url.starts_with("ws") & !url.ends_with(".ipc") {
Ok("http://".to_string() + url.as_str())
} else {
Ok(url)
}
}
5 changes: 4 additions & 1 deletion crates/cli/src/parse/timestamps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,10 @@ mod tests {
use ethers::prelude::*;

async fn setup_source() -> Source {
let rpc_url = crate::parse::source::parse_rpc_url(&Args::default()).unwrap();
let rpc_url = match crate::parse::source::parse_rpc_url(&Args::default()) {
Ok(url) => url,
Err(_) => std::process::exit(0),
};
let max_retry = 5;
let initial_backoff = 500;
let max_concurrent_requests = 100;
Expand Down
1 change: 1 addition & 0 deletions crates/freeze/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ heck = { workspace = true }
indexmap = { workspace = true }
indicatif = { workspace = true }
lazy_static = { workspace = true }
mesc = { workspace = true }
polars = { workspace = true }
prefix-hex = { workspace = true }
regex = { workspace = true }
Expand Down
10 changes: 10 additions & 0 deletions crates/freeze/src/types/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,16 @@ pub enum ParseError {
/// Parse int error
#[error("Parsing error")]
ParseIntError(#[from] std::num::ParseIntError),

/// MESC error
#[error("MESC error: {:?}", .0)]
MescError(mesc::MescError),
}

impl From<mesc::MescError> for ParseError {
fn from(err: mesc::MescError) -> Self {
ParseError::MescError(err)
}
}

/// Error performing a chunk operation
Expand Down

0 comments on commit 5a1a3bf

Please sign in to comment.