|
| 1 | +use serde::{Deserialize, Serialize}; |
| 2 | + |
| 3 | +use super::batch_prover::ProverGuestRunConfig; |
| 4 | + |
| 5 | +/// Light client prover configuration |
| 6 | +#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] |
| 7 | +pub struct LightClientProverConfig { |
| 8 | + /// Prover run mode |
| 9 | + pub proving_mode: ProverGuestRunConfig, |
| 10 | + /// Average number of commitments to prove |
| 11 | + pub proof_sampling_number: usize, |
| 12 | + /// If true prover will try to recover ongoing proving sessions |
| 13 | + pub enable_recovery: bool, |
| 14 | +} |
| 15 | + |
| 16 | +impl Default for LightClientProverConfig { |
| 17 | + fn default() -> Self { |
| 18 | + Self { |
| 19 | + proving_mode: ProverGuestRunConfig::Execute, |
| 20 | + proof_sampling_number: 0, |
| 21 | + enable_recovery: true, |
| 22 | + } |
| 23 | + } |
| 24 | +} |
| 25 | + |
| 26 | +#[cfg(test)] |
| 27 | +mod tests { |
| 28 | + use std::{ |
| 29 | + fs::File, |
| 30 | + io::{Read, Write}, |
| 31 | + path::Path, |
| 32 | + }; |
| 33 | + |
| 34 | + use serde::de::DeserializeOwned; |
| 35 | + use tempfile::NamedTempFile; |
| 36 | + |
| 37 | + use super::*; |
| 38 | + |
| 39 | + /// Reads toml file as a specific type. |
| 40 | + pub fn from_toml_path<P: AsRef<Path>, R: DeserializeOwned>(path: P) -> anyhow::Result<R> { |
| 41 | + let mut contents = String::new(); |
| 42 | + { |
| 43 | + let mut file = File::open(path)?; |
| 44 | + file.read_to_string(&mut contents)?; |
| 45 | + } |
| 46 | + let result: R = toml::from_str(&contents)?; |
| 47 | + |
| 48 | + Ok(result) |
| 49 | + } |
| 50 | + |
| 51 | + fn create_config_from(content: &str) -> NamedTempFile { |
| 52 | + let mut config_file = NamedTempFile::new().unwrap(); |
| 53 | + config_file.write_all(content.as_bytes()).unwrap(); |
| 54 | + config_file |
| 55 | + } |
| 56 | + |
| 57 | + #[test] |
| 58 | + fn test_correct_prover_config() { |
| 59 | + let config = r#" |
| 60 | + proving_mode = "skip" |
| 61 | + proof_sampling_number = 500 |
| 62 | + enable_recovery = true |
| 63 | + "#; |
| 64 | + |
| 65 | + let config_file = create_config_from(config); |
| 66 | + |
| 67 | + let config: LightClientProverConfig = from_toml_path(config_file.path()).unwrap(); |
| 68 | + let expected = LightClientProverConfig { |
| 69 | + proving_mode: ProverGuestRunConfig::Skip, |
| 70 | + proof_sampling_number: 500, |
| 71 | + enable_recovery: true, |
| 72 | + }; |
| 73 | + assert_eq!(config, expected); |
| 74 | + } |
| 75 | +} |
0 commit comments