Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

locally_accepted_blocks_overriden_by_global_rejection fix: Store the rejected block in the database in testing directive case #5390

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 40 additions & 24 deletions stacks-signer/src/v0/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,30 +428,8 @@ impl Signer {
};

#[cfg(any(test, feature = "testing"))]
let block_response = match &*TEST_REJECT_ALL_BLOCK_PROPOSAL.lock().unwrap() {
Some(public_keys) => {
if public_keys.contains(
&stacks_common::types::chainstate::StacksPublicKey::from_private(
&self.private_key,
),
) {
warn!("{self}: Rejecting block proposal automatically due to testing directive";
"block_id" => %block_proposal.block.block_id(),
"height" => block_proposal.block.header.chain_length,
"consensus_hash" => %block_proposal.block.header.consensus_hash
);
Some(BlockResponse::rejected(
block_proposal.block.header.signer_signature_hash(),
RejectCode::TestingDirective,
&self.private_key,
self.mainnet,
))
} else {
None
}
}
None => block_response,
};
let block_response =
self.test_reject_block_proposal(block_proposal, &mut block_info, block_response);

if let Some(block_response) = block_response {
// We know proposal is invalid. Send rejection message, do not do further validation
Expand Down Expand Up @@ -935,6 +913,44 @@ impl Signer {
false
}

#[cfg(any(test, feature = "testing"))]
fn test_reject_block_proposal(
&mut self,
block_proposal: &BlockProposal,
block_info: &mut BlockInfo,
block_response: Option<BlockResponse>,
) -> Option<BlockResponse> {
let Some(public_keys) = &*TEST_REJECT_ALL_BLOCK_PROPOSAL.lock().unwrap() else {
return block_response;
};
if public_keys.contains(
&stacks_common::types::chainstate::StacksPublicKey::from_private(&self.private_key),
) {
warn!("{self}: Rejecting block proposal automatically due to testing directive";
"block_id" => %block_proposal.block.block_id(),
"height" => block_proposal.block.header.chain_length,
"consensus_hash" => %block_proposal.block.header.consensus_hash
);
if let Err(e) = block_info.mark_locally_rejected() {
warn!("{self}: Failed to mark block as locally rejected: {e:?}",);
};
// We must insert the block into the DB to prevent subsequent repeat proposals being accepted (should reject
// as invalid since we rejected in a prior round if this crops up again)
// in case this is the first time we saw this block. Safe to do since this is testing case only.
self.signer_db
.insert_block(block_info)
.unwrap_or_else(|_| panic!("{self}: Failed to insert block in DB"));
Some(BlockResponse::rejected(
block_proposal.block.header.signer_signature_hash(),
RejectCode::TestingDirective,
&self.private_key,
self.mainnet,
))
} else {
None
}
}

/// Send a mock signature to stackerdb to prove we are still alive
fn mock_sign(&mut self, mock_proposal: MockProposal) {
info!("{self}: Mock signing mock proposal: {mock_proposal:?}");
Expand Down
2 changes: 2 additions & 0 deletions testnet/stacks-node/src/tests/signer/v0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4246,6 +4246,8 @@ fn locally_accepted_blocks_overriden_by_global_rejection() {
.unwrap()
.replace(rejecting_signers.clone());
test_observer::clear();
// Make a new stacks transaction to create a different block signature, but make sure to propose it
// AFTER the signers are unfrozen so they don't inadvertently prevent the new block being accepted
let transfer_tx = make_stacks_transfer(
&sender_sk,
sender_nonce,
Expand Down