Skip to content

Commit fd2deae

Browse files
authored
Merge pull request #6282 from jferrant/bug/fix-handle-block-validate-ok
Properly handle block rejection case in handle_block_validate_ok
2 parents 670d185 + 77375f6 commit fd2deae

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

stacks-node/src/tests/signer/v0.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12066,6 +12066,28 @@ fn no_reorg_due_to_successive_block_validation_ok() {
1206612066
TEST_STALL_BLOCK_VALIDATION_SUBMISSION.set(false);
1206712067

1206812068
info!("------------------------- Confirm N+1' is Rejected ------------------------");
12069+
// Confirm that every single signer has rejected the block and recorded its own rejection signature in its own DB
12070+
wait_for(30, || {
12071+
Ok(miners.signer_test.signer_configs.iter().all(|config| {
12072+
let conn = Connection::open(config.db_path.clone()).unwrap();
12073+
let mut stmt = conn
12074+
.prepare(
12075+
"SELECT 1 FROM block_rejection_signer_addrs
12076+
WHERE signer_signature_hash = ?1 AND signer_addr = ?2
12077+
LIMIT 1",
12078+
)
12079+
.unwrap();
12080+
12081+
let mut rows = stmt
12082+
.query(rusqlite::params![
12083+
block_n_1_prime_signature_hash,
12084+
config.stacks_address
12085+
])
12086+
.unwrap();
12087+
rows.next().unwrap().is_some()
12088+
}))
12089+
})
12090+
.expect("Failed to verify all signers recorded a signature rejection");
1206912091
wait_for_block_global_rejection(30, block_n_1_prime_signature_hash, num_signers)
1207012092
.expect("Failed to find block N+1'");
1207112093

stacks-signer/src/chainstate/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ impl SortitionData {
327327

328328
if let Some(info) = last_block_info {
329329
// N.B. this block might not be the last globally accepted block across the network;
330-
// it's just the highest one in this tenure that we knnge: &TenureChangePow about. If this given block is
330+
// it's just the highest one in this tenure that we know about. If this given block is
331331
// no higher than it, then it's definitely no higher than the last globally accepted
332332
// block across the network, so we can do an early rejection here.
333333
if block.header.chain_length <= info.block.header.chain_length {

stacks-signer/src/v0/signer.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,6 +1162,7 @@ impl Signer {
11621162
&mut self,
11631163
stacks_client: &StacksClient,
11641164
block_validate_ok: &BlockValidateOk,
1165+
sortition_state: &mut Option<SortitionsView>,
11651166
) -> Option<BlockResponse> {
11661167
crate::monitoring::actions::increment_block_validation_responses(true);
11671168
let signer_signature_hash = block_validate_ok.signer_signature_hash;
@@ -1201,17 +1202,18 @@ impl Signer {
12011202
if let Some(block_response) =
12021203
self.check_block_against_signer_db_state(stacks_client, &block_info.block)
12031204
{
1205+
let block_rejection = block_response.as_block_rejection()?;
12041206
// The signer db state has changed. We no longer view this block as valid. Override the validation response.
12051207
if let Err(e) = block_info.mark_locally_rejected() {
12061208
if !block_info.has_reached_consensus() {
12071209
warn!("{self}: Failed to mark block as locally rejected: {e:?}");
12081210
}
12091211
};
1210-
self.impl_send_block_response(Some(&block_info.block), block_response);
12111212
self.signer_db
12121213
.insert_block(&block_info)
12131214
.unwrap_or_else(|e| self.handle_insert_block_error(e));
1214-
None
1215+
self.handle_block_rejection(block_rejection, sortition_state);
1216+
Some(block_response)
12151217
} else {
12161218
if let Err(e) = block_info.mark_locally_accepted(false) {
12171219
if !block_info.has_reached_consensus() {
@@ -1301,7 +1303,7 @@ impl Signer {
13011303
crate::monitoring::actions::record_block_validation_latency(
13021304
block_validate_ok.validation_time_ms,
13031305
);
1304-
self.handle_block_validate_ok(stacks_client, block_validate_ok)
1306+
self.handle_block_validate_ok(stacks_client, block_validate_ok, sortition_state)
13051307
}
13061308
BlockValidateResponse::Reject(block_validate_reject) => {
13071309
self.handle_block_validate_reject(block_validate_reject, sortition_state)

0 commit comments

Comments
 (0)