@@ -50,6 +50,17 @@ use crate::net::{Error as NetError, Hash160, NeighborAddress, SortitionDB};
50
50
use crate :: stacks_common:: types:: Address ;
51
51
use crate :: util_lib:: db:: Error as DBError ;
52
52
53
+ impl NakamotoTenureDownloadState {
54
+ pub fn request_time ( & self ) -> Option < u128 > {
55
+ match self {
56
+ Self :: GetTenureStartBlock ( _, ts) => Some ( * ts) ,
57
+ Self :: GetTenureEndBlock ( _, ts) => Some ( * ts) ,
58
+ Self :: GetTenureBlocks ( _, ts) => Some ( * ts) ,
59
+ Self :: Done => None ,
60
+ }
61
+ }
62
+ }
63
+
53
64
impl NakamotoDownloadStateMachine {
54
65
/// Find the list of wanted tenures for the given reward cycle. The reward cycle must
55
66
/// be complete already. Used for testing.
@@ -240,7 +251,10 @@ fn test_nakamoto_tenure_downloader() {
240
251
// must be first block
241
252
assert_eq ! (
242
253
td. state,
243
- NakamotoTenureDownloadState :: GetTenureStartBlock ( tenure_start_block. header. block_id( ) )
254
+ NakamotoTenureDownloadState :: GetTenureStartBlock (
255
+ tenure_start_block. header. block_id( ) ,
256
+ td. state. request_time( ) . unwrap( )
257
+ )
244
258
) ;
245
259
assert ! ( td
246
260
. try_accept_tenure_start_block( blocks. last( ) . unwrap( ) . clone( ) )
@@ -254,7 +268,7 @@ fn test_nakamoto_tenure_downloader() {
254
268
. try_accept_tenure_start_block( blocks. first( ) . unwrap( ) . clone( ) )
255
269
. is_ok( ) ) ;
256
270
257
- let NakamotoTenureDownloadState :: GetTenureEndBlock ( block_id) = td. state else {
271
+ let NakamotoTenureDownloadState :: GetTenureEndBlock ( block_id, .. ) = td. state else {
258
272
panic ! ( "wrong state" ) ;
259
273
} ;
260
274
assert_eq ! ( block_id, next_tenure_start_block. header. block_id( ) ) ;
@@ -274,7 +288,8 @@ fn test_nakamoto_tenure_downloader() {
274
288
assert_eq ! (
275
289
td. state,
276
290
NakamotoTenureDownloadState :: GetTenureBlocks (
277
- next_tenure_start_block. header. parent_block_id. clone( )
291
+ next_tenure_start_block. header. parent_block_id. clone( ) ,
292
+ td. state. request_time( ) . unwrap( ) ,
278
293
)
279
294
) ;
280
295
assert_eq ! ( td. tenure_end_block, Some ( next_tenure_start_block. clone( ) ) ) ;
@@ -299,7 +314,10 @@ fn test_nakamoto_tenure_downloader() {
299
314
// tail pointer moved
300
315
assert_eq ! (
301
316
td. state,
302
- NakamotoTenureDownloadState :: GetTenureBlocks ( block. header. parent_block_id. clone( ) )
317
+ NakamotoTenureDownloadState :: GetTenureBlocks (
318
+ block. header. parent_block_id. clone( ) ,
319
+ td. state. request_time( ) . unwrap( )
320
+ )
303
321
) ;
304
322
}
305
323
@@ -571,7 +589,8 @@ fn test_nakamoto_unconfirmed_tenure_downloader() {
571
589
assert_eq ! (
572
590
ntd. state,
573
591
NakamotoTenureDownloadState :: GetTenureStartBlock (
574
- unconfirmed_wanted_tenure. winning_block_id. clone( )
592
+ unconfirmed_wanted_tenure. winning_block_id. clone( ) ,
593
+ ntd. state. request_time( ) . unwrap( )
575
594
)
576
595
) ;
577
596
}
@@ -669,7 +688,8 @@ fn test_nakamoto_unconfirmed_tenure_downloader() {
669
688
assert_eq ! (
670
689
ntd. state,
671
690
NakamotoTenureDownloadState :: GetTenureStartBlock (
672
- unconfirmed_wanted_tenure. winning_block_id. clone( )
691
+ unconfirmed_wanted_tenure. winning_block_id. clone( ) ,
692
+ ntd. state. request_time( ) . unwrap( )
673
693
)
674
694
) ;
675
695
}
@@ -769,7 +789,8 @@ fn test_nakamoto_unconfirmed_tenure_downloader() {
769
789
assert_eq ! (
770
790
ntd. state,
771
791
NakamotoTenureDownloadState :: GetTenureStartBlock (
772
- unconfirmed_wanted_tenure. winning_block_id. clone( )
792
+ unconfirmed_wanted_tenure. winning_block_id. clone( ) ,
793
+ ntd. state. request_time( ) . unwrap( )
773
794
)
774
795
) ;
775
796
}
@@ -846,7 +867,8 @@ fn test_nakamoto_unconfirmed_tenure_downloader() {
846
867
assert_eq ! (
847
868
ntd. state,
848
869
NakamotoTenureDownloadState :: GetTenureStartBlock (
849
- unconfirmed_wanted_tenure. winning_block_id. clone( )
870
+ unconfirmed_wanted_tenure. winning_block_id. clone( ) ,
871
+ ntd. state. request_time( ) . unwrap( )
850
872
)
851
873
) ;
852
874
}
@@ -986,7 +1008,8 @@ fn test_nakamoto_unconfirmed_tenure_downloader() {
986
1008
assert_eq ! (
987
1009
ntd. state,
988
1010
NakamotoTenureDownloadState :: GetTenureStartBlock (
989
- unconfirmed_wanted_tenure. winning_block_id. clone( )
1011
+ unconfirmed_wanted_tenure. winning_block_id. clone( ) ,
1012
+ ntd. state. request_time( ) . unwrap( )
990
1013
)
991
1014
) ;
992
1015
}
0 commit comments