Skip to content

Commit 3927998

Browse files
committed
Fix block validation test and cleanup comment
Signed-off-by: Jacinta Ferrant <[email protected]>
1 parent 44197c8 commit 3927998

File tree

3 files changed

+27
-26
lines changed

3 files changed

+27
-26
lines changed

stacks-signer/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ pub struct SignerConfig {
129129
pub first_proposal_burn_block_timing: Duration,
130130
/// How much time to wait for a miner to propose a block following a sortition
131131
pub block_proposal_timeout: Duration,
132-
/// How much time ot wait for a block proposal validation response before marking the block invalid
132+
/// How much time to wait for a block proposal validation response before marking the block invalid
133133
pub block_proposal_validation_timeout: Duration,
134134
}
135135

stacks-signer/src/v0/signer.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -691,8 +691,7 @@ impl Signer {
691691
if block_info.state == BlockState::GloballyRejected
692692
|| block_info.state == BlockState::GloballyAccepted
693693
{
694-
// The block has already reached consensus. This should never really hit, but check just to be safe.
695-
self.submitted_block_proposal = None;
694+
// The block has already reached consensus.
696695
return;
697696
}
698697
block_info
@@ -704,12 +703,10 @@ impl Signer {
704703
"signer_sighash" => %signature_sighash,
705704
"block_id" => %block_proposal.block.block_id(),
706705
);
707-
self.submitted_block_proposal = None;
708706
return;
709707
}
710708
Err(e) => {
711709
error!("{self}: Failed to lookup block in signer db: {e:?}",);
712-
self.submitted_block_proposal = None;
713710
return;
714711
}
715712
};

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

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5623,7 +5623,7 @@ fn block_validation_response_timeout() {
56235623

56245624
info!("------------------------- Test Setup -------------------------");
56255625
let num_signers = 5;
5626-
let timeout = Duration::from_secs(60);
5626+
let timeout = Duration::from_secs(30);
56275627
let sender_sk = Secp256k1PrivateKey::new();
56285628
let sender_addr = tests::to_addr(&sender_sk);
56295629
let send_amt = 100;
@@ -5676,7 +5676,12 @@ fn block_validation_response_timeout() {
56765676
})
56775677
.expect("Timed out waiting for block proposal");
56785678

5679-
info!("------------------------- Propose Another Block -------------------------");
5679+
assert!(
5680+
validation_stall_start.elapsed() < timeout,
5681+
"Test was too slow to propose another block before the timeout"
5682+
);
5683+
5684+
info!("------------------------- Propose Another Block Before Hitting the Timeout -------------------------");
56805685
let proposal_conf = ProposalEvalConfig {
56815686
first_proposal_burn_block_timing: Duration::from_secs(0),
56825687
block_proposal_timeout: Duration::from_secs(100),
@@ -5686,26 +5691,27 @@ fn block_validation_response_timeout() {
56865691
txs: vec![],
56875692
};
56885693

5694+
let info_before = get_chain_info(&signer_test.running_nodes.conf);
56895695
// Propose a block to the signers that passes initial checks but will not be submitted to the stacks node due to the submission stall
56905696
let view = SortitionsView::fetch_view(proposal_conf, &signer_test.stacks_client).unwrap();
56915697
block.header.pox_treatment = BitVec::ones(1).unwrap();
56925698
block.header.consensus_hash = view.cur_sortition.consensus_hash;
5693-
block.header.chain_length = 1; // We have mined 1 block so far
5699+
block.header.chain_length = info_before.stacks_tip_height + 1;
56945700

56955701
let block_signer_signature_hash_1 = block.header.signer_signature_hash();
5696-
let info_before = get_chain_info(&signer_test.running_nodes.conf);
5697-
signer_test.propose_block(block, Duration::from_secs(30));
5702+
signer_test.propose_block(block, timeout);
56985703

56995704
info!("------------------------- Waiting for Timeout -------------------------");
57005705
// Sleep the necessary timeout to make sure the validation times out.
57015706
let elapsed = validation_stall_start.elapsed();
5707+
let wait = timeout.saturating_sub(elapsed);
5708+
info!("Sleeping for {} ms", wait.as_millis());
57025709
std::thread::sleep(timeout.saturating_sub(elapsed));
57035710

57045711
info!("------------------------- Wait for Block Rejection Due to Timeout -------------------------");
57055712
// Verify the signers rejected the first block due to timeout
5706-
let start = Instant::now();
57075713
let mut rejected_signers = vec![];
5708-
let mut saw_connectivity_complaint = false;
5714+
let start = Instant::now();
57095715
while rejected_signers.len() < num_signers {
57105716
std::thread::sleep(Duration::from_secs(1));
57115717
let chunks = test_observer::get_stackerdb_chunks();
@@ -5714,32 +5720,30 @@ fn block_validation_response_timeout() {
57145720
else {
57155721
continue;
57165722
};
5717-
if let SignerMessage::BlockResponse(BlockResponse::Rejected(BlockRejection {
5723+
let SignerMessage::BlockResponse(BlockResponse::Rejected(BlockRejection {
57185724
reason: _reason,
57195725
reason_code,
57205726
signer_signature_hash,
57215727
signature,
57225728
..
57235729
})) = message
5724-
{
5725-
if signer_signature_hash == block_signer_signature_hash_1 {
5726-
rejected_signers.push(signature);
5727-
if matches!(reason_code, RejectCode::ConnectivityIssues) {
5728-
saw_connectivity_complaint = true;
5729-
}
5730+
else {
5731+
continue;
5732+
};
5733+
// We are waiting for the original block proposal which will have a diff signature to our
5734+
// second proposed block.
5735+
if signer_signature_hash != block_signer_signature_hash_1 {
5736+
rejected_signers.push(signature);
5737+
if matches!(reason_code, RejectCode::ConnectivityIssues) {
5738+
break;
57305739
}
57315740
}
57325741
}
57335742
assert!(
5734-
start.elapsed() <= Duration::from_secs(10),
5735-
"Timed out after waiting for response from signer"
5743+
start.elapsed() <= timeout,
5744+
"Timed out after waiting for ConenctivityIssues block rejection"
57365745
);
57375746
}
5738-
5739-
assert!(
5740-
saw_connectivity_complaint,
5741-
"We did not see the expected connectity rejection reason"
5742-
);
57435747
// Make sure our chain has still not advanced
57445748
let info_after = get_chain_info(&signer_test.running_nodes.conf);
57455749
assert_eq!(info_before, info_after);

0 commit comments

Comments
 (0)