diff --git a/core/lib/config/src/configs/da_client/avail.rs b/core/lib/config/src/configs/da_client/avail.rs index c5afd31eedfa..d6ec4861b487 100644 --- a/core/lib/config/src/configs/da_client/avail.rs +++ b/core/lib/config/src/configs/da_client/avail.rs @@ -1,10 +1,13 @@ use serde::Deserialize; -use zksync_basic_types::api_key::APIKey; -use zksync_basic_types::seed_phrase::SeedPhrase; +use zksync_basic_types::{api_key::APIKey, seed_phrase::SeedPhrase}; + +pub const AVAIL_GAS_RELAY_CLIENT_NAME: &str = "GasRelay"; +pub const AVAIL_FULL_CLIENT_NAME: &str = "FullClient"; #[derive(Clone, Debug, PartialEq, Deserialize)] +#[serde(tag = "avail_client")] pub enum AvailClientConfig { - Default(AvailDefaultConfig), + FullClient(AvailDefaultConfig), GasRelay(AvailGasRelayConfig), } @@ -12,6 +15,7 @@ pub enum AvailClientConfig { pub struct AvailConfig { pub bridge_api_url: String, pub timeout: usize, + #[serde(flatten)] pub config: AvailClientConfig, } diff --git a/core/lib/config/src/testonly.rs b/core/lib/config/src/testonly.rs index fb8efb739f48..0d6cddbcbe92 100644 --- a/core/lib/config/src/testonly.rs +++ b/core/lib/config/src/testonly.rs @@ -953,7 +953,7 @@ impl Distribution for EncodeDist { Avail(AvailConfig { bridge_api_url: self.sample(rng), timeout: self.sample(rng), - config: AvailClientConfig::Default(AvailDefaultConfig { + config: AvailClientConfig::FullClient(AvailDefaultConfig { api_node_url: self.sample(rng), app_id: self.sample(rng), }), diff --git a/core/lib/env_config/src/da_client.rs b/core/lib/env_config/src/da_client.rs index d07ffdabd374..bf1c3121f16f 100644 --- a/core/lib/env_config/src/da_client.rs +++ b/core/lib/env_config/src/da_client.rs @@ -2,19 +2,35 @@ use std::env; use zksync_config::configs::{ da_client::{ - avail::AvailSecrets, DAClientConfig, AVAIL_CLIENT_CONFIG_NAME, - OBJECT_STORE_CLIENT_CONFIG_NAME, + avail::{ + AvailClientConfig, AvailSecrets, AVAIL_FULL_CLIENT_NAME, AVAIL_GAS_RELAY_CLIENT_NAME, + }, + DAClientConfig, AVAIL_CLIENT_CONFIG_NAME, OBJECT_STORE_CLIENT_CONFIG_NAME, }, secrets::DataAvailabilitySecrets, + AvailConfig, }; use crate::{envy_load, FromEnv}; impl FromEnv for DAClientConfig { fn from_env() -> anyhow::Result { - let client_tag = std::env::var("DA_CLIENT")?; + let client_tag = env::var("DA_CLIENT")?; let config = match client_tag.as_str() { - AVAIL_CLIENT_CONFIG_NAME => Self::Avail(envy_load("da_avail_config", "DA_")?), + AVAIL_CLIENT_CONFIG_NAME => Self::Avail(AvailConfig { + bridge_api_url: env::var("DA_BRIDGE_API_URL").ok().unwrap(), + timeout: env::var("DA_TIMEOUT")?.parse()?, + + config: match env::var("DA_AVAIL_CLIENT_TYPE")?.as_str() { + AVAIL_FULL_CLIENT_NAME => { + AvailClientConfig::FullClient(envy_load("da_avail_full_client", "DA_")?) + } + AVAIL_GAS_RELAY_CLIENT_NAME => { + AvailClientConfig::GasRelay(envy_load("da_avail_gas_relay", "DA_")?) + } + _ => anyhow::bail!("Unknown Avail DA client type"), + }, + }), OBJECT_STORE_CLIENT_CONFIG_NAME => { Self::ObjectStore(envy_load("da_object_store", "DA_")?) } @@ -33,13 +49,11 @@ impl FromEnv for DataAvailabilitySecrets { let seed_phrase: Option = env::var("DA_SECRETS_SEED_PHRASE") .ok() - .map(|s| s.parse()) - .transpose()?; + .map(|s| s.parse().unwrap()); let gas_relay_api_key: Option = env::var("DA_SECRETS_GAS_RELAY_API_KEY") .ok() - .map(|s| s.parse()) - .transpose()?; + .map(|s| s.parse().unwrap()); if seed_phrase.is_none() && gas_relay_api_key.is_none() { anyhow::bail!("No secrets provided for Avail DA client"); } @@ -110,7 +124,7 @@ mod tests { DAClientConfig::Avail(AvailConfig { bridge_api_url: bridge_api_url.to_string(), timeout, - config: AvailClientConfig::Default(AvailDefaultConfig { + config: AvailClientConfig::FullClient(AvailDefaultConfig { api_node_url: api_node_url.to_string(), app_id, }), @@ -122,10 +136,13 @@ mod tests { let mut lock = MUTEX.lock(); let config = r#" DA_CLIENT="Avail" - DA_API_NODE_URL="localhost:12345" + DA_AVAIL_CLIENT_TYPE="FullClient" + DA_BRIDGE_API_URL="localhost:54321" - DA_APP_ID="1" DA_TIMEOUT="2" + + DA_API_NODE_URL="localhost:12345" + DA_APP_ID="1" "#; lock.set_env(config); @@ -148,7 +165,6 @@ mod tests { let config = r#" DA_CLIENT="Avail" DA_SECRETS_SEED_PHRASE="bottom drive obey lake curtain smoke basket hold race lonely fit walk" - DA_SECRETS_GAS_RELAY_API_KEY="abcdefghijklmnopqrstuvwxyz0123456789" "#; lock.set_env(config); @@ -158,12 +174,12 @@ mod tests { }; assert_eq!( - (actual_seed.unwrap(), actual_key.unwrap()), + (actual_seed.unwrap(), actual_key), ( "bottom drive obey lake curtain smoke basket hold race lonely fit walk" .parse() .unwrap(), - "abcdefghijklmnopqrstuvwxyz0123456789".parse().unwrap() + None ) ); } diff --git a/core/lib/protobuf_config/src/da_client.rs b/core/lib/protobuf_config/src/da_client.rs index 98247ff5adab..a398624bbc5d 100644 --- a/core/lib/protobuf_config/src/da_client.rs +++ b/core/lib/protobuf_config/src/da_client.rs @@ -19,18 +19,20 @@ impl ProtoRepr for proto::DataAvailabilityClient { let client = match config { proto::data_availability_client::Config::Avail(conf) => { Avail(match conf.config.as_ref() { - Some(proto::avail_config::Config::Default(default_conf)) => AvailConfig { - bridge_api_url: required(&conf.bridge_api_url) - .context("bridge_api_url")? - .clone(), - timeout: *required(&conf.timeout).context("timeout")? as usize, - config: AvailClientConfig::Default(AvailDefaultConfig { - api_node_url: required(&default_conf.api_node_url) - .context("api_node_url")? + Some(proto::avail_config::Config::FullClient(full_client__conf)) => { + AvailConfig { + bridge_api_url: required(&conf.bridge_api_url) + .context("bridge_api_url")? .clone(), - app_id: *required(&default_conf.app_id).context("app_id")?, - }), - }, + timeout: *required(&conf.timeout).context("timeout")? as usize, + config: AvailClientConfig::FullClient(AvailDefaultConfig { + api_node_url: required(&full_client__conf.api_node_url) + .context("api_node_url")? + .clone(), + app_id: *required(&full_client__conf.app_id).context("app_id")?, + }), + } + } Some(proto::avail_config::Config::GasRelay(gas_relay_conf)) => AvailConfig { bridge_api_url: required(&conf.bridge_api_url) .context("bridge_api_url")? @@ -61,8 +63,8 @@ impl ProtoRepr for proto::DataAvailabilityClient { bridge_api_url: Some(config.bridge_api_url.clone()), timeout: Some(config.timeout as u64), config: match &config.config { - AvailClientConfig::Default(conf) => Some( - proto::avail_config::Config::Default(proto::AvailDefaultConfig { + AvailClientConfig::FullClient(conf) => Some( + proto::avail_config::Config::FullClient(proto::AvailClientConfig { api_node_url: Some(conf.api_node_url.clone()), app_id: Some(conf.app_id), }), diff --git a/core/lib/protobuf_config/src/proto/config/da_client.proto b/core/lib/protobuf_config/src/proto/config/da_client.proto index e98886355789..1dadc22c2685 100644 --- a/core/lib/protobuf_config/src/proto/config/da_client.proto +++ b/core/lib/protobuf_config/src/proto/config/da_client.proto @@ -5,26 +5,25 @@ package zksync.config.da_client; import "zksync/config/object_store.proto"; message AvailConfig { - optional string bridge_api_url = 1; - optional uint64 timeout = 2; + optional string bridge_api_url = 2; + optional uint64 timeout = 5; oneof config { - AvailDefaultConfig default = 4; - AvailGasRelayConfig gas_relay = 5; + AvailClientConfig full_client = 7; + AvailGasRelayConfig gas_relay = 8; } - reserved 3; - reserved "seed"; - reserved 6; - reserved "max_retries"; + reserved 1; reserved "api_node_url"; + reserved 3; reserved "seed"; + reserved 4; reserved "app_id"; + reserved 6; reserved "max_retries"; } -message AvailDefaultConfig { +message AvailClientConfig { optional string api_node_url = 1; optional uint32 app_id = 2; } message AvailGasRelayConfig { optional string gas_relay_api_url = 1; - reserved "gas_relay_api_key"; } message DataAvailabilityClient { diff --git a/core/node/da_clients/src/avail/client.rs b/core/node/da_clients/src/avail/client.rs index 5515978f3d65..5efcb64befd7 100644 --- a/core/node/da_clients/src/avail/client.rs +++ b/core/node/da_clients/src/avail/client.rs @@ -1,8 +1,9 @@ +use std::{fmt::Debug, sync::Arc}; + use anyhow::anyhow; use async_trait::async_trait; use jsonrpsee::ws_client::WsClientBuilder; use serde::{Deserialize, Serialize}; -use std::{fmt::Debug, sync::Arc}; use subxt_signer::ExposeSecret; use zksync_config::configs::da_client::avail::{AvailClientConfig, AvailConfig, AvailSecrets}; use zksync_da_client::{ @@ -111,7 +112,7 @@ impl AvailClient { api_client, }) } - AvailClientConfig::Default(conf) => { + AvailClientConfig::FullClient(conf) => { let seed_phrase = secrets .seed_phrase .ok_or_else(|| anyhow::anyhow!("Seed phrase is missing"))?; @@ -139,7 +140,7 @@ impl DataAvailabilityClient for AvailClient { match self.sdk_client.as_ref() { AvailClientMode::Default(client) => { let default_config = match &self.config.config { - AvailClientConfig::Default(conf) => conf, + AvailClientConfig::FullClient(conf) => conf, _ => unreachable!(), // validated in protobuf config }; let ws_client = WsClientBuilder::default()