Skip to content

Commit 9b941f6

Browse files
committed
Feat truncate config file
1 parent ea87e44 commit 9b941f6

4 files changed

Lines changed: 35 additions & 36 deletions

File tree

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
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)]
1111
pub struct Config {
1212
pub eth_rpc_url: String,
1313
pub eth_ws_url: String,
1414
pub max_proofs_in_queue: u16,
1515
pub proof_aggregation_service_address: String,
1616
pub aligned_service_manager_address: String,
17+
pub last_processed_block: u64,
1718
pub ecdsa: ECDSAConfig,
18-
pub last_processed_block: u64
1919
}
2020

2121
impl Config {
@@ -26,4 +26,11 @@ impl Config {
2626
let config: Config = serde_yaml::from_str(&contents)?;
2727
Ok(config)
2828
}
29+
30+
pub fn save_to_file(&self, file_path: &str) -> Result<(), Box<dyn std::error::Error>> {
31+
let mut file = OpenOptions::new().write(true).truncate(true).open(file_path)?;
32+
let content = serde_yaml::to_string(&self)?;
33+
file.write_all(content.as_bytes())?;
34+
Ok(())
35+
}
2936
}

aggregation_mode/src/backend/fetcher.rs

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -44,33 +44,34 @@ impl ProofsFetcher {
4444
}
4545
}
4646

47-
pub async fn fetch(&self) -> Result<Vec<AlignedProof>, ProofsFetcherError> {
47+
pub async fn fetch(&mut self) -> Result<Vec<AlignedProof>, ProofsFetcherError> {
48+
// Get current block
49+
let current_block = self
50+
.rpc_provider
51+
.get_block_number()
52+
.await
53+
.map_err(|_| ProofsFetcherError::BlockNumber)?;
54+
4855
info!(
49-
"Fetching proofs from batch logs starting from block number {}",
50-
self.last_processed_block
56+
"Fetching proofs from batch logs starting from block number {} upto {}",
57+
self.last_processed_block,
58+
current_block
5159
);
60+
5261
// Subscribe to NewBatch event from AlignedServiceManager
5362
let logs = self
5463
.aligned_service_manager
5564
.NewBatchV3_filter()
5665
.from_block(self.last_processed_block)
66+
.to_block(current_block)
5767
.query()
5868
.await
5969
.map_err(|_| ProofsFetcherError::QueryingLogs)?;
6070

6171
info!("Logs collected {}", logs.len());
6272

63-
// Get current block
64-
self.last_processed_block = self
65-
.rpc_provider
66-
.get_block_number()
67-
.await
68-
.map_err(|_| ProofsFetcherError::BlockNumber)?;
69-
70-
info!(
71-
"Fetched proofs from batch logs upto block number {}",
72-
self.last_processed_block
73-
);
73+
// Update last processed block after collecting logs
74+
self.last_processed_block = current_block;
7475

7576
let mut proofs = vec![];
7677

@@ -127,14 +128,4 @@ impl ProofsFetcher {
127128

128129
Ok(proofs)
129130
}
130-
131-
async fn get_block_number_to_fetch_from(&self) -> Result<u64, ProofsFetcherError> {
132-
let block_number = self
133-
.rpc_provider
134-
.get_block_number()
135-
.await
136-
.map_err(|_| ProofsFetcherError::BlockNumber)?;
137-
138-
Ok(block_number.saturating_sub(self.last_processed_block))
139-
}
140131
}

aggregation_mode/src/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,6 @@ async fn main() {
2828

2929
let mut proof_aggregator = ProofAggregator::new(&config);
3030
proof_aggregator.start().await;
31+
32+
config.save_to_file(&config_file_path).unwrap();
3133
}
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
aligned_service_manager_address: "0x851356ae760d987E095750cCeb3bC6014560891C"
2-
proof_aggregation_service_address: "0xB0D4afd8879eD9F52b28595d31B441D079B2Ca07"
3-
eth_rpc_url: "http://localhost:8545"
4-
eth_ws_url: "ws://localhost:8545"
1+
eth_rpc_url: http://localhost:8545
2+
eth_ws_url: ws://localhost:8545
53
max_proofs_in_queue: 1000
4+
proof_aggregation_service_address: 0xB0D4afd8879eD9F52b28595d31B441D079B2Ca07
5+
aligned_service_manager_address: 0x851356ae760d987E095750cCeb3bC6014560891C
66
last_processed_block: 0
7-
87
ecdsa:
9-
private_key_store_path: "config-files/anvil.proof-aggregator.ecdsa.key.json"
10-
private_key_store_password: ""
8+
private_key_store_path: config-files/anvil.proof-aggregator.ecdsa.key.json
9+
private_key_store_password: ''

0 commit comments

Comments
 (0)