Skip to content

Commit d402179

Browse files
committed
Fix new way to save last block
1 parent c908d6b commit d402179

7 files changed

Lines changed: 36 additions & 11 deletions

File tree

aggregation_mode/src/backend/config.rs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,19 @@ pub struct ECDSAConfig {
77
pub private_key_store_password: String,
88
}
99

10+
#[derive(Debug, Deserialize, Serialize)]
11+
pub struct LastProcessedBlock {
12+
pub last_processed_block: u64,
13+
}
14+
1015
#[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,
17-
pub last_processed_block: u64,
22+
pub last_processed_block_filepath: String,
1823
pub ecdsa: ECDSAConfig,
1924
}
2025

@@ -27,13 +32,30 @@ impl Config {
2732
Ok(config)
2833
}
2934

30-
pub fn save_to_file(&self, file_path: &str) -> Result<(), Box<dyn std::error::Error>> {
35+
pub fn get_last_processed_block(&self) -> Result<u64, Box<dyn std::error::Error>> {
36+
let mut file = File::open(&self.last_processed_block_filepath)?;
37+
let mut contents = String::new();
38+
file.read_to_string(&mut contents)?;
39+
let lpb: LastProcessedBlock = serde_json::from_str(&contents)?;
40+
Ok(lpb.last_processed_block)
41+
}
42+
43+
pub fn update_last_processed_block(
44+
&self,
45+
last_processed_block: u64,
46+
) -> Result<(), Box<dyn std::error::Error>> {
47+
let last_processed_block_struct = LastProcessedBlock {
48+
last_processed_block: last_processed_block,
49+
};
50+
3151
let mut file = OpenOptions::new()
3252
.write(true)
3353
.truncate(true)
34-
.open(file_path)?;
35-
let content = serde_yaml::to_string(&self)?;
54+
.open(&self.last_processed_block_filepath)?;
55+
56+
let content = serde_json::to_string(&last_processed_block_struct)?;
3657
file.write_all(content.as_bytes())?;
58+
3759
Ok(())
3860
}
3961
}

aggregation_mode/src/backend/fetcher.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,12 @@ impl ProofsFetcher {
3737
rpc_provider.clone(),
3838
);
3939

40+
let last_processed_block = config.get_last_processed_block().unwrap();
41+
4042
Self {
4143
rpc_provider,
4244
aligned_service_manager,
43-
last_processed_block: config.last_processed_block,
45+
last_processed_block: last_processed_block,
4446
}
4547
}
4648

aggregation_mode/src/backend/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,17 @@ impl ProofAggregator {
6969
}
7070
}
7171

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

7575
info!("About to aggregate and submit proof to be verified on chain");
7676
let res = self.aggregate_and_submit_proofs_on_chain().await;
7777

7878
match res {
7979
Ok(()) => {
80-
config.last_processed_block = self.fetcher.get_last_processed_block();
80+
config
81+
.update_last_processed_block(self.fetcher.get_last_processed_block())
82+
.unwrap();
8183
info!("Process finished successfully");
8284
}
8385
Err(err) => {

aggregation_mode/src/main.rs

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

2929
let mut proof_aggregator = ProofAggregator::new(&config);
3030
proof_aggregator.start(&mut config).await;
31-
32-
config.save_to_file(&config_file_path).unwrap();
3331
}

config-files/config-proof-aggregator-mock.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ eth_ws_url: ws://localhost:8545
33
max_proofs_in_queue: 1000
44
proof_aggregation_service_address: 0xB0D4afd8879eD9F52b28595d31B441D079B2Ca07
55
aligned_service_manager_address: 0x851356ae760d987E095750cCeb3bC6014560891C
6-
last_processed_block: 0
6+
last_processed_block_filepath: config-files/proof-aggregator.last_processed_block.json
77
ecdsa:
88
private_key_store_path: config-files/anvil.proof-aggregator.ecdsa.key.json
99
private_key_store_password: ''

config-files/config-proof-aggregator.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ proof_aggregation_service_address: "0xcbEAF3BDe82155F56486Fb5a1072cb8baAf547cc"
33
eth_rpc_url: "http://localhost:8545"
44
eth_ws_url: "ws://localhost:8545"
55
max_proofs_in_queue: 1000
6-
last_processed_block: 0
6+
last_processed_block_filepath: config-files/proof-aggregator.last_processed_block.json
77

88
ecdsa:
99
private_key_store_path: "config-files/anvil.proof-aggregator.ecdsa.key.json"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"last_processed_block":1305}

0 commit comments

Comments
 (0)