Skip to content

Commit

Permalink
more docs
Browse files Browse the repository at this point in the history
  • Loading branch information
pablodeymo committed Sep 18, 2024
1 parent 904e4b7 commit fb3ef4d
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 27 deletions.
10 changes: 5 additions & 5 deletions crates/services/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# SDK services
# SDK services

The eigensdk provides 3 services , namely :
The eigensdk provides 3 services, namely :

- OperatorInfoServiceInMemory
- **OperatorInfoServiceInMemory**
- The `eigen-services-operatorsinfo` crate provides functionalities to manage and track operator information using an in-memory database. It supports querying past operato registrations, subscribing to new operator registration events, and retrieving operator information efficiently.

- eigen-services-avsregistry
- The `eigen-services-avsregistry` crate is a wrapper around AvsRegistryReader.
- `eigen-services-avsregistry`
- The `eigen-services-avsregistry` crate is a wrapper around AvsRegistryReader.
1 change: 1 addition & 0 deletions crates/services/operatorsinfo/src/fake_operator_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use eigen_types::operator::{OperatorInfo, OperatorPubKeys};

use crate::{operator_info::OperatorInfoService, operatorsinfo_inmemory::OperatorInfoServiceError};

/// A fake implementation of the `OperatorInfoService` trait that can be used for testing or debug purposes.
pub struct FakeOperatorInfoService {
pub pubkeys: OperatorInfo,
}
Expand Down
2 changes: 2 additions & 0 deletions crates/services/operatorsinfo/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! This crate provides traits and methods to get operator information.

#![doc(
html_logo_url = "https://github.com/Layr-Labs/eigensdk-rs/assets/91280922/bd13caec-3c00-4afc-839a-b83d2890beb5",
issue_tracker_base_url = "https://github.com/Layr-Labs/eigensdk-rs/issues/"
Expand Down
65 changes: 50 additions & 15 deletions crates/services/operatorsinfo/src/operatorsinfo_inmemory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ use tokio_util::sync::CancellationToken;

use crate::operator_info::OperatorInfoService;

