Skip to content

Commit

Permalink
add final functional changes
Browse files Browse the repository at this point in the history
  • Loading branch information
dimazhornyk committed Jan 8, 2025
1 parent cf10dbc commit efa567a
Show file tree
Hide file tree
Showing 15 changed files with 205 additions and 107 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions core/bin/external_node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ zksync_dal.workspace = true
zksync_db_connection.workspace = true
zksync_config.workspace = true
zksync_protobuf_config.workspace = true
zksync_env_config.workspace = true
zksync_eth_client.workspace = true
zksync_storage.workspace = true
zksync_state.workspace = true
Expand Down
17 changes: 15 additions & 2 deletions core/bin/external_node/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@ use zksync_config::{
api::{MaxResponseSize, MaxResponseSizeOverrides},
consensus::{ConsensusConfig, ConsensusSecrets},
en_config::ENConfig,
GeneralConfig, Secrets,
DataAvailabilitySecrets, GeneralConfig, Secrets,
},
ObjectStoreConfig,
DAClientConfig, ObjectStoreConfig,
};
use zksync_consensus_crypto::TextFmt;
use zksync_consensus_roles as roles;
use zksync_core_leftovers::temp_config_store::read_yaml_repr;
#[cfg(test)]
use zksync_dal::{ConnectionPool, Core};
use zksync_env_config::FromEnv;
use zksync_metadata_calculator::MetadataCalculatorRecoveryConfig;
use zksync_node_api_server::{
tx_sender::{TimestampAsserterParams, TxSenderConfig},
Expand Down Expand Up @@ -1300,6 +1301,7 @@ pub(crate) struct ExternalNodeConfig<R = RemoteENConfig> {
pub consensus_secrets: Option<ConsensusSecrets>,
pub api_component: ApiComponentConfig,
pub tree_component: TreeComponentConfig,
pub data_availability: (Option<DAClientConfig>, Option<DataAvailabilitySecrets>),
pub remote: R,
}

Expand All @@ -1323,6 +1325,10 @@ impl ExternalNodeConfig<()> {
.context("could not load external node config (tree component params)")?,
consensus_secrets: read_consensus_secrets()
.context("config::read_consensus_secrets()")?,
data_availability: (
DAClientConfig::from_env().ok(),
DataAvailabilitySecrets::from_env().ok(),
),
remote: (),
})
}
Expand Down Expand Up @@ -1375,6 +1381,10 @@ impl ExternalNodeConfig<()> {

let api_component = ApiComponentConfig::from_configs(&general_config);
let tree_component = TreeComponentConfig::from_configs(&general_config);
let data_availability = (
general_config.da_client_config,
secrets_config.data_availability,
);

Ok(Self {
required,
Expand All @@ -1386,6 +1396,7 @@ impl ExternalNodeConfig<()> {
api_component,
tree_component,
consensus_secrets,
data_availability,
remote: (),
})
}
Expand Down Expand Up @@ -1421,6 +1432,7 @@ impl ExternalNodeConfig<()> {
tree_component: self.tree_component,
api_component: self.api_component,
consensus_secrets: self.consensus_secrets,
data_availability: (None, None),
remote,
})
}
Expand All @@ -1442,6 +1454,7 @@ impl ExternalNodeConfig {
tree_api_remote_url: None,
},
tree_component: TreeComponentConfig { api_port: None },
data_availability: (None, None),
}
}

