Skip to content

Commit 09eb684

Browse files
authored
Merge pull request #1622 from input-output-hk/ensemble/open-message-is-expired-condition
Fix `open_message.is_expired` in aggregator runner
2 parents fa9e594 + 4d0d037 commit 09eb684

File tree

5 files changed

+327
-304
lines changed

5 files changed

+327
-304
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mithril-aggregator/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mithril-aggregator"
3-
version = "0.4.59"
3+
version = "0.4.60"
44
description = "A Mithril Aggregator server"
55
authors = { workspace = true }
66
edition = { workspace = true }

mithril-aggregator/src/configuration.rs

Lines changed: 99 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -262,19 +262,24 @@ impl Configuration {
262262
pub fn list_allowed_signed_entity_types_discriminants(
263263
&self,
264264
) -> StdResult<Vec<SignedEntityTypeDiscriminants>> {
265-
let mut signed_entity_types = Vec::new();
266-
signed_entity_types.push(SignedEntityTypeDiscriminants::MithrilStakeDistribution);
267-
signed_entity_types.push(SignedEntityTypeDiscriminants::CardanoImmutableFilesFull);
265+
let default_discriminants = vec![
266+
SignedEntityTypeDiscriminants::MithrilStakeDistribution,
267+
SignedEntityTypeDiscriminants::CardanoImmutableFilesFull,
268+
];
269+
270+
let mut all_discriminants = default_discriminants;
268271

269272
let discriminant_names = self.signed_entity_types.clone().unwrap_or_default();
270-
let mut signed_entity_types_appended = discriminant_names
273+
for discriminant in discriminant_names
271274
.split(',')
272275
.filter_map(|name| SignedEntityTypeDiscriminants::from_str(name.trim()).ok())
273-
.filter(|signed_entity_type| !signed_entity_types.contains(signed_entity_type))
274-
.collect::<Vec<_>>();
275-
signed_entity_types.append(&mut signed_entity_types_appended);
276+
{
277+
if !all_discriminants.contains(&discriminant) {
278+
all_discriminants.push(discriminant)
279+
}
280+
}
276281

277-
Ok(signed_entity_types)
282+
Ok(all_discriminants)
278283
}
279284

280285
/// Create the deduplicated list of allowed signed entity types.
@@ -503,21 +508,15 @@ mod test {
503508
}
504509

505510
#[test]
506-
fn test_list_allowed_signed_entity_types_without_specific_configuration() {
507-
let beacon = fake_data::beacon();
511+
fn test_list_allowed_signed_entity_types_discriminant_without_specific_configuration() {
508512
let config = Configuration {
509513
signed_entity_types: None,
510-
network: beacon.network.clone(),
511514
..Configuration::new_sample()
512515
};
513-
let time_point = TimePoint::new(*beacon.epoch, beacon.immutable_file_number);
514516

515517
let discriminants = config
516518
.list_allowed_signed_entity_types_discriminants()
517519
.unwrap();
518-
let signed_entity_types = config
519-
.list_allowed_signed_entity_types(&time_point)
520-
.unwrap();
521520

522521
assert_eq!(
523522
vec![
@@ -526,47 +525,122 @@ mod test {
526525
],
527526
discriminants
528527
);
528+
}
529+
530+
#[test]
531+
fn test_list_allowed_signed_entity_types_discriminant_should_not_return_unknown_signed_entity_types_in_configuration(
532+
) {
533+
let config = Configuration {
534+
signed_entity_types: Some("Unknown".to_string()),
535+
..Configuration::new_sample()
536+
};
537+
538+
let discriminants = config
539+
.list_allowed_signed_entity_types_discriminants()
540+
.unwrap();
541+
529542
assert_eq!(
530543
vec![
531-
SignedEntityType::MithrilStakeDistribution(beacon.epoch),
532-
SignedEntityType::CardanoImmutableFilesFull(beacon.clone()),
544+
SignedEntityTypeDiscriminants::MithrilStakeDistribution,
545+
SignedEntityTypeDiscriminants::CardanoImmutableFilesFull,
533546
],
534-
signed_entity_types
547+
discriminants
535548
);
536549
}
537550

538551
#[test]
539-
fn test_list_allowed_signed_entity_types_with_specific_configuration() {
540-
let beacon = fake_data::beacon();
552+
fn test_list_allowed_signed_entity_types_discriminant_should_not_duplicate_a_signed_entity_discriminant_type_already_in_default_ones(
553+
) {
541554
let config = Configuration {
542-
network: beacon.network.clone(),
543555
signed_entity_types: Some(
544-
"MithrilStakeDistribution,Unknown, CardanoStakeDistribution".to_string(),
556+
"CardanoImmutableFilesFull, MithrilStakeDistribution, CardanoImmutableFilesFull"
557+
.to_string(),
545558
),
546559
..Configuration::new_sample()
547560
};
548-
let time_point = TimePoint::new(*beacon.epoch, beacon.immutable_file_number);
549561

550562
let discriminants = config
551563
.list_allowed_signed_entity_types_discriminants()
552564
.unwrap();
553-
let signed_entity_types = config
554-
.list_allowed_signed_entity_types(&time_point)
565+
566+
assert_eq!(
567+
vec![
568+
SignedEntityTypeDiscriminants::MithrilStakeDistribution,
569+
SignedEntityTypeDiscriminants::CardanoImmutableFilesFull,
570+
],
571+
discriminants
572+
);
573+
}
574+
575+
#[test]
576+
fn test_list_allowed_signed_entity_types_discriminants_should_add_signed_entity_types_in_configuration_at_the_end(
577+
) {
578+
let config = Configuration {
579+
signed_entity_types: Some("CardanoStakeDistribution, CardanoTransactions".to_string()),
580+
..Configuration::new_sample()
581+
};
582+
583+
let discriminants = config
584+
.list_allowed_signed_entity_types_discriminants()
555585
.unwrap();
556586

557587
assert_eq!(
558588
vec![
559589
SignedEntityTypeDiscriminants::MithrilStakeDistribution,
560590
SignedEntityTypeDiscriminants::CardanoImmutableFilesFull,
561591
SignedEntityTypeDiscriminants::CardanoStakeDistribution,
592+
SignedEntityTypeDiscriminants::CardanoTransactions,
562593
],
563594
discriminants
564595
);
596+
}
597+
598+
#[test]
599+
fn test_list_allowed_signed_entity_types_discriminants_with_multiple_identical_signed_entity_types_in_configuration_should_not_be_added_several_times(
600+
) {
601+
let config = Configuration {
602+
signed_entity_types: Some(
603+
"CardanoStakeDistribution, CardanoStakeDistribution, CardanoStakeDistribution"
604+
.to_string(),
605+
),
606+
..Configuration::new_sample()
607+
};
608+
609+
let discriminants = config
610+
.list_allowed_signed_entity_types_discriminants()
611+
.unwrap();
612+
613+
assert_eq!(
614+
vec![
615+
SignedEntityTypeDiscriminants::MithrilStakeDistribution,
616+
SignedEntityTypeDiscriminants::CardanoImmutableFilesFull,
617+
SignedEntityTypeDiscriminants::CardanoStakeDistribution,
618+
],
619+
discriminants
620+
);
621+
}
622+
623+
#[test]
624+
fn test_list_allowed_signed_entity_types_with_specific_configuration() {
625+
let beacon = fake_data::beacon();
626+
let time_point = TimePoint::new(*beacon.epoch, beacon.immutable_file_number);
627+
628+
let config = Configuration {
629+
network: beacon.network.clone(),
630+
signed_entity_types: Some("CardanoStakeDistribution, CardanoTransactions".to_string()),
631+
..Configuration::new_sample()
632+
};
633+
634+
let signed_entity_types = config
635+
.list_allowed_signed_entity_types(&time_point)
636+
.unwrap();
637+
565638
assert_eq!(
566639
vec![
567640
SignedEntityType::MithrilStakeDistribution(beacon.epoch),
568641
SignedEntityType::CardanoImmutableFilesFull(beacon.clone()),
569642
SignedEntityType::CardanoStakeDistribution(beacon.epoch),
643+
SignedEntityType::CardanoTransactions(beacon.clone()),
570644
],
571645
signed_entity_types
572646
);

0 commit comments

Comments
 (0)