@@ -14,13 +14,13 @@ use mithril_common::{
1414 CardanoStakeDistributionListMessage , CardanoStakeDistributionMessage ,
1515 CardanoTransactionSnapshotListMessage , CardanoTransactionSnapshotMessage ,
1616 CertificateListMessage , CertificateMessage , EpochSettingsMessage ,
17- MithrilStakeDistributionListMessage , MithrilStakeDistributionMessage , SignerMessagePart ,
18- SnapshotListMessage , SnapshotMessage ,
17+ MithrilStakeDistributionListMessage , MithrilStakeDistributionMessage ,
18+ ProtocolConfigurationMessage , SignerMessagePart , SnapshotListMessage , SnapshotMessage ,
1919 } ,
2020} ;
2121
2222use crate :: {
23- ImmutableFileDigestMapper ,
23+ EpochSettingsStorer , ImmutableFileDigestMapper ,
2424 database:: repository:: { CertificateRepository , SignedEntityStorer } ,
2525 dependency_injection:: EpochServiceWrapper ,
2626} ;
@@ -35,6 +35,13 @@ pub trait MessageService: Sync + Send {
3535 allowed_discriminants : BTreeSet < SignedEntityTypeDiscriminants > ,
3636 ) -> StdResult < EpochSettingsMessage > ;
3737
38+ ///Return the protocol configuration message for the given epoch if it exists.
39+ async fn get_protocol_configuration_message (
40+ & self ,
41+ epoch : Epoch ,
42+ allowed_discriminants : BTreeSet < SignedEntityTypeDiscriminants > ,
43+ ) -> StdResult < ProtocolConfigurationMessage > ;
44+
3845 /// Return the message representation of a certificate if it exists.
3946 async fn get_certificate_message (
4047 & self ,
@@ -130,6 +137,7 @@ pub trait MessageService: Sync + Send {
130137pub struct MithrilMessageService {
131138 certificate_repository : Arc < CertificateRepository > ,
132139 signed_entity_storer : Arc < dyn SignedEntityStorer > ,
140+ epoch_settings_storer : Arc < dyn EpochSettingsStorer > ,
133141 immutable_file_digest_mapper : Arc < dyn ImmutableFileDigestMapper > ,
134142 epoch_service : EpochServiceWrapper ,
135143}
@@ -139,12 +147,14 @@ impl MithrilMessageService {
139147 pub fn new (
140148 certificate_repository : Arc < CertificateRepository > ,
141149 signed_entity_storer : Arc < dyn SignedEntityStorer > ,
150+ epoch_settings_storer : Arc < dyn EpochSettingsStorer > ,
142151 immutable_file_digest_mapper : Arc < dyn ImmutableFileDigestMapper > ,
143152 epoch_service : EpochServiceWrapper ,
144153 ) -> Self {
145154 Self {
146155 certificate_repository,
147156 signed_entity_storer,
157+ epoch_settings_storer,
148158 immutable_file_digest_mapper,
149159 epoch_service,
150160 }
@@ -184,6 +194,27 @@ impl MessageService for MithrilMessageService {
184194 Ok ( epoch_settings_message)
185195 }
186196
197+ async fn get_protocol_configuration_message (
198+ & self ,
199+ epoch : Epoch ,
200+ enabled_discriminants : BTreeSet < SignedEntityTypeDiscriminants > ,
201+ ) -> StdResult < ProtocolConfigurationMessage > {
202+ let epoch_settings = self . epoch_settings_storer . get_epoch_settings ( epoch) . await ?. unwrap ( ) ;
203+
204+ let cardano_transactions_discriminant =
205+ enabled_discriminants. get ( & SignedEntityTypeDiscriminants :: CardanoTransactions ) ;
206+
207+ let cardano_transactions_signing_config = cardano_transactions_discriminant
208+ . map ( |_| epoch_settings. cardano_transactions_signing_config ) ;
209+
210+ let protocol_configuration_message = ProtocolConfigurationMessage {
211+ protocol_parameters : epoch_settings. protocol_parameters ,
212+ cardano_transactions_signing_config,
213+ available_signed_entity_types : enabled_discriminants,
214+ } ;
215+ Ok ( protocol_configuration_message)
216+ }
217+
187218 async fn get_certificate_message (
188219 & self ,
189220 certificate_hash : & str ,
@@ -362,7 +393,9 @@ mod tests {
362393 use tokio:: sync:: RwLock ;
363394
364395 use crate :: database:: record:: SignedEntityRecord ;
365- use crate :: database:: repository:: { ImmutableFileDigestRepository , SignedEntityStore } ;
396+ use crate :: database:: repository:: {
397+ EpochSettingsStore , ImmutableFileDigestRepository , SignedEntityStore ,
398+ } ;
366399 use crate :: database:: test_helper:: main_db_connection;
367400 use crate :: services:: FakeEpochService ;
368401
@@ -419,6 +452,7 @@ mod tests {
419452 let connection = Arc :: new ( main_db_connection ( ) . unwrap ( ) ) ;
420453 let certificate_repository = CertificateRepository :: new ( connection. clone ( ) ) ;
421454 let signed_entity_store = SignedEntityStore :: new ( connection. clone ( ) ) ;
455+ let epoch_settings_storer = EpochSettingsStore :: new ( connection. clone ( ) , None ) ;
422456 let immutable_file_digest_mapper =
423457 ImmutableFileDigestRepository :: new ( connection. clone ( ) ) ;
424458 let epoch_service = self . epoch_service . unwrap_or ( FakeEpochService :: without_data ( ) ) ;
@@ -444,6 +478,7 @@ mod tests {
444478 MithrilMessageService :: new (
445479 Arc :: new ( certificate_repository) ,
446480 Arc :: new ( signed_entity_store) ,
481+ Arc :: new ( epoch_settings_storer) ,
447482 Arc :: new ( immutable_file_digest_mapper) ,
448483 Arc :: new ( RwLock :: new ( epoch_service) ) ,
449484 )
0 commit comments