|
| 1 | +.. _eigensdk.services: |
| 2 | + |
| 3 | +eigensdk.services |
| 4 | +================= |
| 5 | + |
| 6 | +eigensdk.services.operatorsinfo |
| 7 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 8 | + |
| 9 | +The ``OperatorsInfoServiceInMemory`` is a service designed to manage and maintain a local in-memory store of operator details such as public keys and network socket information. It periodically updates its data by querying the blockchain through an ``AvsRegistryReader`` instance. |
| 10 | + |
| 11 | +Initialization |
| 12 | +-------------- |
| 13 | + |
| 14 | +The service is initialized with the following parameters: |
| 15 | + |
| 16 | +- **avs_registry_reader**: An instance of ``AvsRegistryReader`` used to access operator-related data on the blockchain. |
| 17 | +- **start_block_pub**: The starting block number for querying registered public keys. |
| 18 | +- **start_block_socket**: The starting block number for querying socket information. |
| 19 | +- **check_interval**: The interval in seconds between checks for updates. |
| 20 | +- **log_filter_query_block_range**: The range of blocks to query in one request. |
| 21 | +- **logger**: An optional logger instance for logging events and errors. |
| 22 | + |
| 23 | +.. py:class:: OperatorsInfoServiceInMemory(avs_registry_reader: AvsRegistryReader, start_block_pub: int = 0, start_block_socket: int = 0, check_interval: int = 10, log_filter_query_block_range: int = 10000, logger: Optional[logging.Logger] = None) |
| 24 | +
|
| 25 | + Initializes a new instance of the ``OperatorsInfoServiceInMemory``. |
| 26 | + |
| 27 | + :param avs_registry_reader: Instance of ``AvsRegistryReader`` for blockchain queries. |
| 28 | + :param start_block_pub: Starting block number for public key queries. |
| 29 | + :param start_block_socket: Starting block number for socket info queries. |
| 30 | + :param check_interval: Time interval between update checks. |
| 31 | + :param log_filter_query_block_range: Block range for each query to the blockchain. |
| 32 | + :param logger: Logger for event logging. |
| 33 | + |
| 34 | +Functionality |
| 35 | +------------- |
| 36 | + |
| 37 | +The service runs continuously in a separate thread, periodically updating its internal data stores based on the latest information from the blockchain. It supports the following functionalities: |
| 38 | + |
| 39 | +- **Operator Public Key Retrieval**: Fetches and stores the latest public keys registered on the blockchain. |
| 40 | +- **Operator Socket Information Retrieval**: Fetches and stores the latest socket information registered on the blockchain. |
| 41 | +- **Operator Info Retrieval**: Provides a method to retrieve detailed information about an operator given their address. |
| 42 | + |
| 43 | +.. py:method:: get_operator_info(operator_addr: Address) -> OperatorInfo |
| 44 | +
|
| 45 | + Retrieves detailed information about an operator, including their socket information and public keys. |
| 46 | + |
| 47 | + :param operator_addr: The blockchain address of the operator. |
| 48 | + :return: An instance of ``OperatorInfo`` containing the operator's details. |
| 49 | + |
| 50 | +Example Usage |
| 51 | +------------- |
| 52 | + |
| 53 | +The service can be used in an application that requires up-to-date information about blockchain operators, such as in a decentralized application (dApp) that interacts with various blockchain services: |
| 54 | + |
| 55 | +.. code-block:: python |
| 56 | +
|
| 57 | + >>> operator_info_service = OperatorsInfoServiceInMemory(clients.avs_registry_reader) |
| 58 | + >>> operator_info = operator_info_service.get_operator_info('0x123...') |
| 59 | + >>> print(f"Operator Socket: {operator_info.socket}, Public Keys: {operator_info.pub_keys}") |
| 60 | +
|
| 61 | +
|
| 62 | +This example initializes the service and retrieves operator information, demonstrating how to integrate and utilize the ``OperatorsInfoServiceInMemory`` within larger systems. |
| 63 | + |
| 64 | +eigensdk.services.avsregistry |
| 65 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 66 | + |
| 67 | +The ``AvsRegistryService`` is designed to aggregate and provide access to detailed state information about operators and their stakes across different quorums. It utilizes data from both the ``AvsRegistryReader`` and ``OperatorsInfoServiceInMemory`` to construct comprehensive views of the AVS (Autonomous Validation Services) landscape at specific blockchain states. |
| 68 | + |
| 69 | +Initialization |
| 70 | +-------------- |
| 71 | + |
| 72 | +The service is initialized with instances of ``AvsRegistryReader`` and ``OperatorsInfoServiceInMemory``, along with a logger for event logging. |
| 73 | + |
| 74 | +.. py:class:: AvsRegistryService(avs_registry_reader: AvsRegistryReader, operator_info_service: OperatorsInfoServiceInMemory, logger: logging.Logger) |
| 75 | +
|
| 76 | + Initializes a new instance of the ``AvsRegistryService``. |
| 77 | + |
| 78 | + :param avs_registry_reader: Instance of ``AvsRegistryReader`` for reading blockchain data. |
| 79 | + :param operator_info_service: Instance of ``OperatorsInfoServiceInMemory`` for managing in-memory operator data. |
| 80 | + :param logger: Logger for event logging. |
| 81 | + |
| 82 | +Functionality |
| 83 | +------------- |
| 84 | + |
| 85 | +The service offers functionalities to retrieve aggregated operator states and quorum states at specific blocks, helping in the analysis and management of AVS. |
| 86 | + |
| 87 | +.. py:method:: get_operators_avs_state_at_block(quorum_numbers: List[int], block_number: int) -> Dict[bytes, OperatorAvsState] |
| 88 | +
|
| 89 | + Retrieves the AVS state of operators at a specific blockchain block. |
| 90 | + |
| 91 | + :param quorum_numbers: List of quorum numbers to query. |
| 92 | + :param block_number: The blockchain block number at which to get the state. |
| 93 | + :return: A dictionary mapping operator IDs to their ``OperatorAvsState``. |
| 94 | + |
| 95 | +.. py:method:: get_quorums_avs_state_at_block(quorum_numbers: List[int], block_number: int) -> Dict[int, Dict[str, Union[int, G1Point]]] |
| 96 | +
|
| 97 | + Aggregates the state of specified quorums at a given block number, including the aggregated public keys and total stakes. |
| 98 | + |
| 99 | + :param quorum_numbers: List of quorum numbers to aggregate. |
| 100 | + :param block_number: The blockchain block number at which to aggregate the state. |
| 101 | + :return: A dictionary with quorum numbers as keys and details including aggregated public keys, total stakes, and block numbers. |
| 102 | + |
| 103 | +Example Usage |
| 104 | +------------- |
| 105 | + |
| 106 | +The following example demonstrates how to use the ``AvsRegistryService`` to fetch and display operator and quorum states at a specific blockchain block: |
| 107 | + |
| 108 | +.. code-block:: python |
| 109 | +
|
| 110 | + >>> avs_registry_service = AvsRegistryService(clients.avs_registry_reader, operator_info_service, logger) |
| 111 | + >>> quorum_numbers = [0, 1] |
| 112 | + >>> block_number = 12345 |
| 113 | + >>> operators_state = avs_registry_service.get_operators_avs_state_at_block(quorum_numbers, block_number) |
| 114 | + >>> print(operators_state) |
| 115 | + >>> quorums_state = avs_registry_service.get_quorums_avs_state_at_block(quorum_numbers, block_number) |
| 116 | + >>> print(quorums_state) |
| 117 | +
|
| 118 | +This example shows how to initialize the service and retrieve detailed state information for operators and quorums, providing insights into the current and historical configurations of the AVS within the blockchain. |
| 119 | + |
| 120 | + |
| 121 | +eigensdk.services.bls_aggregation.blsagg |
| 122 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 123 | + |
| 124 | +The ``BlsAggregationService`` is integral to aggregating Boneh-Lynn-Shacham (BLS) signatures in distributed validation systems, ensuring task authenticity and integrity across multiple nodes. |
| 125 | + |
| 126 | +Initialization |
| 127 | +-------------- |
| 128 | + |
| 129 | +The service is initiated with an instance of ``AvsRegistryService`` and a cryptographic hash function. These components enable it to verify and aggregate signatures while interacting with blockchain state data. |
| 130 | + |
| 131 | +.. py:class:: BlsAggregationService(avs_registry_service: AvsRegistryService, hash_function: any) |
| 132 | +
|
| 133 | + Initializes a new instance of ``BlsAggregationService``. |
| 134 | + |
| 135 | + :param avs_registry_service: An instance of ``AvsRegistryService`` used for querying blockchain data. |
| 136 | + :param hash_function: A cryptographic hash function used for digest generation. |
| 137 | + |
| 138 | +Functionality |
| 139 | +------------- |
| 140 | + |
| 141 | +The service provides methods to initialize new tasks, process new signatures, and retrieve aggregated responses. It verifies signatures against blockchain data and aggregates them if they meet predefined quorum requirements. |
| 142 | + |
| 143 | +.. py:method:: initialize_new_task(task_index: int, task_created_block: int, quorum_numbers: List[int], quorum_threshold_percentages: List[int], time_to_expiry: int) |
| 144 | +
|
| 145 | + Prepares a new task for aggregation, setting initial parameters and storing them internally. |
| 146 | + |
| 147 | +.. py:method:: process_new_signature(task_index: int, task_response: str, bls_signature: Signature, operator_id: int) |
| 148 | +
|
| 149 | + Processes and aggregates a new BLS signature related to a specific task, verifying its authenticity and adding it to the aggregate. |
| 150 | + |
| 151 | +.. py:method:: get_aggregated_responses() -> Iterator[BlsAggregationServiceResponse] |
| 152 | +
|
| 153 | + Yields completed task responses once they meet aggregation criteria, indicating successful validation. |
| 154 | + |
| 155 | +Data Structures |
| 156 | +--------------- |
| 157 | + |
| 158 | +- **TaskListItem**: Maintains task-specific data, including state of operator signatures and stake thresholds. |
| 159 | +- **AggregatedOperators**: Stores aggregated public keys and signatures for operators who have signed a specific task response. |
| 160 | + |
| 161 | +Example Usage |
| 162 | +------------- |
| 163 | + |
| 164 | +The following example demonstrates initializing the service, managing task signatures, and validating task completion: |
| 165 | + |
| 166 | +.. code-block:: python |
| 167 | +
|
| 168 | + >>> bls_aggregation_service = BlsAggregationService(avs_registry_service, hash_function) |
| 169 | + >>> task_index = 1 |
| 170 | + >>> quorum_numbers = [0, 1] |
| 171 | + >>> quorum_thresholds = [70, 70] |
| 172 | + >>> # Initialize a new task |
| 173 | + >>> bls_aggregation_service.initialize_new_task(task_index, 123456, quorum_numbers, quorum_thresholds, 3600) |
| 174 | + >>> # Process a new signature |
| 175 | + >>> operator_id = 101 |
| 176 | + >>> task_response = 'response data' |
| 177 | + >>> bls_signature = Signature(...) # Assuming a valid BLS signature |
| 178 | + >>> bls_aggregation_service.process_new_signature(task_index, task_response, bls_signature, operator_id) |
| 179 | + >>> # Retrieve and handle aggregated responses |
| 180 | + >>> for response in bls_aggregation_service.get_aggregated_responses(): |
| 181 | + ... print(response) |
| 182 | +
|
| 183 | +This service is crucial for ensuring tasks are validated correctly and efficiently, using cryptographic guarantees provided by BLS signatures and blockchain data. |
| 184 | + |
0 commit comments