diff --git a/scripts/process.rs b/scripts/process.rs index 525549361..a2739d76a 100644 --- a/scripts/process.rs +++ b/scripts/process.rs @@ -4,7 +4,7 @@ use std::{ process::{Command, Stdio}, }; -use anyhow::{ensure, Context as _, Result}; +use anyhow::{ensure, Context as _}; /// A means of running a command as a subprocess. pub struct Process { @@ -33,7 +33,7 @@ impl Process { /// Create the file specified by `output_filepath` and set it as the stdout /// and stderr of the command. - pub fn pipe(mut self, output_filepath: &Path) -> Result { + pub fn pipe(mut self, output_filepath: &Path) -> anyhow::Result { let out = File::create(output_filepath)?; let err = out.try_clone()?; self.stdout = Stdio::from(out); @@ -42,7 +42,7 @@ impl Process { } /// Run the command. - pub fn run(self) -> Result<()> { + pub fn run(self) -> anyhow::Result<()> { let output = Command::new(&self.cmd) .args(&self.args) .stdout(self.stdout) diff --git a/scripts/prove_rpc.rs b/scripts/prove_rpc.rs index e0c3427c5..048ec1bad 100644 --- a/scripts/prove_rpc.rs +++ b/scripts/prove_rpc.rs @@ -6,7 +6,6 @@ use std::{ }; use alloy::{eips::BlockId, transports::http::reqwest::Url}; -use anyhow::Result; use clap::{arg, Args, ValueEnum, ValueHint}; use crate::process::Process; @@ -42,14 +41,10 @@ pub struct ProveRpcArgs { /// The node RPC URL. #[arg(value_hint = ValueHint::Url)] rpc_url: Url, - /// The RPC type (jerigon or native). - #[arg()] rpc_type: RpcType, /// Whether to generate a proof and verify it or not. - #[arg()] mode: RunMode, /// The start of the block range to prove (inclusive). - #[arg()] start_block: BlockId, /// The end of the block range to prove. If None, start_block-1 is used. #[arg(short = 'c', long)] @@ -73,7 +68,7 @@ pub struct ProveRpcArgs { } /// Run leader binary to prove a block range via RPC. -pub fn prove_via_rpc(args: ProveRpcArgs) -> Result<()> { +pub fn prove_via_rpc(args: ProveRpcArgs) -> anyhow::Result<()> { // Set rustc environment variables. set_var("RUST_MIN_STACK", "33554432"); set_var("RUST_BACKTRACE", "1"); @@ -99,10 +94,7 @@ pub fn prove_via_rpc(args: ProveRpcArgs) -> Result<()> { }; // Create the output directory if it does not exist. - let proof_output_dirpath = Path::new(&args.output_dir); - if !proof_output_dirpath.exists() { - create_dir_all(proof_output_dirpath)?; - } + create_dir_all(args.output_dir.clone())?; // Set file handle limit. const RECOMMENDED_FILE_LIMIT: isize = 8192; if !sysinfo::set_open_files_limit(RECOMMENDED_FILE_LIMIT) { @@ -114,7 +106,7 @@ pub fn prove_via_rpc(args: ProveRpcArgs) -> Result<()> { "--runtime=in-memory", "--load-strategy=on-demand", "--proof-output-dir", - proof_output_dirpath.to_str().unwrap(), + args.output_dir.to_str().unwrap(), "--block-batch-size", &args.block_batch_size.to_string(), "rpc", @@ -123,11 +115,11 @@ pub fn prove_via_rpc(args: ProveRpcArgs) -> Result<()> { "--rpc-url", args.rpc_url.as_ref(), "--start-block", - &block_string(start_block), + &block_string(start_block)?, "--checkpoint-block", - &block_string(checkpoint_block), + &block_string(checkpoint_block)?, "--end-block", - &block_string(end_block), + &block_string(end_block)?, "--backoff", &args.backoff.to_string(), "--max-retries", @@ -156,9 +148,10 @@ pub fn prove_via_rpc(args: ProveRpcArgs) -> Result<()> { Process::new("cargo").args(&cmd_args).run()?; // Verify the proof. - let proof_filepath = - proof_output_dirpath.join(format!("b{}.zkproof", block_string(end_block))); - let verify_output_filepath = proof_output_dirpath.join("verify.out"); + let proof_filepath = args + .output_dir + .join(format!("b{}.zkproof", block_string(end_block)?)); + let verify_output_filepath = args.output_dir.join("verify.out"); let verify_runner = Process::new("cargo") .args(&[ "run", @@ -176,10 +169,13 @@ pub fn prove_via_rpc(args: ProveRpcArgs) -> Result<()> { } /// Converts a block ID to an appropriate string based on its variant. -fn block_string(block: BlockId) -> String { +fn block_string(block: BlockId) -> anyhow::Result { match block { - BlockId::Number(number) => number.as_number().unwrap().to_string(), - BlockId::Hash(hash) => hash.to_string(), + BlockId::Number(number) => Ok(number + .as_number() + .ok_or(anyhow::anyhow!("BlockId must be a number"))? + .to_string()), + BlockId::Hash(hash) => Ok(hash.to_string()), } }