Skip to content

Commit

Permalink
chore: cleanup rpc tool parameters (#595)
Browse files Browse the repository at this point in the history
  • Loading branch information
atanmarko authored Sep 5, 2024
1 parent d207439 commit 6aa25a1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
8 changes: 0 additions & 8 deletions zero_bin/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,6 @@ pub enum RpcType {
Native,
}

#[derive(Clone, Debug, Copy)]
pub struct RpcParams {
pub start_block: u64,
pub end_block: u64,
pub checkpoint_block_number: Option<u64>,
pub rpc_type: RpcType,
}

/// Obtain the prover input for one block
pub async fn block_prover_input<ProviderT, TransportT>(
cached_provider: Arc<CachedProvider<ProviderT, TransportT>>,
Expand Down
30 changes: 19 additions & 11 deletions zero_bin/rpc/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use anyhow::anyhow;
use clap::{Args, Parser, Subcommand, ValueHint};
use futures::StreamExt;
use prover::BlockProverInput;
use rpc::{retry::build_http_retry_provider, RpcParams, RpcType};
use rpc::{retry::build_http_retry_provider, RpcType};
use tracing_subscriber::{prelude::*, EnvFilter};
use url::Url;
use zero_bin_common::block_interval::BlockIntervalStream;
Expand All @@ -19,8 +19,16 @@ use zero_bin_common::provider::CachedProvider;
use zero_bin_common::version;
use zero_bin_common::{block_interval::BlockInterval, prover_state::persistence::CIRCUIT_VERSION};

#[derive(Clone, Debug, Copy)]
struct FetchParams {
pub start_block: u64,
pub end_block: u64,
pub checkpoint_block_number: Option<u64>,
pub rpc_type: RpcType,
}

#[derive(Args, Clone, Debug)]
pub(crate) struct RpcConfig {
struct RpcToolConfig {
/// The RPC URL.
#[arg(short = 'u', long, value_hint = ValueHint::Url)]
rpc_url: Url,
Expand All @@ -36,7 +44,7 @@ pub(crate) struct RpcConfig {
}

#[derive(Subcommand)]
pub(crate) enum Command {
enum Command {
Fetch {
/// Starting block of interval to fetch.
#[arg(short, long)]
Expand All @@ -60,18 +68,18 @@ pub(crate) enum Command {
}

#[derive(Parser)]
pub(crate) struct Cli {
struct Cli {
#[clap(flatten)]
pub(crate) config: RpcConfig,
pub(crate) config: RpcToolConfig,

/// Fetch and generate prover input from the RPC endpoint.
#[command(subcommand)]
pub(crate) command: Command,
}

pub(crate) async fn retrieve_block_prover_inputs<ProviderT, TransportT>(
pub(crate) async fn fetch_block_prover_inputs<ProviderT, TransportT>(
cached_provider: Arc<CachedProvider<ProviderT, TransportT>>,
params: RpcParams,
params: FetchParams,
) -> Result<Vec<BlockProverInput>, anyhow::Error>
where
ProviderT: Provider<TransportT>,
Expand Down Expand Up @@ -127,15 +135,15 @@ impl Cli {
end_block,
checkpoint_block_number,
} => {
let params = RpcParams {
let params = FetchParams {
start_block,
end_block,
checkpoint_block_number,
rpc_type: self.config.rpc_type,
};

let block_prover_inputs =
retrieve_block_prover_inputs(cached_provider, params).await?;
fetch_block_prover_inputs(cached_provider, params).await?;
serde_json::to_writer_pretty(std::io::stdout(), &block_prover_inputs)?;
}
Command::Extract { tx, batch_size } => {
Expand All @@ -153,15 +161,15 @@ impl Cli {
"transaction {} does not have block number",
tx_hash
))?;
let params = RpcParams {
let params = FetchParams {
start_block: block_number,
end_block: block_number,
checkpoint_block_number: None,
rpc_type: self.config.rpc_type,
};

let block_prover_inputs =
retrieve_block_prover_inputs(cached_provider, params).await?;
fetch_block_prover_inputs(cached_provider, params).await?;

let block_prover_input =
block_prover_inputs.into_iter().next().ok_or(anyhow!(
Expand Down

0 comments on commit 6aa25a1

Please sign in to comment.