@@ -16,7 +16,7 @@ use commonware_cryptography::{Digest, Scheme};
1616use commonware_macros:: select;
1717use commonware_p2p:: { Receiver , Recipients , Sender } ;
1818use commonware_runtime:: { Clock , Handle , Metrics , Spawner , Storage } ;
19- use commonware_storage:: journal:: variable:: Journal ;
19+ use commonware_storage:: journal:: variable:: { Config as JConfig , Journal } ;
2020use commonware_utils:: quorum;
2121use futures:: {
2222 channel:: { mpsc, oneshot} ,
@@ -322,8 +322,10 @@ pub struct Actor<
322322 reporter : F ,
323323 supervisor : S ,
324324
325+ partition : String ,
326+ compression : Option < u8 > ,
325327 replay_concurrency : usize ,
326- journal : Option < Journal < E > > ,
328+ journal : Option < Journal < E , usize , Voter < C :: Signature , D > > > ,
327329
328330 genesis : Option < D > ,
329331
@@ -361,11 +363,7 @@ impl<
361363 S : Supervisor < Index = View , PublicKey = C :: PublicKey > ,
362364 > Actor < E , C , D , A , R , F , S >
363365{
364- pub fn new (
365- context : E ,
366- journal : Journal < E > ,
367- cfg : Config < C , D , A , R , F , S > ,
368- ) -> ( Self , Mailbox < C :: Signature , D > ) {
366+ pub fn new ( context : E , cfg : Config < C , D , A , R , F , S > ) -> ( Self , Mailbox < C :: Signature , D > ) {
369367 // Assert correctness of timeouts
370368 if cfg. leader_timeout > cfg. notarization_timeout {
371369 panic ! ( "leader timeout must be less than or equal to notarization timeout" ) ;
@@ -415,8 +413,10 @@ impl<
415413 reporter : cfg. reporter ,
416414 supervisor : cfg. supervisor ,
417415
416+ partition : cfg. partition ,
417+ compression : cfg. compression ,
418418 replay_concurrency : cfg. replay_concurrency ,
419- journal : Some ( journal ) ,
419+ journal : None ,
420420
421421 genesis : None ,
422422
@@ -708,9 +708,7 @@ impl<
708708 } ) ;
709709
710710 // Handle nullify
711- let msg = Voter :: Nullify :: < C :: Signature , D > ( nullify. clone ( ) )
712- . encode ( )
713- . into ( ) ;
711+ let msg = Voter :: Nullify ( nullify. clone ( ) ) ;
714712 if round. add_verified_nullify ( nullify) . await && self . journal . is_some ( ) {
715713 self . journal
716714 . as_mut ( )
@@ -1021,9 +1019,7 @@ impl<
10211019 } ) ;
10221020
10231021 // Handle notarize
1024- let msg = Voter :: Notarize :: < C :: Signature , D > ( notarize. clone ( ) )
1025- . encode ( )
1026- . into ( ) ;
1022+ let msg = Voter :: Notarize ( notarize. clone ( ) ) ;
10271023 if round. add_verified_notarize ( notarize) . await && self . journal . is_some ( ) {
10281024 self . journal
10291025 . as_mut ( )
@@ -1075,9 +1071,7 @@ impl<
10751071 } ) ;
10761072 for signature in & notarization. signatures {
10771073 let notarize = Notarize :: new ( notarization. proposal . clone ( ) , signature. clone ( ) ) ;
1078- let msg = Voter :: Notarize :: < C :: Signature , D > ( notarize. clone ( ) )
1079- . encode ( )
1080- . into ( ) ;
1074+ let msg = Voter :: Notarize :: < C :: Signature , D > ( notarize. clone ( ) ) ;
10811075 if round. add_verified_notarize ( notarize) . await && self . journal . is_some ( ) {
10821076 self . journal
10831077 . as_mut ( )
@@ -1146,9 +1140,7 @@ impl<
11461140 } ) ;
11471141 for signature in & nullification. signatures {
11481142 let nullify = Nullify :: new ( view, signature. clone ( ) ) ;
1149- let msg = Voter :: Nullify :: < C :: Signature , D > ( nullify. clone ( ) )
1150- . encode ( )
1151- . into ( ) ;
1143+ let msg = Voter :: Nullify ( nullify. clone ( ) ) ;
11521144 if round. add_verified_nullify ( nullify) . await && self . journal . is_some ( ) {
11531145 self . journal
11541146 . as_mut ( )
@@ -1205,9 +1197,7 @@ impl<
12051197 } ) ;
12061198
12071199 // Handle finalize
1208- let msg = Voter :: Finalize :: < C :: Signature , D > ( finalize. clone ( ) )
1209- . encode ( )
1210- . into ( ) ;
1200+ let msg = Voter :: Finalize ( finalize. clone ( ) ) ;
12111201 if round. add_verified_finalize ( finalize) . await && self . journal . is_some ( ) {
12121202 self . journal
12131203 . as_mut ( )
@@ -1259,9 +1249,7 @@ impl<
12591249 } ) ;
12601250 for signature in & finalization. signatures {
12611251 let finalize = Finalize :: new ( finalization. proposal . clone ( ) , signature. clone ( ) ) ;
1262- let msg = Voter :: Finalize :: < C :: Signature , D > ( finalize. clone ( ) )
1263- . encode ( )
1264- . into ( ) ;
1252+ let msg = Voter :: Finalize ( finalize. clone ( ) ) ;
12651253 if round. add_verified_finalize ( finalize) . await && self . journal . is_some ( ) {
12661254 self . journal
12671255 . as_mut ( )
@@ -1685,21 +1673,28 @@ impl<
16851673 // We start on view 1 because the genesis container occupies view 0/height 0.
16861674 self . enter_view ( 1 ) ;
16871675
1676+ // Initialize journal
1677+ let mut journal = Journal :: < _ , _ , Voter < C :: Signature , D > > :: init (
1678+ self . context . with_label ( "journal" ) ,
1679+ JConfig {
1680+ partition : self . partition . clone ( ) ,
1681+ compression : self . compression ,
1682+ codec_config : usize:: MAX , // anything we read from journal is already verified
1683+ } ,
1684+ )
1685+ . await
1686+ . expect ( "unable to open journal" ) ;
1687+
16881688 // Rebuild from journal
16891689 let mut observed_view = 1 ;
1690- let mut journal = self . journal . take ( ) . expect ( "missing journal" ) ;
16911690 {
16921691 let stream = journal
1693- . replay ( self . replay_concurrency , None )
1692+ . replay ( self . replay_concurrency )
16941693 . await
16951694 . expect ( "unable to replay journal" ) ;
16961695 pin_mut ! ( stream) ;
16971696 while let Some ( msg) = stream. next ( ) . await {
16981697 let ( _, _, _, msg) = msg. expect ( "unable to decode journal message" ) ;
1699- // We must wrap the message in Voter so we decode the right type of message (otherwise,
1700- // we can parse a finalize as a notarize)
1701- let msg = Voter :: decode_cfg ( msg, & self . max_participants )
1702- . expect ( "journal message is unexpected format" ) ;
17031698 let view = msg. view ( ) ;
17041699 let public_key_index = self
17051700 . supervisor
0 commit comments