Skip to content

Commit

Permalink
feat(da-clients): add Celestia client
Browse files Browse the repository at this point in the history
  • Loading branch information
dimazhornyk committed Sep 25, 2024
1 parent 46e7348 commit f7d2ccb
Show file tree
Hide file tree
Showing 31 changed files with 1,217 additions and 249 deletions.
872 changes: 810 additions & 62 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ subxt-metadata = "0.34.0"
parity-scale-codec = { version = "3.6.9", default-features = false }
subxt-signer = { version = "0.34", default-features = false }

# Celestia
celestia-rpc = "0.4.1"
celestia-types = "0.5.0"

# Here and below:
# We *always* pin the latest version of protocol to disallow accidental changes in the execution logic.
# However, for the historical version of protocol crates, we have lax requirements. Otherwise,
Expand Down
2 changes: 0 additions & 2 deletions core/bin/zksync_server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use zksync_config::{
},
fri_prover_group::FriProverGroupConfig,
house_keeper::HouseKeeperConfig,
secrets::DataAvailabilitySecrets,
BasicWitnessInputProducerConfig, ContractsConfig, DatabaseSecrets, ExperimentalVmConfig,
ExternalPriceApiClientConfig, FriProofCompressorConfig, FriProverConfig,
FriProverGatewayConfig, FriWitnessGeneratorConfig, FriWitnessVectorGeneratorConfig,
Expand Down Expand Up @@ -127,7 +126,6 @@ fn main() -> anyhow::Result<()> {
consensus: config::read_consensus_secrets().context("read_consensus_secrets()")?,
database: DatabaseSecrets::from_env().ok(),
l1: L1Secrets::from_env().ok(),
data_availability: DataAvailabilitySecrets::from_env().ok(),
},
};

