Skip to content

Commit

Permalink
Initial PR fixes before arg and process refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
sergerad committed Nov 20, 2024
1 parent 84d710f commit 33d1b52
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 23 deletions.
6 changes: 3 additions & 3 deletions scripts/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<Self> {
pub fn pipe(mut self, output_filepath: &Path) -> anyhow::Result<Self> {
let out = File::create(output_filepath)?;
let err = out.try_clone()?;
self.stdout = Stdio::from(out);
Expand All @@ -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)
Expand Down
36 changes: 16 additions & 20 deletions scripts/prove_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)]
Expand All @@ -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");
Expand All @@ -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) {
Expand All @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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<String> {
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()),
}
}

Expand Down

0 comments on commit 33d1b52

Please sign in to comment.