Skip to content

Commit 844cf1e

Browse files
committed
Add defaul value when file dont exist
1 parent d402179 commit 844cf1e

3 files changed

Lines changed: 15 additions & 7 deletions

File tree

aggregation_mode/src/backend/config.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,18 @@ impl Config {
3333
}
3434

3535
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)
36+
match File::open(&self.last_processed_block_filepath) {
37+
Err(_) =>{
38+
// if file doesn't exist, default 0
39+
Ok(0)
40+
}
41+
Ok(mut file) => {
42+
let mut contents = String::new();
43+
file.read_to_string(&mut contents)?;
44+
let lpb: LastProcessedBlock = serde_json::from_str(&contents)?;
45+
Ok(lpb.last_processed_block)
46+
}
47+
}
4148
}
4249

4350
pub fn update_last_processed_block(
@@ -51,6 +58,7 @@ impl Config {
5158
let mut file = OpenOptions::new()
5259
.write(true)
5360
.truncate(true)
61+
.create(true)
5462
.open(&self.last_processed_block_filepath)?;
5563

5664
let content = serde_json::to_string(&last_processed_block_struct)?;

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_filepath: config-files/proof-aggregator.last_processed_block.json
6+
last_processed_block_filepath: config-files/proof-aggregator2.last_processed_block.json
77
ecdsa:
88
private_key_store_path: config-files/anvil.proof-aggregator.ecdsa.key.json
99
private_key_store_password: ''
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"last_processed_block":1305}
1+
{"last_processed_block":1346}

0 commit comments

Comments
 (0)