Skip to content

Commit 8309ea8

Browse files
committed
Merge branch 'staging' into feat/aggregation-mode-risc0
2 parents d0a4be6 + 16e61ad commit 8309ea8

30 files changed

+714
-83
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ batcher/aligned/batch_inclusion_responses/*
1212
**/broadcast
1313
volume
1414
config-files/*.last_processed_batch.json
15+
config-files/*.last_aggregated_block.json
1516

1617
nonce_*.bin
1718

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ AGG_CONFIG_FILE?=config-files/config-aggregator.yaml
99

1010
OPERATOR_VERSION=v0.15.1
1111
EIGEN_SDK_GO_VERSION_TESTNET=v0.2.0-beta.1
12-
EIGEN_SDK_GO_VERSION_MAINNET=v0.1.13
12+
EIGEN_SDK_GO_VERSION_MAINNET=v0.2.0-beta.1
1313

1414
ifeq ($(OS),Linux)
1515
BUILD_ALL_FFI = $(MAKE) build_all_ffi_linux

aggregation_mode/Cargo.lock

Lines changed: 31 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
1-
use serde::Deserialize;
2-
use std::{fs::File, io::Read};
1+
use serde::{Deserialize, Serialize};
2+
use std::{fs::File, fs::OpenOptions, io::Read, io::Write};
33

4-
#[derive(Debug, Deserialize)]
4+
#[derive(Debug, Deserialize, Serialize)]
55
pub struct ECDSAConfig {
66
pub private_key_store_path: String,
77
pub private_key_store_password: String,
88
}
99

10-
#[derive(Debug, Deserialize)]
10+
#[derive(Debug, Deserialize, Serialize)]
11+
pub struct LastAggregatedBlock {
12+
pub last_aggregated_block: u64,
13+
}
14+
15+
#[derive(Debug, Deserialize, Serialize)]
1116
pub struct Config {
1217
pub eth_rpc_url: String,
1318
pub eth_ws_url: String,
1419
pub max_proofs_in_queue: u16,
1520
pub proof_aggregation_service_address: String,
1621
pub aligned_service_manager_address: String,
22+
pub last_aggregated_block_filepath: String,
1723
pub ecdsa: ECDSAConfig,
18-
pub fetch_logs_from_secs_ago: u64,
19-
pub block_time_secs: u64,
2024
}
2125

2226
impl Config {
@@ -27,4 +31,32 @@ impl Config {
2731
let config: Config = serde_yaml::from_str(&contents)?;
2832
Ok(config)
2933
}
34+
35+
pub fn get_last_aggregated_block(&self) -> Result<u64, Box<dyn std::error::Error>> {
36+
let mut file = File::open(&self.last_aggregated_block_filepath)?;
37+
let mut contents = String::new();
38+
file.read_to_string(&mut contents)?;
39+
let lab: LastAggregatedBlock = serde_json::from_str(&contents)?;
40+
Ok(lab.last_aggregated_block)
41+
}
42+
43+
pub fn update_last_aggregated_block(
44+
&self,
45+
last_aggregated_block: u64,
46+
) -> Result<(), Box<dyn std::error::Error>> {
47+
let last_aggregated_block_struct = LastAggregatedBlock {
48+
last_aggregated_block,
49+
};
50+
51+
let mut file = OpenOptions::new()
52+
.write(true)
53+
.truncate(true)
54+
.create(true)
55+
.open(&self.last_aggregated_block_filepath)?;
56+
57+
let content = serde_json::to_string(&last_aggregated_block_struct)?;
58+
file.write_all(content.as_bytes())?;
59+
60+
Ok(())
61+
}
3062
}

aggregation_mode/src/backend/fetcher.rs

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ pub enum ProofsFetcherError {
2828
pub struct ProofsFetcher {
2929
rpc_provider: RPCProvider,
3030
aligned_service_manager: AlignedLayerServiceManagerContract,
31-
fetch_from_secs_ago: u64,
32-
block_time_secs: u64,
31+
last_aggregated_block: u64,
3332
}
3433

3534
impl ProofsFetcher {
@@ -42,31 +41,52 @@ impl ProofsFetcher {
4241
rpc_provider.clone(),
4342
);
4443

44+
let last_aggregated_block = config.get_last_aggregated_block().unwrap();
45+
4546
Self {
4647
rpc_provider,
4748
aligned_service_manager,
48-
fetch_from_secs_ago: config.fetch_logs_from_secs_ago,
49-
block_time_secs: config.block_time_secs,
49+
last_aggregated_block,
5050
}
5151
}
5252

53-
pub async fn fetch(&self, engine: ZKVMEngine) -> Result<Vec<AlignedProof>, ProofsFetcherError> {
54-
let from_block = self.get_block_number_to_fetch_from().await?;
53+
pub async fn fetch(
54+
&mut self,
55+
engine: ZKVMEngine,
56+
) -> Result<Vec<AlignedProof>, ProofsFetcherError> {
57+
// Get current block
58+
let current_block = self
59+
.rpc_provider
60+
.get_block_number()
61+
.await
62+
.map_err(|e| ProofsFetcherError::GetBlockNumber(e.to_string()))?;
63+
64+
if current_block < self.last_aggregated_block {
65+
return Err(ProofsFetcherError::GetBlockNumber(
66+
"Invalid last processed block".to_string(),
67+
));
68+
}
69+
5570
info!(
56-
"Fetching proofs from batch logs starting from block number {}",
57-
from_block
71+
"Fetching proofs from batch logs starting from block number {} upto {}",
72+
self.last_aggregated_block, current_block
5873
);
74+
5975
// Subscribe to NewBatch event from AlignedServiceManager
6076
let logs = self
6177
.aligned_service_manager
6278
.NewBatchV3_filter()
63-
.from_block(from_block)
79+
.from_block(self.last_aggregated_block)
80+
.to_block(current_block)
6481
.query()
6582
.await
6683
.map_err(|e| ProofsFetcherError::GetLogs(e.to_string()))?;
6784

6885
info!("Logs collected {}", logs.len());
6986

87+
// Update last processed block after collecting logs
88+
self.last_aggregated_block = current_block;
89+
7090
let mut proofs = vec![];
7191

7292
for (batch, _) in logs {
@@ -145,15 +165,7 @@ impl ProofsFetcher {
145165
Ok(proofs)
146166
}
147167

148-
async fn get_block_number_to_fetch_from(&self) -> Result<u64, ProofsFetcherError> {
149-
let block_number = self
150-
.rpc_provider
151-
.get_block_number()
152-
.await
153-
.map_err(|e| ProofsFetcherError::GetBlockNumber(e.to_string()))?;
154-
155-
let number_of_blocks_in_the_past = self.fetch_from_secs_ago / self.block_time_secs;
156-
157-
Ok(block_number.saturating_sub(number_of_blocks_in_the_past))
168+
pub fn get_last_aggregated_block(&self) -> u64 {
169+
self.last_aggregated_block
158170
}
159171
}

aggregation_mode/src/backend/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,17 @@ impl ProofAggregator {
7474
}
7575
}
7676

77-
pub async fn start(&mut self) {
77+
pub async fn start(&mut self, config: &Config) {
7878
info!("Starting proof aggregator service",);
7979

8080
info!("About to aggregate and submit proof to be verified on chain");
8181
let res = self.aggregate_and_submit_proofs_on_chain().await;
8282

8383
match res {
8484
Ok(()) => {
85+
config
86+
.update_last_aggregated_block(self.fetcher.get_last_aggregated_block())
87+
.unwrap();
8588
info!("Process finished successfully");
8689
}
8790
Err(err) => {

aggregation_mode/src/main.rs

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

2929
let mut proof_aggregator = ProofAggregator::new(&config);
30-
proof_aggregator.start().await;
30+
proof_aggregator.start(&config).await;
3131
}

batcher/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

batcher/aligned-sdk/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ hex = "0.4.3"
2525
ciborium = "=0.2.2"
2626
serde_repr = "0.1.19"
2727
dialoguer = "0.11.0"
28+
reqwest = { version = "0.12", features = ["json"] }

batcher/aligned-sdk/abi/AlignedProofAggregationService.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)