@@ -68,31 +68,7 @@ use crate::util_lib::db::{DBConn, Error as DBError};
68
68
pub enum NakamotoTenureDownloadState {
69
69
/// Getting the tenure-start block (the given StacksBlockId is it's block ID).
70
70
GetTenureStartBlock ( StacksBlockId ) ,
71
- /// Waiting for the child tenure's tenure-start block to arrive, which is usually (but not
72
- /// always) handled by the execution of another NakamotoTenureDownloader. The only
73
- /// exceptions are as follows:
74
- ///
75
- /// * if this tenure contains the anchor block, and it's the last tenure in the
76
- /// reward cycle. In this case, the end-block must be directly fetched, since there will be no
77
- /// follow-on NakamotTenureDownloader in the same reward cycle who can provide this.
78
- ///
79
- /// * if this tenure is the highest complete tenure, and we just learned the start-block of the
80
- /// ongoing tenure, then a NakamotoTenureDownloader will be instantiated with this tenure-end-block
81
- /// already known. This step will be skipped because the end-block is already present in the
82
- /// state machine.
83
- ///
84
- /// * if the deadline (second parameter) is exceeded, the state machine transitions to
85
- /// GetTenureEndBlock.
86
- ///
87
- /// The two fields here are:
88
- /// * the block ID of the last block in the tenure (which happens to be the block ID of the
89
- /// start block of the next tenure)
90
- /// * the deadline by which this state machine needs to have obtained the tenure end-block
91
- /// before transitioning to `GetTenureEndBlock`.
92
- WaitForTenureEndBlock ( StacksBlockId , Instant ) ,
93
- /// Getting the tenure-end block directly. This only happens for tenures whose end-blocks
94
- /// cannot be provided by tenure downloaders within the same reward cycle, and for tenures in
95
- /// which we cannot quickly get the tenure-end block.
71
+ /// Getting the tenure-end block.
96
72
///
97
73
/// The field here is the block ID of the tenure end block.
98
74
GetTenureEndBlock ( StacksBlockId ) ,
@@ -163,8 +139,7 @@ pub struct NakamotoTenureDownloader {
163
139
pub tenure_start_block : Option < NakamotoBlock > ,
164
140
/// Pre-stored tenure end block.
165
141
/// An instance of this state machine will be used to fetch the highest-confirmed tenure, once
166
- /// the start-block for the current tenure is downloaded. This is that start-block, which is
167
- /// used to transition from the `WaitForTenureEndBlock` step to the `GetTenureBlocks` step.
142
+ /// the start-block for the current tenure is downloaded.
168
143
pub tenure_end_block : Option < NakamotoBlock > ,
169
144
/// Tenure blocks
170
145
pub tenure_blocks : Option < Vec < NakamotoBlock > > ,
@@ -205,16 +180,6 @@ impl NakamotoTenureDownloader {
205
180
self
206
181
}
207
182
208
- /// Is this downloader waiting for the tenure-end block data from some other downloader? Per
209
- /// the struct documentation, this is case 2(a).
210
- pub fn is_waiting ( & self ) -> bool {
211
- if let NakamotoTenureDownloadState :: WaitForTenureEndBlock ( ..) = self . state {
212
- return true ;
213
- } else {
214
- return false ;
215
- }
216
- }
217
-
218
183
/// Validate and accept a given tenure-start block. If accepted, then advance the state.
219
184
/// Returns Ok(()) if the start-block is valid.
220
185
/// Returns Err(..) if it is not valid.
@@ -266,66 +231,15 @@ impl NakamotoTenureDownloader {
266
231
tenure_end_block. block_id( ) ,
267
232
& self . tenure_id_consensus_hash
268
233
) ;
269
- self . state = NakamotoTenureDownloadState :: WaitForTenureEndBlock (
270
- tenure_end_block. block_id ( ) ,
271
- Instant :: now ( )
272
- . checked_add ( Duration :: new ( WAIT_FOR_TENURE_END_BLOCK_TIMEOUT , 0 ) )
273
- . ok_or ( NetError :: OverflowError ( "Deadline is too big" . into ( ) ) ) ?,
274
- ) ;
275
234
self . try_accept_tenure_end_block ( & tenure_end_block) ?;
276
235
} else {
277
- // need to get tenure_end_block. By default, assume that another
278
- // NakamotoTenureDownloader will provide this block, and allow the
279
- // NakamotoTenureDownloaderSet instance that manages a collection of these
280
- // state-machines make the call to require this one to fetch the block directly.
281
- self . state = NakamotoTenureDownloadState :: WaitForTenureEndBlock (
282
- self . tenure_end_block_id . clone ( ) ,
283
- Instant :: now ( )
284
- . checked_add ( Duration :: new ( WAIT_FOR_TENURE_END_BLOCK_TIMEOUT , 0 ) )
285
- . ok_or ( NetError :: OverflowError ( "Deadline is too big" . into ( ) ) ) ?,
286
- ) ;
236
+ // need to get tenure_end_block.
237
+ self . state =
238
+ NakamotoTenureDownloadState :: GetTenureEndBlock ( self . tenure_end_block_id . clone ( ) ) ;
287
239
}
288
240
Ok ( ( ) )
289
241
}
290
242
291
- /// Transition this state-machine from waiting for its tenure-end block from another
292
- /// state-machine to directly fetching it. This only needs to happen if the tenure this state
293
- /// machine is downloading contains the PoX anchor block, and it's also the last confirmed
294
- /// tenurein this reward cycle.
295
- ///
296
- /// This function is called by `NakamotoTenureDownloadSet`, which instantiates, schedules, and
297
- /// runs a set of these machines based on the peers' inventory vectors. But because we don't
298
- /// know if this is the PoX anchor block tenure (or even the last tenure) until we have
299
- /// inventory vectors for this tenure's reward cycle, this state-transition must be driven
300
- /// after this machine's instantiation.
301
- pub fn transition_to_fetch_end_block ( & mut self ) -> Result < ( ) , NetError > {
302
- let NakamotoTenureDownloadState :: WaitForTenureEndBlock ( end_block_id, ..) = self . state
303
- else {
304
- return Err ( NetError :: InvalidState ) ;
305
- } ;
306
- debug ! (
307
- "Transition downloader to {} to directly fetch tenure-end block {} (direct transition)" ,
308
- & self . naddr, & end_block_id
309
- ) ;
310
- self . state = NakamotoTenureDownloadState :: GetTenureEndBlock ( end_block_id) ;
311
- Ok ( ( ) )
312
- }
313
-
314
- /// Transition to fetching the tenure-end block directly if waiting has taken too long.
315
- pub fn transition_to_fetch_end_block_on_timeout ( & mut self ) {
316
- if let NakamotoTenureDownloadState :: WaitForTenureEndBlock ( end_block_id, wait_deadline) =
317
- self . state
318
- {
319
- if wait_deadline < Instant :: now ( ) {
320
- debug ! (
321
- "Transition downloader to {} to directly fetch tenure-end block {} (timed out)" ,
322
- & self . naddr, & end_block_id
323
- ) ;
324
- self . state = NakamotoTenureDownloadState :: GetTenureEndBlock ( end_block_id) ;
325
- }
326
- }
327
- }
328
-
329
243
/// Validate and accept a tenure-end block. If accepted, then advance the state.
330
244
/// Once accepted, this function extracts the tenure-change transaction and block header from
331
245
/// this block (it does not need the entire block).
@@ -338,8 +252,7 @@ impl NakamotoTenureDownloader {
338
252
) -> Result < ( ) , NetError > {
339
253
if !matches ! (
340
254
& self . state,
341
- NakamotoTenureDownloadState :: WaitForTenureEndBlock ( ..)
342
- | NakamotoTenureDownloadState :: GetTenureEndBlock ( _)
255
+ NakamotoTenureDownloadState :: GetTenureEndBlock ( _)
343
256
) {
344
257
warn ! ( "Invalid state for this method" ;
345
258
"state" => %self . state) ;
@@ -577,14 +490,6 @@ impl NakamotoTenureDownloader {
577
490
debug ! ( "Request tenure-start block {}" , & start_block_id) ;
578
491
StacksHttpRequest :: new_get_nakamoto_block ( peerhost, start_block_id. clone ( ) )
579
492
}
580
- NakamotoTenureDownloadState :: WaitForTenureEndBlock ( _block_id, _deadline) => {
581
- // we're waiting for some other downloader's block-fetch to complete
582
- debug ! (
583
- "Waiting for tenure-end block {} until {:?}" ,
584
- & _block_id, _deadline
585
- ) ;
586
- return Ok ( None ) ;
587
- }
588
493
NakamotoTenureDownloadState :: GetTenureEndBlock ( end_block_id) => {
589
494
debug ! ( "Request tenure-end block {}" , & end_block_id) ;
590
495
StacksHttpRequest :: new_get_nakamoto_block ( peerhost, end_block_id. clone ( ) )
@@ -665,10 +570,6 @@ impl NakamotoTenureDownloader {
665
570
self . try_accept_tenure_start_block ( block) ?;
666
571
Ok ( None )
667
572
}
668
- NakamotoTenureDownloadState :: WaitForTenureEndBlock ( ..) => {
669
- debug ! ( "Invalid state -- Got download response for WaitForTenureBlock" ) ;
670
- Err ( NetError :: InvalidState )
671
- }
672
573
NakamotoTenureDownloadState :: GetTenureEndBlock ( _block_id) => {
673
574
debug ! ( "Got download response to tenure-end block {}" , & _block_id) ;
674
575
let block = response. decode_nakamoto_block ( ) . map_err ( |e| {
0 commit comments