/// Fetchs operator information from the registry.
/// Loads and stores operators info (addresses and public key) in memory.
#[allow(dead_code)]
#[derive(Debug, Clone)]
pub struct OperatorInfoServiceInMemory {
Expand All @@ -35,12 +37,14 @@ pub struct OperatorInfoServiceInMemory {
pub_keys: UnboundedSender<OperatorsInfoMessage>,
}

/// State of the operator info service.
#[derive(Debug, Clone)]
struct OperatorState {
operator_info_data: Arc<RwLock<HashMap<Address, OperatorPubKeys>>>,
operator_addr_to_id: Arc<RwLock<HashMap<Address, FixedBytes<32>>>>,
}

/// Error type for the operator info service.
#[derive(Error, Debug, Clone, PartialEq, Eq)]
pub enum OperatorInfoServiceError {
#[error("failed to retrieve operator info")]
Expand Down Expand Up @@ -85,6 +89,17 @@ impl OperatorInfoService for OperatorInfoServiceInMemory {
}

impl OperatorInfoServiceInMemory {
/// Creates a new operator info service given a logger, an avs registry chain reader and a web socket.
///
/// # Arguments
///
/// * `logger` - A shared logger.
/// * `avs_registry_chain_reader` - An avs registry chain reader.
/// * `web_socket` - A web socket.
///
/// # Returns
///
/// A new operator info service.
pub async fn new(
logger: SharedLogger,
avs_registry_chain_reader: AvsRegistryChainReader,
Expand Down Expand Up @@ -131,6 +146,17 @@ impl OperatorInfoServiceInMemory {
}
}

/// Starts the operator info service.
///
/// # Arguments
///
/// * `cancellation_token` - A cancellation token than can be used to stop the service.
/// * `start_block` - The start block to query for past operator registrations.
/// * `end_block` - The end block to query for past operator registrations.
///
/// # Returns
///
/// Ok(()) if successful, otherwise an error.
pub async fn start_service(
&self,
cancellation_token: &CancellationToken,
Expand Down Expand Up @@ -215,6 +241,18 @@ impl OperatorInfoServiceInMemory {
Ok(())
}

/// Queries past operator registration events and fills the database by sending messages
/// to the operator info service channel.
/// This information is then stored in OperatorState`.
///
/// # Arguments
///
/// * `start_block` - The start block to query for past operator registrations.
/// * `end_block` - The end block to query for past operator registrations.
///
/// # Returns
///
/// Ok(()) if successful, otherwise an error.
pub async fn query_past_registered_operator_events_and_fill_db(
&self,
start_block: u64,
Expand Down Expand Up @@ -470,23 +508,20 @@ mod tests {
.unwrap();

let bls_key_pair = BlsKeyPair::new(bls_key.to_string()).unwrap();
let salt: FixedBytes<32> = FixedBytes::from([
0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,
0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,
0x02, 0x02, 0x02, 0x02,
]);
let salt: FixedBytes<32> = FixedBytes::from([0x02; 32]);
let now = SystemTime::now();
let mut expiry: U256 = U256::from(0);

// Convert SystemTime to a Duration since the UNIX epoch
if let Ok(duration_since_epoch) = now.duration_since(UNIX_EPOCH) {
// Convert the duration to seconds
let seconds = duration_since_epoch.as_secs(); // Returns a u64

// Convert seconds to U256
expiry = U256::from(seconds) + U256::from(10000);
} else {
println!("System time seems to be before the UNIX epoch.");
}
let duration_since_epoch = now
.duration_since(UNIX_EPOCH)
.inspect_err(|_| println!("System time seems to be before the UNIX epoch."))
.unwrap();
// Convert the duration to seconds
let seconds = duration_since_epoch.as_secs(); // Returns a u64

// Convert seconds to U256
let expiry = U256::from(seconds) + U256::from(10000);

let quorum_numbers = Bytes::from_str("0x00").unwrap();
let socket = "socket";

Expand Down
4 changes: 2 additions & 2 deletions crates/signer/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Eigen Signer

The `eigen-signer` crates provides utilities for creating and managing different types of signers for Ethereum transactions.
The `eigen-signer` crates provides utilities for creating and managing different types of signers for Ethereum transactions.
This includes Private Key signers, keystore signers, AWS KMS-based signers and Web3Signer.

## Example
## Example
1 change: 1 addition & 0 deletions crates/signer/src/web3_signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub struct Web3Signer {
pub address: Address,
}

/// Parameters for the `eth_signTransaction` method
#[derive(Serialize, Clone, Debug)]
#[serde(rename_all = "camelCase")]
struct SignTransactionParams {
Expand Down
2 changes: 1 addition & 1 deletion crates/types/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Eigen types

This crate contains commonly used type definitions used across the SDK.
This crate contains commonly used type definitions used across the SDK.
2 changes: 2 additions & 0 deletions crates/types/src/avs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub type TaskIndex = u32;

pub type TaskResponseDigest = FixedBytes<32>;

/// Error type for signature verification
#[derive(Error, Debug, Clone, PartialEq, Eq)]
pub enum SignatureVerificationError {
#[error("incorrect signature error")]
Expand All @@ -16,6 +17,7 @@ pub enum SignatureVerificationError {
OperatorNotFound,
}

/// Represents a signed task response digest
#[derive(Debug, Clone)]
pub struct SignedTaskResponseDigest {
pub task_response_digest: TaskResponseDigest,
Expand Down
8 changes: 4 additions & 4 deletions crates/types/src/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ use ethers::{types::U64, utils::keccak256};
use num_bigint::BigUint;
use std::collections::HashMap;

const MAX_NUMBER_OF_QUORUMS: usize = 192;
const MAX_NUMBER_OF_QUORUMS: u8 = 192;

pub type OperatorId = FixedBytes<32>;

pub fn bitmap_to_quorum_ids(quorum_bitmaps: U256) -> Vec<u8> {
let bytes = quorum_bitmaps.to_be_bytes::<32>();

let mut quorum_ids: Vec<u8> = Vec::with_capacity(MAX_NUMBER_OF_QUORUMS);
let mut quorum_ids: Vec<u8> = Vec::with_capacity(usize::from(MAX_NUMBER_OF_QUORUMS));

for i in 0..MAX_NUMBER_OF_QUORUMS {
let bitmap = BigUint::from_bytes_be(&bytes);
if bitmap.bit(i.try_into().unwrap()) {
quorum_ids.push(i.try_into().unwrap());
if bitmap.bit(u64::from(i)) {
quorum_ids.push(i);
}
}
quorum_ids
Expand Down
2 changes: 2 additions & 0 deletions crates/types/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::collections::HashMap;

type StakeAmount = U256;

/// Test operator for testing purposes
#[derive(Clone)]
pub struct TestOperator {
pub operator_id: B256,
Expand All @@ -13,6 +14,7 @@ pub struct TestOperator {
}

impl TestOperator {
/// Get the BLS keypair of the operator
pub fn get_bls_keypair(&self) -> &BlsKeyPair {
&self.bls_keypair
}
Expand Down

0 comments on commit fb3ef4d

Please sign in to comment.