From 26a554666ae03c471a2eb51127e85e65416fe1fb Mon Sep 17 00:00:00 2001 From: Gianbelinche <39842759+gianbelinche@users.noreply.github.com> Date: Tue, 17 Dec 2024 15:19:02 -0300 Subject: [PATCH 1/6] Change settlement layer for u32 --- core/lib/config/src/configs/da_client/eigen.rs | 2 +- core/lib/protobuf_config/src/proto/config/da_client.proto | 2 +- core/node/da_clients/src/eigen/client_tests.rs | 4 ++-- core/node/da_clients/src/eigen/sdk.rs | 3 +-- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/core/lib/config/src/configs/da_client/eigen.rs b/core/lib/config/src/configs/da_client/eigen.rs index fd720df17b38..cd036e407427 100644 --- a/core/lib/config/src/configs/da_client/eigen.rs +++ b/core/lib/config/src/configs/da_client/eigen.rs @@ -7,7 +7,7 @@ pub struct EigenConfig { pub disperser_rpc: String, /// Block height needed to reach in order to consider the blob finalized /// a value less or equal to 0 means that the disperser will not wait for finalization - pub settlement_layer_confirmation_depth: i32, + pub settlement_layer_confirmation_depth: u32, /// URL of the Ethereum RPC server pub eigenda_eth_rpc: Option, /// Address of the service manager contract diff --git a/core/lib/protobuf_config/src/proto/config/da_client.proto b/core/lib/protobuf_config/src/proto/config/da_client.proto index dd44d0ad14d1..cf4318c520d7 100644 --- a/core/lib/protobuf_config/src/proto/config/da_client.proto +++ b/core/lib/protobuf_config/src/proto/config/da_client.proto @@ -38,7 +38,7 @@ message CelestiaConfig { message EigenConfig { optional string disperser_rpc = 3; - optional int32 settlement_layer_confirmation_depth = 4; + optional uint32 settlement_layer_confirmation_depth = 4; optional string eigenda_eth_rpc = 5; optional string eigenda_svc_manager_address = 6; optional bool wait_for_finalization = 7; diff --git a/core/node/da_clients/src/eigen/client_tests.rs b/core/node/da_clients/src/eigen/client_tests.rs index 7141259f950c..f88b7bd1115d 100644 --- a/core/node/da_clients/src/eigen/client_tests.rs +++ b/core/node/da_clients/src/eigen/client_tests.rs @@ -70,7 +70,7 @@ mod tests { async fn test_non_auth_dispersal() { let config = EigenConfig { disperser_rpc: "https://disperser-holesky.eigenda.xyz:443".to_string(), - settlement_layer_confirmation_depth: -1, + 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, @@ -110,7 +110,7 @@ mod tests { async fn test_auth_dispersal() { let config = EigenConfig { disperser_rpc: "https://disperser-holesky.eigenda.xyz:443".to_string(), - settlement_layer_confirmation_depth: -1, + 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, diff --git a/core/node/da_clients/src/eigen/sdk.rs b/core/node/da_clients/src/eigen/sdk.rs index 362c52ffc82a..ea9fc7894e3b 100644 --- a/core/node/da_clients/src/eigen/sdk.rs +++ b/core/node/da_clients/src/eigen/sdk.rs @@ -62,8 +62,7 @@ impl RawEigenClient { max_blob_size: Self::BLOB_SIZE_LIMIT as u32, g1_url: config.g1_url.clone(), g2_url: config.g2_url.clone(), - settlement_layer_confirmation_depth: config.settlement_layer_confirmation_depth.max(0) - as u32, + settlement_layer_confirmation_depth: config.settlement_layer_confirmation_depth, private_key: hex::encode(private_key.secret_bytes()), chain_id: config.chain_id, }; From 6dd94d42b78e7e9dabe5df06922ff59b2006fd6f Mon Sep 17 00:00:00 2001 From: Gianbelinche <39842759+gianbelinche@users.noreply.github.com> Date: Tue, 17 Dec 2024 15:31:22 -0300 Subject: [PATCH 2/6] Change string to address --- .../lib/config/src/configs/da_client/eigen.rs | 4 ++-- core/lib/env_config/src/da_client.rs | 10 +++++++-- core/lib/protobuf_config/src/da_client.rs | 12 ++++++---- .../node/da_clients/src/eigen/client_tests.rs | 12 +++++----- core/node/da_clients/src/eigen/sdk.rs | 6 ++--- core/node/da_clients/src/eigen/verifier.rs | 22 ++++++------------- .../da_clients/src/eigen/verifier_tests.rs | 8 +++---- 7 files changed, 37 insertions(+), 37 deletions(-) diff --git a/core/lib/config/src/configs/da_client/eigen.rs b/core/lib/config/src/configs/da_client/eigen.rs index cd036e407427..8c099ac89488 100644 --- a/core/lib/config/src/configs/da_client/eigen.rs +++ b/core/lib/config/src/configs/da_client/eigen.rs @@ -1,5 +1,5 @@ use serde::Deserialize; -use zksync_basic_types::secrets::PrivateKey; +use zksync_basic_types::{secrets::PrivateKey, Address}; /// Configuration for the EigenDA remote disperser client. #[derive(Clone, Debug, PartialEq, Deserialize, Default)] pub struct EigenConfig { @@ -11,7 +11,7 @@ pub struct EigenConfig { /// URL of the Ethereum RPC server pub eigenda_eth_rpc: Option, /// Address of the service manager contract - pub eigenda_svc_manager_address: String, + pub eigenda_svc_manager_address: Address, /// Wait for the blob to be finalized before returning the response pub wait_for_finalization: bool, /// Authenticated dispersal diff --git a/core/lib/env_config/src/da_client.rs b/core/lib/env_config/src/da_client.rs index deda1ce3f5c2..e0239f75b7f4 100644 --- a/core/lib/env_config/src/da_client.rs +++ b/core/lib/env_config/src/da_client.rs @@ -90,6 +90,9 @@ impl FromEnv for DataAvailabilitySecrets { #[cfg(test)] mod tests { + use std::str::FromStr; + + use zksync_basic_types::Address; use zksync_config::{ configs::{ da_client::{ @@ -251,7 +254,7 @@ mod tests { DA_DISPERSER_RPC="http://localhost:8080" DA_SETTLEMENT_LAYER_CONFIRMATION_DEPTH=0 DA_EIGENDA_ETH_RPC="http://localhost:8545" - DA_EIGENDA_SVC_MANAGER_ADDRESS="0x123" + DA_EIGENDA_SVC_MANAGER_ADDRESS="0xD4A7E1Bd8015057293f0D0A557088c286942e84b" DA_WAIT_FOR_FINALIZATION=true DA_AUTHENTICATED=false DA_G1_URL="resources1" @@ -267,7 +270,10 @@ mod tests { disperser_rpc: "http://localhost:8080".to_string(), settlement_layer_confirmation_depth: 0, eigenda_eth_rpc: Some("http://localhost:8545".to_string()), - eigenda_svc_manager_address: "0x123".to_string(), + eigenda_svc_manager_address: Address::from_str( + "0xD4A7E1Bd8015057293f0D0A557088c286942e84b" + ) + .unwrap(), wait_for_finalization: true, authenticated: false, g1_url: "resources1".to_string(), diff --git a/core/lib/protobuf_config/src/da_client.rs b/core/lib/protobuf_config/src/da_client.rs index 84e94aeae1a2..63b73b42436b 100644 --- a/core/lib/protobuf_config/src/da_client.rs +++ b/core/lib/protobuf_config/src/da_client.rs @@ -1,3 +1,5 @@ +use std::str::FromStr; + use anyhow::Context; use zksync_config::configs::{ self, @@ -9,6 +11,7 @@ use zksync_config::configs::{ }, }; use zksync_protobuf::{required, ProtoRepr}; +use zksync_types::Address; use crate::proto::{ da_client::{self as proto}, @@ -64,9 +67,10 @@ impl ProtoRepr for proto::DataAvailabilityClient { ) .context("settlement_layer_confirmation_depth")?, eigenda_eth_rpc: required(&conf.eigenda_eth_rpc).ok().cloned(), - eigenda_svc_manager_address: required(&conf.eigenda_svc_manager_address) - .context("eigenda_svc_manager_address")? - .clone(), + eigenda_svc_manager_address: Address::from_str( + required(&conf.eigenda_svc_manager_address) + .context("eigenda_svc_manager_address")?, + )?, wait_for_finalization: *required(&conf.wait_for_finalization) .context("wait_for_finalization")?, authenticated: *required(&conf.authenticated).context("authenticated")?, @@ -116,7 +120,7 @@ impl ProtoRepr for proto::DataAvailabilityClient { config.settlement_layer_confirmation_depth, ), eigenda_eth_rpc: config.eigenda_eth_rpc.clone(), - eigenda_svc_manager_address: Some(config.eigenda_svc_manager_address.clone()), + eigenda_svc_manager_address: Some(config.eigenda_svc_manager_address.to_string()), wait_for_finalization: Some(config.wait_for_finalization), authenticated: Some(config.authenticated), g1_url: Some(config.g1_url.clone()), diff --git a/core/node/da_clients/src/eigen/client_tests.rs b/core/node/da_clients/src/eigen/client_tests.rs index f88b7bd1115d..7b41ed85b5ab 100644 --- a/core/node/da_clients/src/eigen/client_tests.rs +++ b/core/node/da_clients/src/eigen/client_tests.rs @@ -13,7 +13,7 @@ mod tests { types::{DAError, DispatchResponse}, DataAvailabilityClient, }; - use zksync_types::secrets::PrivateKey; + use zksync_types::{secrets::PrivateKey, Address}; use crate::eigen::{blob_info::BlobInfo, EigenClient, GetBlobData}; @@ -72,7 +72,7 @@ mod tests { 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(), + eigenda_svc_manager_address: Address::from_str("0xD4A7E1Bd8015057293f0D0A557088c286942e84b").unwrap(), wait_for_finalization: false, authenticated: false, g1_url: "https://github.com/Layr-Labs/eigenda-proxy/raw/2fd70b99ef5bf137d7bbca3461cf9e1f2c899451/resources/g1.point".to_string(), @@ -112,7 +112,7 @@ mod tests { 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(), + eigenda_svc_manager_address: Address::from_str("0xD4A7E1Bd8015057293f0D0A557088c286942e84b").unwrap(), wait_for_finalization: false, authenticated: true, g1_url: "https://github.com/Layr-Labs/eigenda-proxy/raw/2fd70b99ef5bf137d7bbca3461cf9e1f2c899451/resources/g1.point".to_string(), @@ -156,7 +156,7 @@ mod tests { g2_url: "https://github.com/Layr-Labs/eigenda-proxy/raw/2fd70b99ef5bf137d7bbca3461cf9e1f2c899451/resources/g2.point.powerOf2".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(), + eigenda_svc_manager_address: Address::from_str("0xD4A7E1Bd8015057293f0D0A557088c286942e84b").unwrap(), chain_id: 17000, }; let secrets = EigenSecrets { @@ -192,7 +192,7 @@ mod tests { disperser_rpc: "https://disperser-holesky.eigenda.xyz:443".to_string(), settlement_layer_confirmation_depth: 5, eigenda_eth_rpc: Some("https://ethereum-holesky-rpc.publicnode.com".to_string()), - eigenda_svc_manager_address: "0xD4A7E1Bd8015057293f0D0A557088c286942e84b".to_string(), + eigenda_svc_manager_address:Address::from_str("0xD4A7E1Bd8015057293f0D0A557088c286942e84b").unwrap(), wait_for_finalization: false, authenticated: false, g1_url: "https://github.com/Layr-Labs/eigenda-proxy/raw/2fd70b99ef5bf137d7bbca3461cf9e1f2c899451/resources/g1.point".to_string(), @@ -232,7 +232,7 @@ mod tests { disperser_rpc: "https://disperser-holesky.eigenda.xyz:443".to_string(), settlement_layer_confirmation_depth: 5, eigenda_eth_rpc: Some("https://ethereum-holesky-rpc.publicnode.com".to_string()), - eigenda_svc_manager_address: "0xD4A7E1Bd8015057293f0D0A557088c286942e84b".to_string(), + eigenda_svc_manager_address: Address::from_str("0xD4A7E1Bd8015057293f0D0A557088c286942e84b").unwrap(), wait_for_finalization: false, authenticated: true, g1_url: "https://github.com/Layr-Labs/eigenda-proxy/raw/2fd70b99ef5bf137d7bbca3461cf9e1f2c899451/resources/g1.point".to_string(), diff --git a/core/node/da_clients/src/eigen/sdk.rs b/core/node/da_clients/src/eigen/sdk.rs index ea9fc7894e3b..c9b9b379b8b8 100644 --- a/core/node/da_clients/src/eigen/sdk.rs +++ b/core/node/da_clients/src/eigen/sdk.rs @@ -10,7 +10,7 @@ use tonic::{ use zksync_config::EigenConfig; use zksync_da_client::types::DAError; use zksync_eth_client::clients::PKSigningClient; -use zksync_types::{url::SensitiveUrl, K256PrivateKey, SLChainId, H160}; +use zksync_types::{url::SensitiveUrl, K256PrivateKey, SLChainId}; use zksync_web3_decl::client::{Client, DynClient, L1}; use super::{ @@ -58,7 +58,7 @@ impl RawEigenClient { .eigenda_eth_rpc .clone() .ok_or(anyhow::anyhow!("EigenDA ETH RPC not set"))?, - svc_manager_addr: config.eigenda_svc_manager_address.clone(), + svc_manager_addr: 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(), @@ -74,7 +74,7 @@ impl RawEigenClient { K256PrivateKey::from_bytes(zksync_types::H256::from_str( &verifier_config.private_key, )?)?, - H160::from_str(&verifier_config.svc_manager_addr)?, + verifier_config.svc_manager_addr, Verifier::DEFAULT_PRIORITY_FEE_PER_GAS, SLChainId(verifier_config.chain_id), query_client, diff --git a/core/node/da_clients/src/eigen/verifier.rs b/core/node/da_clients/src/eigen/verifier.rs index 4a314a751b87..4b42d17191ca 100644 --- a/core/node/da_clients/src/eigen/verifier.rs +++ b/core/node/da_clients/src/eigen/verifier.rs @@ -1,4 +1,4 @@ -use std::{collections::HashMap, fs::File, io::copy, path::Path, str::FromStr}; +use std::{collections::HashMap, fs::File, io::copy, path::Path}; use ark_bn254::{Fq, G1Affine}; use ethabi::{encode, ParamType, Token}; @@ -9,7 +9,7 @@ use zksync_basic_types::web3::CallRequest; use zksync_eth_client::{clients::PKSigningClient, EnrichedClientResult}; use zksync_types::{ web3::{self, BlockId, BlockNumber}, - H160, U256, U64, + Address, U256, U64, }; use super::blob_info::{BatchHeader, BlobHeader, BlobInfo, G1Commitment}; @@ -68,7 +68,7 @@ pub enum VerificationError { #[derive(Debug, Clone)] pub struct VerifierConfig { pub rpc_url: String, - pub svc_manager_addr: String, + pub svc_manager_addr: Address, pub max_blob_size: u32, pub g1_url: String, pub g2_url: String, @@ -342,10 +342,7 @@ impl Verifier { data.append(batch_id_vec.to_vec().as_mut()); let call_request = CallRequest { - to: Some( - H160::from_str(&self.cfg.svc_manager_addr) - .map_err(|_| VerificationError::ServiceManagerError)?, - ), + to: Some(self.cfg.svc_manager_addr), data: Some(zksync_basic_types::web3::Bytes(data)), ..Default::default() }; @@ -445,10 +442,8 @@ impl Verifier { let data = func_selector.to_vec(); let call_request = CallRequest { - to: Some( - H160::from_str(&self.cfg.svc_manager_addr) - .map_err(|_| VerificationError::ServiceManagerError)?, - ), + to: Some(self.cfg.svc_manager_addr), + data: Some(zksync_basic_types::web3::Bytes(data)), ..Default::default() }; @@ -474,10 +469,7 @@ impl Verifier { let func_selector = ethabi::short_signature("quorumNumbersRequired", &[]); let data = func_selector.to_vec(); let call_request = CallRequest { - to: Some( - H160::from_str(&self.cfg.svc_manager_addr) - .map_err(|_| VerificationError::ServiceManagerError)?, - ), + to: Some(self.cfg.svc_manager_addr), data: Some(zksync_basic_types::web3::Bytes(data)), ..Default::default() }; diff --git a/core/node/da_clients/src/eigen/verifier_tests.rs b/core/node/da_clients/src/eigen/verifier_tests.rs index bdea8f9a9960..2c03b2ba6405 100644 --- a/core/node/da_clients/src/eigen/verifier_tests.rs +++ b/core/node/da_clients/src/eigen/verifier_tests.rs @@ -6,7 +6,7 @@ mod test { use zksync_types::{ url::SensitiveUrl, web3::{BlockId, Bytes, CallRequest}, - K256PrivateKey, SLChainId, H160, U64, + Address, K256PrivateKey, SLChainId, H160, U64, }; use zksync_web3_decl::client::{Client, DynClient, L1}; @@ -21,7 +21,7 @@ mod test { fn get_verifier_config() -> VerifierConfig { VerifierConfig { rpc_url: "https://ethereum-holesky-rpc.publicnode.com".to_string(), - svc_manager_addr: "0xD4A7E1Bd8015057293f0D0A557088c286942e84b".to_string(), + svc_manager_addr: Address::from_str("0xD4A7E1Bd8015057293f0D0A557088c286942e84b").unwrap(), max_blob_size: 2 * 1024 * 1024, 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(), @@ -82,9 +82,7 @@ mod test { ) .map_err(|_| VerificationError::ServiceManagerError) .unwrap(), - zksync_types::H160::from_str(&cfg.svc_manager_addr) - .map_err(|_| VerificationError::ServiceManagerError) - .unwrap(), + cfg.svc_manager_addr, Verifier::DEFAULT_PRIORITY_FEE_PER_GAS, SLChainId(cfg.chain_id), query_client, From f68e4262067d7b53061fe8817838786a4fd99044 Mon Sep 17 00:00:00 2001 From: Gianbelinche <39842759+gianbelinche@users.noreply.github.com> Date: Tue, 17 Dec 2024 15:37:06 -0300 Subject: [PATCH 3/6] Remove unwraps --- core/node/da_clients/src/eigen/blob_info.rs | 34 ++++++++++----------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/core/node/da_clients/src/eigen/blob_info.rs b/core/node/da_clients/src/eigen/blob_info.rs index a44117fd4ed7..3bde4f1f3822 100644 --- a/core/node/da_clients/src/eigen/blob_info.rs +++ b/core/node/da_clients/src/eigen/blob_info.rs @@ -106,16 +106,15 @@ impl BlobHeader { impl TryFrom for BlobHeader { type Error = ConversionError; fn try_from(value: DisperserBlobHeader) -> Result { - if value.commitment.is_none() { - return Err(ConversionError::NotPresentError); - } let blob_quorum_params: Vec = value .blob_quorum_params .iter() .map(|param| BlobQuorumParam::from(param.clone())) .collect(); Ok(Self { - commitment: G1Commitment::from(value.commitment.unwrap()), + commitment: G1Commitment::from( + value.commitment.ok_or(ConversionError::NotPresentError)?, + ), data_length: value.data_length, blob_quorum_params, }) @@ -179,11 +178,10 @@ impl BatchMetadata { impl TryFrom for BatchMetadata { type Error = ConversionError; fn try_from(value: DisperserBatchMetadata) -> Result { - if value.batch_header.is_none() { - return Err(ConversionError::NotPresentError); - } Ok(Self { - batch_header: BatchHeader::from(value.batch_header.unwrap()), + batch_header: BatchHeader::from( + value.batch_header.ok_or(ConversionError::NotPresentError)?, + ), signatory_record_hash: value.signatory_record_hash, fee: value.fee, confirmation_block_number: value.confirmation_block_number, @@ -219,13 +217,14 @@ impl BlobVerificationProof { impl TryFrom for BlobVerificationProof { type Error = ConversionError; fn try_from(value: DisperserBlobVerificationProof) -> Result { - if value.batch_metadata.is_none() { - return Err(ConversionError::NotPresentError); - } Ok(Self { batch_id: value.batch_id, blob_index: value.blob_index, - batch_medatada: BatchMetadata::try_from(value.batch_metadata.unwrap())?, + batch_medatada: BatchMetadata::try_from( + value + .batch_metadata + .ok_or(ConversionError::NotPresentError)?, + )?, inclusion_proof: value.inclusion_proof, quorum_indexes: value.quorum_indexes, }) @@ -253,13 +252,14 @@ impl BlobInfo { impl TryFrom for BlobInfo { type Error = ConversionError; fn try_from(value: DisperserBlobInfo) -> Result { - if value.blob_header.is_none() || value.blob_verification_proof.is_none() { - return Err(ConversionError::NotPresentError); - } Ok(Self { - blob_header: BlobHeader::try_from(value.blob_header.unwrap())?, + blob_header: BlobHeader::try_from( + value.blob_header.ok_or(ConversionError::NotPresentError)?, + )?, blob_verification_proof: BlobVerificationProof::try_from( - value.blob_verification_proof.unwrap(), + value + .blob_verification_proof + .ok_or(ConversionError::NotPresentError)?, )?, }) } From 0618fe75905880094819cae432c21663aa1f4e16 Mon Sep 17 00:00:00 2001 From: Gianbelinche <39842759+gianbelinche@users.noreply.github.com> Date: Tue, 17 Dec 2024 15:40:38 -0300 Subject: [PATCH 4/6] Remove error from name --- core/node/da_clients/src/eigen/blob_info.rs | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/core/node/da_clients/src/eigen/blob_info.rs b/core/node/da_clients/src/eigen/blob_info.rs index 3bde4f1f3822..dcc12185ed2d 100644 --- a/core/node/da_clients/src/eigen/blob_info.rs +++ b/core/node/da_clients/src/eigen/blob_info.rs @@ -12,13 +12,13 @@ use super::{ #[derive(Debug)] pub enum ConversionError { - NotPresentError, + NotPresent, } impl fmt::Display for ConversionError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - ConversionError::NotPresentError => write!(f, "Failed to convert BlobInfo"), + ConversionError::NotPresent => write!(f, "Failed to convert BlobInfo"), } } } @@ -112,9 +112,7 @@ impl TryFrom for BlobHeader { .map(|param| BlobQuorumParam::from(param.clone())) .collect(); Ok(Self { - commitment: G1Commitment::from( - value.commitment.ok_or(ConversionError::NotPresentError)?, - ), + commitment: G1Commitment::from(value.commitment.ok_or(ConversionError::NotPresent)?), data_length: value.data_length, blob_quorum_params, }) @@ -179,9 +177,7 @@ impl TryFrom for BatchMetadata { type Error = ConversionError; fn try_from(value: DisperserBatchMetadata) -> Result { Ok(Self { - batch_header: BatchHeader::from( - value.batch_header.ok_or(ConversionError::NotPresentError)?, - ), + batch_header: BatchHeader::from(value.batch_header.ok_or(ConversionError::NotPresent)?), signatory_record_hash: value.signatory_record_hash, fee: value.fee, confirmation_block_number: value.confirmation_block_number, @@ -221,9 +217,7 @@ impl TryFrom for BlobVerificationProof { batch_id: value.batch_id, blob_index: value.blob_index, batch_medatada: BatchMetadata::try_from( - value - .batch_metadata - .ok_or(ConversionError::NotPresentError)?, + value.batch_metadata.ok_or(ConversionError::NotPresent)?, )?, inclusion_proof: value.inclusion_proof, quorum_indexes: value.quorum_indexes, @@ -254,12 +248,12 @@ impl TryFrom for BlobInfo { fn try_from(value: DisperserBlobInfo) -> Result { Ok(Self { blob_header: BlobHeader::try_from( - value.blob_header.ok_or(ConversionError::NotPresentError)?, + value.blob_header.ok_or(ConversionError::NotPresent)?, )?, blob_verification_proof: BlobVerificationProof::try_from( value .blob_verification_proof - .ok_or(ConversionError::NotPresentError)?, + .ok_or(ConversionError::NotPresent)?, )?, }) } From b794f662f324bee0af88a9967ba685ac71740447 Mon Sep 17 00:00:00 2001 From: Gianbelinche <39842759+gianbelinche@users.noreply.github.com> Date: Tue, 17 Dec 2024 15:43:11 -0300 Subject: [PATCH 5/6] Remove unused to bytes --- core/node/da_clients/src/eigen/blob_info.rs | 92 --------------------- 1 file changed, 92 deletions(-) diff --git a/core/node/da_clients/src/eigen/blob_info.rs b/core/node/da_clients/src/eigen/blob_info.rs index dcc12185ed2d..63fece177c59 100644 --- a/core/node/da_clients/src/eigen/blob_info.rs +++ b/core/node/da_clients/src/eigen/blob_info.rs @@ -29,18 +29,6 @@ pub struct G1Commitment { pub y: Vec, } -impl G1Commitment { - pub fn to_bytes(&self) -> Vec { - let mut bytes = vec![]; - bytes.extend(&self.x.len().to_be_bytes()); - bytes.extend(&self.x); - bytes.extend(&self.y.len().to_be_bytes()); - bytes.extend(&self.y); - - bytes - } -} - impl From for G1Commitment { fn from(value: DisperserG1Commitment) -> Self { Self { @@ -58,18 +46,6 @@ pub struct BlobQuorumParam { pub chunk_length: u32, } -impl BlobQuorumParam { - pub fn to_bytes(&self) -> Vec { - let mut bytes = vec![]; - bytes.extend(&self.quorum_number.to_be_bytes()); - bytes.extend(&self.adversary_threshold_percentage.to_be_bytes()); - bytes.extend(&self.confirmation_threshold_percentage.to_be_bytes()); - bytes.extend(&self.chunk_length.to_be_bytes()); - - bytes - } -} - impl From for BlobQuorumParam { fn from(value: DisperserBlobQuorumParam) -> Self { Self { @@ -88,21 +64,6 @@ pub struct BlobHeader { pub blob_quorum_params: Vec, } -impl BlobHeader { - pub fn to_bytes(&self) -> Vec { - let mut bytes = vec![]; - bytes.extend(self.commitment.to_bytes()); - bytes.extend(&self.data_length.to_be_bytes()); - bytes.extend(&self.blob_quorum_params.len().to_be_bytes()); - - for quorum in &self.blob_quorum_params { - bytes.extend(quorum.to_bytes()); - } - - bytes - } -} - impl TryFrom for BlobHeader { type Error = ConversionError; fn try_from(value: DisperserBlobHeader) -> Result { @@ -127,21 +88,6 @@ pub struct BatchHeader { pub reference_block_number: u32, } -impl BatchHeader { - pub fn to_bytes(&self) -> Vec { - let mut bytes = vec![]; - bytes.extend(&self.batch_root.len().to_be_bytes()); - bytes.extend(&self.batch_root); - bytes.extend(&self.quorum_numbers.len().to_be_bytes()); - bytes.extend(&self.quorum_numbers); - bytes.extend(&self.quorum_signed_percentages.len().to_be_bytes()); - bytes.extend(&self.quorum_signed_percentages); - bytes.extend(&self.reference_block_number.to_be_bytes()); - - bytes - } -} - impl From for BatchHeader { fn from(value: DisperserBatchHeader) -> Self { Self { @@ -162,17 +108,6 @@ pub struct BatchMetadata { pub batch_header_hash: Vec, } -impl BatchMetadata { - pub fn to_bytes(&self) -> Vec { - let mut bytes = vec![]; - bytes.extend(self.batch_header.to_bytes()); - bytes.extend(&self.signatory_record_hash); - bytes.extend(&self.confirmation_block_number.to_be_bytes()); - - bytes - } -} - impl TryFrom for BatchMetadata { type Error = ConversionError; fn try_from(value: DisperserBatchMetadata) -> Result { @@ -195,21 +130,6 @@ pub struct BlobVerificationProof { pub quorum_indexes: Vec, } -impl BlobVerificationProof { - pub fn to_bytes(&self) -> Vec { - let mut bytes = vec![]; - bytes.extend(&self.batch_id.to_be_bytes()); - bytes.extend(&self.blob_index.to_be_bytes()); - bytes.extend(self.batch_medatada.to_bytes()); - bytes.extend(&self.inclusion_proof.len().to_be_bytes()); - bytes.extend(&self.inclusion_proof); - bytes.extend(&self.quorum_indexes.len().to_be_bytes()); - bytes.extend(&self.quorum_indexes); - - bytes - } -} - impl TryFrom for BlobVerificationProof { type Error = ConversionError; fn try_from(value: DisperserBlobVerificationProof) -> Result { @@ -231,18 +151,6 @@ pub struct BlobInfo { pub blob_verification_proof: BlobVerificationProof, } -impl BlobInfo { - pub fn to_bytes(&self) -> Vec { - let mut bytes = vec![]; - let blob_header_bytes = self.blob_header.to_bytes(); - bytes.extend(blob_header_bytes.len().to_be_bytes()); - bytes.extend(blob_header_bytes); - let blob_verification_proof_bytes = self.blob_verification_proof.to_bytes(); - bytes.extend(blob_verification_proof_bytes); - bytes - } -} - impl TryFrom for BlobInfo { type Error = ConversionError; fn try_from(value: DisperserBlobInfo) -> Result { From 0c1aae004a38d1752b7f88a6520aa9009854c683 Mon Sep 17 00:00:00 2001 From: Gianbelinche <39842759+gianbelinche@users.noreply.github.com> Date: Tue, 17 Dec 2024 15:44:40 -0300 Subject: [PATCH 6/6] Rename call for get blob data --- core/node/da_clients/src/eigen/client.rs | 2 +- core/node/da_clients/src/eigen/client_tests.rs | 2 +- core/node/da_clients/src/eigen/sdk.rs | 2 +- .../src/implementations/layers/da_clients/eigen.rs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/core/node/da_clients/src/eigen/client.rs b/core/node/da_clients/src/eigen/client.rs index 430b5bb4c4a7..ef4baa1c2ad0 100644 --- a/core/node/da_clients/src/eigen/client.rs +++ b/core/node/da_clients/src/eigen/client.rs @@ -14,7 +14,7 @@ use crate::utils::to_retriable_da_error; #[async_trait] pub trait GetBlobData: Clone + std::fmt::Debug + Send + Sync { - async fn call(&self, input: &str) -> anyhow::Result>>; + async fn get_blob_data(&self, input: &str) -> anyhow::Result>>; } /// EigenClient is a client for the Eigen DA service. diff --git a/core/node/da_clients/src/eigen/client_tests.rs b/core/node/da_clients/src/eigen/client_tests.rs index 7b41ed85b5ab..b90fa4cdbad2 100644 --- a/core/node/da_clients/src/eigen/client_tests.rs +++ b/core/node/da_clients/src/eigen/client_tests.rs @@ -59,7 +59,7 @@ mod tests { #[async_trait::async_trait] impl GetBlobData for MockGetBlobData { - async fn call(&self, _input: &'_ str) -> anyhow::Result>> { + async fn get_blob_data(&self, _input: &'_ str) -> anyhow::Result>> { Ok(None) } } diff --git a/core/node/da_clients/src/eigen/sdk.rs b/core/node/da_clients/src/eigen/sdk.rs index c9b9b379b8b8..e435e9525fc7 100644 --- a/core/node/da_clients/src/eigen/sdk.rs +++ b/core/node/da_clients/src/eigen/sdk.rs @@ -184,7 +184,7 @@ impl RawEigenClient { let Some(data) = self.get_blob_data(blob_info.clone()).await? else { return Err(anyhow::anyhow!("Failed to get blob data")); }; - let data_db = self.get_blob_data.call(request_id).await?; + let data_db = self.get_blob_data.get_blob_data(request_id).await?; if let Some(data_db) = data_db { if data_db != data { return Err(anyhow::anyhow!( 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 02e3d5b2f8fd..ce3a4d52bdc4 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 @@ -66,7 +66,7 @@ pub struct GetBlobFromDB { #[async_trait::async_trait] impl GetBlobData for GetBlobFromDB { - async fn call(&self, input: &'_ str) -> anyhow::Result>> { + async fn get_blob_data(&self, input: &'_ str) -> anyhow::Result>> { let pool = self.pool.clone(); let input = input.to_string(); let mut conn = pool.connection_tagged("eigen_client").await?;