Skip to content

Commit e37c878

Browse files
committed
Fix test
Signed-off-by: Jacinta Ferrant <[email protected]>
1 parent 1e4a6f3 commit e37c878

File tree

2 files changed

+43
-36
lines changed

2 files changed

+43
-36
lines changed

stackslib/src/net/api/postblock_proposal.rs

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,17 @@ impl NakamotoBlockProposal {
343343
sortdb: &SortitionDB,
344344
chainstate: &mut StacksChainState, // not directly used; used as a handle to open other chainstates
345345
) -> Result<BlockValidateOk, BlockValidateRejectReason> {
346+
#[cfg(any(test, feature = "testing"))]
347+
{
348+
if *TEST_VALIDATE_STALL.lock().unwrap() == Some(true) {
349+
// Do an extra check just so we don't log EVERY time.
350+
warn!("Block validation is stalled due to testing directive.");
351+
while *TEST_VALIDATE_STALL.lock().unwrap() == Some(true) {
352+
std::thread::sleep(std::time::Duration::from_millis(10));
353+
}
354+
info!("Block validation is no longer stalled due to testing directive.");
355+
}
356+
}
346357
let ts_start = get_epoch_time_ms();
347358
// Measure time from start of function
348359
let time_elapsed = || get_epoch_time_ms().saturating_sub(ts_start);
@@ -533,24 +544,6 @@ impl NakamotoBlockProposal {
533544
});
534545
}
535546

536-
#[cfg(any(test, feature = "testing"))]
537-
{
538-
if *TEST_VALIDATE_STALL.lock().unwrap() == Some(true) {
539-
// Do an extra check just so we don't log EVERY time.
540-
warn!("Block validation is stalled due to testing directive.";
541-
"block_id" => %block.block_id(),
542-
"height" => block.header.chain_length,
543-
);
544-
while *TEST_VALIDATE_STALL.lock().unwrap() == Some(true) {
545-
std::thread::sleep(std::time::Duration::from_millis(10));
546-
}
547-
info!("Block validation is no longer stalled due to testing directive.";
548-
"block_id" => %block.block_id(),
549-
"height" => block.header.chain_length,
550-
);
551-
}
552-
}
553-
554547
info!(
555548
"Participant: validated anchored block";
556549
"block_header_hash" => %computed_block_header_hash,

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

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,8 @@ impl SignerTest<SpawnedSigner> {
431431
/// The stacks node is advanced to epoch 3.0 reward set calculation to ensure the signer set is determined.
432432
/// An invalid block proposal is forcibly written to the miner's slot to simulate the miner proposing a block.
433433
/// The signers process the invalid block by first verifying it against the stacks node block proposal endpoint.
434-
/// The signers then broadcast a rejection of the miner's proposed block back to the respective .signers-XXX-YYY contract.
434+
/// The signer that submitted the initial block validation request, should issue a broadcast a rejection of the
435+
/// miner's proposed block back to the respective .signers-XXX-YYY contract.
435436
///
436437
/// Test Assertion:
437438
/// Each signer successfully rejects the invalid block proposal.
@@ -6240,8 +6241,9 @@ fn block_commit_delay() {
62406241
signer_test.shutdown();
62416242
}
62426243

6243-
// Ensures that a signer will issue ConnectivityIssues rejections if a block submission
6244-
// times out. Also ensures that no other proposal gets submitted for validation if we
6244+
// Ensures that a signer that successfully submits a block to the node for validation
6245+
// will issue ConnectivityIssues rejections if a block submission times out.
6246+
// Also ensures that no other proposal gets submitted for validation if we
62456247
// are already waiting for a block submission response.
62466248
#[test]
62476249
#[ignore]
@@ -6344,11 +6346,8 @@ fn block_validation_response_timeout() {
63446346
std::thread::sleep(timeout.saturating_sub(elapsed));
63456347

63466348
info!("------------------------- Wait for Block Rejection Due to Timeout -------------------------");
6347-
// Verify the signers rejected the first block due to timeout
6348-
let mut rejected_signers = vec![];
6349-
let start = Instant::now();
6350-
while rejected_signers.len() < num_signers {
6351-
std::thread::sleep(Duration::from_secs(1));
6349+
// Verify that the signer that submits the block to the node will issue a ConnectivityIssues rejection
6350+
wait_for(30, || {
63526351
let chunks = test_observer::get_stackerdb_chunks();
63536352
for chunk in chunks.into_iter().flat_map(|chunk| chunk.modified_slots) {
63546353
let Ok(message) = SignerMessage::consensus_deserialize(&mut chunk.data.as_slice())
@@ -6359,7 +6358,6 @@ fn block_validation_response_timeout() {
63596358
reason: _reason,
63606359
reason_code,
63616360
signer_signature_hash,
6362-
signature,
63636361
..
63646362
})) = message
63656363
else {
@@ -6372,27 +6370,43 @@ fn block_validation_response_timeout() {
63726370
"Received a rejection for the wrong block"
63736371
);
63746372
if matches!(reason_code, RejectCode::ConnectivityIssues) {
6375-
rejected_signers.push(signature);
6373+
return Ok(true);
63766374
}
63776375
}
6378-
assert!(
6379-
start.elapsed() <= timeout,
6380-
"Timed out after waiting for ConenctivityIssues block rejection"
6381-
);
6382-
}
6376+
Ok(false)
6377+
})
6378+
.expect("Timed out waiting for block proposal rejections");
63836379
// Make sure our chain has still not advanced
63846380
let info_after = get_chain_info(&signer_test.running_nodes.conf);
63856381
assert_eq!(info_before, info_after);
6386-
6382+
let info_before = info_after;
63876383
info!("Unpausing block validation");
6388-
// Disable the stall and wait for the block to be processed
6384+
// Disable the stall and wait for the block to be processed successfully
63896385
TEST_VALIDATE_STALL.lock().unwrap().replace(false);
6386+
wait_for(30, || {
6387+
let info = get_chain_info(&signer_test.running_nodes.conf);
6388+
Ok(info.stacks_tip_height > info_before.stacks_tip_height)
6389+
})
6390+
.expect("Timed out waiting for block to be processed");
63906391

6392+
let info_after = get_chain_info(&signer_test.running_nodes.conf);
6393+
assert_eq!(
6394+
info_after.stacks_tip_height,
6395+
info_before.stacks_tip_height + 1,
6396+
);
63916397
info!("------------------------- Test Mine and Verify Confirmed Nakamoto Block -------------------------");
6398+
let info_before = info_after;
63926399
signer_test.mine_and_verify_confirmed_naka_block(timeout, num_signers);
63936400

6401+
wait_for(30, || {
6402+
let info = get_chain_info(&signer_test.running_nodes.conf);
6403+
Ok(info.stacks_tip_height > info_before.stacks_tip_height)
6404+
})
6405+
.unwrap();
6406+
6407+
let info_after = get_chain_info(&signer_test.running_nodes.conf);
63946408
assert_eq!(
6395-
get_chain_info(&signer_test.running_nodes.conf).stacks_tip_height,
6409+
info_after.stacks_tip_height,
63966410
info_before.stacks_tip_height + 1,
63976411
);
63986412
}

0 commit comments

Comments
 (0)