Skip to content

Commit 015c54c

Browse files
committed
replace openmessage with signed entity type & protocol message in aggregator state machine SigningState since it doesn't need the extra data
1 parent 9f2a55a commit 015c54c

File tree

1 file changed

+22
-29
lines changed

1 file changed

+22
-29
lines changed

mithril-aggregator/src/runtime/state_machine.rs

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
use crate::{
2-
database::provider::OpenMessageRecord,
3-
runtime::{AggregatorRunnerTrait, RuntimeError},
4-
};
1+
use crate::runtime::{AggregatorRunnerTrait, RuntimeError};
52

6-
use mithril_common::entities::{Beacon, SignedEntityType};
3+
use mithril_common::entities::{Beacon, ProtocolMessage, SignedEntityType};
74
use slog_scope::{crit, info, trace, warn};
85
use std::fmt::Display;
96
use std::sync::Arc;
@@ -22,7 +19,8 @@ pub struct ReadyState {
2219
#[derive(Clone, Debug, PartialEq)]
2320
pub struct SigningState {
2421
current_beacon: Beacon,
25-
open_message: OpenMessageRecord,
22+
signed_entity_type: SignedEntityType,
23+
protocol_message: ProtocolMessage,
2624
}
2725

2826
#[derive(Clone, Debug, PartialEq)]
@@ -276,7 +274,7 @@ impl AggregatorRuntime {
276274
trace!("launching transition from SIGNING to IDLE state");
277275
let certificate = self
278276
.runner
279-
.create_certificate(&state.open_message.signed_entity_type)
277+
.create_certificate(&state.signed_entity_type)
280278
.await?
281279
.ok_or_else(|| RuntimeError::KeepState {
282280
message: "not enough signature yet to create a certificate, waiting…".to_string(),
@@ -286,7 +284,7 @@ impl AggregatorRuntime {
286284
self.runner.drop_pending_certificate().await?;
287285
let ongoing_snapshot = self
288286
.runner
289-
.create_snapshot_archive(&state.current_beacon, &state.open_message.protocol_message)
287+
.create_snapshot_archive(&state.current_beacon, &state.protocol_message)
290288
.await?;
291289
let locations = self
292290
.runner
@@ -333,8 +331,7 @@ impl AggregatorRuntime {
333331
.runner
334332
.compute_protocol_message(digester_result)
335333
.await?;
336-
let open_message = self
337-
.runner
334+
self.runner
338335
.create_open_message(&signed_entity_type, &protocol_message)
339336
.await?;
340337
let certificate_pending = self
@@ -349,7 +346,8 @@ impl AggregatorRuntime {
349346
.await?;
350347
let state = SigningState {
351348
current_beacon: new_beacon,
352-
open_message,
349+
signed_entity_type,
350+
protocol_message,
353351
};
354352

355353
Ok(state)
@@ -359,12 +357,14 @@ impl AggregatorRuntime {
359357
#[cfg(test)]
360358
mod tests {
361359

360+
use std::path::Path;
361+
362362
use crate::database::provider::OpenMessageRecord;
363+
use crate::snapshotter::OngoingSnapshot;
363364

364365
use super::super::runner::MockAggregatorRunner;
365366
use super::*;
366367

367-
use mithril_common::entities::ProtocolMessage;
368368
use mithril_common::era::UnsupportedEraError;
369369
use mithril_common::test_utils::fake_data;
370370
use mockall::predicate;
@@ -642,7 +642,8 @@ mod tests {
642642

643643
beacon
644644
},
645-
open_message: OpenMessageRecord::dummy(),
645+
signed_entity_type: SignedEntityType::dummy(),
646+
protocol_message: ProtocolMessage::default(),
646647
};
647648
let mut runtime = init_runtime(Some(AggregatorState::Signing(state)), runner).await;
648649
runtime.cycle().await.unwrap();
@@ -651,7 +652,7 @@ mod tests {
651652
}
652653

653654
#[tokio::test]
654-
async fn signing_multisig_is_not_created() {
655+
async fn signing_certificate_is_not_created() {
655656
let mut runner = MockAggregatorRunner::new();
656657
runner
657658
.expect_get_beacon_from_chain()
@@ -663,7 +664,8 @@ mod tests {
663664
.returning(|_| Ok(None));
664665
let state = SigningState {
665666
current_beacon: fake_data::beacon(),
666-
open_message: OpenMessageRecord::dummy(),
667+
signed_entity_type: SignedEntityType::dummy(),
668+
protocol_message: ProtocolMessage::default(),
667669
};
668670
let mut runtime = init_runtime(Some(AggregatorState::Signing(state)), runner).await;
669671
runtime
@@ -674,29 +676,24 @@ mod tests {
674676
assert_eq!("signing".to_string(), runtime.get_state());
675677
}
676678

677-
/* TODO: create a fake certificate to test the certificate creation.
678679
#[tokio::test]
679-
async fn signing_multisig_is_created() {
680-
let (certificate_chain, _) = setup_certificate_chain(5, 1);
681-
let first_certificate = certificate_chain[0].clone();
682-
let multi_signature: ProtocolMultiSignature =
683-
key_decode_hex(&first_certificate.multi_signature as &HexEncodedKey).unwrap();
680+
async fn signing_certificate_is_created() {
684681
let mut runner = MockAggregatorRunner::new();
685682
runner
686683
.expect_get_beacon_from_chain()
687684
.once()
688685
.returning(|| Ok(fake_data::beacon()));
689686
runner
690687
.expect_create_certificate()
691-
.return_once(move |_| Ok(Some(multi_signature)));
688+
.return_once(move |_| Ok(Some(fake_data::certificate("whatever".to_string()))));
692689
runner
693690
.expect_drop_pending_certificate()
694691
.once()
695692
.returning(|| Ok(Some(fake_data::certificate_pending())));
696693
runner
697694
.expect_create_snapshot_archive()
698695
.once()
699-
.returning(|_| {
696+
.returning(|_, _| {
700697
Ok(OngoingSnapshot::new(
701698
Path::new("/tmp/archive.zip").to_path_buf(),
702699
1234,
@@ -706,25 +703,21 @@ mod tests {
706703
.expect_upload_snapshot_archive()
707704
.once()
708705
.returning(|_path| Ok(vec!["locA".to_string(), "locB".to_string()]));
709-
runner
710-
.expect_create_and_save_certificate()
711-
.once()
712-
.returning(|_, _| Ok(fake_data::certificate("whatever".to_string())));
713706
runner
714707
.expect_create_and_save_snapshot()
715708
.once()
716709
.returning(|_, _, _| Ok(fake_data::snapshots(1)[0].clone()));
717710

718711
let state = SigningState {
719712
current_beacon: fake_data::beacon(),
720-
working_certificate: WorkingCertificate::fake(),
713+
signed_entity_type: SignedEntityType::dummy(),
714+
protocol_message: ProtocolMessage::default(),
721715
};
722716
let mut runtime = init_runtime(Some(AggregatorState::Signing(state)), runner).await;
723717
runtime.cycle().await.unwrap();
724718

725719
assert_eq!("idle".to_string(), runtime.get_state());
726720
}
727-
*/
728721

729722
#[tokio::test]
730723
pub async fn critical_error() {

0 commit comments

Comments
 (0)