Skip to content

Commit 6d2347f

Browse files
committed
fix: re-add early exit after checking proposal
In f52dedc I had previously removed this early exit, but now I've realized that this early exit can and should still be there, it just needs a proper check to only exit if the current proposal is for the current sortition which is being marked as invalid.
1 parent f52dedc commit 6d2347f

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

stacks-signer/src/chainstate.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -213,17 +213,19 @@ impl SortitionsView {
213213
.cur_sortition
214214
.is_timed_out(self.config.block_proposal_timeout, signer_db)?
215215
{
216-
// Note that this is only checking the current sortition, and it is
217-
// not necessarily related to the proposal being checked. For this
218-
// reason, we do not return an error here, just set the state and
219-
// log what happened.
220216
info!(
221217
"Current miner timed out, marking as invalid.";
222218
"block_height" => block.header.chain_length,
223219
"block_proposal_timeout" => ?self.config.block_proposal_timeout,
224220
"current_sortition_consensus_hash" => ?self.cur_sortition.consensus_hash,
225221
);
226222
self.cur_sortition.miner_status = SortitionMinerStatus::InvalidatedBeforeFirstBlock;
223+
224+
// If the current proposal is also for this current
225+
// sortition, then we can return early here.
226+
if self.cur_sortition.consensus_hash == block.header.consensus_hash {
227+
return Err(RejectReason::InvalidMiner);
228+
}
227229
} else if let Some(tip) = signer_db
228230
.get_canonical_tip()
229231
.map_err(SignerChainstateError::from)?
@@ -250,17 +252,19 @@ impl SortitionsView {
250252
&self.config.first_proposal_burn_block_timing,
251253
)?;
252254
if !is_valid_parent_tenure {
253-
// Note that this is only checking the current sortition,
254-
// and it is not necessarily related to the proposal being
255-
// checked. For this reason, we do not return an error
256-
// here, just set the state and log what happened.
257255
warn!(
258256
"Current sortition does not build off of canonical tip tenure, marking as invalid";
259257
"current_sortition_parent" => ?self.cur_sortition.parent_tenure_id,
260258
"tip_consensus_hash" => ?tip.block.header.consensus_hash,
261259
);
262260
self.cur_sortition.miner_status =
263261
SortitionMinerStatus::InvalidatedBeforeFirstBlock;
262+
263+
// If the current proposal is also for this current
264+
// sortition, then we can return early here.
265+
if self.cur_sortition.consensus_hash == block.header.consensus_hash {
266+
return Err(RejectReason::ReorgNotAllowed);
267+
}
264268
}
265269
}
266270
}

0 commit comments

Comments
 (0)