11use std:: { sync:: Arc , time:: Duration } ;
22
3+ use aleph_primitives:: BlockNumber ;
34use futures:: channel:: oneshot;
45use log:: { debug, warn} ;
56use parking_lot:: Mutex ;
67use sc_client_api:: HeaderBackend ;
78use sp_consensus:: SelectChain ;
89use sp_runtime:: {
9- traits:: { Block as BlockT , Header as HeaderT , NumberFor , One , Zero } ,
10+ traits:: { Block as BlockT , Header as HeaderT , NumberFor , Zero } ,
1011 SaturatedConversion ,
1112} ;
1213
@@ -41,13 +42,14 @@ where
4142pub fn get_parent < B , C > ( client : & C , block : & BlockHashNum < B > ) -> Option < BlockHashNum < B > >
4243where
4344 B : BlockT ,
45+ B :: Header : HeaderT < Number = BlockNumber > ,
4446 C : HeaderBackend < B > ,
4547{
4648 if block. num . is_zero ( ) {
4749 return None ;
4850 }
4951 if let Some ( header) = client. header ( block. hash ) . expect ( "client must respond" ) {
50- Some ( ( * header. parent_hash ( ) , block. num - < NumberFor < B > > :: one ( ) ) . into ( ) )
52+ Some ( ( * header. parent_hash ( ) , block. num - 1 ) . into ( ) )
5153 } else {
5254 warn ! ( target: "aleph-data-store" , "Trying to fetch the parent of an unknown block {:?}." , block) ;
5355 None
@@ -61,6 +63,7 @@ pub fn get_proposal<B, C>(
6163) -> Result < AlephData < B > , ( ) >
6264where
6365 B : BlockT ,
66+ B :: Header : HeaderT < Number = BlockNumber > ,
6467 C : HeaderBackend < B > ,
6568{
6669 let mut curr_block = best_block;
@@ -115,27 +118,29 @@ struct ChainInfo<B: BlockT> {
115118pub struct ChainTracker < B , SC , C >
116119where
117120 B : BlockT ,
121+ B :: Header : HeaderT < Number = BlockNumber > ,
118122 C : HeaderBackend < B > + ' static ,
119123 SC : SelectChain < B > + ' static ,
120124{
121125 select_chain : SC ,
122126 client : Arc < C > ,
123127 data_to_propose : Arc < Mutex < Option < AlephData < B > > > > ,
124- session_boundaries : SessionBoundaries < B > ,
128+ session_boundaries : SessionBoundaries ,
125129 prev_chain_info : Option < ChainInfo < B > > ,
126130 config : ChainTrackerConfig ,
127131}
128132
129133impl < B , SC , C > ChainTracker < B , SC , C >
130134where
131135 B : BlockT ,
136+ B :: Header : HeaderT < Number = BlockNumber > ,
132137 C : HeaderBackend < B > + ' static ,
133138 SC : SelectChain < B > + ' static ,
134139{
135140 pub fn new (
136141 select_chain : SC ,
137142 client : Arc < C > ,
138- session_boundaries : SessionBoundaries < B > ,
143+ session_boundaries : SessionBoundaries ,
139144 config : ChainTrackerConfig ,
140145 metrics : Option < Metrics < <B :: Header as HeaderT >:: Hash > > ,
141146 ) -> ( Self , DataProvider < B > ) {
@@ -335,7 +340,7 @@ mod tests {
335340 client_chain_builder:: ClientChainBuilder ,
336341 mocks:: { aleph_data_from_blocks, TBlock , TestClientBuilder , TestClientBuilderExt } ,
337342 } ,
338- SessionBoundaries , SessionId , SessionPeriod ,
343+ SessionBoundaryInfo , SessionId , SessionPeriod ,
339344 } ;
340345
341346 const SESSION_LEN : u32 = 100 ;
@@ -354,7 +359,8 @@ mod tests {
354359
355360 let chain_builder =
356361 ClientChainBuilder :: new ( client. clone ( ) , Arc :: new ( TestClientBuilder :: new ( ) . build ( ) ) ) ;
357- let session_boundaries = SessionBoundaries :: new ( SessionId ( 0 ) , SessionPeriod ( SESSION_LEN ) ) ;
362+ let session_boundaries = SessionBoundaryInfo :: new ( SessionPeriod ( SESSION_LEN ) )
363+ . boundaries_for_session ( SessionId ( 0 ) ) ;
358364
359365 let config = ChainTrackerConfig {
360366 refresh_interval : REFRESH_INTERVAL ,
0 commit comments