Skip to content

Commit

Permalink
fix review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
temaniarpit27 committed Aug 30, 2024
1 parent f0f4bf9 commit 5dff3b3
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 27 deletions.
6 changes: 3 additions & 3 deletions zero_bin/leader/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub struct ProofParams {
/// The main function for the client.
pub(crate) async fn client_main(
block_proof_runtime: Runtime,
segment_runtime: Runtime,
segment_proof_runtime: Runtime,
rpc_params: RpcParams,
block_interval: BlockInterval,
mut params: ProofParams,
Expand Down Expand Up @@ -84,14 +84,14 @@ pub(crate) async fn client_main(
let proved_blocks = prover::prove(
block_prover_inputs,
&block_proof_runtime,
&segment_runtime,
&segment_proof_runtime,
params.previous_proof.take(),
params.prover_config,
params.proof_output_dir.clone(),
)
.await;
block_proof_runtime.close().await?;
segment_runtime.close().await?;
segment_proof_runtime.close().await?;
let proved_blocks = proved_blocks?;

if params.prover_config.test_only {
Expand Down
14 changes: 7 additions & 7 deletions zero_bin/leader/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use tracing::{debug, error, info};
/// The main function for the HTTP mode.
pub(crate) async fn http_main(
block_proof_runtime: Runtime,
segment_runtime: Runtime,
segment_proof_runtime: Runtime,
port: u16,
output_dir: PathBuf,
prover_config: ProverConfig,
Expand All @@ -22,17 +22,17 @@ pub(crate) async fn http_main(
debug!("listening on {}", addr);

let block_proof_runtime = Arc::new(block_proof_runtime);
let segment_runtime = Arc::new(segment_runtime);
let segment_proof_runtime = Arc::new(segment_proof_runtime);
let app = Router::new().route(
"/prove",
post({
let block_proof_runtime = block_proof_runtime.clone();
let segment_runtime = segment_runtime.clone();
let segment_proof_runtime = segment_proof_runtime.clone();
move |body| {
prove(
body,
block_proof_runtime,
segment_runtime,
segment_proof_runtime,
output_dir.clone(),
prover_config,
)
Expand Down Expand Up @@ -75,7 +75,7 @@ struct HttpProverInput {
async fn prove(
Json(payload): Json<HttpProverInput>,
block_proof_runtime: Arc<Runtime>,
segment_runtime: Arc<Runtime>,
segment_proof_runtime: Arc<Runtime>,
output_dir: PathBuf,
prover_config: ProverConfig,
) -> StatusCode {
Expand All @@ -87,7 +87,7 @@ async fn prove(
payload
.prover_input
.prove_test(
&segment_runtime,
&segment_proof_runtime,
payload.previous.map(futures::future::ok),
prover_config,
)
Expand All @@ -97,7 +97,7 @@ async fn prove(
.prover_input
.prove(
&block_proof_runtime,
&segment_runtime,
&segment_proof_runtime,
payload.previous.map(futures::future::ok),
prover_config,
)
Expand Down
18 changes: 11 additions & 7 deletions zero_bin/leader/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ fn get_previous_proof(path: Option<PathBuf>) -> Result<Option<GeneratedBlockProo
Ok(Some(proof))
}

const SEGMENT_PROOF_ROUTING_KEY: &str = "segment_proof";
const BLOCK_PROOF_ROUTING_KEY: &str = "block_proof";

#[tokio::main]
async fn main() -> Result<()> {
load_dotenvy_vars_if_present();
Expand All @@ -56,13 +59,14 @@ async fn main() -> Result<()> {
let args = cli::Cli::parse();

let mut block_proof_paladin_args = args.paladin.clone();
block_proof_paladin_args.task_bus_routing_key = Some("block_proof".to_string());
block_proof_paladin_args.task_bus_routing_key = Some(BLOCK_PROOF_ROUTING_KEY.to_string());

let mut segment_paladin_args = args.paladin.clone();
segment_paladin_args.task_bus_routing_key = Some("segment".to_string());
let mut segment_proof_paladin_args = args.paladin.clone();
segment_proof_paladin_args.task_bus_routing_key = Some(SEGMENT_PROOF_ROUTING_KEY.to_string());

let block_proof_runtime = Runtime::from_config(&block_proof_paladin_args, register()).await?;
let segment_runtime = Runtime::from_config(&segment_paladin_args, register()).await?;
let segment_proof_runtime =
Runtime::from_config(&segment_proof_paladin_args, register()).await?;

let prover_config: ProverConfig = args.prover_config.into();

Expand All @@ -82,7 +86,7 @@ async fn main() -> Result<()> {
let previous_proof = get_previous_proof(previous_proof)?;
stdio::stdio_main(
block_proof_runtime,
segment_runtime,
segment_proof_runtime,
previous_proof,
prover_config,
)
Expand All @@ -100,7 +104,7 @@ async fn main() -> Result<()> {

http::http_main(
block_proof_runtime,
segment_runtime,
segment_proof_runtime,
port,
output_dir,
prover_config,
Expand Down Expand Up @@ -133,7 +137,7 @@ async fn main() -> Result<()> {
info!("Proving interval {block_interval}");
client_main(
block_proof_runtime,
segment_runtime,
segment_proof_runtime,
RpcParams {
rpc_url,
rpc_type,
Expand Down
6 changes: 3 additions & 3 deletions zero_bin/leader/src/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use tracing::info;
/// The main function for the stdio mode.
pub(crate) async fn stdio_main(
block_proof_runtime: Runtime,
segment_runtime: Runtime,
segment_proof_runtime: Runtime,
previous: Option<GeneratedBlockProof>,
prover_config: ProverConfig,
) -> Result<()> {
Expand All @@ -25,14 +25,14 @@ pub(crate) async fn stdio_main(
let proved_blocks = prover::prove(
block_prover_inputs,
&block_proof_runtime,
&segment_runtime,
&segment_proof_runtime,
previous,
prover_config,
None,
)
.await;
block_proof_runtime.close().await?;
segment_runtime.close().await?;
segment_proof_runtime.close().await?;
let proved_blocks = proved_blocks?;

if prover_config.test_only {
Expand Down
14 changes: 7 additions & 7 deletions zero_bin/prover/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl BlockProverInput {
pub async fn prove(
self,
block_proof_runtime: &Runtime,
segment_runtime: &Runtime,
segment_proof_runtime: &Runtime,
previous: Option<impl Future<Output = Result<GeneratedBlockProof>>>,
prover_config: ProverConfig,
) -> Result<GeneratedBlockProof> {
Expand Down Expand Up @@ -100,7 +100,7 @@ impl BlockProverInput {

Directive::map(IndexedStream::from(segment_data_iterator), &seg_prove_ops)
.fold(&seg_agg_ops)
.run(segment_runtime)
.run(segment_proof_runtime)
.map(move |e| {
e.map(|p| (idx, proof_gen::proof_types::BatchAggregatableProof::from(p)))
})
Expand Down Expand Up @@ -140,7 +140,7 @@ impl BlockProverInput {

pub async fn prove_test(
self,
segment_runtime: &Runtime,
segment_proof_runtime: &Runtime,
previous: Option<impl Future<Output = Result<GeneratedBlockProof>>>,
prover_config: ProverConfig,
) -> Result<GeneratedBlockProof> {
Expand Down Expand Up @@ -176,7 +176,7 @@ impl BlockProverInput {
);

simulation
.run(segment_runtime)
.run(segment_proof_runtime)
.await?
.try_for_each(|_| future::ok(()))
.await?;
Expand Down Expand Up @@ -206,7 +206,7 @@ impl BlockProverInput {
pub async fn prove(
block_prover_inputs: Vec<BlockProverInputFuture>,
block_proof_runtime: &Runtime,
segment_runtime: &Runtime,
segment_proof_runtime: &Runtime,
previous_proof: Option<GeneratedBlockProof>,
prover_config: ProverConfig,
proof_output_dir: Option<PathBuf>,
Expand All @@ -228,7 +228,7 @@ pub async fn prove(
// Prove the block
let block_proof = if prover_config.test_only {
block
.prove_test(segment_runtime, previous_block_proof, prover_config)
.prove_test(segment_proof_runtime, previous_block_proof, prover_config)
.then(move |proof| async move {
let proof = proof?;
let block_number = proof.b_height;
Expand All @@ -254,7 +254,7 @@ pub async fn prove(
block
.prove(
block_proof_runtime,
segment_runtime,
segment_proof_runtime,
previous_block_proof,
prover_config,
)
Expand Down

0 comments on commit 5dff3b3

Please sign in to comment.