Expand Down
44 changes: 41 additions & 3 deletions core/bin/external_node/src/node_builder.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
//! This module provides a "builder" for the external node,
//! as well as an interface to run the node with the specified components.
use anyhow::Context as _;
use anyhow::{bail, Context as _};
use zksync_block_reverter::NodeRole;
use zksync_config::{
configs::{
api::{HealthCheckConfig, MerkleTreeApiConfig},
database::MerkleTreeMode,
DatabaseSecrets,
DataAvailabilitySecrets, DatabaseSecrets,
},
PostgresConfig,
DAClientConfig, PostgresConfig,
};
use zksync_metadata_calculator::{
MerkleTreeReaderConfig, MetadataCalculatorConfig, MetadataCalculatorRecoveryConfig,
Expand All @@ -22,6 +22,10 @@ use zksync_node_framework::{
commitment_generator::CommitmentGeneratorLayer,
consensus::ExternalNodeConsensusLayer,
consistency_checker::ConsistencyCheckerLayer,
da_clients::{
avail::AvailWiringLayer, celestia::CelestiaWiringLayer, eigen::EigenWiringLayer,
no_da::NoDAClientWiringLayer, object_store::ObjectStorageClientWiringLayer,
},
data_availability_fetcher::DataAvailabilityFetcherLayer,
healtcheck_server::HealthCheckLayer,
l1_batch_commitment_mode_validation::L1BatchCommitmentModeValidationLayer,
Expand Down Expand Up @@ -338,6 +342,40 @@ impl ExternalNodeBuilder {
Ok(self)
}

fn add_da_client_layer(mut self) -> anyhow::Result<Self> {
let (da_client_config, da_client_secrets) = self.config.data_availability.clone();
let Some(da_client_config) = da_client_config else {
bail!("DA client config is missing");
};

let Some(da_client_secrets) = da_client_secrets else {
bail!("DA client secrets are missing");
};

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

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

(DAClientConfig::Eigen(config), DataAvailabilitySecrets::Eigen(secret)) => {
self.node.add_layer(EigenWiringLayer::new(config, secret));
}

(DAClientConfig::ObjectStore(config), _) => {
self.node
.add_layer(ObjectStorageClientWiringLayer::new(config));
}
_ => bail!("invalid pair of da_client and da_secrets"),
}

Ok(self)
}

fn add_data_availability_fetcher_layer(mut self) -> anyhow::Result<Self> {
let layer = DataAvailabilityFetcherLayer::new();
self.node.add_layer(layer);
Expand Down

This file was deleted.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions core/lib/dal/src/data_availability_dal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use zksync_types::{
};

use crate::{
models::storage_data_availability::{L1BatchDA, StorageDABlob},
models::storage_data_availability::{L1BatchDA, StorageDABlob, StorageDADetails},
Core,
};

Expand Down Expand Up @@ -238,11 +238,11 @@ impl DataAvailabilityDal<'_, '_> {
number: L1BatchNumber,
) -> DalResult<Option<DataAvailabilityDetails>> {
Ok(sqlx::query_as!(
StorageDABlob,
StorageDADetails,
r#"
SELECT
l1_batch_number,
blob_id,
client_type,
inclusion_data,
sent_at
FROM
Expand All @@ -256,7 +256,7 @@ impl DataAvailabilityDal<'_, '_> {
.with_arg("number", &number)
.fetch_optional(self.storage)
.await?
.map(DataAvailabilityBlob::from))
.map(DataAvailabilityDetails::from))
}

pub async fn get_latest_batch_with_inclusion_data(
Expand Down
1 change: 1 addition & 0 deletions core/node/api_server/src/web3/backend_jsonrpsee/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ impl MethodTracer {
| Web3Error::TooManyTopics
| Web3Error::FilterNotFound
| Web3Error::InvalidFilterBlockHash
| Web3Error::InvalidPubdataCommitmentMode(_)
| Web3Error::LogsLimitExceeded(_, _, _) => ErrorCode::InvalidParams.code(),
Web3Error::SubmitTransactionError(_, _)
| Web3Error::SerializationError(_)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ impl ZksNamespaceServer for ZksNamespace {
batch: L1BatchNumber,
) -> RpcResult<DataAvailabilityDetails> {
self.get_data_availability_details_impl(batch)
.await
.map_err(|err| self.current_method().map_err(err))
}
}

Expand Down
2 changes: 2 additions & 0 deletions core/node/api_server/src/web3/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ enum Web3ErrorKind {
InvalidFilterBlockHash,
TreeApiUnavailable,
Internal,
InvalidPubdataCommitmentMode,
}

impl Web3ErrorKind {
Expand All @@ -188,6 +189,7 @@ impl Web3ErrorKind {
Web3Error::InvalidFilterBlockHash => Self::InvalidFilterBlockHash,
Web3Error::TreeApiUnavailable => Self::TreeApiUnavailable,
Web3Error::InternalError(_) | Web3Error::MethodNotImplemented => Self::Internal,
Web3Error::InvalidPubdataCommitmentMode(_) => Self::InvalidPubdataCommitmentMode,
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ use crate::{

/// Wiring layer for [`DataAvailabilityFetcher`].
#[derive(Debug)]
pub struct DataAvailabilityFetcherLayer {
l1_diamond_proxy_addr: Address,
l2_chain_id: L2ChainId,
}
pub struct DataAvailabilityFetcherLayer {}

#[derive(Debug, FromContext)]
#[context(crate = crate)]
Expand All @@ -41,11 +38,8 @@ pub struct Output {
}

impl DataAvailabilityFetcherLayer {
pub fn new(l1_diamond_proxy_addr: Address, l2_chain_id: L2ChainId) -> Self {
Self {
l1_diamond_proxy_addr,
l2_chain_id,
}
pub fn new() -> Self {
Self {}
}
}

Expand Down
Loading

0 comments on commit efa567a

Please sign in to comment.