Skip to content

Commit

Permalink
refactor: separate interface and service in bls_aggr (#363)
Browse files Browse the repository at this point in the history
### What Changed?
This PR refactors the BLS Aggregator by separating its interface from
the internal service logic.
- Add new struct `ServiceHandle` to serve as the interface for
communicating with the BLS Aggregator service. This interface provides
two new methods
- `initialize_task`: Sends a message to the BLS Aggregator Service to
initialize a new task.
- `process_signature`: Sends a message to the BLS Aggregator Service to
process a signature.
- Add new struct `AggregateReceiver` to receive the aggregated responses
from the BLS Aggregator Service.
- Remove channels from `BlsAggregatorService`
- Add new methods to `BlsAggregatorService`:
- `start`: Starts the BLS Aggregator Service running the main loop in
background. This method return a tuple with `ServiceHandle` and
`AggregateReceiver`. User can use these methods to interact with the
service.
  - `run`: Runs the main loop of the BLS Aggregator Service.
- Remove `initialize_new_task` and `process_new_signature` functions
since their logic is now integrated in `run()`.

Close #257 

### Reviewer Checklist

- [ ] New features are tested and documented
- [ ] PR updates the changelog with a description of changes
- [ ] PR has one of the `changelog-X` labels (if applies)
- [ ] Code deprecates any old functionality before removing it

---------

Co-authored-by: Tomás Grüner <47506558+MegaRedHand@users.noreply.github.com>
  • Loading branch information
damiramirez and MegaRedHand authored Feb 19, 2025
1 parent cd287d8 commit cf37ee2
Show file tree
Hide file tree
Showing 3 changed files with 456 additions and 491 deletions.
55 changes: 55 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,61 @@ Those changes in added, changed or breaking changes, should include usage exampl

* `TaskMetadata.task_created_block` field changed to `u64` [#362](https://github.com/Layr-Labs/eigensdk-rs/pull/362)

* Refactor `bls_aggr` module in [#363](https://github.com/Layr-Labs/eigensdk-rs/pull/363).
- Separated the interface and service in the `bls_aggr` module.
- To interact with the BLS aggregation service, use the `ServiceHandle` struct. Aggregation responses are now handled by the `AggregateReceiver` struct.
- To initialize both structs, use the `BLSAggregationService::start` method. It returns a tuple with the `ServiceHandle` and `AggregateReceiver` structs.
- Add methods `start` and `run` to `BLSAggregationService` struct.
- Removed `initialize_new_task` and `process_new_signature` functions since their logic is now integrated in `run()`.

```rust
// Before
let bls_agg_service = BlsAggregatorService::new(avs_registry_service, get_test_logger());
let metadata = TaskMetadata::new(
task_index,
block_number,
quorum_numbers,
quorum_threshold_percentages,
time_to_expiry,
);

bls_agg_service.initialize_new_task(metadata).await.unwrap();

bls_agg_service
.process_new_signature(TaskSignature::new(
task_index,
task_response_digest,
bls_signature,
test_operator_1.operator_id,
))
.await
.unwrap();

// After
let bls_agg_service = BlsAggregatorService::new(avs_registry_service, get_test_logger());
let (handle, mut aggregator_response) = bls_agg_service.start();

let metadata = TaskMetadata::new(
task_index,
block_number,
quorum_numbers,
quorum_threshold_percentages,
time_to_expiry,
);
handle.initialize_task(metadata).await.unwrap();

handle
.process_signature(TaskSignature::new(
task_index,
task_response_digest,
bls_signature,
test_operator_1.operator_id,
))
.await
.unwrap();
```


### Deprecated ⚠️

### Removed 🗑
Expand Down
Loading

0 comments on commit cf37ee2

Please # to comment.