@@ -262,31 +262,41 @@ impl SortitionData {
262
262
Ok ( true )
263
263
}
264
264
265
- /// Get the last locally signed block from the given tenure if it has not timed out
265
+ /// Get the last signed block from the given tenure if it has not timed out.
266
+ /// Even globally accepted blocks are allowed to be timed out, as that
267
+ /// triggers the signer to consult the Stacks node for the latest globally
268
+ /// accepted block. This is needed to handle Bitcoin reorgs correctly.
266
269
pub fn get_tenure_last_block_info (
267
270
consensus_hash : & ConsensusHash ,
268
271
signer_db : & SignerDb ,
269
272
tenure_last_block_proposal_timeout : Duration ,
270
273
) -> Result < Option < BlockInfo > , ClientError > {
271
- // Get the last known block in the previous tenure
272
- let last_locally_accepted_block = signer_db
274
+ // Get the last accepted block in the tenure
275
+ let last_accepted_block = signer_db
273
276
. get_last_accepted_block ( consensus_hash)
274
277
. map_err ( |e| ClientError :: InvalidResponse ( e. to_string ( ) ) ) ?;
275
- let Some ( local_info) = last_locally_accepted_block else {
278
+
279
+ let Some ( block_info) = last_accepted_block else {
276
280
return Ok ( None ) ;
277
281
} ;
278
282
279
- let Some ( signed_over_time) = local_info . signed_self else {
283
+ let Some ( signed_over_time) = block_info . signed_self else {
280
284
return Ok ( None ) ;
281
285
} ;
282
286
283
287
if signed_over_time. saturating_add ( tenure_last_block_proposal_timeout. as_secs ( ) )
284
288
> get_epoch_time_secs ( )
285
289
{
286
- // The last locally accepted block is not timed out, return it
287
- Ok ( Some ( local_info ) )
290
+ // The last accepted block is not timed out, return it
291
+ Ok ( Some ( block_info ) )
288
292
} else {
289
- // The last locally accepted block is timed out
293
+ // The last accepted block is timed out
294
+ info ! (
295
+ "Last accepted block has timed out" ;
296
+ "signer_signature_hash" => %block_info. block. header. signer_signature_hash( ) ,
297
+ "signed_over_time" => signed_over_time,
298
+ "state" => %block_info. state,
299
+ ) ;
290
300
Ok ( None )
291
301
}
292
302
}
0 commit comments