-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): Split config definitions and deserialization (#414)
Instead of a thousand words: <img width="392" alt="image" src="https://github.com/matter-labs/zksync-era/assets/12111581/b0230f94-29bb-4ef5-a779-7017fa4977f2"> This is the first PR of N preparing zkSync codebase for zkStack. --- In this episode: - `<ConfigName>::from_env()` methods were extracted from `zksync_config` to a new crate `zksync_env_config`. - Any usage of `from_env()` has been removed from `core/lib` directory. In other words, configs are now deserialized only in binaries. - Some crates were redesigned somewhat, for example, `ObjectStoreFactory` now lacks `*_from_env` methods and can only be created via config. - Some configs obtained `for_tests()` constructors that allow creating configs without accessing env variables. Values there mostly match localhost defaults. Some tests have been rewritten to enforce values in the configs (thus they are now more resilient than they were before). The focus for this PR has been to remove any `from_env()` usage, so there are some unsolved issues, e.g. - We still access some env variables via `std::env::var`. - We have introduced a temporary ugly structure `TempConfigStore` that _reminds_ the former `ZkSyncConfig` but doesn't have the same level of danger. These (and other) things are to be resolved soon.
- Loading branch information
Showing
117 changed files
with
2,763 additions
and
2,270 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,8 @@ | ||
// Built-in uses | ||
// External uses | ||
use serde::Deserialize; | ||
|
||
use super::envy_load; | ||
|
||
#[derive(Debug, Deserialize, Clone, PartialEq)] | ||
pub struct AlertsConfig { | ||
/// List of panics' messages from external crypto code, | ||
/// that are sporadic and needed to be handled separately | ||
pub sporadic_crypto_errors_substrs: Vec<String>, | ||
} | ||
|
||
impl AlertsConfig { | ||
pub fn from_env() -> anyhow::Result<Self> { | ||
envy_load("sporadic_crypto_errors_substrs", "ALERTS_") | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use crate::configs::test_utils::EnvMutex; | ||
|
||
static MUTEX: EnvMutex = EnvMutex::new(); | ||
|
||
fn expected_config() -> AlertsConfig { | ||
AlertsConfig { | ||
sporadic_crypto_errors_substrs: vec![ | ||
"EventDestroyErr".to_string(), | ||
"Can't free memory of DeviceBuf".to_string(), | ||
"value: PoisonError".to_string(), | ||
], | ||
} | ||
} | ||
|
||
#[test] | ||
fn test_from_env() { | ||
let mut lock = MUTEX.lock(); | ||
let config = r#" | ||
ALERTS_SPORADIC_CRYPTO_ERRORS_SUBSTRS="EventDestroyErr,Can't free memory of DeviceBuf,value: PoisonError" | ||
"#; | ||
lock.set_env(config); | ||
|
||
assert_eq!(AlertsConfig::from_env().unwrap(), expected_config()); | ||
} | ||
} |
Oops, something went wrong.