Skip to content

Commit 9168007

Browse files
committed
wip: aggregator can run custom aggregation proof type
1 parent 57d6728 commit 9168007

File tree

28 files changed

+350
-158
lines changed

28 files changed

+350
-158
lines changed

mithril-aggregator/src/configuration.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use mithril_common::entities::{
1414
SignedEntityTypeDiscriminants,
1515
};
1616
use mithril_common::era::adapters::EraReaderAdapterType;
17-
use mithril_common::{CardanoNetwork, StdResult};
17+
use mithril_common::{CardanoNetwork, StdResult, StmAggrSigType};
1818
use mithril_doc::{Documenter, DocumenterDefault, StructDoc};
1919

2020
use crate::entities::AggregatorEpochSettings;
@@ -212,6 +212,9 @@ pub struct Configuration {
212212
/// Custom origin tag of client request added to the whitelist (comma
213213
/// separated list).
214214
pub custom_origin_tag_white_list: Option<String>,
215+
216+
/// Aggregation type used to compute the multi-signature
217+
pub aggregation_type: StmAggrSigType,
215218
}
216219

217220
/// Uploader needed to copy the snapshot once computed.
@@ -331,6 +334,7 @@ impl Configuration {
331334
persist_usage_report_interval_in_seconds: 10,
332335
leader_aggregator_endpoint: None,
333336
custom_origin_tag_white_list: None,
337+
aggregation_type: StmAggrSigType::StmAggrSigConcatenation,
334338
}
335339
}
336340

mithril-aggregator/src/dependency_injection/builder/enablers/epoch.rs

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ impl DependenciesBuilder {
2626
stake_store,
2727
),
2828
allowed_discriminants,
29+
self.configuration.aggregation_type,
2930
self.root_logger(),
3031
)));
3132

mithril-aggregator/src/dependency_injection/builder/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ impl DependenciesBuilder {
421421
cardano_node_version: self.configuration.cardano_node_version.clone(),
422422
allow_http_serve_directory: self.configuration.allow_http_serve_directory(),
423423
origin_tag_white_list: self.configuration.compute_origin_tag_white_list(),
424+
aggregation_type: self.configuration.aggregation_type,
424425
},
425426
);
426427

mithril-aggregator/src/http_server/routes/root_routes.rs

+8
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,17 @@ fn root(
2121
.and(middlewares::extract_config(router_state, |config| {
2222
config.cardano_transactions_prover_max_hashes_allowed_by_request
2323
}))
24+
.and(middlewares::extract_config(router_state, |config| {
25+
config.aggregation_type
26+
}))
2427
.and_then(handlers::root)
2528
}
2629

2730
mod handlers {
2831
use std::collections::BTreeSet;
2932
use std::{convert::Infallible, sync::Arc};
3033

34+
use mithril_common::StmAggrSigType;
3135
use slog::Logger;
3236
use warp::http::StatusCode;
3337

@@ -46,6 +50,7 @@ mod handlers {
4650
api_version_provider: Arc<APIVersionProvider>,
4751
allowed_signed_entity_type_discriminants: BTreeSet<SignedEntityTypeDiscriminants>,
4852
max_hashes_allowed_by_request: usize,
53+
aggregation_type: StmAggrSigType,
4954
) -> Result<impl warp::Reply, Infallible> {
5055
let open_api_version = unwrap_to_internal_server_error!(
5156
api_version_provider.compute_current_version(),
@@ -72,6 +77,7 @@ mod handlers {
7277
open_api_version: open_api_version.to_string(),
7378
documentation_url: env!("CARGO_PKG_HOMEPAGE").to_string(),
7479
capabilities,
80+
aggregation_type: aggregation_type.to_string(),
7581
},
7682
StatusCode::OK,
7783
))
@@ -87,6 +93,7 @@ mod tests {
8793
AggregatorCapabilities, AggregatorFeaturesMessage, CardanoTransactionsProverCapabilities,
8894
};
8995
use mithril_common::test_utils::apispec::APISpec;
96+
use mithril_common::StmAggrSigType;
9097
use serde_json::Value::Null;
9198
use std::collections::BTreeSet;
9299
use std::sync::Arc;
@@ -156,6 +163,7 @@ mod tests {
156163
]),
157164
cardano_transactions_prover: None,
158165
},
166+
aggregation_type: StmAggrSigType::StmAggrSigConcatenation.to_string(),
159167
}
160168
);
161169

