@@ -2,13 +2,9 @@ use slog::Logger;
22use std:: sync:: Arc ;
33use tokio:: sync:: RwLock ;
44
5- use mithril_cardano_node_chain:: chain_observer:: ChainObserver ;
65use mithril_common:: {
76 api_version:: APIVersionProvider ,
8- entities:: {
9- CardanoTransactionsSigningConfig , Epoch , ProtocolParameters , SignerWithStake ,
10- StakeDistribution ,
11- } ,
7+ entities:: { Epoch , SignerWithStake , StakeDistribution } ,
128 signable_builder:: SignableBuilderService ,
139 test:: builder:: MithrilFixture ,
1410} ;
@@ -24,7 +20,6 @@ use crate::{
2420 database:: repository:: {
2521 CertificateRepository , SignedEntityStorer , SignerGetter , StakePoolStore ,
2622 } ,
27- entities:: AggregatorEpochSettings ,
2823 event_store:: { EventMessage , TransmitterService } ,
2924 services:: {
3025 CertificateChainSynchronizer , CertifierService , EpochService , MessageService ,
@@ -55,9 +50,6 @@ pub struct ServeCommandDependenciesContainer {
5550 /// Epoch settings storer.
5651 pub epoch_settings_storer : Arc < dyn EpochSettingsStorer > ,
5752
58- /// Chain observer service.
59- pub ( crate ) chain_observer : Arc < dyn ChainObserver > ,
60-
6153 /// Certificate chain synchronizer service
6254 pub ( crate ) certificate_chain_synchronizer : Arc < dyn CertificateChainSynchronizer > ,
6355
@@ -132,94 +124,27 @@ pub struct ServeCommandDependenciesContainer {
132124impl ServeCommandDependenciesContainer {
133125 /// `TEST METHOD ONLY`
134126 ///
135- /// Get the first two epochs that will be used by a newly started aggregator
136- pub async fn get_genesis_epochs ( & self ) -> ( Epoch , Epoch ) {
137- let current_epoch = self
138- . chain_observer
139- . get_current_epoch ( )
140- . await
141- . expect ( "get_current_epoch should not fail" )
142- . expect ( "an epoch should've been set to the chain observer" ) ;
143- let work_epoch = current_epoch
144- . offset_to_signer_retrieval_epoch ( )
145- . expect ( "epoch.offset_by SIGNER_EPOCH_RETRIEVAL_OFFSET should not fail" ) ;
146- let epoch_to_sign = current_epoch. offset_to_next_signer_retrieval_epoch ( ) ;
147-
148- ( work_epoch, epoch_to_sign)
149- }
150-
151- /// `TEST METHOD ONLY`
152- ///
153- /// Fill the stores of a [DependencyManager] in a way to simulate an aggregator state
127+ /// Fill the stores of this container in a way to simulate an aggregator state
154128 /// using the data from a precomputed fixture.
129+ ///
130+ /// Data will be inserted in the given `next_aggregation_epoch`, the current aggregation epoch
131+ /// (`next_aggregation_epoch - 1`), and the signer registration epoch (`next_aggregation_epoch + 1`).
132+ ///
133+ /// Note: `epoch_settings` store must have data for the inserted epochs, this should be done
134+ /// automatically when building the [ServeCommandDependenciesContainer] by `handle_discrepancies_at_startup`
155135 pub async fn init_state_from_fixture (
156136 & self ,
157137 fixture : & MithrilFixture ,
158- cardano_transactions_signing_config : & CardanoTransactionsSigningConfig ,
159- target_epochs : & [ Epoch ] ,
138+ next_aggregation_epoch : Epoch ,
160139 ) {
161- for epoch in target_epochs {
162- self . epoch_settings_storer
163- . save_epoch_settings (
164- * epoch,
165- AggregatorEpochSettings {
166- protocol_parameters : fixture. protocol_parameters ( ) ,
167- cardano_transactions_signing_config : cardano_transactions_signing_config
168- . clone ( ) ,
169- } ,
170- )
171- . await
172- . expect ( "save_epoch_settings should not fail" ) ;
173- self . fill_verification_key_store ( * epoch, & fixture. signers_with_stake ( ) )
140+ for epoch in [
141+ next_aggregation_epoch. offset_to_signer_retrieval_epoch ( ) . unwrap ( ) ,
142+ next_aggregation_epoch,
143+ next_aggregation_epoch. offset_to_recording_epoch ( ) ,
144+ ] {
145+ self . fill_verification_key_store ( epoch, & fixture. signers_with_stake ( ) )
174146 . await ;
175- self . fill_stakes_store ( * epoch, fixture. signers_with_stake ( ) ) . await ;
176- }
177- }
178-
179- /// `TEST METHOD ONLY`
180- ///
181- /// Fill the stores of a [DependencyManager] in a way to simulate an aggregator genesis state.
182- ///
183- /// For the current and the next epoch:
184- /// * Fill the [VerificationKeyStorer] with the given signers keys.
185- /// * Fill the [StakeStore] with the given signers stakes.
186- /// * Fill the [ProtocolParametersStore] with the given parameters.
187- pub async fn prepare_for_genesis (
188- & self ,
189- genesis_signers : Vec < SignerWithStake > ,
190- second_epoch_signers : Vec < SignerWithStake > ,
191- genesis_protocol_parameters : & ProtocolParameters ,
192- cardano_transactions_signing_config : & CardanoTransactionsSigningConfig ,
193- ) {
194- self . init_epoch_settings_storer ( & AggregatorEpochSettings {
195- protocol_parameters : genesis_protocol_parameters. clone ( ) ,
196- cardano_transactions_signing_config : cardano_transactions_signing_config. clone ( ) ,
197- } )
198- . await ;
199-
200- let ( work_epoch, epoch_to_sign) = self . get_genesis_epochs ( ) . await ;
201- for ( epoch, signers) in
202- [ ( work_epoch, genesis_signers) , ( epoch_to_sign, second_epoch_signers) ]
203- {
204- self . fill_verification_key_store ( epoch, & signers) . await ;
205- self . fill_stakes_store ( epoch, signers) . await ;
206- }
207- }
208-
209- /// `TEST METHOD ONLY`
210- ///
211- /// Fill up to the first three epochs of the [EpochSettingsStorer] with the given value.
212- pub async fn init_epoch_settings_storer ( & self , epoch_settings : & AggregatorEpochSettings ) {
213- let ( work_epoch, epoch_to_sign) = self . get_genesis_epochs ( ) . await ;
214- let mut epochs_to_save = Vec :: new ( ) ;
215- epochs_to_save. push ( work_epoch) ;
216- epochs_to_save. push ( epoch_to_sign) ;
217- epochs_to_save. push ( epoch_to_sign. next ( ) ) ;
218- for epoch in epochs_to_save {
219- self . epoch_settings_storer
220- . save_epoch_settings ( epoch, epoch_settings. clone ( ) )
221- . await
222- . expect ( "save_epoch_settings should not fail" ) ;
147+ self . fill_stakes_store ( epoch, fixture. signers_with_stake ( ) ) . await ;
223148 }
224149 }
225150
@@ -250,13 +175,11 @@ impl ServeCommandDependenciesContainer {
250175
251176#[ cfg( test) ]
252177pub ( crate ) mod tests {
178+ use std:: path:: PathBuf ;
253179
254- use std :: { path :: PathBuf , sync :: Arc } ;
180+ use crate :: { ServeCommandConfiguration , dependency_injection :: DependenciesBuilder } ;
255181
256- use crate :: {
257- ServeCommandConfiguration , ServeCommandDependenciesContainer ,
258- dependency_injection:: DependenciesBuilder ,
259- } ;
182+ use super :: * ;
260183
261184 /// Initialize dependency container with a unique temporary snapshot directory build from test path.
262185 /// This macro should used directly in a function test to be able to retrieve the function name.
0 commit comments