Skip to content

Commit

Permalink
Change proxy name and remove generic
Browse files Browse the repository at this point in the history
  • Loading branch information
gianbelinche committed Dec 13, 2024
1 parent 051c661 commit 7bef5b3
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 37 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/node/da_clients/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,4 @@ pbjson-types.workspace = true

# Eigen dependencies
eigenda-client-rs.workspace = true
zksync_dal.workspace = true
40 changes: 32 additions & 8 deletions core/node/da_clients/src/eigen/client.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<T: GetBlobData> {
client: EigenClient<T>,
pub struct EigenDAClient {
client: EigenClient<GetBlobFromDB>,
}
impl<T: GetBlobData> EigenClientProxy<T> {
impl EigenDAClient {
pub async fn new(
config: EigenConfig,
secrets: EigenSecrets,
get_blob_data: Box<T>,
pool: ConnectionPool<Core>,
) -> anyhow::Result<Self> {
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,
Expand All @@ -35,15 +38,36 @@ impl<T: GetBlobData> EigenClientProxy<T> {
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<Core>,
}

#[async_trait::async_trait]
impl GetBlobData for GetBlobFromDB {
async fn call(&self, input: &'_ str) -> Result<Option<Vec<u8>>, Box<dyn Error + Send + Sync>> {
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<T: GetBlobData + 'static> DataAvailabilityClient for EigenClientProxy<T> {
impl DataAvailabilityClient for EigenDAClient {
async fn dispatch_blob(
&self,
_: u32, // batch number
Expand Down
2 changes: 1 addition & 1 deletion core/node/da_clients/src/eigen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ mod client;

pub use eigenda_client_rs::client::GetBlobData;

pub use self::client::EigenClientProxy;
pub use self::client::EigenDAClient;
Original file line number Diff line number Diff line change
@@ -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::{
Expand Down Expand Up @@ -50,33 +47,11 @@ impl WiringLayer for EigenWiringLayer {

async fn wire(self, input: Self::Input) -> Result<Self::Output, WiringError> {
let master_pool = input.master_pool.get().await?;
let get_blob_from_db = GetBlobFromDB { pool: master_pool };
let client: Box<dyn DataAvailabilityClient> = Box::new(
EigenClientProxy::new(self.config, self.secrets, Box::new(get_blob_from_db)).await?,
);
let client: Box<dyn DataAvailabilityClient> =
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<Core>,
}

#[async_trait::async_trait]
impl GetBlobData for GetBlobFromDB {
async fn call(&self, input: &'_ str) -> Result<Option<Vec<u8>>, Box<dyn Error + Send + Sync>> {
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))
}
}

0 comments on commit 7bef5b3

Please sign in to comment.