mithril-aggregator/src/http_server/routes/router.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ use crate::DependencyContainer;
88

99
use mithril_common::api_version::APIVersionProvider;
1010
use mithril_common::entities::SignedEntityTypeDiscriminants;
11-
use mithril_common::{CardanoNetwork, MITHRIL_API_VERSION_HEADER, MITHRIL_ORIGIN_TAG_HEADER};
11+
use mithril_common::{
12+
CardanoNetwork, StmAggrSigType, MITHRIL_API_VERSION_HEADER, MITHRIL_ORIGIN_TAG_HEADER,
13+
};
1214

1315
use slog::{warn, Logger};
1416
use std::collections::{BTreeSet, HashSet};
@@ -42,6 +44,7 @@ pub struct RouterConfig {
4244
pub cardano_node_version: String,
4345
pub allow_http_serve_directory: bool,
4446
pub origin_tag_white_list: HashSet<String>,
47+
pub aggregation_type: StmAggrSigType,
4548
}
4649

4750
#[cfg(test)]
@@ -60,6 +63,7 @@ impl RouterConfig {
6063
cardano_node_version: "1.2.3".to_string(),
6164
allow_http_serve_directory: false,
6265
origin_tag_white_list: HashSet::from(["DUMMY_TAG".to_string()]),
66+
aggregation_type: StmAggrSigType::StmAggrSigConcatenation,
6367
}
6468
}
6569

mithril-aggregator/src/http_server/routes/status.rs

+48-16
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use warp::Filter;
22

3-
use mithril_common::{messages::AggregatorStatusMessage, StdResult};
3+
use mithril_common::{messages::AggregatorStatusMessage, StdResult, StmAggrSigType};
44

