@@ -66,16 +66,18 @@ use crate::util_lib::db::{DBConn, Error as DBError};
66
66
/// start and end block. This includes all tenures except for the two most recent ones.
67
67
#[ derive( Debug , Clone , PartialEq ) ]
68
68
pub enum NakamotoTenureDownloadState {
69
- /// Getting the tenure-start block (the given StacksBlockId is it's block ID).
70
- GetTenureStartBlock ( StacksBlockId ) ,
69
+ /// Getting the tenure-start block (the given StacksBlockId is it's block ID), as well as the
70
+ /// millisecond epoch timestamp at which the request began
71
+ GetTenureStartBlock ( StacksBlockId , u128 ) ,
71
72
/// Getting the tenure-end block.
72
- ///
73
- /// The field here is the block ID of the tenure end block.
74
- GetTenureEndBlock ( StacksBlockId ) ,
73
+ /// The fields here are the block ID of the tenure end block, as well as the millisecond epoch
74
+ /// timestamp at which the request begahn
75
+ GetTenureEndBlock ( StacksBlockId , u128 ) ,
75
76
/// Receiving tenure blocks.
76
- /// The field here is the hash of the _last_ block in the tenure that must be downloaded. This
77
- /// is because a tenure is fetched in order from highest block to lowest block.
78
- GetTenureBlocks ( StacksBlockId ) ,
77
+ /// The fields here are the hash of the _last_ block in the tenure that must be downloaded, as well
78
+ /// as the millisecond epoch timestamp at which the request began. The first field is needed
79
+ /// because a tenure is fetched in order from highest block to lowest block.
80
+ GetTenureBlocks ( StacksBlockId , u128 ) ,
79
81
/// We have gotten all the blocks for this tenure
80
82
Done ,
81
83
}
@@ -166,7 +168,7 @@ impl NakamotoTenureDownloader {
166
168
start_signer_keys,
167
169
end_signer_keys,
168
170
idle : false ,
169
- state : NakamotoTenureDownloadState :: GetTenureStartBlock ( tenure_start_block_id. clone ( ) ) ,
171
+ state : NakamotoTenureDownloadState :: GetTenureStartBlock ( tenure_start_block_id. clone ( ) , get_epoch_time_ms ( ) ) ,
170
172
tenure_start_block : None ,
171
173
tenure_end_block : None ,
172
174
tenure_blocks : None ,
@@ -187,7 +189,7 @@ impl NakamotoTenureDownloader {
187
189
& mut self ,
188
190
tenure_start_block : NakamotoBlock ,
189
191
) -> Result < ( ) , NetError > {
190
- let NakamotoTenureDownloadState :: GetTenureStartBlock ( _ ) = & self . state else {
192
+ let NakamotoTenureDownloadState :: GetTenureStartBlock ( .. ) = & self . state else {
191
193
// not the right state for this
192
194
warn ! ( "Invalid state for this method" ;
193
195
"state" => %self . state) ;
@@ -235,7 +237,7 @@ impl NakamotoTenureDownloader {
235
237
} else {
236
238
// need to get tenure_end_block.
237
239
self . state =
238
- NakamotoTenureDownloadState :: GetTenureEndBlock ( self . tenure_end_block_id . clone ( ) ) ;
240
+ NakamotoTenureDownloadState :: GetTenureEndBlock ( self . tenure_end_block_id . clone ( ) , get_epoch_time_ms ( ) ) ;
239
241
}
240
242
Ok ( ( ) )
241
243
}
@@ -252,7 +254,7 @@ impl NakamotoTenureDownloader {
252
254
) -> Result < ( ) , NetError > {
253
255
if !matches ! (
254
256
& self . state,
255
- NakamotoTenureDownloadState :: GetTenureEndBlock ( _ )
257
+ NakamotoTenureDownloadState :: GetTenureEndBlock ( .. )
256
258
) {
257
259
warn ! ( "Invalid state for this method" ;
258
260
"state" => %self . state) ;
@@ -326,6 +328,7 @@ impl NakamotoTenureDownloader {
326
328
self . tenure_end_block = Some ( tenure_end_block. clone ( ) ) ;
327
329
self . state = NakamotoTenureDownloadState :: GetTenureBlocks (
328
330
tenure_end_block. header . parent_block_id . clone ( ) ,
331
+ get_epoch_time_ms ( )
329
332
) ;
330
333
Ok ( ( ) )
331
334
}
@@ -361,7 +364,7 @@ impl NakamotoTenureDownloader {
361
364
& mut self ,
362
365
mut tenure_blocks : Vec < NakamotoBlock > ,
363
366
) -> Result < Option < Vec < NakamotoBlock > > , NetError > {
364
- let NakamotoTenureDownloadState :: GetTenureBlocks ( block_cursor) = & self . state else {
367
+ let NakamotoTenureDownloadState :: GetTenureBlocks ( block_cursor, start_request_time ) = & self . state else {
365
368
warn ! ( "Invalid state for this method" ;
366
369
"state" => %self . state) ;
367
370
return Err ( NetError :: InvalidState ) ;
@@ -461,7 +464,7 @@ impl NakamotoTenureDownloader {
461
464
& earliest_block. block_id( ) ,
462
465
& next_block_id
463
466
) ;
464
- self . state = NakamotoTenureDownloadState :: GetTenureBlocks ( next_block_id) ;
467
+ self . state = NakamotoTenureDownloadState :: GetTenureBlocks ( next_block_id, * start_request_time ) ;
465
468
return Ok ( None ) ;
466
469
}
467
470
@@ -486,16 +489,16 @@ impl NakamotoTenureDownloader {
486
489
peerhost : PeerHost ,
487
490
) -> Result < Option < StacksHttpRequest > , ( ) > {
488
491
let request = match self . state {
489
- NakamotoTenureDownloadState :: GetTenureStartBlock ( start_block_id) => {
490
- debug ! ( "Request tenure-start block {}" , & start_block_id) ;
492
+ NakamotoTenureDownloadState :: GetTenureStartBlock ( start_block_id, start_request_time ) => {
493
+ debug ! ( "Request tenure-start block {} at {} " , & start_block_id, start_request_time ) ;
491
494
StacksHttpRequest :: new_get_nakamoto_block ( peerhost, start_block_id. clone ( ) )
492
495
}
493
- NakamotoTenureDownloadState :: GetTenureEndBlock ( end_block_id) => {
494
- debug ! ( "Request tenure-end block {}" , & end_block_id) ;
496
+ NakamotoTenureDownloadState :: GetTenureEndBlock ( end_block_id, start_request_time ) => {
497
+ debug ! ( "Request tenure-end block {} at {} " , & end_block_id, start_request_time ) ;
495
498
StacksHttpRequest :: new_get_nakamoto_block ( peerhost, end_block_id. clone ( ) )
496
499
}
497
- NakamotoTenureDownloadState :: GetTenureBlocks ( end_block_id) => {
498
- debug ! ( "Downloading tenure ending at {}" , & end_block_id) ;
500
+ NakamotoTenureDownloadState :: GetTenureBlocks ( end_block_id, start_request_time ) => {
501
+ debug ! ( "Downloading tenure ending at {} at {} " , & end_block_id, start_request_time ) ;
499
502
StacksHttpRequest :: new_get_nakamoto_tenure ( peerhost, end_block_id. clone ( ) , None )
500
503
}
501
504
NakamotoTenureDownloadState :: Done => {
@@ -558,10 +561,10 @@ impl NakamotoTenureDownloader {
558
561
response : StacksHttpResponse ,
559
562
) -> Result < Option < Vec < NakamotoBlock > > , NetError > {
560
563
let handle_result = match self . state {
561
- NakamotoTenureDownloadState :: GetTenureStartBlock ( _block_id) => {
564
+ NakamotoTenureDownloadState :: GetTenureStartBlock ( _block_id, _start_request_time ) => {
562
565
debug ! (
563
- "Got download response for tenure-start block {}" ,
564
- & _block_id
566
+ "Got download response for tenure-start block {} in {}ms " ,
567
+ & _block_id, get_epoch_time_ms ( ) . saturating_sub ( _start_request_time )
565
568
) ;
566
569
let block = response. decode_nakamoto_block ( ) . map_err ( |e| {
567
570
warn ! ( "Failed to decode response for a Nakamoto block: {:?}" , & e) ;
@@ -570,19 +573,19 @@ impl NakamotoTenureDownloader {
570
573
self . try_accept_tenure_start_block ( block) ?;
571
574
Ok ( None )
572
575
}
573
- NakamotoTenureDownloadState :: GetTenureEndBlock ( _block_id) => {
574
- debug ! ( "Got download response to tenure-end block {}" , & _block_id) ;
576
+ NakamotoTenureDownloadState :: GetTenureEndBlock ( _block_id, _start_request_time ) => {
577
+ debug ! ( "Got download response to tenure-end block {} in {}ms " , & _block_id, get_epoch_time_ms ( ) . saturating_sub ( _start_request_time ) ) ;
575
578
let block = response. decode_nakamoto_block ( ) . map_err ( |e| {
576
579
warn ! ( "Failed to decode response for a Nakamoto block: {:?}" , & e) ;
577
580
e
578
581
} ) ?;
579
582
self . try_accept_tenure_end_block ( & block) ?;
580
583
Ok ( None )
581
584
}
582
- NakamotoTenureDownloadState :: GetTenureBlocks ( _end_block_id) => {
585
+ NakamotoTenureDownloadState :: GetTenureBlocks ( _end_block_id, _start_request_time ) => {
583
586
debug ! (
584
- "Got download response for tenure blocks ending at {}" ,
585
- & _end_block_id
587
+ "Got download response for tenure blocks ending at {} in {}ms " ,
588
+ & _end_block_id, get_epoch_time_ms ( ) . saturating_sub ( _start_request_time )
586
589
) ;
587
590
let blocks = response. decode_nakamoto_tenure ( ) . map_err ( |e| {
588
591
warn ! ( "Failed to decode response for a Nakamoto tenure: {:?}" , & e) ;
0 commit comments