Expand Down
18 changes: 10 additions & 8 deletions core/bin/zksync_server/src/node_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
use anyhow::Context;
use zksync_config::{
configs::{
da_client::DAClientConfig, eth_sender::PubdataSendingMode,
secrets::DataAvailabilitySecrets, wallets::Wallets, GeneralConfig, Secrets,
da_client::DAClientConfig, eth_sender::PubdataSendingMode, wallets::Wallets, GeneralConfig,
Secrets,
},
ContractsConfig, GenesisConfig,
};
Expand All @@ -28,7 +28,7 @@ use zksync_node_framework::{
consensus::MainNodeConsensusLayer,
contract_verification_api::ContractVerificationApiLayer,
da_clients::{
avail::AvailWiringLayer, no_da::NoDAClientWiringLayer,
avail::AvailWiringLayer, celestia::CelestiaWiringLayer, no_da::NoDAClientWiringLayer,
object_store::ObjectStorageClientWiringLayer,
},
da_dispatcher::DataAvailabilityDispatcherLayer,
Expand Down Expand Up @@ -509,14 +509,16 @@ impl MainNodeBuilder {
return Ok(self);
};

let secrets = try_load_config!(self.secrets.data_availability);
match da_client_config {
DAClientConfig::Avail(config) => {
self.node.add_layer(AvailWiringLayer::new(config));
}

match (da_client_config, secrets) {
(DAClientConfig::Avail(config), DataAvailabilitySecrets::Avail(secret)) => {
self.node.add_layer(AvailWiringLayer::new(config, secret));
DAClientConfig::Celestia(config) => {
self.node.add_layer(CelestiaWiringLayer::new(config));
}

(DAClientConfig::ObjectStore(config), _) => {
DAClientConfig::ObjectStore(config) => {
self.node
.add_layer(ObjectStorageClientWiringLayer::new(config));
}
Expand Down
2 changes: 1 addition & 1 deletion core/lib/basic_types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub mod commitment;
pub mod network;
pub mod protocol_version;
pub mod prover_dal;
pub mod seed_phrase;
pub mod secrets;
pub mod settlement;
pub mod tee_types;
pub mod url;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,20 @@ impl FromStr for SeedPhrase {
Ok(SeedPhrase(s.parse()?))
}
}

#[derive(Debug, Clone)]
pub struct PrivateKey(pub Secret<String>);

impl PartialEq for PrivateKey {
fn eq(&self, other: &Self) -> bool {
self.0.expose_secret().eq(other.0.expose_secret())
}
}

impl FromStr for PrivateKey {
type Err = anyhow::Error;

fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(PrivateKey(s.parse()?))
}
}
8 changes: 5 additions & 3 deletions core/lib/config/src/configs/da_client/avail.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
use serde::Deserialize;
use zksync_basic_types::seed_phrase::SeedPhrase;
use zksync_basic_types::secrets::SeedPhrase;

#[derive(Clone, Debug, PartialEq, Deserialize)]
#[derive(Clone, Debug, Default, PartialEq, Deserialize)]
pub struct AvailConfig {
pub api_node_url: String,
pub bridge_api_url: String,
pub app_id: u32,
pub timeout: usize,
pub max_retries: usize,
#[serde(skip)]
pub secrets: Option<AvailSecrets>,
}

#[derive(Clone, Debug, PartialEq)]
pub struct AvailSecrets {
pub seed_phrase: Option<SeedPhrase>,
pub seed_phrase: SeedPhrase,
}
15 changes: 15 additions & 0 deletions core/lib/config/src/configs/da_client/celestia.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use serde::Deserialize;
use zksync_basic_types::secrets::PrivateKey;

#[derive(Clone, Debug, Default, PartialEq, Deserialize)]
pub struct CelestiaConfig {
pub api_node_url: String,
pub namespace: String,
#[serde(skip)]
pub secrets: Option<CelestiaSecrets>,
}

#[derive(Clone, Debug, PartialEq)]
pub struct CelestiaSecrets {
pub private_key: PrivateKey,
}
5 changes: 4 additions & 1 deletion core/lib/config/src/configs/da_client/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
use crate::{AvailConfig, ObjectStoreConfig};
use crate::{AvailConfig, CelestiaConfig, ObjectStoreConfig};

pub mod avail;
pub mod celestia;

pub const AVAIL_CLIENT_CONFIG_NAME: &str = "Avail";
pub const CELESTIA_CLIENT_CONFIG_NAME: &str = "Celestia";
pub const OBJECT_STORE_CLIENT_CONFIG_NAME: &str = "ObjectStore";

#[derive(Debug, Clone, PartialEq)]
pub enum DAClientConfig {
Avail(AvailConfig),
Celestia(CelestiaConfig),
ObjectStore(ObjectStoreConfig),
}
2 changes: 1 addition & 1 deletion core/lib/config/src/configs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub use self::{
commitment_generator::CommitmentGeneratorConfig,
contract_verifier::ContractVerifierConfig,
contracts::{ContractsConfig, EcosystemContracts},
da_client::{avail::AvailConfig, DAClientConfig},
da_client::{avail::AvailConfig, celestia::CelestiaConfig, DAClientConfig},
da_dispatcher::DADispatcherConfig,
database::{DBConfig, PostgresConfig},
eth_sender::{EthConfig, GasAdjusterConfig},
Expand Down
8 changes: 1 addition & 7 deletions core/lib/config/src/configs/secrets.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use anyhow::Context;
use zksync_basic_types::url::SensitiveUrl;

use crate::configs::{consensus::ConsensusSecrets, da_client::avail::AvailSecrets};
use crate::configs::consensus::ConsensusSecrets;

#[derive(Debug, Clone, PartialEq)]
pub struct DatabaseSecrets {
Expand All @@ -15,17 +15,11 @@ pub struct L1Secrets {
pub l1_rpc_url: SensitiveUrl,
}

#[derive(Debug, Clone, PartialEq)]
pub enum DataAvailabilitySecrets {
Avail(AvailSecrets),
}

#[derive(Debug, Clone, PartialEq)]
pub struct Secrets {
pub consensus: Option<ConsensusSecrets>,
pub database: Option<DatabaseSecrets>,
pub l1: Option<L1Secrets>,
pub data_availability: Option<DataAvailabilitySecrets>,
}

impl DatabaseSecrets {
Expand Down
4 changes: 2 additions & 2 deletions core/lib/config/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#![allow(clippy::upper_case_acronyms, clippy::derive_partial_eq_without_eq)]

pub use crate::configs::{
ApiConfig, AvailConfig, BaseTokenAdjusterConfig, ContractVerifierConfig, ContractsConfig,
DAClientConfig, DADispatcherConfig, DBConfig, EthConfig, EthWatchConfig,
ApiConfig, AvailConfig, BaseTokenAdjusterConfig, CelestiaConfig, ContractVerifierConfig,
ContractsConfig, DAClientConfig, DADispatcherConfig, DBConfig, EthConfig, EthWatchConfig,
ExternalProofIntegrationApiConfig, GasAdjusterConfig, GenesisConfig, ObjectStoreConfig,
PostgresConfig, SnapshotsCreatorConfig,
};
Expand Down
13 changes: 4 additions & 9 deletions core/lib/config/src/testonly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use zksync_basic_types::{
commitment::L1BatchCommitmentMode,
network::Network,
protocol_version::{ProtocolSemanticVersion, ProtocolVersionId, VersionPatch},
seed_phrase::SeedPhrase,
secrets::SeedPhrase,
vm::FastVmMode,
L1BatchNumber, L1ChainId, L2ChainId,
};
Expand Down Expand Up @@ -865,7 +865,6 @@ impl Distribution<configs::secrets::Secrets> for EncodeDist {
consensus: self.sample_opt(|| self.sample(rng)),
database: self.sample_opt(|| self.sample(rng)),
l1: self.sample_opt(|| self.sample(rng)),
data_availability: self.sample_opt(|| self.sample(rng)),
}
}
}
Expand Down Expand Up @@ -943,14 +942,10 @@ impl Distribution<configs::da_client::DAClientConfig> for EncodeDist {
app_id: self.sample(rng),
timeout: self.sample(rng),
max_retries: self.sample(rng),
})
}
}

impl Distribution<configs::secrets::DataAvailabilitySecrets> for EncodeDist {
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> configs::secrets::DataAvailabilitySecrets {
configs::secrets::DataAvailabilitySecrets::Avail(configs::da_client::avail::AvailSecrets {
seed_phrase: Some(SeedPhrase(Secret::new(self.sample(rng)))),
secrets: Some(configs::da_client::avail::AvailSecrets {
seed_phrase: SeedPhrase(Secret::new(self.sample(rng))),
}),
})
}
}
Expand Down
Loading

0 comments on commit f7d2ccb

Please sign in to comment.