55
use crate::{
66
dependency_injection::EpochServiceWrapper,
@@ -27,13 +27,17 @@ fn status(
2727
.and(middlewares::extract_config(router_state, |config| {
2828
config.network.to_string()
2929
}))
30+
.and(middlewares::extract_config(router_state, |config| {
31+
config.aggregation_type
32+
}))
3033
.and_then(handlers::status)
3134
}
3235

3336
async fn get_aggregator_status_message(
3437
epoch_service: EpochServiceWrapper,
3538
cardano_node_version: String,
3639
cardano_network: String,
40+
aggregation_type: StmAggrSigType,
3741
) -> StdResult<AggregatorStatusMessage> {
3842
let epoch_service = epoch_service.read().await;
3943

@@ -65,6 +69,7 @@ async fn get_aggregator_status_message(
6569
total_next_stakes_signers,
6670
total_cardano_spo,
6771
total_cardano_stake,
72+
aggregation_type,
6873
};
6974

7075
Ok(message)
@@ -73,6 +78,7 @@ async fn get_aggregator_status_message(
7378
mod handlers {
7479
use std::convert::Infallible;
7580

81+
use mithril_common::StmAggrSigType;
7682
use slog::{warn, Logger};
7783
use warp::http::StatusCode;
7884

@@ -87,10 +93,15 @@ mod handlers {
8793
epoch_service: EpochServiceWrapper,
8894
cardano_node_version: String,
8995
cardano_network: String,
96+
aggregation_type: StmAggrSigType,
9097
) -> Result<impl warp::Reply, Infallible> {
91-
let aggregator_status_message =
92-
get_aggregator_status_message(epoch_service, cardano_node_version, cardano_network)
93-
.await;
98+
let aggregator_status_message = get_aggregator_status_message(
99+
epoch_service,
100+
cardano_node_version,
101+
cardano_network,
102+
aggregation_type,
103+
)
104+
.await;
94105

95106
match aggregator_status_message {
96107
Ok(message) => Ok(reply::json(&message, StatusCode::OK)),
@@ -217,9 +228,14 @@ mod tests {
217228
.build();
218229
let epoch_service = Arc::new(RwLock::new(epoch_service));
219230

220-
let message = get_aggregator_status_message(epoch_service, String::new(), String::new())
221-
.await
222-
.unwrap();
231+
let message = get_aggregator_status_message(
232+
epoch_service,
233+
String::new(),
234+
String::new(),
235+
StmAggrSigType::StmAggrSigConcatenation,
236+
)
237+
.await
238+
.unwrap();
223239

224240
assert_eq!(
225241
message.protocol_parameters,
@@ -242,9 +258,14 @@ mod tests {
242258
.build();
243259
let epoch_service = Arc::new(RwLock::new(epoch_service));
244260

245-
let message = get_aggregator_status_message(epoch_service, String::new(), String::new())
246-
.await
247-
.unwrap();
261+
let message = get_aggregator_status_message(
262+
epoch_service,
263+
String::new(),
264+
String::new(),
265+
StmAggrSigType::StmAggrSigConcatenation,
266+
)
267+
.await
268+
.unwrap();
248269

249270
assert_eq!(message.total_cardano_spo, 0);
250271
assert_eq!(message.total_cardano_stake, 0);
@@ -262,9 +283,14 @@ mod tests {
262283
.build();
263284
let epoch_service = Arc::new(RwLock::new(epoch_service));
264285

265-
let message = get_aggregator_status_message(epoch_service, String::new(), String::new())
266-
.await
267-
.unwrap();
286+
let message = get_aggregator_status_message(
287+
epoch_service,
288+
String::new(),
289+
String::new(),
290+
StmAggrSigType::StmAggrSigConcatenation,
291+
)
292+
.await
293+
.unwrap();
268294

269295
assert_eq!(message.total_signers, total_signers);
270296
assert_eq!(message.total_next_signers, total_next_signers);
@@ -288,9 +314,14 @@ mod tests {
288314
.build();
289315
let epoch_service = Arc::new(RwLock::new(epoch_service));
290316

291-
let message = get_aggregator_status_message(epoch_service, String::new(), String::new())
292-
.await
293-
.unwrap();
317+
let message = get_aggregator_status_message(
318+
epoch_service,
319+
String::new(),
320+
String::new(),
321+
StmAggrSigType::StmAggrSigConcatenation,
322+
)
323+
.await
324+
.unwrap();
294325

295326
assert_eq!(message.total_stakes_signers, total_stakes_signers);
296327
assert_eq!(message.total_next_stakes_signers, total_next_stakes_signers);
@@ -305,6 +336,7 @@ mod tests {
305336
epoch_service,
306337
"1.0.4".to_string(),
307338
"network".to_string(),
339+
StmAggrSigType::StmAggrSigConcatenation,
308340
)
309341
.await
310342
.unwrap();

mithril-aggregator/src/services/epoch_service.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use mithril_common::entities::{
1414
};
1515
use mithril_common::logging::LoggerExtensions;
1616
use mithril_common::protocol::{MultiSigner as ProtocolMultiSigner, SignerBuilder};
17-
use mithril_common::StdResult;
17+
use mithril_common::{StdResult, StmAggrSigType};
1818
use mithril_persistence::store::StakeStorer;
1919

2020
use crate::{entities::AggregatorEpochSettings, EpochSettingsStorer, VerificationKeyStorer};
@@ -145,6 +145,7 @@ struct EpochData {
145145
signed_entity_config: SignedEntityConfig,
146146
total_spo: Option<TotalSPOs>,
147147
total_stake: Option<Stake>,
148+
aggregation_type: StmAggrSigType,
148149
}
149150

150151
struct ComputedEpochData {
@@ -194,6 +195,7 @@ pub struct MithrilEpochService {
194195
era_checker: Arc<EraChecker>,
195196
stake_store: Arc<dyn StakeStorer>,
196197
allowed_signed_entity_discriminants: BTreeSet<SignedEntityTypeDiscriminants>,
198+
aggregation_type: StmAggrSigType,
197199
logger: Logger,
198200
}
199201

@@ -203,6 +205,7 @@ impl MithrilEpochService {
203205
future_epoch_settings: AggregatorEpochSettings,
204206
dependencies: EpochServiceDependencies,
205207
allowed_discriminants: BTreeSet<SignedEntityTypeDiscriminants>,
208+
aggregation_type: StmAggrSigType,
206209
logger: Logger,
207210
) -> Self {
208211
Self {
@@ -215,6 +218,7 @@ impl MithrilEpochService {
215218
era_checker: dependencies.era_checker,
216219
stake_store: dependencies.stake_store,
217220
allowed_signed_entity_discriminants: allowed_discriminants,
221+
aggregation_type,
218222
logger: logger.new_with_component_name::<Self>(),
219223
}
220224
}
@@ -350,6 +354,8 @@ impl EpochService for MithrilEpochService {
350354
.clone(),
351355
};
352356

357+
let aggregation_type = self.aggregation_type;
358+
353359
let (total_spo, total_stake) = self
354360
.get_total_spo_and_total_stake(signer_retrieval_epoch)
355361
.await?;
@@ -370,6 +376,7 @@ impl EpochService for MithrilEpochService {
370376
signed_entity_config,
371377
total_spo,
372378
total_stake,
379+
aggregation_type,
373380
});
374381
self.computed_epoch_data = None;
375382

@@ -417,13 +424,15 @@ impl EpochService for MithrilEpochService {
417424
let protocol_multi_signer = SignerBuilder::new(
418425
&data.current_signers_with_stake,
419426
&data.current_epoch_settings.protocol_parameters,
427+
data.aggregation_type,
420428
)
421429
.with_context(|| "Epoch service failed to build protocol multi signer")?
422430
.build_multi_signer();
423431

424432
let next_protocol_multi_signer = SignerBuilder::new(
425433
&data.next_signers_with_stake,
426434
&data.next_epoch_settings.protocol_parameters,
435+
data.aggregation_type,
427436
)
428437
.with_context(|| "Epoch service failed to build next protocol multi signer")?
429438
.build_multi_signer();
@@ -587,6 +596,7 @@ impl FakeEpochServiceBuilder {
587596
}
588597

589598
pub fn build(self) -> FakeEpochService {
599+
let aggregation_type = StmAggrSigType::StmAggrSigConcatenation;
590600
let current_signers = Signer::vec_from(self.current_signers_with_stake.clone());
591601
let next_signers = Signer::vec_from(self.next_signers_with_stake.clone());
592602
let total_stakes_signers = self
@@ -599,13 +609,15 @@ impl FakeEpochServiceBuilder {
599609
let protocol_multi_signer = SignerBuilder::new(
600610
&self.current_signers_with_stake,
601611
&self.current_epoch_settings.protocol_parameters,
612+
aggregation_type,
602613
)
603614
.with_context(|| "Could not build protocol_multi_signer for epoch service")
604615
.unwrap()
605616
.build_multi_signer();
606617
let next_protocol_multi_signer = SignerBuilder::new(
607618
&self.next_signers_with_stake,
608619
&self.next_epoch_settings.protocol_parameters,
620+
aggregation_type,
609621
)
610622
.with_context(|| "Could not build protocol_multi_signer for epoch service")
611623
.unwrap()
@@ -628,6 +640,7 @@ impl FakeEpochServiceBuilder {
628640
signed_entity_config: self.signed_entity_config,
629641
total_spo: self.total_spo,
630642
total_stake: self.total_stake,
643+
aggregation_type,
631644
}),
632645
computed_epoch_data: Some(ComputedEpochData {
633646
aggregate_verification_key: protocol_multi_signer
@@ -1066,6 +1079,7 @@ mod tests {
10661079
Arc::new(stake_store),
10671080
),
10681081
self.allowed_discriminants,
1082+
StmAggrSigType::StmAggrSigConcatenation,
10691083
TestLogger::stdout(),
10701084
)
10711085
}
@@ -1231,6 +1245,7 @@ mod tests {
12311245
let signer_builder = SignerBuilder::new(
12321246
&fixture.signers_with_stake(),
12331247
&fixture.protocol_parameters(),
1248+
StmAggrSigType::StmAggrSigConcatenation,
12341249
)
12351250
.unwrap();
12361251
service.computed_epoch_data = Some(ComputedEpochData {

0 commit comments

Comments
 (0)