@@ -29,8 +29,8 @@ use std::{
2929 time:: Duration ,
3030} ;
3131
32- use futures:: StreamExt ;
33- use futures_ticker :: Ticker ;
32+ use futures:: FutureExt ;
33+ use futures_timer :: Delay ;
3434use prometheus_client:: registry:: Registry ;
3535use rand:: { seq:: SliceRandom , thread_rng} ;
3636
@@ -283,7 +283,7 @@ pub struct Behaviour<D = IdentityTransform, F = AllowAllSubscriptionFilter> {
283283 mcache : MessageCache ,
284284
285285 /// Heartbeat interval stream.
286- heartbeat : Ticker ,
286+ heartbeat : Delay ,
287287
288288 /// Number of heartbeats since the beginning of time; this allows us to amortize some resource
289289 /// clean up -- eg backoff clean up.
@@ -301,7 +301,7 @@ pub struct Behaviour<D = IdentityTransform, F = AllowAllSubscriptionFilter> {
301301
302302 /// Stores optional peer score data together with thresholds, decay interval and gossip
303303 /// promises.
304- peer_score : Option < ( PeerScore , PeerScoreThresholds , Ticker , GossipPromises ) > ,
304+ peer_score : Option < ( PeerScore , PeerScoreThresholds , Delay , GossipPromises ) > ,
305305
306306 /// Counts the number of `IHAVE` received from each peer since the last heartbeat.
307307 count_received_ihave : HashMap < PeerId , usize > ,
@@ -448,10 +448,7 @@ where
448448 config. backoff_slack ( ) ,
449449 ) ,
450450 mcache : MessageCache :: new ( config. history_gossip ( ) , config. history_length ( ) ) ,
451- heartbeat : Ticker :: new_with_next (
452- config. heartbeat_interval ( ) ,
453- config. heartbeat_initial_delay ( ) ,
454- ) ,
451+ heartbeat : Delay :: new ( config. heartbeat_interval ( ) + config. heartbeat_initial_delay ( ) ) ,
455452 heartbeat_ticks : 0 ,
456453 px_peers : HashSet :: new ( ) ,
457454 outbound_peers : HashSet :: new ( ) ,
@@ -879,7 +876,7 @@ where
879876 return Err ( "Peer score set twice" . into ( ) ) ;
880877 }
881878
882- let interval = Ticker :: new ( params. decay_interval ) ;
879+ let interval = Delay :: new ( params. decay_interval ) ;
883880 let peer_score = PeerScore :: new_with_message_delivery_time_callback ( params, callback) ;
884881 self . peer_score = Some ( ( peer_score, threshold, interval, GossipPromises :: default ( ) ) ) ;
885882 Ok ( ( ) )
@@ -1145,7 +1142,7 @@ where
11451142 }
11461143
11471144 fn score_below_threshold_from_scores (
1148- peer_score : & Option < ( PeerScore , PeerScoreThresholds , Ticker , GossipPromises ) > ,
1145+ peer_score : & Option < ( PeerScore , PeerScoreThresholds , Delay , GossipPromises ) > ,
11491146 peer_id : & PeerId ,
11501147 threshold : impl Fn ( & PeerScoreThresholds ) -> f64 ,
11511148 ) -> ( bool , f64 ) {
@@ -3105,14 +3102,16 @@ where
31053102 }
31063103
31073104 // update scores
3108- if let Some ( ( peer_score, _, interval , _) ) = & mut self . peer_score {
3109- while let Poll :: Ready ( Some ( _ ) ) = interval . poll_next_unpin ( cx ) {
3105+ if let Some ( ( peer_score, _, delay , _) ) = & mut self . peer_score {
3106+ if delay . poll_unpin ( cx ) . is_ready ( ) {
31103107 peer_score. refresh_scores ( ) ;
3108+ delay. reset ( peer_score. params . decay_interval ) ;
31113109 }
31123110 }
31133111
3114- while let Poll :: Ready ( Some ( _ ) ) = self . heartbeat . poll_next_unpin ( cx) {
3112+ if self . heartbeat . poll_unpin ( cx) . is_ready ( ) {
31153113 self . heartbeat ( ) ;
3114+ self . heartbeat . reset ( self . config . heartbeat_interval ( ) ) ;
31163115 }
31173116
31183117 Poll :: Pending
0 commit comments