1919//! Substrate transaction pool implementation.
2020
2121use crate :: LOG_TARGET ;
22- use num_traits:: CheckedSub ;
2322use sc_transaction_pool_api:: ChainEvent ;
2423use sp_blockchain:: TreeRoute ;
25- use sp_runtime:: traits:: { Block as BlockT , NumberFor } ;
24+ use sp_runtime:: traits:: { Block as BlockT , NumberFor , Saturating } ;
2625
2726/// The threshold since the last update where we will skip any maintenance for blocks.
2827///
@@ -101,17 +100,16 @@ where
101100 TreeRouteF : Fn ( Block :: Hash , Block :: Hash ) -> Result < TreeRoute < Block > , String > ,
102101 BlockNumberF : Fn ( Block :: Hash ) -> Result < Option < NumberFor < Block > > , String > ,
103102 {
104- let ( new_hash, current_hash, finalized) = match event {
105- ChainEvent :: NewBestBlock { hash, .. } => ( * hash, self . recent_best_block , false ) ,
106- ChainEvent :: Finalized { hash, .. } => ( * hash, self . recent_finalized_block , true ) ,
107- } ;
103+ let new_hash = event. hash ( ) ;
104+ let finalized = event. is_finalized ( ) ;
108105
109106 // do not proceed with txpool maintain if block distance is to high
110- let skip_maintenance = match ( hash_to_number ( new_hash) , hash_to_number ( current_hash) ) {
111- ( Ok ( Some ( new) ) , Ok ( Some ( current) ) ) =>
112- new. checked_sub ( & current) > Some ( SKIP_MAINTENANCE_THRESHOLD . into ( ) ) ,
113- _ => true ,
114- } ;
107+ let skip_maintenance =
108+ match ( hash_to_number ( new_hash) , hash_to_number ( self . recent_best_block ) ) {
109+ ( Ok ( Some ( new) ) , Ok ( Some ( current) ) ) =>
110+ new. saturating_sub ( current) > SKIP_MAINTENANCE_THRESHOLD . into ( ) ,
111+ _ => true ,
112+ } ;
115113
116114 if skip_maintenance {
117115 log:: debug!( target: LOG_TARGET , "skip maintain: tree_route would be too long" ) ;
@@ -131,10 +129,10 @@ where
131129
132130 log:: debug!(
133131 target: LOG_TARGET ,
134- "resolve hash:{ :?} finalized:{:?} tree_route:{ :?} best_block:{:?} finalized_block:{:?}" ,
135- new_hash ,
136- finalized ,
137- tree_route,
132+ "resolve hash: {new_hash :?} finalized: {finalized :?} \
133+ tree_route: (common {:?}, last {:?}) best_block: {:?} finalized_block:{:?}" ,
134+ tree_route . common_block ( ) ,
135+ tree_route. last ( ) ,
138136 self . recent_best_block,
139137 self . recent_finalized_block
140138 ) ;
0 commit comments