1
1
use anyhow:: anyhow;
2
2
use async_trait:: async_trait;
3
- use mithril_common:: messages:: TryFromMessageAdapter ;
4
3
use reqwest:: header:: { self , HeaderValue } ;
5
4
use reqwest:: { self , Client , Proxy , RequestBuilder , Response , StatusCode } ;
6
5
use semver:: Version ;
@@ -16,9 +15,6 @@ use mithril_common::{
16
15
messages:: EpochSettingsMessage ,
17
16
} ;
18
17
19
- use crate :: http:: from_epoch_settings:: FromEpochSettingsAdapter ;
20
- use crate :: signer_epoch_settings:: SignerEpochSettings ;
21
-
22
18
const JSON_CONTENT_TYPE : HeaderValue = HeaderValue :: from_static ( "application/json" ) ;
23
19
24
20
const API_VERSION_MISMATCH_WARNING_MESSAGE : & str =
@@ -59,10 +55,6 @@ pub enum AggregatorClientError {
59
55
#[ error( "proxy creation failed" ) ]
60
56
ProxyCreation ( #[ source] StdError ) ,
61
57
62
- /// Adapter error
63
- #[ error( "adapter failed" ) ]
64
- Adapter ( #[ source] StdError ) ,
65
-
66
58
/// No signer registration round opened yet
67
59
#[ error( "a signer registration round is not opened yet, please try again later" ) ]
68
60
RegistrationRoundNotYetOpened ( #[ source] StdError ) ,
@@ -131,7 +123,7 @@ pub trait AggregatorClient: Sync + Send {
131
123
/// Retrieves epoch settings from the aggregator
132
124
async fn retrieve_epoch_settings (
133
125
& self ,
134
- ) -> Result < Option < SignerEpochSettings > , AggregatorClientError > ;
126
+ ) -> Result < Option < EpochSettingsMessage > , AggregatorClientError > ;
135
127
}
136
128
137
129
/// AggregatorHTTPClient is a http client for an aggregator
@@ -230,7 +222,7 @@ impl AggregatorHTTPClient {
230
222
impl AggregatorClient for AggregatorHTTPClient {
231
223
async fn retrieve_epoch_settings (
232
224
& self ,
233
- ) -> Result < Option < SignerEpochSettings > , AggregatorClientError > {
225
+ ) -> Result < Option < EpochSettingsMessage > , AggregatorClientError > {
234
226
debug ! ( self . logger, "Retrieve epoch settings" ) ;
235
227
let url = format ! ( "{}/epoch-settings" , self . aggregator_endpoint) ;
236
228
let response = self
@@ -243,11 +235,7 @@ impl AggregatorClient for AggregatorHTTPClient {
243
235
StatusCode :: OK => {
244
236
self . warn_if_api_version_mismatch ( & response) ;
245
237
match response. json :: < EpochSettingsMessage > ( ) . await {
246
- Ok ( message) => {
247
- let epoch_settings = FromEpochSettingsAdapter :: try_adapt ( message)
248
- . map_err ( |e| AggregatorClientError :: Adapter ( anyhow ! ( e) ) ) ?;
249
- Ok ( Some ( epoch_settings) )
250
- }
238
+ Ok ( message) => Ok ( Some ( message) ) ,
251
239
Err ( err) => Err ( AggregatorClientError :: JsonParseFailed ( anyhow ! ( err) ) ) ,
252
240
}
253
241
}
@@ -269,7 +257,7 @@ pub(crate) mod dumb {
269
257
/// It actually does not communicate with an aggregator host but mimics this behavior.
270
258
/// It is driven by a Tester that controls the data it can return, and it can return its internal state for testing.
271
259
pub struct DumbAggregatorClient {
272
- epoch_settings : RwLock < Option < SignerEpochSettings > > ,
260
+ epoch_settings : RwLock < Option < EpochSettingsMessage > > ,
273
261
}
274
262
275
263
// impl DumbAggregatorClient {
@@ -282,7 +270,7 @@ pub(crate) mod dumb {
282
270
impl Default for DumbAggregatorClient {
283
271
fn default ( ) -> Self {
284
272
Self {
285
- epoch_settings : RwLock :: new ( Some ( SignerEpochSettings :: dummy ( ) ) ) ,
273
+ epoch_settings : RwLock :: new ( Some ( EpochSettingsMessage :: dummy ( ) ) ) ,
286
274
}
287
275
}
288
276
}
@@ -291,7 +279,7 @@ pub(crate) mod dumb {
291
279
impl AggregatorClient for DumbAggregatorClient {
292
280
async fn retrieve_epoch_settings (
293
281
& self ,
294
- ) -> Result < Option < SignerEpochSettings > , AggregatorClientError > {
282
+ ) -> Result < Option < EpochSettingsMessage > , AggregatorClientError > {
295
283
let epoch_settings = self . epoch_settings . read ( ) . await . clone ( ) ;
296
284
297
285
Ok ( epoch_settings)
@@ -389,10 +377,7 @@ mod tests {
389
377
390
378
let epoch_settings = client. retrieve_epoch_settings ( ) . await ;
391
379
epoch_settings. as_ref ( ) . expect ( "unexpected error" ) ;
392
- assert_eq ! (
393
- FromEpochSettingsAdapter :: try_adapt( epoch_settings_expected) . unwrap( ) ,
394
- epoch_settings. unwrap( ) . unwrap( )
395
- ) ;
380
+ assert_eq ! ( epoch_settings_expected, epoch_settings. unwrap( ) . unwrap( ) ) ;
396
381
}
397
382
398
383
#[ tokio:: test]
0 commit comments