Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,16 @@ NETWORK=anvil make deploy-contracts
Most of the Shielder is licensed under the Apache-2.0 License. See the LICENSE file for more details.

Some of the crates are licensed with LICENSE-GPL-3.0-only-with-Classpath-exception:
* `crates/shielder-circuits`

- `crates/shielder-circuits`

Some of the crates are licensed with MIT:
* `crates/transcript`

- `crates/transcript`

## Circuits

Originally, `shielder-circuits` crate was placed in a different [repo](https://github.com/Cardinal-Cryptography/zkOS-circuits) and migrated without
Originally, `shielder-circuits` crate was placed in a different [repo](https://github.com/Cardinal-Cryptography/zkOS-circuits) and migrated without
preserving git history to this repo, so in case one needs to check `git blame`, please visit original repo.

[blanksquare-homepage]: https://blanksquare.io/
Expand Down
32 changes: 25 additions & 7 deletions crates/shielder-relayer/src/config/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use std::{
collections::HashSet,
fmt::{Debug, Formatter},
str::FromStr,
time::Duration,
};

use anyhow::anyhow;
use anyhow::{anyhow, Result};
use clap::Parser;
use cli::CLIConfig;
use defaults::*;
Expand Down Expand Up @@ -100,11 +101,11 @@ pub struct ServerConfig {

/// Resolves the configuration for the Shielder relayer using the command line arguments,
/// environment variables, and default values.
pub fn resolve_config() -> ServerConfig {
pub fn resolve_config() -> Result<ServerConfig> {
resolve_config_from_cli_config(CLIConfig::parse())
}

fn resolve_config_from_cli_config(
pub fn resolve_config_from_cli_config(
CLIConfig {
logging_format,
host,
Expand All @@ -127,7 +128,7 @@ fn resolve_config_from_cli_config(
quote_validity,
max_pocket_money,
}: CLIConfig,
) -> ServerConfig {
) -> Result<ServerConfig> {
let to_address = |s: &str| Address::from_str(s).expect("Invalid address");

let signing_keys = signing_keys.unwrap_or_else(|| {
Expand Down Expand Up @@ -166,7 +167,9 @@ fn resolve_config_from_cli_config(
let token_config = token_config
.or_else(|| std::env::var(TOKEN_CONFIG_ENV).ok())
.expect("Missing token configuration");
let token_config = serde_json::from_str(&token_config).expect("Invalid token configuration");
let token_config: Vec<TokenInfo> =
serde_json::from_str(&token_config).expect("Invalid token configuration");
check_token_config(&token_config)?;

let operational_config = OperationalConfig {
balance_monitor_interval: resolve_value_map(
Expand Down Expand Up @@ -227,7 +230,7 @@ fn resolve_config_from_cli_config(
),
};

ServerConfig {
Ok(ServerConfig {
logging_format: resolve_value(
logging_format,
LOGGING_FORMAT_ENV,
Expand All @@ -237,7 +240,7 @@ fn resolve_config_from_cli_config(
chain: chain_config,
operations: operational_config,
keys: key_config,
}
})
}

fn resolve_value<T: FromStr<Err: Debug>>(value: Option<T>, env_var: &str, default: Option<T>) -> T {
Expand All @@ -263,3 +266,18 @@ fn resolve_value_map<T, Map: Fn(&str) -> anyhow::Result<T>>(
.expect("Missing required configuration")
})
}

fn check_token_config(token_config: &[TokenInfo]) -> Result<(), anyhow::Error> {
let mut kinds = HashSet::new();

for token in token_config {
if kinds.contains(&token.kind) {
return Err(anyhow!(
"Duplicate token kind {token:?} in token configuration"
Comment thread
obrok marked this conversation as resolved.
));
}
kinds.insert(token.kind);
}

Ok(())
}
7 changes: 5 additions & 2 deletions crates/shielder-relayer/src/config/tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use alloy_primitives::address;
use anyhow::Result;
use assert2::assert;
use rust_decimal::Decimal;
use shielder_relayer::{RELAYER_PORT_ENV, RELAYER_SIGNING_KEYS_ENV};
Expand All @@ -12,7 +13,7 @@ fn verify_cli() {
}

#[test]
fn config_resolution() {
fn config_resolution() -> Result<()> {
// ---- Target configuration. --------------------------------------------------------------
let logging_format = LoggingFormat::Json;
let host = DEFAULT_HOST.to_string();
Expand Down Expand Up @@ -138,6 +139,8 @@ fn config_resolution() {
}

// ---- Test. ------------------------------------------------------------------------------
let resolved_config = resolve_config_from_cli_config(cli_config);
let resolved_config = resolve_config_from_cli_config(cli_config)?;
assert!(resolved_config == expected_config);

Ok(())
}
2 changes: 1 addition & 1 deletion crates/shielder-relayer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ struct ApiDoc;

#[tokio::main]
async fn main() -> Result<()> {
let server_config = resolve_config();
let server_config = resolve_config()?;
init_logging(server_config.logging_format)?;

info!("Starting Shielder relayer.");
Expand Down
Loading