Skip to content

Commit 250272f

Browse files
apollo_proof_manager: create proof manager (#10943)
1 parent d5ccc13 commit 250272f

File tree

9 files changed

+99
-6
lines changed

9 files changed

+99
-6
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ members = [
6767
"crates/apollo_proc_macros",
6868
"crates/apollo_proc_macros_tests",
6969
"crates/apollo_proof_manager",
70+
"crates/apollo_proof_manager_config",
7071
"crates/apollo_propeller",
7172
"crates/apollo_protobuf",
7273
"crates/apollo_reverts",
@@ -185,6 +186,7 @@ apollo_p2p_sync_config.path = "crates/apollo_p2p_sync_config"
185186
apollo_proc_macros = { path = "crates/apollo_proc_macros", version = "0.0.0" }
186187
apollo_proc_macros_tests.path = "crates/apollo_proc_macros_tests"
187188
apollo_proof_manager.path = "crates/apollo_proof_manager"
189+
apollo_proof_manager_config.path = "crates/apollo_proof_manager_config"
188190
apollo_propeller.path = "crates/apollo_propeller"
189191
apollo_protobuf.path = "crates/apollo_protobuf"
190192
apollo_reverts.path = "crates/apollo_reverts"

crates/apollo_proof_manager/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ testing = []
1212
workspace = true
1313

1414
[dependencies]
15+
apollo_proof_manager_config.workspace = true
1516
hex.workspace = true
1617
starknet-types-core = { workspace = true, features = ["hash"] }
1718
starknet_api.workspace = true
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1+
pub mod proof_manager;
12
pub mod proof_storage;
2-
3-
pub use proof_storage::ProofStorage;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,34 @@
1+
use apollo_proof_manager_config::config::ProofManagerConfig;
2+
use starknet_api::transaction::fields::Proof;
3+
use starknet_types_core::felt::Felt;
14

5+
use crate::proof_storage::{FsProofStorage, FsProofStorageError, ProofStorage};
6+
/// Proof manager that wraps filesystem-based proof storage.
7+
pub struct ProofManager {
8+
pub proof_storage: FsProofStorage,
9+
// TODO(Einat): Add cache.
10+
}
11+
12+
impl ProofManager {
13+
pub fn new(config: ProofManagerConfig) -> Self {
14+
let proof_storage =
15+
FsProofStorage::new(config.persistent_root).expect("Failed to create proof storage.");
16+
Self { proof_storage }
17+
}
18+
}
19+
20+
impl ProofStorage for ProofManager {
21+
type Error = FsProofStorageError;
22+
23+
fn set_proof(&self, facts_hash: Felt, proof: Proof) -> Result<(), Self::Error> {
24+
self.proof_storage.set_proof(facts_hash, proof)
25+
}
26+
27+
fn get_proof(&self, facts_hash: Felt) -> Result<Option<Proof>, Self::Error> {
28+
self.proof_storage.get_proof(facts_hash)
29+
}
30+
31+
fn contains_proof(&self, facts_hash: Felt) -> Result<bool, Self::Error> {
32+
self.proof_storage.contains_proof(facts_hash)
33+
}
34+
}

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,
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[package]
2+
name = "apollo_proof_manager_config"
3+
edition.workspace = true
4+
license.workspace = true
5+
repository.workspace = true
6+
version.workspace = true
7+
description = "Configuration for Apollo proof manager"
8+
9+
[features]
10+
testing = []
11+
12+
[lints]
13+
workspace = true
14+
15+
[dependencies]
16+
apollo_config.workspace = true
17+
serde = { workspace = true, features = ["derive"] }
18+
validator.workspace = true
19+
20+
21+
[dev-dependencies]
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
use std::collections::BTreeMap;
2+
use std::path::PathBuf;
3+
4+
use apollo_config::dumping::{ser_param, SerializeConfig};
5+
use apollo_config::{ParamPath, ParamPrivacyInput, SerializedParam};
6+
use serde::{Deserialize, Serialize};
7+
use validator::Validate;
8+
9+
/// Configuration for the proof manager.
10+
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Validate)]
11+
pub struct ProofManagerConfig {
12+
pub persistent_root: PathBuf,
13+
}
14+
15+
impl Default for ProofManagerConfig {
16+
fn default() -> Self {
17+
Self { persistent_root: "/data/proofs".into() }
18+
}
19+
}
20+
21+
impl SerializeConfig for ProofManagerConfig {
22+
fn dump(&self) -> BTreeMap<ParamPath, SerializedParam> {
23+
BTreeMap::from([ser_param(
24+
"persistent_root",
25+
&self.persistent_root,
26+
"Persistent root for proof storage.",
27+
ParamPrivacyInput::Public,
28+
)])
29+
}
30+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub mod config;

0 commit comments

Comments
 (0)