From 7bef5b395520e3733134448d7f4f835547277817 Mon Sep 17 00:00:00 2001 From: Gianbelinche <39842759+gianbelinche@users.noreply.github.com> Date: Fri, 13 Dec 2024 16:42:36 -0300 Subject: [PATCH] Change proxy name and remove generic --- Cargo.lock | 1 + core/node/da_clients/Cargo.toml | 1 + core/node/da_clients/src/eigen/client.rs | 40 +++++++++++++++---- core/node/da_clients/src/eigen/mod.rs | 2 +- .../layers/da_clients/eigen.rs | 31 ++------------ 5 files changed, 38 insertions(+), 37 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8e2efd511741..efe8e0bb0b71 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -12646,6 +12646,7 @@ dependencies = [ "zksync_basic_types", "zksync_config", "zksync_da_client", + "zksync_dal", "zksync_env_config", "zksync_object_store", "zksync_types", diff --git a/core/node/da_clients/Cargo.toml b/core/node/da_clients/Cargo.toml index f6ed907eea49..8776db81546c 100644 --- a/core/node/da_clients/Cargo.toml +++ b/core/node/da_clients/Cargo.toml @@ -55,3 +55,4 @@ pbjson-types.workspace = true # Eigen dependencies eigenda-client-rs.workspace = true +zksync_dal.workspace = true diff --git a/core/node/da_clients/src/eigen/client.rs b/core/node/da_clients/src/eigen/client.rs index a070f1c42849..c48670fa56b9 100644 --- a/core/node/da_clients/src/eigen/client.rs +++ b/core/node/da_clients/src/eigen/client.rs @@ -1,4 +1,4 @@ -use std::str::FromStr; +use std::{error::Error, str::FromStr}; use eigenda_client_rs::{client::GetBlobData, EigenClient}; use subxt_signer::ExposeSecret; @@ -7,24 +7,27 @@ use zksync_da_client::{ types::{DAError, DispatchResponse, InclusionData}, DataAvailabilityClient, }; +use zksync_dal::{ConnectionPool, Core, CoreDal}; use crate::utils::to_retriable_da_error; // We can't implement DataAvailabilityClient for an outside struct, so it is needed to defined this intermediate struct #[derive(Debug, Clone)] -pub struct EigenClientProxy { - client: EigenClient, +pub struct EigenDAClient { + client: EigenClient, } -impl EigenClientProxy { +impl EigenDAClient { pub async fn new( config: EigenConfig, secrets: EigenSecrets, - get_blob_data: Box, + pool: ConnectionPool, ) -> anyhow::Result { let eigen_config = eigenda_client_rs::config::EigenConfig { disperser_rpc: config.disperser_rpc, settlement_layer_confirmation_depth: config.settlement_layer_confirmation_depth, - eigenda_eth_rpc: config.eigenda_eth_rpc, + eigenda_eth_rpc: config.eigenda_eth_rpc.ok_or(anyhow::anyhow!( + "eigenda_eth_rpc is required for EigenClient" + ))?, eigenda_svc_manager_address: config.eigenda_svc_manager_address, wait_for_finalization: config.wait_for_finalization, authenticated: config.authenticated, @@ -35,15 +38,36 @@ impl EigenClientProxy { eigenda_client_rs::config::PrivateKey::from_str(secrets.private_key.0.expose_secret()) .map_err(|_| anyhow::anyhow!("Invalid private key"))?; let eigen_secrets = eigenda_client_rs::config::EigenSecrets { private_key }; - let client = EigenClient::new(eigen_config, eigen_secrets, get_blob_data) + let get_blob_data = GetBlobFromDB { pool }; + let client = EigenClient::new(eigen_config, eigen_secrets, Box::new(get_blob_data)) .await .map_err(|e| anyhow::anyhow!("Eigen client Error: {:?}", e))?; Ok(Self { client }) } } +#[derive(Debug, Clone)] +pub struct GetBlobFromDB { + pool: ConnectionPool, +} + +#[async_trait::async_trait] +impl GetBlobData for GetBlobFromDB { + async fn call(&self, input: &'_ str) -> Result>, Box> { + let pool = self.pool.clone(); + let input = input.to_string(); + let mut conn = pool.connection_tagged("eigen_client").await?; + let batch = conn + .data_availability_dal() + .get_blob_data_by_blob_id(&input) + .await?; + drop(conn); + Ok(batch.map(|b| b.pubdata)) + } +} + #[async_trait::async_trait] -impl DataAvailabilityClient for EigenClientProxy { +impl DataAvailabilityClient for EigenDAClient { async fn dispatch_blob( &self, _: u32, // batch number diff --git a/core/node/da_clients/src/eigen/mod.rs b/core/node/da_clients/src/eigen/mod.rs index 64454dc2e8ca..e5300f44d0eb 100644 --- a/core/node/da_clients/src/eigen/mod.rs +++ b/core/node/da_clients/src/eigen/mod.rs @@ -2,4 +2,4 @@ mod client; pub use eigenda_client_rs::client::GetBlobData; -pub use self::client::EigenClientProxy; +pub use self::client::EigenDAClient; diff --git a/core/node/node_framework/src/implementations/layers/da_clients/eigen.rs b/core/node/node_framework/src/implementations/layers/da_clients/eigen.rs index 77f52a1e2767..92e4b82930f1 100644 --- a/core/node/node_framework/src/implementations/layers/da_clients/eigen.rs +++ b/core/node/node_framework/src/implementations/layers/da_clients/eigen.rs @@ -1,9 +1,6 @@ -use std::error::Error; - use zksync_config::{configs::da_client::eigen::EigenSecrets, EigenConfig}; use zksync_da_client::DataAvailabilityClient; -use zksync_da_clients::eigen::{EigenClientProxy, GetBlobData}; -use zksync_dal::{ConnectionPool, Core, CoreDal}; +use zksync_da_clients::eigen::EigenDAClient; use zksync_node_framework_derive::FromContext; use crate::{ @@ -50,33 +47,11 @@ impl WiringLayer for EigenWiringLayer { async fn wire(self, input: Self::Input) -> Result { let master_pool = input.master_pool.get().await?; - let get_blob_from_db = GetBlobFromDB { pool: master_pool }; - let client: Box = Box::new( - EigenClientProxy::new(self.config, self.secrets, Box::new(get_blob_from_db)).await?, - ); + let client: Box = + Box::new(EigenDAClient::new(self.config, self.secrets, master_pool).await?); Ok(Self::Output { client: DAClientResource(client), }) } } - -#[derive(Debug, Clone)] -pub struct GetBlobFromDB { - pool: ConnectionPool, -} - -#[async_trait::async_trait] -impl GetBlobData for GetBlobFromDB { - async fn call(&self, input: &'_ str) -> Result>, Box> { - let pool = self.pool.clone(); - let input = input.to_string(); - let mut conn = pool.connection_tagged("eigen_client").await?; - let batch = conn - .data_availability_dal() - .get_blob_data_by_blob_id(&input) - .await?; - drop(conn); - Ok(batch.map(|b| b.pubdata)) - } -}