Skip to content

Commit

Permalink
create verifier client trait
Browse files Browse the repository at this point in the history
  • Loading branch information
juan518munoz committed Nov 26, 2024
1 parent 799d762 commit 410ce91
Show file tree
Hide file tree
Showing 3 changed files with 277 additions and 219 deletions.
28 changes: 19 additions & 9 deletions core/node/da_clients/src/eigen/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ use super::{blob_info::BlobInfo, sdk::RawEigenClient};
use crate::utils::to_non_retriable_da_error;

/// EigenClient is a client for the Eigen DA service.
/// It can be configured to use one of two dispersal methods:
/// - Remote: Dispatch blobs to a remote Eigen service.
/// - Memstore: Stores blobs in memory, used for testing purposes.
#[derive(Debug, Clone)]
pub struct EigenClient {
client: Arc<RawEigenClient>,
Expand Down Expand Up @@ -83,12 +80,10 @@ impl DataAvailabilityClient for EigenClient {
}
}

#[cfg(test)]
impl EigenClient {
pub async fn get_blob_data(&self, blob_id: &str) -> anyhow::Result<Option<Vec<u8>>, DAError> {
self.client.get_blob_data(blob_id).await
}
}
/// EigenDA Client tests are ignored by default, because they require a remote dependency,
/// which may not always be available, causing tests to be flaky.
/// To run these tests, use the following command:
/// `cargo test -p zksync_da_clients -- --ignored`
#[cfg(test)]
mod tests {
use serial_test::serial;
Expand All @@ -97,6 +92,16 @@ mod tests {
use super::*;
use crate::eigen::blob_info::BlobInfo;

impl EigenClient {
pub async fn get_blob_data(
&self,
blob_id: &str,
) -> anyhow::Result<Option<Vec<u8>>, DAError> {
self.client.get_blob_data(blob_id).await
}
}

#[ignore = "remote dependency"]
#[tokio::test]
#[serial]
async fn test_non_auth_dispersal() {
Expand Down Expand Up @@ -137,6 +142,7 @@ mod tests {
assert_eq!(retrieved_data.unwrap(), data);
}

#[ignore = "remote dependency"]
#[tokio::test]
#[serial]
async fn test_auth_dispersal() {
Expand Down Expand Up @@ -177,6 +183,7 @@ mod tests {
assert_eq!(retrieved_data.unwrap(), data);
}

#[ignore = "remote dependency"]
#[tokio::test]
#[serial]
async fn test_wait_for_finalization() {
Expand Down Expand Up @@ -217,6 +224,7 @@ mod tests {
assert_eq!(retrieved_data.unwrap(), data);
}

#[ignore = "remote dependency"]
#[tokio::test]
async fn test_eigenda_dispatch_blob_too_large() {
let config = EigenConfig {
Expand Down Expand Up @@ -251,6 +259,7 @@ mod tests {
assert_eq!(format!("{}", actual_error), format!("{}", expected_error));
}

#[ignore = "remote dependency"]
#[tokio::test]
#[serial]
async fn test_eth_confirmation_depth() {
Expand Down Expand Up @@ -291,6 +300,7 @@ mod tests {
assert_eq!(retrieved_data.unwrap(), data);
}

#[ignore = "remote dependency"]
#[tokio::test]
#[serial]
async fn test_auth_dispersal_eth_confirmation_depth() {
Expand Down
33 changes: 31 additions & 2 deletions core/node/da_clients/src/eigen/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@ use tonic::{
use zksync_config::EigenConfig;
#[cfg(test)]
use zksync_da_client::types::DAError;
use zksync_eth_client::clients::PKSigningClient;
use zksync_types::{url::SensitiveUrl, K256PrivateKey, SLChainId, H160};
use zksync_web3_decl::client::{Client, DynClient, L1};

use super::{
blob_info::BlobInfo,
disperser::BlobInfo as DisperserBlobInfo,
verifier::{Verifier, VerifierConfig},
verifier::{VerificationError, Verifier, VerifierConfig},
};
use crate::eigen::{
blob_info,
Expand Down Expand Up @@ -58,7 +61,33 @@ impl RawEigenClient {
private_key: hex::encode(private_key.secret_bytes()),
chain_id: config.chain_id,
};
let verifier = Verifier::new(verifier_config)

let url = SensitiveUrl::from_str(&verifier_config.rpc_url)
.map_err(|_| VerificationError::WrongUrl)
.unwrap();
let query_client: Client<L1> = Client::http(url)
.map_err(|_| VerificationError::WrongUrl)
.unwrap()
.build();
let query_client = Box::new(query_client) as Box<DynClient<L1>>;
let signing_client = PKSigningClient::new_raw(
K256PrivateKey::from_bytes(
zksync_types::H256::from_str(&verifier_config.private_key)
.map_err(|_| VerificationError::ServiceManagerError)
.unwrap(),
)
.map_err(|_| VerificationError::ServiceManagerError)
.unwrap(),
H160::from_str(&verifier_config.svc_manager_addr)
.map_err(|_| VerificationError::ServiceManagerError)
.unwrap(),
Verifier::DEFAULT_PRIORITY_FEE_PER_GAS,
SLChainId(verifier_config.chain_id),
query_client,
);

// let verifier = Verifier::new(verifier_config, MockVerifierClient::new(HashMap::new()))
let verifier = Verifier::new(verifier_config, signing_client)
.map_err(|e| anyhow::anyhow!(format!("Failed to create verifier {:?}", e)))?;
Ok(RawEigenClient {
client,
Expand Down
Loading

0 comments on commit 410ce91

Please sign in to comment.