Skip to content

Commit 0801697

Browse files
apollo_proof_manager: create proof manager
1 parent d1c8766 commit 0801697

File tree

3 files changed

+46
-4
lines changed

3 files changed

+46
-4
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
pub mod proof_manager;
12
pub mod proof_storage;
23

4+
pub use proof_manager::{ProofManager, ProofManagerConfig};
35
pub use proof_storage::ProofStorage;
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,45 @@
1+
use std::path::PathBuf;
12

3+
use starknet_api::transaction::fields::Proof;
4+
use starknet_types_core::felt::Felt;
5+
6+
use crate::proof_storage::{FsProofStorage, FsProofStorageError, ProofStorage};
7+
8+
/// Configuration for the proof manager.
9+
#[derive(Clone, Debug)]
10+
pub struct ProofManagerConfig {
11+
pub persistent_root: PathBuf,
12+
}
13+
14+
/// Proof manager that wraps filesystem-based proof storage.
15+
pub struct ProofManager {
16+
pub proof_storage: FsProofStorage,
17+
}
18+
19+
impl ProofManager {
20+
pub fn new(config: ProofManagerConfig) -> Self {
21+
let proof_storage =
22+
FsProofStorage::new(config.persistent_root).expect("Failed to create proof storage.");
23+
Self { proof_storage }
24+
}
25+
}
26+
27+
impl ProofStorage for ProofManager {
28+
type Error = FsProofStorageError;
29+
30+
fn set_proof(&self, facts_hash: Felt, proof: Proof) -> Result<(), Self::Error> {
31+
self.proof_storage.set_proof(facts_hash, proof)
32+
}
33+
34+
fn get_proof(&self, facts_hash: Felt) -> Result<Option<Proof>, Self::Error> {
35+
self.proof_storage.get_proof(facts_hash)
36+
}
37+
38+
fn contains_proof(&self, facts_hash: Felt) -> Result<bool, Self::Error> {
39+
self.proof_storage.contains_proof(facts_hash)
40+
}
41+
}
42+
43+
pub fn create_proof_manager(config: ProofManagerConfig) -> ProofManager {
44+
ProofManager::new(config)
45+
}

crates/apollo_proof_manager/src/proof_storage.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,17 @@ impl FsProofStorage {
4646
/// a1/
4747
/// └── b2/
4848
/// └── a1b2c3d4.../
49-
#[allow(dead_code)]
5049
fn get_proof_dir(&self, facts_hash: Felt) -> PathBuf {
5150
let facts_hash = hex::encode(facts_hash.to_bytes_be());
5251
let (first_msb_byte, second_msb_byte, _rest_of_bytes) =
5352
(&facts_hash[..2], &facts_hash[2..4], &facts_hash[4..]);
5453
PathBuf::from(first_msb_byte).join(second_msb_byte).join(facts_hash)
5554
}
5655

57-
#[allow(dead_code)]
5856
fn get_persistent_dir(&self, facts_hash: Felt) -> PathBuf {
5957
self.persistent_root.join(self.get_proof_dir(facts_hash))
6058
}
6159

62-
#[allow(dead_code)]
6360
fn get_persistent_dir_with_create(&self, facts_hash: Felt) -> FsProofStorageResult<PathBuf> {
6461
let path = self.get_persistent_dir(facts_hash);
6562
if let Some(parent) = path.parent() {
@@ -69,7 +66,6 @@ impl FsProofStorage {
6966
Ok(path)
7067
}
7168

72-
#[allow(dead_code)]
7369
fn create_tmp_dir(
7470
&self,
7571
facts_hash: Felt,

0 commit comments

Comments
 (0)