1
1
use async_trait:: async_trait;
2
2
use chrono:: Utc ;
3
+ use mithril_common:: crypto_helper:: ProtocolMultiSignature ;
3
4
use mithril_common:: entities:: Epoch ;
4
5
use mithril_common:: entities:: PartyId ;
5
6
use mithril_common:: store:: StakeStorer ;
6
- use slog_scope:: { debug, info , warn} ;
7
+ use slog_scope:: { debug, warn} ;
7
8
8
9
use mithril_common:: crypto_helper:: ProtocolStakeDistribution ;
9
10
use mithril_common:: entities:: {
@@ -134,8 +135,10 @@ pub trait AggregatorRunnerTrait: Sync + Send {
134
135
& self ,
135
136
) -> Result < Option < CertificatePending > , Box < dyn StdError + Sync + Send > > ;
136
137
137
- /// Check if the multisigner has issued a multi-signature.
138
- async fn is_multisig_created ( & self ) -> Result < bool , Box < dyn StdError + Sync + Send > > ;
138
+ /// Create multi-signature.
139
+ async fn create_multi_signature (
140
+ & self ,
141
+ ) -> Result < Option < ProtocolMultiSignature > , Box < dyn StdError + Sync + Send > > ;
139
142
140
143
/// Create an archive of the cardano node db directory naming it after the given beacon.
141
144
///
@@ -157,6 +160,7 @@ pub trait AggregatorRunnerTrait: Sync + Send {
157
160
async fn create_and_save_certificate (
158
161
& self ,
159
162
working_certificate : & WorkingCertificate ,
163
+ multi_signature : ProtocolMultiSignature ,
160
164
) -> Result < Certificate , Box < dyn StdError + Sync + Send > > ;
161
165
162
166
/// Create a snapshot and save it to the given locations.
@@ -546,25 +550,18 @@ impl AggregatorRunnerTrait for AggregatorRunner {
546
550
Ok ( certificate_pending)
547
551
}
548
552
549
- /// Is a multi-signature ready?
550
- /// Can we create a multi-signature.
551
- async fn is_multisig_created ( & self ) -> Result < bool , Box < dyn StdError + Sync + Send > > {
552
- debug ! ( "RUNNER: check if we can create a multi-signature" ) ;
553
- let has_multisig = self
553
+ async fn create_multi_signature (
554
+ & self ,
555
+ ) -> Result < Option < ProtocolMultiSignature > , Box < dyn StdError + Sync + Send > > {
556
+ debug ! ( "RUNNER: create multi-signature" ) ;
557
+
558
+ Ok ( self
554
559
. dependencies
555
560
. multi_signer
556
561
. write ( )
557
562
. await
558
563
. create_multi_signature ( )
559
- . await ?
560
- . is_some ( ) ;
561
-
562
- if has_multisig {
563
- debug ! ( " > new multi-signature created" ) ;
564
- } else {
565
- info ! ( " > no multi-signature created" ) ;
566
- }
567
- Ok ( has_multisig)
564
+ . await ?)
568
565
}
569
566
570
567
async fn create_snapshot_archive (
@@ -633,10 +630,10 @@ impl AggregatorRunnerTrait for AggregatorRunner {
633
630
async fn create_and_save_certificate (
634
631
& self ,
635
632
working_certificate : & WorkingCertificate ,
633
+ multi_signature : ProtocolMultiSignature ,
636
634
) -> Result < Certificate , Box < dyn StdError + Sync + Send > > {
637
635
debug ! ( "RUNNER: create and save certificate" ) ;
638
636
let certificate_store = self . dependencies . certificate_store . clone ( ) ;
639
- let multisigner = self . dependencies . multi_signer . read ( ) . await ;
640
637
let signatures_party_ids: Vec < PartyId > = self
641
638
. dependencies
642
639
. single_signature_store
@@ -645,12 +642,6 @@ impl AggregatorRunnerTrait for AggregatorRunner {
645
642
. unwrap_or_default ( )
646
643
. into_keys ( )
647
644
. collect :: < Vec < _ > > ( ) ;
648
- let multi_signature = multisigner. get_multi_signature ( ) . await ?. ok_or_else ( || {
649
- RunnerError :: NoComputedMultiSignature ( format ! (
650
- "no multi signature generated for beacon {:?}" ,
651
- working_certificate. beacon
652
- ) )
653
- } ) ?;
654
645
655
646
let certificate = MithrilCertificateCreator :: create_certificate (
656
647
working_certificate,
@@ -1183,6 +1174,7 @@ pub mod tests {
1183
1174
let first_certificate = certificate_chain[ 0 ] . clone ( ) ;
1184
1175
let multi_signature: ProtocolMultiSignature =
1185
1176
key_decode_hex ( & first_certificate. multi_signature as & HexEncodedKey ) . unwrap ( ) ;
1177
+ let multi_signature_clone = multi_signature. clone ( ) ;
1186
1178
let working_certificate = WorkingCertificate {
1187
1179
beacon : first_certificate. beacon . clone ( ) ,
1188
1180
signers : first_certificate. metadata . signers . clone ( ) ,
@@ -1193,16 +1185,13 @@ pub mod tests {
1193
1185
..WorkingCertificate :: fake ( )
1194
1186
} ;
1195
1187
let ( mut deps, config) = initialize_dependencies ( ) . await ;
1196
- let mut mock_multi_signer = MockMultiSigner :: new ( ) ;
1197
- mock_multi_signer
1198
- . expect_get_multi_signature ( )
1199
- . return_once ( move || Ok ( Some ( multi_signature) ) ) ;
1188
+ let mock_multi_signer = MockMultiSigner :: new ( ) ;
1200
1189
deps. multi_signer = Arc :: new ( RwLock :: new ( mock_multi_signer) ) ;
1201
1190
deps. init_state_from_chain ( & certificate_chain, vec ! [ ] ) . await ;
1202
1191
let runner = AggregatorRunner :: new ( config, Arc :: new ( deps) ) ;
1203
1192
1204
1193
let certificate = runner
1205
- . create_and_save_certificate ( & working_certificate)
1194
+ . create_and_save_certificate ( & working_certificate, multi_signature_clone )
1206
1195
. await ;
1207
1196
certificate. expect ( "a certificate should have been created and saved" ) ;
1208
1197
}
0 commit comments