Skip to content

Commit fbe745d

Browse files
authored
Merge pull request #6286 from obycode/fix/tenure-last-block
fix: last locally or globally accepted block in tenure
2 parents 32461ef + 7f7d360 commit fbe745d

File tree

1 file changed

+18
-8
lines changed
  • stacks-signer/src/chainstate

1 file changed

+18
-8
lines changed

stacks-signer/src/chainstate/mod.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -262,31 +262,41 @@ impl SortitionData {
262262
Ok(true)
263263
}
264264

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.
266269
pub fn get_tenure_last_block_info(
267270
consensus_hash: &ConsensusHash,
268271
signer_db: &SignerDb,
269272
tenure_last_block_proposal_timeout: Duration,
270273
) -> 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
273276
.get_last_accepted_block(consensus_hash)
274277
.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 {
276280
return Ok(None);
277281
};
278282

279-
let Some(signed_over_time) = local_info.signed_self else {
283+
let Some(signed_over_time) = block_info.signed_self else {
280284
return Ok(None);
281285
};
282286

283287
if signed_over_time.saturating_add(tenure_last_block_proposal_timeout.as_secs())
284288
> get_epoch_time_secs()
285289
{
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))
288292
} 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+
);
290300
Ok(None)
291301
}
292302
}

0 commit comments

Comments
 (0)