Skip to content

Conversation

@Alenar
Copy link
Collaborator

@Alenar Alenar commented Jul 31, 2025

Content

This PR add a new mithril-aggregator-client internal crate that define a api allowing to fetch and send data through Http to a Mithril Aggregator.

This is a first step that define the internal mechanism but all available queries are yet to be implemented in order to replace existing clients in the aggregator, signer and client lib.

Details

  • new mithril-aggregator-client internal crate
    • Define a AggregatorClient struct that expose one method: send
    • This send method can take any object that implement the, crate internal, AggregatorQuery trait
    • The AggregatorClient is meant to be built using a builder pattern accessible from either AggregatorClient::builder or directly though the builder: AggregatorClientBuilder::new(aggregator_url)
    • The client have all features that are available on our three builders:
      • timeout
      • relay endpoint proxy
      • aggregator url sanitation
      • mithril api version header
      • api version mismatch warning
      • configurable additional header
      • error analysis
      • mithril specific 450 http code error handling (registration round not opened)
    • One query is defined as example, including tests: CertificateDetailsQuery to retrieve a certificate with a given hash or the latest genesis
  • mithril-common - make ApiVersionProviderTestExtensions that defines three test utilities: update_open_api_versions (test method moved from ApiVersionProvider public api), new_with_default_version({Version}), and new_failing

Pre-submit checklist

  • Branch
    • Tests are provided (if possible)
    • Crates versions are updated (if relevant)
    • Commit sequence broadly makes sense
    • Key commits have useful messages
  • PR
    • All check jobs of the CI have succeeded
    • Self-reviewed the diff
    • Useful pull request description
    • Reviewer requested
  • Documentation
    • Update README file (if relevant)
    • No new TODOs introduced

Comments

Todo

A TODO is added because of an unwrap in AggregatorClient.send:

// Todo: error handling ? Reuse the version in `warn_if_api_version_mismatch` ?
let current_api_version = self.api_version_provider.compute_current_version().unwrap();

This unwrap is a strict copy from all three existing aggregator client behavior, this raise a question if a mithril api version, and by extension sending the mithril-api-version header, is mandatory or not. Especially since the behavior of warn_if_api_version_mismatch, that is used afterward when handling the response, in all three clients is to not crash if an error is raised when computing the version.

Api design choice

The choice have been made of making the AggregatorQuery trait internal to the crate, this means childs crates can't define custom queries.
The idea behind this choice is that the public api of the crate avoid exposing types from third party, non-mithril, crates, but the AggregatorQuery mechanism need to pass around a reqwest::Response, so making this trait public would be exposing a "leaking" abstraction.

We may decide instead to take that upfront if we think that defining queries on a child crate is useful, but since all messages that are available from a mithril aggregator are defined in the shared mithril-common crate right now there's no difficulty to define all queries in the mithril-aggregator-client crate.

Issue(s)

Relates to #2640

@Alenar Alenar self-assigned this Jul 31, 2025
@Alenar Alenar added the refactoring 🛠️ Code refactoring and enhancements label Jul 31, 2025
Copy link

Copilot AI left a 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 introduces a new shared aggregator client for the Mithril network, providing a reusable HTTP client library for communicating with Mithril aggregators. The client includes query abstractions, error handling, API version compatibility checking, and comprehensive test coverage.

Key changes:

  • New mithril-aggregator-client crate with HTTP client functionality
  • API version provider extensions for testing
  • Certificate details query implementation
  • Comprehensive error handling and logging

Reviewed Changes

Copilot reviewed 18 out of 19 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
internal/mithril-aggregator-client/ Complete new crate implementing the aggregator client with builder pattern, query system, and error handling
mithril-common/src/api_version.rs Added Default implementation and test extensions for APIVersionProvider
mithril-common/src/test/api_version_extensions.rs New test utilities for API version provider testing
README.md Updated documentation to include the new aggregator client
Cargo.toml Added new crate to workspace members
.github/workflows/ci.yml Updated CI to include documentation generation for the new crate

@github-actions
Copy link

github-actions bot commented Jul 31, 2025

Test Results

    4 files  ±  0    158 suites  +4   22m 33s ⏱️ -11s
2 152 tests + 31  2 152 ✅ + 31  0 💤 ±0  0 ❌ ±0 
6 602 runs  +124  6 602 ✅ +124  0 💤 ±0  0 ❌ ±0 

Results for commit 70c6c51. ± Comparison against base commit cdc4548.

♻️ This comment has been updated with latest results.

@Alenar Alenar temporarily deployed to testing-preview July 31, 2025 10:02 — with GitHub Actions Inactive
Copy link
Collaborator

@dlachaume dlachaume left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just need to add WASM compatibility, otherwise LGTM 🚀.

Copy link
Collaborator

@turmelclem turmelclem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🦙

@Alenar Alenar force-pushed the ensemble/2640/shared-aggretator-client branch 2 times, most recently from cf54bcc to 2b0a600 Compare July 31, 2025 12:21
Alenar added 6 commits July 31, 2025 14:25
and move certificate_details query to `query::certificate::get_certificate_details`
This is useful for context when the `APIVersionProvider` don't need to
return response that may evolve at runtime, such as with the
aggregator-client in the mithril-client.

This also enable the new shared aggregator-client to have a default api
version provider, that will always use the base `openapi.yml`, but
provide a way to use another provider in its builder (for the aggregator
and the client that will fetch the version discriminant based on the
chain).
@Alenar Alenar force-pushed the ensemble/2640/shared-aggretator-client branch from 2b0a600 to fc997ea Compare July 31, 2025 12:32
@Alenar Alenar temporarily deployed to testing-preview July 31, 2025 12:43 — with GitHub Actions Inactive
Alenar added 3 commits July 31, 2025 14:47
Make one test for shared features on http method instead of testing them
on both get and post
…t latest genesis

imported and adapted from the associated route tests in the
`mithril-aggregator` aggregator client.
* mithril-aggregator from `0.7.77` to `0.7.78`
* mithril-common from `0.6.12` to `0.6.13`
* mithril-signer from `0.2.262` to `0.2.263`
@Alenar Alenar force-pushed the ensemble/2640/shared-aggretator-client branch from fc997ea to 70c6c51 Compare July 31, 2025 12:48
@Alenar Alenar temporarily deployed to testing-preview July 31, 2025 12:57 — with GitHub Actions Inactive
@Alenar Alenar merged commit 3657df1 into main Jul 31, 2025
41 checks passed
@Alenar Alenar deleted the ensemble/2640/shared-aggretator-client branch July 31, 2025 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactoring 🛠️ Code refactoring and enhancements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants