-
Notifications
You must be signed in to change notification settings - Fork 52
feat: simple aggregator discovery #2779
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| type Item = AggregatorEndpoint; | ||
|
|
||
| fn next(&mut self) -> Option<Self::Item> { | ||
| while let Some(aggregator_endpoint) = self.inner_iterator.next() { |
Check warning
Code scanning / clippy
this loop could be written as a for loop Warning
| type Item = AggregatorEndpoint; | ||
|
|
||
| fn next(&mut self) -> Option<Self::Item> { | ||
| while let Some(aggregator_endpoint) = self.inner_iterator.next() { |
Check warning
Code scanning / clippy
this loop could be written as a for loop Warning
| if let Ok(aggregator_capabilities) = aggregator_capabilities { | ||
| if CapableAggregatorDiscoverer::capabilities_match( | ||
| &self.capabilities, | ||
| &aggregator_capabilities, | ||
| ) { | ||
| return Some(aggregator_endpoint); | ||
| } | ||
| } |
Check warning
Code scanning / clippy
this if statement can be collapsed Warning
| if let Ok(aggregator_capabilities) = aggregator_capabilities { | ||
| if CapableAggregatorDiscoverer::capabilities_match( | ||
| &self.capabilities, | ||
| &aggregator_capabilities, | ||
| ) { | ||
| return Some(aggregator_endpoint); | ||
| } | ||
| } |
Check warning
Code scanning / clippy
this if statement can be collapsed Warning
| return Err(anyhow!( | ||
| "The genesis verification key must be provided to build the client with the 'with_genesis_verification_key' function" | ||
| ) | ||
| .into()); |
Check warning
Code scanning / clippy
useless conversion to the same type: anyhow::Error Warning
| return Err(anyhow!( | ||
| "The genesis verification key must be provided to build the client with the 'with_genesis_verification_key' function" | ||
| ) | ||
| .into()); |
Check warning
Code scanning / clippy
useless conversion to the same type: anyhow::Error Warning
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements a simple aggregator discovery mechanism to enable the Mithril client to automatically discover and connect to available aggregators in a network.
Key changes:
- Introduces a new
mithril-aggregator-discoverycrate with discoverer implementations - Refactors the
ClientBuilderAPI to support aggregator discovery modes (automatic vs. explicit URL) - Adds capability-based filtering and randomization of aggregator selection
Reviewed Changes
Copilot reviewed 18 out of 20 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
internal/mithril-aggregator-discovery/Cargo.toml |
Defines the new aggregator discovery crate with dependencies |
internal/mithril-aggregator-discovery/src/lib.rs |
Exports the public API for aggregator discovery |
internal/mithril-aggregator-discovery/src/interface.rs |
Defines the AggregatorDiscoverer trait |
internal/mithril-aggregator-discovery/src/model.rs |
Implements MithrilNetwork and AggregatorEndpoint models |
internal/mithril-aggregator-discovery/src/http_config_discoverer.rs |
HTTP-based discoverer that fetches aggregator lists from remote configuration |
internal/mithril-aggregator-discovery/src/capabilities_discoverer.rs |
Filters aggregators by required capabilities |
internal/mithril-aggregator-discovery/src/rand_discoverer.rs |
Shuffles aggregator order using randomization |
internal/mithril-aggregator-discovery/src/test/ |
Test utilities and doubles for testing |
mithril-client/src/client.rs |
Refactors client builder to support aggregator discovery |
mithril-client/Cargo.toml |
Adds dependency on the new discovery crate |
Makefile, Cargo.toml, .github/workflows/ci.yml |
Build configuration updates |
README.md |
Documentation for the new crate |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| impl AggregatorDiscovererFake { | ||
| /// Creates a new `AggregatorDiscovererFake` instance with the provided results. | ||
| pub fn new(results: Vec<AggregatorListReturn>) -> Self { | ||
| dbg!(&results); |
Copilot
AI
Nov 14, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Debug statement should be removed. This dbg! macro call will print to stderr in production code and is typically used only during development.
| dbg!(&results); |
| pub trait AggregatorDiscoverer: Sync + Send { | ||
| /// Get an iterator over a list of available aggregators in a Mithril network. | ||
| /// | ||
| /// Note: there is no guarantee that the returned aggregators is sorted, complete or up-to-date. |
Copilot
AI
Nov 14, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected grammar: 'aggregators is' should be 'aggregators are'.
| /// Note: there is no guarantee that the returned aggregators is sorted, complete or up-to-date. | |
| /// Note: there is no guarantee that the returned aggregators are sorted, complete or up-to-date. |
| @@ -0,0 +1,44 @@ | |||
| [package] | |||
| name = "mithril-aggregator-discovery" | |||
| description = "Mechanisms to discover aggregator available in a Mithril network." | |||
Copilot
AI
Nov 14, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected grammar: 'aggregator available' should be 'aggregators available'.
| description = "Mechanisms to discover aggregator available in a Mithril network." | |
| description = "Mechanisms to discover aggregators available in a Mithril network." |
mithril-client/src/client.rs
Outdated
| let aggregator_endpoint = match self.aggregator_discovery { | ||
| AggregatorDiscoveryType::Url(ref url) => url.clone(), | ||
| AggregatorDiscoveryType::Automatic => { | ||
| todo!("Implement automatic aggregator discovery") |
Copilot
AI
Nov 14, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The todo!() macro will panic at runtime if this code path is executed. Since AggregatorDiscoveryType::Automatic is a public API variant, this creates a potential runtime failure. Consider either removing the Automatic variant until implemented, or returning a proper error with context.
| todo!("Implement automatic aggregator discovery") | |
| return Err(anyhow!("Automatic aggregator discovery is not yet implemented")); |
|
|
||
| - [**Mithril aggregator client**](./internal/mithril-aggregator-client): a client to request data from a Mithril aggregator, used by **Mithril network** nodes and client library. | ||
|
|
||
| - [**Mithril aggregator discovery**](./internal/mithril-aggregator-discovery): mechanisms to discover available Mithril aggregator, used by **Mithril network** nodes and client library. |
Copilot
AI
Nov 14, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected grammar: 'aggregator' should be 'aggregators'.
| - [**Mithril aggregator discovery**](./internal/mithril-aggregator-discovery): mechanisms to discover available Mithril aggregator, used by **Mithril network** nodes and client library. | |
| - [**Mithril aggregator discovery**](./internal/mithril-aggregator-discovery): mechanisms to discover available Mithril aggregators, used by **Mithril network** nodes and client library. |
Implementation for 'AggregatorDiscoverer' trait.
…ementation of 'Iterator' trait
945d3c2 to
c74fb50
Compare
| .into() | ||
| } | ||
| None => { | ||
| return Err(anyhow!("The aggregator discoverer must be provided to build the client with automatic discovery using the 'with_aggregator_discoverer' function").into()); |
Check warning
Code scanning / clippy
useless conversion to the same type: anyhow::Error Warning
| .into() | ||
| } | ||
| None => { | ||
| return Err(anyhow!("The aggregator discoverer must be provided to build the client with automatic discovery using the 'with_aggregator_discoverer' function").into()); |
Check warning
Code scanning / clippy
useless conversion to the same type: anyhow::Error Warning
Content
This PR includes...
Pre-submit checklist
Issue(s)
Closes #2726