Skip to content

Commit

Permalink
clear all nits
Browse files Browse the repository at this point in the history
  • Loading branch information
supernovahs committed May 10, 2024
1 parent eb21bc2 commit 33b6bea
Show file tree
Hide file tree
Showing 13 changed files with 158 additions and 128 deletions.
16 changes: 16 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ rustdoc.all = "warn"
[workspace.dependencies]
ethers = "2.0.14"
ark-ff = "0.4.0"
eyre = "0.6.12"
reth = {git = "https://github.com/paradigmxyz/reth"}
prometheus-client = "0.22.2"
bn254 = {git = "https://github.com/sedaprotocol/bn254"}
Expand All @@ -62,12 +63,10 @@ eigensdk-services-avsregistry = {path = "crates/services/avsregistry"}
eigensdk-services-bls_aggregation = {path = "crates/services/bls_aggregation"}
eigensdk-services-operatorsinfo = {path = "crates/services/operatorsinfo"}
tokio = {version = "1.37.0" , features = ["test-util", "full","sync"] }

futures-util = "0.3.30"
thiserror = "1.0"
tracing = "0.1.40"



#misc
parking_lot = "0.12"

Expand All @@ -85,7 +84,7 @@ alloy-rpc-types-engine = { git = "https://github.com/alloy-rs/alloy", rev = "af7
alloy-genesis = { git = "https://github.com/alloy-rs/alloy", rev = "af788af" }
alloy-node-bindings = { git = "https://github.com/alloy-rs/alloy", rev = "af788af" }
alloy-provider = { git = "https://github.com/alloy-rs/alloy", rev = "af788af", default-features = false, features = [
"reqwest",
"reqwest","ws"
] }
alloy-transport-http = {git = "https://github.com/alloy-rs/alloy", rev = "af788af"}
alloy-eips = { git = "https://github.com/alloy-rs/alloy", default-features = false, rev = "af788af" }
Expand All @@ -95,4 +94,5 @@ alloy-network = { git = "https://github.com/alloy-rs/alloy", rev = "af788af" }
alloy-consensus = { git = "https://github.com/alloy-rs/alloy", rev = "af788af" }
alloy-contract = {git = "https://github.com/alloy-rs/alloy", rev = "af788af" }
alloy-transport = {git = "https://github.com/alloy-rs/alloy", rev = "af788af"}
alloy-transport-ws = {git = "https://github.com/alloy-rs/alloy", rev = "af788af"}
alloy-transport-ws = {git = "https://github.com/alloy-rs/alloy", rev = "af788af"}
alloy-rpc-client = {git = "https://github.com/alloy-rs/alloy", rev = "af788af"}
75 changes: 24 additions & 51 deletions crates/chainio/clients/avsregistry/src/reader.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
use crate::{error::AvsRegistryError, reader::BLSApkRegistry::NewPubkeyRegistration};

use alloy_contract::SolCallBuilder;
use alloy_eips::eip1898::BlockNumberOrTag;
use alloy_primitives::address;
use alloy_primitives::{
hex::check, keccak256, Address, BlockNumber, Bytes, FixedBytes, B256, U256, U64,
};
use crate::error::AvsRegistryError;
use alloy_primitives::{Address, Bytes, FixedBytes, B256, U256};
use alloy_provider::{Provider, ProviderBuilder};
use alloy_rpc_types::{Filter, FilterBlockOption, FilterSet, Topic, ValueOrArray};
use alloy_sol_types::{sol, SolConstructor, SolEventInterface};
use eigensdk_types::operator::bitmap_to_quorum_ids;
use alloy_rpc_types::Filter;
use alloy_sol_types::sol;
use eigensdk_types::operator::{bitmap_to_quorum_ids, BLSApkRegistry, OperatorPubKeys};
use num_bigint::BigInt;
use std::collections::HashMap;
use std::fmt::Debug;
Expand Down Expand Up @@ -42,20 +36,7 @@ sol!(
"../../../../crates/contracts/bindings/utils/json/OperatorStateRetriever.json"
);

sol!(
#[allow(missing_docs)]
#[derive(Debug)]
#[sol(rpc)]
BLSApkRegistry,
"../../../../crates/contracts/bindings/utils/json/BLSApkRegistry.json"
);

use self::RegistryCoordinator::RegistryCoordinatorInstance;
use BLSApkRegistry::{G1Point, G2Point};
use OperatorStateRetriever::OperatorStateRetrieverCalls;
use RegistryCoordinator::RegistryCoordinatorEvents;
use StakeRegistry::StakeRegistryEvents;

/// Avs Registry chainreader
#[derive(Debug, Clone)]
pub struct AvsRegistryChainReader {
Expand All @@ -66,12 +47,6 @@ pub struct AvsRegistryChainReader {
provider: String,
}

#[derive(Debug, Clone)]
pub struct OperatorPubKeys {
pub g1_pub_key: G1Point,
pub g2_pub_key: G2Point,
}

trait AvsRegistryReader {
fn get_quorum_count() -> Result<u8, String>;
}
Expand Down Expand Up @@ -452,7 +427,6 @@ impl AvsRegistryChainReader {
.event("NewPubkeyRegistration(address,(uint256,uint256),(uint256[2],uint256[2]))")
.address(self.bls_apk_registry_addr);

let contract_bls_apk_registry = BLSApkRegistry::new(self.bls_apk_registry_addr, &provider);
let logs = provider.get_logs(&filter).await?;

debug!(transactionLogs = ?logs, "avsRegistryChainReader.QueryExistingRegisteredOperatorPubKeys");
Expand Down Expand Up @@ -538,37 +512,36 @@ impl AvsRegistryChainReader {
}
}

#[test]
fn test_build_avs_registry_chain_reader() {
let provider = "http://localhost:8545";
let instance = AvsRegistryChainReader::new(
Address::from_word(keccak256("registry")),
// Address::from_word(keccak256(("registry").into())),
Address::from_word(keccak256("blsapkregistry")),
Address::from_word(keccak256("operatorstateretriever")),
Address::from_word(keccak256("stakeregistry")),
provider.to_string(),
);
let _ = AvsRegistryChainReader::build_avs_registry_chain_reader(
&instance,
Address::from_word(keccak256("registry")),
Address::from_word(keccak256("operator")),
Address::from_word(keccak256("stake")),
);
}

#[cfg(test)]
mod tests {

use super::*;
use alloy_primitives::keccak256;
use hex::FromHex;
use std::str::FromStr;

const HOLESKY_REGISTRY_COORDINATOR: &str = "0x53012C69A189cfA2D9d29eb6F19B32e0A2EA3490";
const HOLESKY_OPERATOR_STATE_RETRIEVER: &str = "0xB4baAfee917fb4449f5ec64804217bccE9f46C67";
const HOLESKY_STAKE_REGISTRY: &str = "0xBDACD5998989Eec814ac7A0f0f6596088AA2a270";
const HOLESKY_BLS_APK_REGISTRY: &str = "0x066cF95c1bf0927124DFB8B02B401bc23A79730D";

#[tokio::test]
async fn test_build_avs_registry_chain_reader() {
let provider = "http://localhost:8545";
let instance = AvsRegistryChainReader::new(
Address::from_word(keccak256("registry")),
// Address::from_word(keccak256(("registry").into())),
Address::from_word(keccak256("blsapkregistry")),
Address::from_word(keccak256("operatorstateretriever")),
Address::from_word(keccak256("stakeregistry")),
provider.to_string(),
);
let _ = AvsRegistryChainReader::build_avs_registry_chain_reader(
&instance,
Address::from_word(keccak256("registry")),
Address::from_word(keccak256("operator")),
Address::from_word(keccak256("stake")),
);
}
fn build_avs_registry_chain_reader() -> AvsRegistryChainReader {
let holesky_registry_coordinator =
Address::from_str(HOLESKY_REGISTRY_COORDINATOR).expect("failed to parse address");
Expand Down
2 changes: 1 addition & 1 deletion crates/chainio/clients/avsregistry/src/subscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl AvsRegistryChainSubscriber {
.with_recommended_fillers()
.on_builtin(&self.provider)
.await?;
let current_block_number = provider.get_block_number().await.unwrap();
let current_block_number = provider.get_block_number().await?;

let filter = Filter::new()
.event("NewPubkeyRegistration(address,(uint256,uint256),(uint256[2],uint256[2]))")
Expand Down
1 change: 1 addition & 0 deletions crates/metrics/collectors/economic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ repository.workspace = true
ethers.workspace = true
eigensdk-client-elcontracts.workspace = true
eigensdk-client-avsregistry.workspace = true
alloy-primitives.workspace = true
2 changes: 1 addition & 1 deletion crates/metrics/collectors/economic/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use alloy_primitives::{Address, U256};
use eigensdk_client_avsregistry::reader::AvsRegistryChainReader;
use eigensdk_client_elcontracts::reader::ELChainReader;
use ethers_core::types::{Address, U256};
use std::collections::HashMap;

pub struct Collector {
Expand Down
4 changes: 3 additions & 1 deletion crates/services/avsregistry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ eigensdk-services-operatorsinfo.workspace = true
eigensdk-types.workspace = true
eigensdk-contract-bindings.workspace = true
eigensdk-crypto-bls.workspace = true
eigensdk-crypto-bn254.workspace = true
eigensdk-crypto-bn254.workspace = true
alloy-primitives.workspace = true
eigensdk-chainio-utils.workspace = true
27 changes: 16 additions & 11 deletions crates/services/avsregistry/src/chaincaller.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
use alloy_primitives::{Bytes, FixedBytes, U256};
use eigensdk_chainio_utils::convert_to_bn254_g1_point;
use eigensdk_client_avsregistry::reader::AvsRegistryChainReader;
use eigensdk_contract_bindings::BLSApkRegistry::{G1Point, G2Point};
use eigensdk_crypto_bls::attestation::G1Point as BlsG1Point;
use eigensdk_crypto_bn254::utils::u256_to_bigint256;
use eigensdk_services_operatorsinfo::operatorsinfo_inmemory::OperatorInfoServiceInMemory;
use eigensdk_types::operator::BLSApkRegistry::{G1Point, G2Point};
use eigensdk_types::operator::{
self, OperatorAvsState, OperatorInfo, OperatorPubKeys, QuorumAvsState,
};
use ethers_core::types::{Bytes, U256, U64};
use std::collections::HashMap;

#[derive(Debug, Clone)]
#[derive(Debug)]
pub struct AvsRegistryServiceChainCaller {
avs_registry: AvsRegistryChainReader,
operators_info_service: OperatorInfoServiceInMemory,
Expand All @@ -34,8 +35,8 @@ impl AvsRegistryServiceChainCaller {
&self,
block_num: u32,
quorum_nums: Bytes,
) -> HashMap<[u8; 32], OperatorAvsState> {
let mut operators_avs_state: HashMap<[u8; 32], OperatorAvsState> = HashMap::new();
) -> HashMap<FixedBytes<32>, OperatorAvsState> {
let mut operators_avs_state: HashMap<FixedBytes<32>, OperatorAvsState> = HashMap::new();

let operators_stakes_in_quorums = self
.avs_registry
Expand All @@ -49,12 +50,12 @@ impl AvsRegistryServiceChainCaller {

for (quorum_id, quorum_num) in quorum_nums.iter().enumerate() {
for operator in &operators_stakes_in_quorums[quorum_id] {
let info = self.get_operator_info(operator.operator_id).await;
let info = self.get_operator_info(*operator.operatorId).await;
let stake_per_quorum = HashMap::new();
let avs_state = operators_avs_state
.entry(operator.operator_id)
.entry(FixedBytes(*operator.operatorId))
.or_insert_with(|| OperatorAvsState {
operator_id: operator.operator_id,
operator_id: *operator.operatorId,
operator_info: OperatorInfo { pub_keys: info },
stake_per_quorum: stake_per_quorum,
block_num: block_num.into(),
Expand Down Expand Up @@ -89,20 +90,24 @@ impl AvsRegistryServiceChainCaller {
if !operator.stake_per_quorum[quorum_num].is_zero() {
if let Some(pubkeys) = &operator.operator_info.pub_keys {
let g1_point = BlsG1Point::new(
u256_to_bigint256(pubkeys.g1_pub_key.x),
u256_to_bigint256(pubkeys.g1_pub_key.y),
u256_to_bigint256(pubkeys.g1_pub_key.X),
u256_to_bigint256(pubkeys.g1_pub_key.Y),
);
pub_key_g1.add(g1_point);
total_stake += operator.stake_per_quorum[quorum_num];
}
}
}
let g1_point = convert_to_bn254_g1_point(pub_key_g1.point);
quorums_avs_state.insert(
*quorum_num,
QuorumAvsState {
quorum_num: *quorum_num,
total_stake: total_stake,
agg_pub_key_g1: pub_key_g1,
agg_pub_key_g1: G1Point {
X: g1_point.X,
Y: g1_point.Y,
},
block_num: block_num,
},
);
Expand Down
3 changes: 2 additions & 1 deletion crates/services/bls_aggregation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ eigensdk-crypto-bls.workspace = true
eigensdk-services-avsregistry.workspace = true
parking_lot.workspace = true
tokio = {workspace = true, features = ["full"]}
eigensdk-crypto-bn254.workspace = true
eigensdk-crypto-bn254.workspace = true
alloy-primitives.workspace = true
Loading

0 comments on commit 33b6bea

Please sign in to comment.