Skip to content

Commit 9f94d11

Browse files
committed
feat: remove looping and run service only once
1 parent 407808b commit 9f94d11

File tree

2 files changed

+19
-31
lines changed

2 files changed

+19
-31
lines changed

aggregation-mode/src/backend/mod.rs

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use config::Config;
2020
use fetcher::{ProofsFetcher, ProofsFetcherError};
2121
use merkle_tree::compute_proofs_merkle_root;
2222
use sp1_sdk::HashableKey;
23-
use std::{str::FromStr, time::Duration};
23+
use std::str::FromStr;
2424
use tracing::{error, info, warn};
2525
use types::{AlignedProofAggregationService, AlignedProofAggregationServiceContract};
2626

@@ -35,7 +35,6 @@ pub enum AggregatedProofSubmissionError {
3535

3636
pub struct ProofAggregator {
3737
engine: ZKVMEngine,
38-
submit_proof_every_secs: u64,
3938
proof_aggregation_service: AlignedProofAggregationServiceContract,
4039
fetcher: ProofsFetcher,
4140
}
@@ -59,37 +58,29 @@ impl ProofAggregator {
5958

6059
Self {
6160
engine: ZKVMEngine::SP1,
62-
submit_proof_every_secs: config.submit_proofs_every_secs,
6361
proof_aggregation_service,
6462
fetcher,
6563
}
6664
}
6765

6866
pub async fn start(&mut self) {
69-
info!(
70-
"Starting proof aggregator service, configured to run every {}",
71-
self.submit_proof_every_secs
72-
);
67+
info!("Starting proof aggregator service",);
68+
69+
info!("About to aggregate and submit proof to be verified on chain");
70+
let res = self.aggregate_and_submit_proofs_on_chain().await;
7371

74-
loop {
75-
tokio::time::sleep(Duration::from_secs(self.submit_proof_every_secs)).await;
76-
info!("About to aggregate and submit proof to be verified on chain");
77-
let res = self.aggregate_and_submit_proofs_on_chain().await;
78-
79-
match res {
80-
Ok(()) => {
81-
info!(
82-
"Finished iteration, next aggregated proof is in {} seconds",
83-
self.submit_proof_every_secs
84-
);
85-
}
86-
Err(err) => {
87-
error!("Error while aggregating and submitting proofs: {:?}", err);
88-
if let Err(err) = self.set_aggregated_proof_as_missed().await {
89-
error!("Error while marking proof as failed: {:?}", err);
90-
};
91-
}
92-
};
72+
match res {
73+
Ok(()) => {
74+
info!("Process finished successfully");
75+
}
76+
Err(err) => {
77+
error!("Error while aggregating and submitting proofs: {:?}", err);
78+
info!("About to set aggregated proof as missed");
79+
if let Err(err) = self.set_aggregated_proof_as_missed().await {
80+
error!("Error while marking proof as failed: {:?}", err);
81+
};
82+
info!("Proofs set as missed");
83+
}
9384
}
9485
}
9586

@@ -103,7 +94,7 @@ impl ProofAggregator {
10394
.map_err(AggregatedProofSubmissionError::FetchingProofs)?;
10495

10596
if proofs.len() == 0 {
106-
warn!("No proofs in queue, skipping iteration...");
97+
warn!("No proofs collected, skipping aggregation...");
10798
return Ok(());
10899
}
109100

aggregation-mode/src/main.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,5 @@ async fn main() {
2727
tracing::info!("Config loaded");
2828

2929
let mut proof_aggregator = ProofAggregator::new(&config);
30-
31-
let proof_aggregator_handle = tokio::spawn(async move { proof_aggregator.start().await });
32-
33-
let _ = tokio::join!(proof_aggregator_handle);
30+
proof_aggregator.start().await;
3431
}

0 commit comments

Comments
 (0)