Skip to content

Commit cef6e1a

Browse files
committed
feat: main method initializer
1 parent f7ed7b9 commit cef6e1a

File tree

1 file changed

+17
-32
lines changed

1 file changed

+17
-32
lines changed

aggregation-mode/src/main.rs

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
use std::{env, fs};
2-
3-
use proof_aggregator::{
4-
backend::{config::Config, ProofAggregator},
5-
zk::{
6-
backends::sp1::{vk_from_elf, SP1Proof},
7-
Proof,
8-
},
1+
use std::{env, sync::Arc};
2+
3+
use proof_aggregator::backend::{
4+
config::Config, fetcher::ProofsFetcher, queue::ProofsQueue, ProofAggregator,
95
};
10-
use sp1_sdk::SP1ProofWithPublicValues;
6+
use tokio::sync::Mutex;
117
use tracing_subscriber::FmtSubscriber;
128

139
fn read_config_filepath_from_args() -> String {
@@ -27,30 +23,19 @@ async fn main() {
2723
let subscriber = FmtSubscriber::builder().finish();
2824
tracing::subscriber::set_global_default(subscriber).expect("setting default subscriber failed");
2925

30-
// init proof aggregator
26+
// load config
3127
let config_file_path = read_config_filepath_from_args();
32-
tracing::info!("Loading config from {}..", config_file_path);
28+
tracing::info!("Loading config from {}...", config_file_path);
3329
let config = Config::from_file(&config_file_path).expect("Config is valid");
34-
let mut proof_aggregator = ProofAggregator::new(config);
35-
tracing::info!("Config loaded proof aggregator initialized");
36-
37-
// push some proofs from fs
38-
for _ in 0..2 {
39-
let sp1_proof =
40-
SP1ProofWithPublicValues::load("scripts/test_files/sp1/sp1_fibonacci_4_1_3.proof")
41-
.expect("loading proof failed");
42-
let proof_elf =
43-
fs::read("scripts/test_files/sp1/sp1_fibonacci_4_1_3.elf").expect("elf bytes");
44-
let proof = Proof::SP1(SP1Proof {
45-
proof: sp1_proof,
46-
vk: vk_from_elf(&proof_elf),
47-
});
48-
49-
proof_aggregator
50-
.add_proof(proof, &proof_elf)
51-
.expect("Proof to be valid");
52-
}
30+
tracing::info!("Config loaded");
31+
32+
let queue = Arc::new(Mutex::new(ProofsQueue::new(config.max_proofs_in_queue)));
33+
let mut proof_aggregator = ProofAggregator::new(&config, queue.clone()).await;
34+
let proofs_fetcher = ProofsFetcher::new(&config, queue).await;
35+
36+
// start tasks -> Proof aggregator + Proofs fetcher
37+
let proof_aggregator_handle = tokio::spawn(async move { proof_aggregator.start().await });
38+
let proofs_fetcher_handle = tokio::spawn(async move { proofs_fetcher.start().await });
5339

54-
// start service
55-
proof_aggregator.start().await;
40+
let _ = tokio::join!(proof_aggregator_handle, proofs_fetcher_handle);
5641
}

0 commit comments

Comments
 (0)