@@ -32,7 +32,7 @@ use futures::StreamExt;
3232use fvm_ipld_encoding:: to_vec;
3333use itertools:: Itertools ;
3434use nonzero_ext:: nonzero;
35- use parking_lot:: { Mutex , RwLock as SyncRwLock } ;
35+ use parking_lot:: RwLock as SyncRwLock ;
3636use tokio:: { sync:: broadcast:: error:: RecvError , task:: JoinSet , time:: interval} ;
3737use tracing:: warn;
3838
@@ -177,7 +177,7 @@ pub struct MessagePool<T> {
177177 /// A map of pending messages where the key is the address
178178 pub pending : Arc < SyncRwLock < HashMap < Address , MsgSet > > > ,
179179 /// The current tipset (a set of blocks)
180- pub cur_tipset : Arc < Mutex < Arc < Tipset > > > ,
180+ pub cur_tipset : Arc < SyncRwLock < Arc < Tipset > > > ,
181181 /// The underlying provider
182182 pub api : Arc < T > ,
183183 /// Sender half to send messages to other components
@@ -202,6 +202,11 @@ impl<T> MessagePool<T>
202202where
203203 T : Provider ,
204204{
205+ /// Gets the current tipset
206+ pub fn current_tipset ( & self ) -> Arc < Tipset > {
207+ self . cur_tipset . read ( ) . clone ( )
208+ }
209+
205210 /// Add a signed message to the pool and its address.
206211 fn add_local ( & self , m : SignedMessage ) -> Result < ( ) , Error > {
207212 self . local_addrs . write ( ) . push ( m. from ( ) ) ;
@@ -214,7 +219,7 @@ where
214219 pub async fn push ( & self , msg : SignedMessage ) -> Result < Cid , Error > {
215220 self . check_message ( & msg) ?;
216221 let cid = msg. cid ( ) ;
217- let cur_ts = self . cur_tipset . lock ( ) . clone ( ) ;
222+ let cur_ts = self . current_tipset ( ) ;
218223 let publish = self . add_tipset ( msg. clone ( ) , & cur_ts, true ) ?;
219224 let msg_ser = to_vec ( & msg) ?;
220225 let network_name = self . chain_config . network . genesis_name ( ) ;
@@ -249,10 +254,8 @@ where
249254 /// fits the parameters to be pushed to the `MessagePool`.
250255 pub fn add ( & self , msg : SignedMessage ) -> Result < ( ) , Error > {
251256 self . check_message ( & msg) ?;
252-
253- let tip = self . cur_tipset . lock ( ) . clone ( ) ;
254-
255- self . add_tipset ( msg, & tip, false ) ?;
257+ let ts = self . current_tipset ( ) ;
258+ self . add_tipset ( msg, & ts, false ) ?;
256259 Ok ( ( ) )
257260 }
258261
@@ -320,7 +323,7 @@ where
320323 /// the pending hash-map.
321324 fn add_helper ( & self , msg : SignedMessage ) -> Result < ( ) , Error > {
322325 let from = msg. from ( ) ;
323- let cur_ts = self . cur_tipset . lock ( ) . clone ( ) ;
326+ let cur_ts = self . current_tipset ( ) ;
324327 add_helper (
325328 self . api . as_ref ( ) ,
326329 self . bls_sig_cache . as_ref ( ) ,
@@ -333,7 +336,7 @@ where
333336 /// Get the sequence for a given address, return Error if there is a failure
334337 /// to retrieve the respective sequence.
335338 pub fn get_sequence ( & self , addr : & Address ) -> Result < u64 , Error > {
336- let cur_ts = self . cur_tipset . lock ( ) . clone ( ) ;
339+ let cur_ts = self . current_tipset ( ) ;
337340
338341 let sequence = self . get_state_sequence ( addr, & cur_ts) ?;
339342
@@ -378,7 +381,7 @@ where
378381 )
379382 }
380383
381- let cur_ts = self . cur_tipset . lock ( ) . clone ( ) ;
384+ let cur_ts = self . current_tipset ( ) ;
382385
383386 Ok ( ( out, cur_ts) )
384387 }
@@ -471,7 +474,7 @@ where
471474 {
472475 let local_addrs = Arc :: new ( SyncRwLock :: new ( Vec :: new ( ) ) ) ;
473476 let pending = Arc :: new ( SyncRwLock :: new ( HashMap :: new ( ) ) ) ;
474- let tipset = Arc :: new ( Mutex :: new ( api. get_heaviest_tipset ( ) ) ) ;
477+ let tipset = Arc :: new ( SyncRwLock :: new ( api. get_heaviest_tipset ( ) ) ) ;
475478 let bls_sig_cache = Arc :: new ( SizeTrackingLruCache :: new_with_default_metrics_registry (
476479 "bls_sig_cache" . into ( ) ,
477480 BLS_SIG_CACHE_SIZE ,
0 commit comments