Skip to content

Commit 5401815

Browse files
apollo_proof_manager: create proof manager
1 parent ba460f3 commit 5401815

File tree

5 files changed

+68
-4
lines changed

5 files changed

+68
-4
lines changed

Cargo.lock

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

crates/apollo_proof_manager/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@ testing = []
1212
workspace = true
1313

1414
[dependencies]
15+
apollo_config.workspace = true
1516
hex.workspace = true
17+
serde = { workspace = true, features = ["derive"] }
1618
starknet-types-core = { workspace = true, features = ["hash"] }
1719
starknet_api.workspace = true
1820
tempfile.workspace = true
1921
thiserror.workspace = true
22+
validator.workspace = true
2023

2124

2225
[dev-dependencies]
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: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,61 @@
1+
use std::collections::BTreeMap;
2+
use std::path::PathBuf;
13

4+
use apollo_config::dumping::{ser_param, SerializeConfig};
5+
use apollo_config::{ParamPath, ParamPrivacyInput, SerializedParam};
6+
use serde::{Deserialize, Serialize};
7+
use starknet_api::transaction::fields::Proof;
8+
use starknet_types_core::felt::Felt;
9+
use validator::Validate;
10+
11+
use crate::proof_storage::{FsProofStorage, FsProofStorageError, ProofStorage};
12+
13+
/// Configuration for the proof manager.
14+
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Validate)]
15+
pub struct ProofManagerConfig {
16+
pub persistent_root: PathBuf,
17+
}
18+
impl Default for ProofManagerConfig {
19+
fn default() -> Self {
20+
Self { persistent_root: "/data/proofs".into() }
21+
}
22+
}
23+
impl SerializeConfig for ProofManagerConfig {
24+
fn dump(&self) -> BTreeMap<ParamPath, SerializedParam> {
25+
BTreeMap::from([ser_param(
26+
"persistent_root",
27+
&self.persistent_root,
28+
"Persistent root for proof storage.",
29+
ParamPrivacyInput::Public,
30+
)])
31+
}
32+
}
33+
/// Proof manager that wraps filesystem-based proof storage.
34+
pub struct ProofManager {
35+
pub proof_storage: FsProofStorage,
36+
// TODO(Einat): Add cache.
37+
}
38+
39+
impl ProofManager {
40+
pub fn new(config: ProofManagerConfig) -> Self {
41+
let proof_storage =
42+
FsProofStorage::new(config.persistent_root).expect("Failed to create proof storage.");
43+
Self { proof_storage }
44+
}
45+
}
46+
47+
impl ProofStorage for ProofManager {
48+
type Error = FsProofStorageError;
49+
50+
fn set_proof(&self, facts_hash: Felt, proof: Proof) -> Result<(), Self::Error> {
51+
self.proof_storage.set_proof(facts_hash, proof)
52+
}
53+
54+
fn get_proof(&self, facts_hash: Felt) -> Result<Option<Proof>, Self::Error> {
55+
self.proof_storage.get_proof(facts_hash)
56+
}
57+
58+
fn contains_proof(&self, facts_hash: Felt) -> Result<bool, Self::Error> {
59+
self.proof_storage.contains_proof(facts_hash)
60+
}
61+
}

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)