Skip to content

Commit

Permalink
Address code review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
pbeza committed Oct 22, 2024
1 parent 76a8c2b commit 60334cd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 38 deletions.
51 changes: 14 additions & 37 deletions core/lib/config/src/configs/proof_data_handler.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
use std::{fmt, fmt::Display, marker::PhantomData, str::FromStr, time::Duration};
use std::time::Duration;

use serde::{de, Deserialize};
use serde::Deserialize;
use zksync_basic_types::L1BatchNumber;

#[derive(Debug, Deserialize, Clone, PartialEq)]
pub struct TeeConfig {
/// If true, the TEE support is enabled.
#[serde(deserialize_with = "deserialize_stringified_any")]
pub tee_support: bool,
/// All batches before this one are considered to be processed.
#[serde(deserialize_with = "deserialize_stringified_any", default)]
pub first_tee_processed_batch: L1BatchNumber,
}

impl Default for TeeConfig {
fn default() -> Self {
TeeConfig {
tee_support: false,
first_tee_processed_batch: L1BatchNumber(0),
}
}
}

#[derive(Debug, Deserialize, Clone, PartialEq)]
pub struct ProofDataHandlerConfig {
pub http_port: u16,
pub proof_generation_timeout_in_secs: u16,
#[serde(flatten)]
#[serde(skip)]
// ^ Filled in separately in `Self::from_env()`. We cannot use `serde(flatten)` because it
// doesn't work with `envy`: https://github.com/softprops/envy/issues/26
pub tee_config: TeeConfig,
}

Expand All @@ -26,35 +35,3 @@ impl ProofDataHandlerConfig {
Duration::from_secs(self.proof_generation_timeout_in_secs as u64)
}
}

// Boilerplate to workaround https://github.com/softprops/envy/issues/26

pub fn deserialize_stringified_any<'de, D, T>(deserializer: D) -> Result<T, D::Error>
where
D: de::Deserializer<'de>,
T: FromStr,
T::Err: Display,
{
deserializer.deserialize_any(StringifiedAnyVisitor(PhantomData))
}

pub struct StringifiedAnyVisitor<T>(PhantomData<T>);

impl<'de, T> de::Visitor<'de> for StringifiedAnyVisitor<T>
where
T: FromStr,
T::Err: Display,
{
type Value = T;

fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.write_str("a string containing json data")
}

fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
where
E: de::Error,
{
Self::Value::from_str(v).map_err(E::custom)
}
}
2 changes: 1 addition & 1 deletion core/lib/protobuf_config/src/proto/config/prover.proto
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,5 @@ message ProofDataHandler {
optional uint32 http_port = 1; // required; u16
optional uint32 proof_generation_timeout_in_secs = 2; // required; s
optional bool tee_support = 3; // required
optional uint64 first_tee_processed_batch = 4; // required
optional uint64 first_tee_processed_batch = 4; // optional
}

0 comments on commit 60334cd

Please sign in to comment.