Skip to content

Commit 76a1ea5

Browse files
committed
chore(aggregator): remove update_epoch_settings from epoch_service, cleanup dependency injection
1 parent b69115a commit 76a1ea5

File tree

7 files changed

+22
-91
lines changed

7 files changed

+22
-91
lines changed

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,9 +401,6 @@ impl DependenciesBuilder {
401401
signed_entity_service: self.get_signed_entity_service().await?,
402402
certifier_service: self.get_certifier_service().await?,
403403
epoch_service: self.get_epoch_service().await?,
404-
mithril_network_configuration_provider: self
405-
.get_mithril_network_configuration_provider()
406-
.await?,
407404
ticker_service: self.get_ticker_service().await?,
408405
signed_entity_storer: self.get_signed_entity_storer().await?,
409406
signer_getter: self.get_signer_store().await?,

mithril-aggregator/src/dependency_injection/containers/serve.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use mithril_protocol_config::interface::MithrilNetworkConfigurationProvider;
21
use slog::Logger;
32
use std::sync::Arc;
43
use tokio::sync::RwLock;
@@ -101,9 +100,6 @@ pub struct ServeCommandDependenciesContainer {
101100
/// Epoch service
102101
pub(crate) epoch_service: EpochServiceWrapper,
103102

104-
/// Mithril network configuration provider
105-
pub(crate) mithril_network_configuration_provider: Arc<dyn MithrilNetworkConfigurationProvider>,
106-
107103
/// Ticker Service
108104
pub(crate) ticker_service: Arc<dyn TickerService>,
109105

mithril-aggregator/src/runtime/runner.rs

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,6 @@ pub trait AggregatorRunnerTrait: Sync + Send {
7878
force_sync: bool,
7979
) -> StdResult<()>;
8080

81-
/// Ask the EpochService to update the epoch settings.
82-
async fn update_epoch_settings(&self) -> StdResult<()>;
83-
8481
/// Compute the protocol message
8582
async fn compute_protocol_message(
8683
&self,
@@ -298,16 +295,6 @@ impl AggregatorRunnerTrait for AggregatorRunner {
298295
.map_err(|e| e.into())
299296
}
300297

301-
async fn update_epoch_settings(&self) -> StdResult<()> {
302-
debug!(self.logger, ">> update_epoch_settings");
303-
self.dependencies
304-
.epoch_service
305-
.write()
306-
.await
307-
.update_epoch_settings()
308-
.await
309-
}
310-
311298
async fn compute_protocol_message(
312299
&self,
313300
signed_entity_type: &SignedEntityType,
@@ -908,48 +895,6 @@ pub mod tests {
908895
runner.upkeep(Epoch(5)).await.unwrap();
909896
}
910897

911-
#[tokio::test]
912-
async fn test_update_epoch_settings() {
913-
let mut mock_certifier_service = MockCertifierService::new();
914-
mock_certifier_service
915-
.expect_inform_epoch()
916-
.returning(|_| Ok(()))
917-
.times(1);
918-
919-
let config = ServeCommandConfiguration::new_sample(temp_dir!());
920-
let mut deps = DependenciesBuilder::new_with_stdout_logger(Arc::new(config.clone()))
921-
.build_serve_dependencies_container()
922-
.await
923-
.unwrap();
924-
deps.certifier_service = Arc::new(mock_certifier_service);
925-
let epoch_settings_storer = deps.epoch_settings_storer.clone();
926-
let current_epoch = deps.ticker_service.get_current_epoch().await.unwrap();
927-
let insert_epoch = current_epoch.offset_to_epoch_settings_recording_epoch();
928-
929-
let runner = build_runner_with_fixture_data(deps).await;
930-
runner.inform_new_epoch(current_epoch).await.unwrap();
931-
runner
932-
.update_epoch_settings()
933-
.await
934-
.expect("update_epoch_settings should not fail");
935-
936-
let saved_epoch_settings = epoch_settings_storer
937-
.get_epoch_settings(insert_epoch)
938-
.await
939-
.unwrap()
940-
.unwrap_or_else(|| panic!("should have epoch settings for epoch {insert_epoch}",));
941-
942-
assert_eq!(
943-
AggregatorEpochSettings {
944-
protocol_parameters: config.protocol_parameters.clone(),
945-
cardano_transactions_signing_config: config
946-
.cardano_transactions_signing_config
947-
.clone(),
948-
},
949-
saved_epoch_settings
950-
);
951-
}
952-
953898
#[tokio::test]
954899
async fn test_precompute_epoch_data() {
955900
let mut deps = initialize_dependencies!().await;

mithril-aggregator/src/runtime/state_machine.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,6 @@ impl AggregatorRuntime {
268268
self.runner.inform_new_epoch(new_time_point.epoch).await?;
269269
self.runner.upkeep(new_time_point.epoch).await?;
270270
self.runner.open_signer_registration_round(&new_time_point).await?;
271-
self.runner.update_epoch_settings().await?;
272271
if self.config.is_follower {
273272
self.runner
274273
.synchronize_follower_aggregator_signer_registration()
@@ -447,7 +446,6 @@ mod tests {
447446
.with(predicate::eq(TimePoint::dummy().epoch))
448447
.once()
449448
.returning(|_| Ok(()));
450-
runner.expect_update_epoch_settings().once().returning(|| Ok(()));
451449
runner.expect_precompute_epoch_data().once().returning(|| Ok(()));
452450
runner
453451
.expect_upkeep()
@@ -510,7 +508,6 @@ mod tests {
510508
.with(predicate::eq(TimePoint::dummy().epoch))
511509
.once()
512510
.returning(|_| Ok(()));
513-
runner.expect_update_epoch_settings().once().returning(|| Ok(()));
514511
runner.expect_precompute_epoch_data().once().returning(|| Ok(()));
515512
runner
516513
.expect_upkeep()
@@ -936,7 +933,6 @@ mod tests {
936933
.with(predicate::eq(new_time_point_clone.clone().epoch))
937934
.once()
938935
.returning(|_| Ok(()));
939-
runner.expect_update_epoch_settings().once().returning(|| Ok(()));
940936
runner.expect_precompute_epoch_data().once().returning(|| Ok(()));
941937
runner
942938
.expect_upkeep()

mithril-aggregator/src/services/epoch_service.rs

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use anyhow::{Context, anyhow};
22
use async_trait::async_trait;
33
use mithril_protocol_config::interface::MithrilNetworkConfigurationProvider;
4-
use mithril_protocol_config::model::MithrilNetworkConfiguration;
54
use slog::{Logger, debug};
65
use std::collections::BTreeSet;
76
use std::sync::Arc;
@@ -46,11 +45,6 @@ pub trait EpochService: Sync + Send {
4645
/// internal state for the new epoch.
4746
async fn inform_epoch(&mut self, epoch: Epoch) -> StdResult<()>;
4847

49-
/// Insert future epoch settings in the store based on this service current epoch (epoch offset +2).
50-
///
51-
/// Note: must be called after `inform_epoch`.
52-
async fn update_epoch_settings(&mut self) -> StdResult<()>;
53-
5448
/// Update the next signers with stake for the next epoch.
5549
async fn update_next_signers_with_stake(&mut self) -> StdResult<()>;
5650

@@ -390,11 +384,6 @@ impl EpochService for MithrilEpochService {
390384
Ok(())
391385
}
392386

393-
async fn update_epoch_settings(&mut self) -> StdResult<()> {
394-
debug!(self.logger, ">> update_epoch_settings");
395-
todo!("remove")
396-
}
397-
398387
async fn update_next_signers_with_stake(&mut self) -> StdResult<()> {
399388
debug!(self.logger, ">> update_next_signers_with_stake");
400389

@@ -542,7 +531,6 @@ pub(crate) struct FakeEpochService {
542531
epoch_data: Option<EpochData>,
543532
computed_epoch_data: Option<ComputedEpochData>,
544533
inform_epoch_error: bool,
545-
update_epoch_settings_error: bool,
546534
precompute_epoch_data_error: bool,
547535
update_next_signers_with_stake_error: bool,
548536
}
@@ -631,7 +619,6 @@ impl FakeEpochServiceBuilder {
631619
next_protocol_multi_signer,
632620
}),
633621
inform_epoch_error: false,
634-
update_epoch_settings_error: false,
635622
precompute_epoch_data_error: false,
636623
update_next_signers_with_stake_error: false,
637624
}
@@ -678,7 +665,6 @@ impl FakeEpochService {
678665
epoch_data: None,
679666
computed_epoch_data: None,
680667
inform_epoch_error: false,
681-
update_epoch_settings_error: false,
682668
precompute_epoch_data_error: false,
683669
update_next_signers_with_stake_error: false,
684670
}
@@ -687,12 +673,10 @@ impl FakeEpochService {
687673
pub fn toggle_errors(
688674
&mut self,
689675
inform_epoch: bool,
690-
update_protocol_parameters: bool,
691676
precompute_epoch: bool,
692677
update_next_signers_with_stake: bool,
693678
) {
694679
self.inform_epoch_error = inform_epoch;
695-
self.update_epoch_settings_error = update_protocol_parameters;
696680
self.precompute_epoch_data_error = precompute_epoch;
697681
self.update_next_signers_with_stake_error = update_next_signers_with_stake;
698682
}
@@ -720,13 +704,6 @@ impl EpochService for FakeEpochService {
720704
Ok(())
721705
}
722706

723-
async fn update_epoch_settings(&mut self) -> StdResult<()> {
724-
if self.update_epoch_settings_error {
725-
anyhow::bail!("update_epoch_settings fake error");
726-
}
727-
Ok(())
728-
}
729-
730707
async fn precompute_epoch_data(&mut self) -> StdResult<()> {
731708
if self.precompute_epoch_data_error {
732709
anyhow::bail!("precompute_epoch_data fake error");

mithril-aggregator/src/services/signer_registration/follower.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ mod tests {
456456
let signer_registration_follower = MithrilSignerRegistrationFollowerBuilder::default()
457457
.with_epoch_service({
458458
let mut epoch_service = FakeEpochService::without_data();
459-
epoch_service.toggle_errors(false, false, false, true);
459+
epoch_service.toggle_errors(false, false, true);
460460

461461
epoch_service
462462
})

mithril-aggregator/tests/test_extensions/leader_aggregator_http_server.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use axum_test::TestServer;
1111
use reqwest::Url;
1212

1313
use mithril_aggregator::services::MessageService;
14-
use mithril_common::entities::SignedEntityTypeDiscriminants;
14+
use mithril_common::entities::{Epoch, SignedEntityTypeDiscriminants};
1515
use mithril_common::logging::LoggerExtensions;
1616
use mithril_common::{StdError, StdResult};
1717

@@ -33,6 +33,10 @@ impl LeaderAggregatorHttpServer {
3333
.route("/certificates", get(certificates_list))
3434
.route("/certificate/genesis", get(certificate_last_genesis))
3535
.route("/certificate/{hash}", get(certificate_by_hash))
36+
.route(
37+
"/protocol-configuration/{epoch}",
38+
get(protocol_configuration_by_epoch),
39+
)
3640
.with_state(state);
3741

3842
let server = TestServer::builder().http_transport().build(router)?;
@@ -98,3 +102,19 @@ async fn certificate_by_hash(
98102
Err(err) => internal_server_error(err).into_response(),
99103
}
100104
}
105+
106+
async fn protocol_configuration_by_epoch(
107+
Path(epoch): Path<u64>,
108+
state: State<LeaderAggregatorRoutesState>,
109+
) -> Response {
110+
slog::debug!(state.logger, "/protocol-configuration/{epoch}");
111+
match state
112+
.message_service
113+
.get_protocol_configuration_message(Epoch(epoch), SignedEntityTypeDiscriminants::all())
114+
.await
115+
{
116+
Ok(Some(message)) => (StatusCode::OK, Json(message)).into_response(),
117+
Ok(None) => StatusCode::NOT_FOUND.into_response(),
118+
Err(err) => internal_server_error(err).into_response(),
119+
}
120+
}

0 commit comments

Comments
 (0)