Skip to content

Commit

Permalink
feat(eigen-client-extra-features): address PR comments (part 2) (#374)
Browse files Browse the repository at this point in the history
* initial commit

* clippy suggestion

* feat(eigen-client-extra-features): address PR comments (part 3) (#376)

* use keccak256 fn

* simplify get_context_block

* use saturating sub

* feat(eigen-client-extra-features): address PR comments (part 4) (#378)

* Replace decode bytes for ethabi

* Add default to eigenconfig

* Change str to url

* Add index to data availability table

* Address comments

* Change error to verificationerror

* Format code

* feat(eigen-client-extra-features): address PR comments (part 5) (#377)

* use trait object

* prevent blocking non async code

* clippy suggestion

---------

Co-authored-by: juan518munoz <[email protected]>

---------

Co-authored-by: Gianbelinche <[email protected]>

---------

Co-authored-by: Gianbelinche <[email protected]>
  • Loading branch information
juan518munoz and gianbelinche authored Dec 19, 2024
1 parent d824eba commit bf2f818
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 168 deletions.
18 changes: 17 additions & 1 deletion core/lib/config/src/configs/da_client/eigen.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use serde::Deserialize;
use zksync_basic_types::secrets::PrivateKey;
/// Configuration for the EigenDA remote disperser client.
#[derive(Clone, Debug, PartialEq, Deserialize, Default)]
#[derive(Clone, Debug, PartialEq, Deserialize)]
pub struct EigenConfig {
/// URL of the Disperser RPC server
pub disperser_rpc: String,
Expand All @@ -24,6 +24,22 @@ pub struct EigenConfig {
pub chain_id: u64,
}

impl Default for EigenConfig {
fn default() -> Self {
Self {
disperser_rpc: "https://disperser-holesky.eigenda.xyz:443".to_string(),
settlement_layer_confirmation_depth: 0,
eigenda_eth_rpc: Some("https://ethereum-holesky-rpc.publicnode.com".to_string()),
eigenda_svc_manager_address: "0xD4A7E1Bd8015057293f0D0A557088c286942e84b".to_string(),
wait_for_finalization: false,
authenticated: false,
g1_url: "https://github.com/Layr-Labs/eigenda-proxy/raw/2fd70b99ef5bf137d7bbca3461cf9e1f2c899451/resources/g1.point".to_string(),
g2_url: "https://github.com/Layr-Labs/eigenda-proxy/raw/2fd70b99ef5bf137d7bbca3461cf9e1f2c899451/resources/g2.point.powerOf2".to_string(),
chain_id: 19000,
}
}
}

#[derive(Clone, Debug, PartialEq)]
pub struct EigenSecrets {
pub private_key: PrivateKey,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE INDEX idx_blob_id_l1_batch_number ON data_availability (blob_id, l1_batch_number);
4 changes: 3 additions & 1 deletion core/node/da_clients/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ ethabi.workspace = true
rust-kzg-bn254.workspace = true
ark-bn254.workspace = true
num-bigint.workspace = true
serial_test.workspace = true
zksync_web3_decl.workspace = true
zksync_eth_client.workspace = true
url.workspace = true

[dev-dependencies]
serial_test.workspace = true
16 changes: 9 additions & 7 deletions core/node/da_clients/src/eigen/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,23 @@ use super::sdk::RawEigenClient;
use crate::utils::to_retriable_da_error;

#[async_trait]
pub trait GetBlobData: Clone + std::fmt::Debug + Send + Sync {
pub trait GetBlobData: std::fmt::Debug + Send + Sync {
async fn get_blob_data(&self, input: &str) -> anyhow::Result<Option<Vec<u8>>>;

fn clone_boxed(&self) -> Box<dyn GetBlobData>;
}

/// EigenClient is a client for the Eigen DA service.
#[derive(Debug, Clone)]
pub struct EigenClient<T: GetBlobData> {
pub(crate) client: Arc<RawEigenClient<T>>,
pub struct EigenClient {
pub(crate) client: Arc<RawEigenClient>,
}

impl<T: GetBlobData> EigenClient<T> {
impl EigenClient {
pub async fn new(
config: EigenConfig,
secrets: EigenSecrets,
get_blob_data: Box<T>,
get_blob_data: Box<dyn GetBlobData>,
) -> anyhow::Result<Self> {
let private_key = SecretKey::from_str(secrets.private_key.0.expose_secret().as_str())
.map_err(|e| anyhow::anyhow!("Failed to parse private key: {}", e))?;
Expand All @@ -40,7 +42,7 @@ impl<T: GetBlobData> EigenClient<T> {
}

#[async_trait]
impl<T: GetBlobData + 'static> DataAvailabilityClient for EigenClient<T> {
impl DataAvailabilityClient for EigenClient {
async fn dispatch_blob(
&self,
_: u32, // batch number
Expand Down Expand Up @@ -75,6 +77,6 @@ impl<T: GetBlobData + 'static> DataAvailabilityClient for EigenClient<T> {
}

fn blob_size_limit(&self) -> Option<usize> {
Some(RawEigenClient::<T>::blob_size_limit())
Some(RawEigenClient::blob_size_limit())
}
}
10 changes: 7 additions & 3 deletions core/node/da_clients/src/eigen/client_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ mod tests {

use crate::eigen::{blob_info::BlobInfo, EigenClient, GetBlobData};

impl<T: GetBlobData> EigenClient<T> {
impl EigenClient {
pub async fn get_blob_data(
&self,
blob_id: BlobInfo,
Expand All @@ -32,8 +32,8 @@ mod tests {
const STATUS_QUERY_TIMEOUT: u64 = 1800000; // 30 minutes
const STATUS_QUERY_INTERVAL: u64 = 5; // 5 ms

async fn get_blob_info<T: GetBlobData>(
client: &EigenClient<T>,
async fn get_blob_info(
client: &EigenClient,
result: &DispatchResponse,
) -> anyhow::Result<BlobInfo> {
let blob_info = (|| async {
Expand Down Expand Up @@ -62,6 +62,10 @@ mod tests {
async fn get_blob_data(&self, _input: &'_ str) -> anyhow::Result<Option<Vec<u8>>> {
Ok(None)
}

fn clone_boxed(&self) -> Box<dyn GetBlobData> {
Box::new(self.clone())
}
}

#[ignore = "depends on external RPC"]
Expand Down
27 changes: 20 additions & 7 deletions core/node/da_clients/src/eigen/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use tonic::{
transport::{Channel, ClientTlsConfig, Endpoint},
Streaming,
};
use url::Url;
use zksync_config::EigenConfig;
use zksync_da_client::types::DAError;
use zksync_eth_client::clients::PKSigningClient;
Expand All @@ -30,24 +31,36 @@ use crate::eigen::{
verifier::VerificationError,
};

#[derive(Debug, Clone)]
pub(crate) struct RawEigenClient<T: GetBlobData> {
#[derive(Debug)]
pub(crate) struct RawEigenClient {
client: Arc<Mutex<DisperserClient<Channel>>>,
private_key: SecretKey,
pub config: EigenConfig,
verifier: Verifier,
get_blob_data: Box<T>,
get_blob_data: Box<dyn GetBlobData>,
}

impl Clone for RawEigenClient {
fn clone(&self) -> Self {
Self {
client: self.client.clone(),
private_key: self.private_key,
config: self.config.clone(),
verifier: self.verifier.clone(),
get_blob_data: self.get_blob_data.clone_boxed(),
}
}
}

pub(crate) const DATA_CHUNK_SIZE: usize = 32;

impl<T: GetBlobData> RawEigenClient<T> {
impl RawEigenClient {
const BLOB_SIZE_LIMIT: usize = 1024 * 1024 * 2; // 2 MB

pub async fn new(
private_key: SecretKey,
config: EigenConfig,
get_blob_data: Box<T>,
get_blob_data: Box<dyn GetBlobData>,
) -> anyhow::Result<Self> {
let endpoint =
Endpoint::from_str(config.disperser_rpc.as_str())?.tls_config(ClientTlsConfig::new())?;
Expand All @@ -60,8 +73,8 @@ impl<T: GetBlobData> RawEigenClient<T> {
.ok_or(anyhow::anyhow!("EigenDA ETH RPC not set"))?,
svc_manager_addr: Address::from_str(&config.eigenda_svc_manager_address)?,
max_blob_size: Self::BLOB_SIZE_LIMIT as u32,
g1_url: config.g1_url.clone(),
g2_url: config.g2_url.clone(),
g1_url: Url::parse(&config.g1_url)?,
g2_url: Url::parse(&config.g2_url)?,
settlement_layer_confirmation_depth: config.settlement_layer_confirmation_depth,
private_key: hex::encode(private_key.secret_bytes()),
chain_id: config.chain_id,
Expand Down
Loading

0 comments on commit bf2f818

Please sign in to comment.