@@ -25,14 +25,14 @@ pub fn attestation_signers(
2525 Box :: leak ( Box :: new ( Mutex :: new ( HashMap :: new ( ) ) ) ) ;
2626
2727 // Whenever the indexer's active or recently closed allocations change, make sure
28- // we have attestation signers for all of them
28+ // we have attestation signers for all of them.
2929 let ( mut signers_writer, signers_reader) =
3030 Eventual :: < HashMap < Address , AttestationSigner > > :: new ( ) ;
3131
3232 tokio:: spawn ( async move {
33- //listening to the allocation eventual and converting them to reciever
34- //using pipe for updation
35- //for temporary pupose only
33+ // Listening to the allocation eventual and converting them to reciever.
34+ // Using pipe for updation.
35+ // For temporary pupose only.
3636 let ( allocations_tx, mut allocations_rx) =
3737 watch:: channel ( indexer_allocations. value ( ) . await . unwrap ( ) ) ;
3838 let _p1 = indexer_allocations. pipe ( move |allocatons| {
@@ -42,25 +42,25 @@ pub fn attestation_signers(
4242 loop {
4343 select ! {
4444 Ok ( _) = allocations_rx. changed( ) =>{
45- signers_writer = modify_sigers(
45+ modify_sigers(
4646 Arc :: new( indexer_mnemonic. clone( ) ) ,
4747 chain_id,
4848 attestation_signers_map,
4949 allocations_rx. clone( ) ,
5050 dispute_manager_rx. clone( ) ,
51- signers_writer) . await ;
51+ & mut signers_writer) . await ;
5252 } ,
5353 Ok ( _) = dispute_manager_rx. changed( ) =>{
54- signers_writer = modify_sigers( Arc :: new( indexer_mnemonic. clone( ) ) ,
54+ modify_sigers( Arc :: new( indexer_mnemonic. clone( ) ) ,
5555 chain_id,
5656 attestation_signers_map,
5757 allocations_rx. clone( ) ,
5858 dispute_manager_rx. clone( ) ,
59- signers_writer) . await ;
59+ & mut signers_writer) . await ;
6060 } ,
6161 else=>{
62- //something is wrong
63- break ;
62+ // Something is wrong.
63+ panic! ( "dispute_manager_rx or allocations_rx was dropped" ) ;
6464 }
6565 }
6666 }
@@ -74,15 +74,13 @@ async fn modify_sigers(
7474 attestation_signers_map : & ' static Mutex < HashMap < Address , AttestationSigner > > ,
7575 allocations_rx : Receiver < HashMap < Address , Allocation > > ,
7676 dispute_manager_rx : Receiver < Option < Address > > ,
77- mut signers_writer : EventualWriter < HashMap < Address , AttestationSigner > > ,
78- ) -> EventualWriter < HashMap < Address , AttestationSigner > > {
77+ signers_writer : & mut EventualWriter < HashMap < Address , AttestationSigner > > ,
78+ ) {
7979 let mut signers = attestation_signers_map. lock ( ) . await ;
8080 let allocations = allocations_rx. borrow ( ) . clone ( ) ;
81- let dispute_manager = * dispute_manager_rx. borrow ( ) ;
82- if dispute_manager. is_none ( ) {
83- return signers_writer;
84- }
85- let dispute_manager = dispute_manager. unwrap ( ) ;
81+ let Some ( dispute_manager) = * dispute_manager_rx. borrow ( ) else {
82+ return ;
83+ } ;
8684 // Remove signers for allocations that are no longer active or recently closed
8785 signers. retain ( |id, _| allocations. contains_key ( id) ) ;
8886
@@ -104,7 +102,6 @@ async fn modify_sigers(
104102 }
105103
106104 signers_writer. write ( signers. clone ( ) ) ;
107- signers_writer
108105}
109106
110107#[ cfg( test) ]
0 commit comments