@@ -11,10 +11,12 @@ use crate::{
1111 } ,
1212 Automaton , Relay , Reporter , Supervisor , LATENCY ,
1313} ;
14- use commonware_codec:: { Decode , Encode } ;
1514use commonware_cryptography:: { Digest , Scheme } ;
1615use commonware_macros:: select;
17- use commonware_p2p:: { Receiver , Recipients , Sender } ;
16+ use commonware_p2p:: {
17+ utils:: codec:: { wrap, WrappedSender } ,
18+ Receiver , Recipients , Sender ,
19+ } ;
1820use commonware_runtime:: { Clock , Handle , Metrics , Spawner , Storage } ;
1921use commonware_storage:: journal:: variable:: { Config as JConfig , Journal } ;
2022use commonware_utils:: quorum;
@@ -598,7 +600,10 @@ impl<
598600 null_retry
599601 }
600602
601- async fn timeout ( & mut self , sender : & mut impl Sender ) {
603+ async fn timeout < Sr : Sender > (
604+ & mut self ,
605+ sender : & mut WrappedSender < Sr , usize , Voter < C :: Signature , D > > ,
606+ ) {
602607 // Set timeout fired
603608 let round = self . views . get_mut ( & self . view ) . unwrap ( ) ;
604609 let mut retry = false ;
@@ -616,16 +621,14 @@ impl<
616621 let past_view = self . view - 1 ;
617622 if retry && past_view > 0 {
618623 if let Some ( notarization) = self . construct_notarization ( past_view, true ) {
619- let msg = Voter :: Notarization ( notarization) . encode ( ) . into ( ) ;
624+ let msg = Voter :: Notarization ( notarization) ;
620625 sender. send ( Recipients :: All , msg, true ) . await . unwrap ( ) ;
621626 self . broadcast_messages
622627 . get_or_create ( & metrics:: NOTARIZATION )
623628 . inc ( ) ;
624629 debug ! ( view = past_view, "rebroadcast entry notarization" ) ;
625630 } else if let Some ( nullification) = self . construct_nullification ( past_view, true ) {
626- let msg = Voter :: Nullification :: < C :: Signature , D > ( nullification)
627- . encode ( )
628- . into ( ) ;
631+ let msg = Voter :: Nullification ( nullification) ;
629632 sender. send ( Recipients :: All , msg, true ) . await . unwrap ( ) ;
630633 self . broadcast_messages
631634 . get_or_create ( & metrics:: NULLIFICATION )
@@ -663,7 +666,7 @@ impl<
663666 . expect ( "unable to sync journal" ) ;
664667
665668 // Broadcast nullify
666- let msg = Voter :: Nullify :: < C :: Signature , D > ( nullify) . encode ( ) . into ( ) ;
669+ let msg = Voter :: Nullify ( nullify) ;
667670 sender. send ( Recipients :: All , msg, true ) . await . unwrap ( ) ;
668671 self . broadcast_messages
669672 . get_or_create ( & metrics:: NULLIFY )
@@ -1444,10 +1447,10 @@ impl<
14441447 Some ( Finalization :: new ( proposal, signatures) )
14451448 }
14461449
1447- async fn notify (
1450+ async fn notify < Sr : Sender > (
14481451 & mut self ,
14491452 backfiller : & mut resolver:: Mailbox < C :: Signature , D > ,
1450- sender : & mut impl Sender ,
1453+ sender : & mut WrappedSender < Sr , usize , Voter < C :: Signature , D > > ,
14511454 view : u64 ,
14521455 ) {
14531456 // Attempt to notarize
@@ -1464,7 +1467,7 @@ impl<
14641467 . expect ( "unable to sync journal" ) ;
14651468
14661469 // Broadcast the notarize
1467- let msg = Voter :: Notarize ( notarize) . encode ( ) . into ( ) ;
1470+ let msg = Voter :: Notarize ( notarize) ;
14681471 sender. send ( Recipients :: All , msg, true ) . await . unwrap ( ) ;
14691472 self . broadcast_messages
14701473 . get_or_create ( & metrics:: NOTARIZE )
@@ -1500,7 +1503,7 @@ impl<
15001503 . await ;
15011504
15021505 // Broadcast the notarization
1503- let msg = Voter :: Notarization ( notarization) . encode ( ) . into ( ) ;
1506+ let msg = Voter :: Notarization ( notarization) ;
15041507 sender. send ( Recipients :: All , msg, true ) . await . unwrap ( ) ;
15051508 self . broadcast_messages
15061509 . get_or_create ( & metrics:: NOTARIZATION )
@@ -1531,9 +1534,7 @@ impl<
15311534 . await ;
15321535
15331536 // Broadcast the nullification
1534- let msg = Voter :: Nullification :: < C :: Signature , D > ( nullification)
1535- . encode ( )
1536- . into ( ) ;
1537+ let msg = Voter :: Nullification ( nullification) ;
15371538 sender. send ( Recipients :: All , msg, true ) . await . unwrap ( ) ;
15381539 self . broadcast_messages
15391540 . get_or_create ( & metrics:: NULLIFICATION )
@@ -1573,7 +1574,7 @@ impl<
15731574 ) ;
15741575 let finalization = self . construct_finalization ( self . last_finalized , true ) ;
15751576 if let Some ( finalization) = finalization {
1576- let msg = Voter :: Finalization ( finalization) . encode ( ) . into ( ) ;
1577+ let msg = Voter :: Finalization ( finalization) ;
15771578 sender
15781579 . send ( Recipients :: All , msg, true )
15791580 . await
@@ -1605,7 +1606,7 @@ impl<
16051606 . expect ( "unable to sync journal" ) ;
16061607
16071608 // Broadcast the finalize
1608- let msg = Voter :: Finalize ( finalize) . encode ( ) . into ( ) ;
1609+ let msg = Voter :: Finalize ( finalize) ;
16091610 sender. send ( Recipients :: All , msg, true ) . await . unwrap ( ) ;
16101611 self . broadcast_messages
16111612 . get_or_create ( & metrics:: FINALIZE )
@@ -1641,7 +1642,7 @@ impl<
16411642 . await ;
16421643
16431644 // Broadcast the finalization
1644- let msg = Voter :: Finalization ( finalization) . encode ( ) . into ( ) ;
1645+ let msg = Voter :: Finalization ( finalization) ;
16451646 sender. send ( Recipients :: All , msg, true ) . await . unwrap ( ) ;
16461647 self . broadcast_messages
16471648 . get_or_create ( & metrics:: FINALIZATION )
@@ -1661,9 +1662,12 @@ impl<
16611662 async fn run (
16621663 mut self ,
16631664 mut backfiller : resolver:: Mailbox < C :: Signature , D > ,
1664- mut sender : impl Sender ,
1665- mut receiver : impl Receiver ,
1665+ sender : impl Sender ,
1666+ receiver : impl Receiver ,
16661667 ) {
1668+ // Wrap channel
1669+ let ( mut sender, mut receiver) = wrap ( self . max_participants , sender, receiver) ;
1670+
16671671 // Compute genesis
16681672 let genesis = self . automaton . genesis ( ) . await ;
16691673 self . genesis = Some ( genesis) ;
@@ -1907,11 +1911,13 @@ impl<
19071911 }
19081912 } ,
19091913 msg = receiver. recv( ) => {
1910- // Parse message
1914+ // Break if there is an internal error
19111915 let Ok ( ( s, msg) ) = msg else {
19121916 break ;
19131917 } ;
1914- let Ok ( msg) = Voter :: decode_cfg( msg, & self . max_participants) else {
1918+
1919+ // Skip if there is a decoding error
1920+ let Ok ( msg) = msg else {
19151921 continue ;
19161922 } ;
19171923
0 commit comments