Skip to content

Commit ff9ec9a

Browse files
committed
test: fix two integration tests which rely on block-commits when no tenure change has occurred
1 parent c8a035b commit ff9ec9a

File tree

1 file changed

+26
-31
lines changed
  • testnet/stacks-node/src/tests/signer

1 file changed

+26
-31
lines changed

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

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -966,6 +966,10 @@ fn forked_tenure_testing(
966966
},
967967
|config| {
968968
config.miner.tenure_cost_limit_per_block_percentage = None;
969+
// this test relies on the miner submitting these timed out commits.
970+
// the test still passes without this override, but the default timeout
971+
// makes the test take longer than strictly necessary
972+
config.miner.block_commit_delay = Duration::from_secs(10);
969973
},
970974
None,
971975
None,
@@ -1204,8 +1208,6 @@ fn forked_tenure_testing(
12041208
(None, None)
12051209
} else {
12061210
// Now let's produce a second block for tenure C and ensure it builds off of block C.
1207-
let blocks_before = mined_blocks.load(Ordering::SeqCst);
1208-
let start_time = Instant::now();
12091211
// submit a tx so that the miner will mine an extra block
12101212
let sender_nonce = 0;
12111213
let transfer_tx = make_stacks_transfer(
@@ -1218,16 +1220,10 @@ fn forked_tenure_testing(
12181220
);
12191221
let tx = submit_tx(&http_origin, &transfer_tx);
12201222
info!("Submitted tx {tx} in Tenure C to mine a second block");
1221-
while mined_blocks.load(Ordering::SeqCst) <= blocks_before {
1222-
assert!(
1223-
start_time.elapsed() < Duration::from_secs(30),
1224-
"FAIL: Test timed out while waiting for block production",
1225-
);
1226-
thread::sleep(Duration::from_secs(1));
1227-
}
1228-
1229-
// give C's second block a moment to process
1230-
sleep_ms(1000);
1223+
wait_for(60, || {
1224+
Ok(get_account(&http_origin, &sender_addr).nonce > sender_nonce)
1225+
})
1226+
.unwrap();
12311227

12321228
info!("Tenure C produced a second block!");
12331229

@@ -1240,27 +1236,22 @@ fn forked_tenure_testing(
12401236
(Some(block_2_tenure_c), Some(block_2_c))
12411237
};
12421238

1243-
// allow block C2 to be processed
1244-
sleep_ms(1000);
1239+
// make sure that a block commit has been submitted
1240+
let burn_ht = signer_test.get_peer_info().burn_block_height;
1241+
wait_for(60, || {
1242+
let submitted_ht = signer_test
1243+
.running_nodes
1244+
.counters
1245+
.naka_submitted_commit_last_burn_height
1246+
.load(Ordering::SeqCst);
1247+
Ok(submitted_ht >= burn_ht)
1248+
})
1249+
.unwrap();
12451250

12461251
info!("Starting Tenure D.");
12471252

1248-
// Submit a block commit op for tenure D and mine a stacks block
1249-
let commits_before = commits_submitted.load(Ordering::SeqCst);
1250-
let blocks_before = mined_blocks.load(Ordering::SeqCst);
1251-
next_block_and(
1252-
&mut signer_test.running_nodes.btc_regtest_controller,
1253-
60,
1254-
|| {
1255-
let commits_count = commits_submitted.load(Ordering::SeqCst);
1256-
let blocks_count = mined_blocks.load(Ordering::SeqCst);
1257-
Ok(commits_count > commits_before && blocks_count > blocks_before)
1258-
},
1259-
)
1260-
.unwrap();
1261-
1262-
// allow block D to be processed
1263-
sleep_ms(1000);
1253+
// Mine tenure D
1254+
signer_test.mine_nakamoto_block(Duration::from_secs(60), false);
12641255

12651256
let tip_d = NakamotoChainState::get_canonical_block_header(chainstate.db(), &sortdb)
12661257
.unwrap()
@@ -10211,6 +10202,10 @@ fn no_reorg_due_to_successive_block_validation_ok() {
1021110202
config.node.data_url = format!("http://{localhost}:{node_1_rpc}");
1021210203
config.node.p2p_address = format!("{localhost}:{node_1_p2p}");
1021310204
config.miner.wait_on_interim_blocks = Duration::from_secs(5);
10205+
// Override this option, because this test depends on a block commit being submitted
10206+
// without a tenure change being detected. The default option would work, but it would
10207+
// make the test take unnecessarily long (and could be close to test failing timeouts)
10208+
config.miner.block_commit_delay = Duration::from_secs(5);
1021410209
config.node.pox_sync_sample_secs = 30;
1021510210
config.burnchain.pox_reward_length = Some(max_nakamoto_tenures);
1021610211

@@ -10448,7 +10443,7 @@ fn no_reorg_due_to_successive_block_validation_ok() {
1044810443
let burn_height_before = get_burn_height();
1044910444
next_block_and(
1045010445
&mut signer_test.running_nodes.btc_regtest_controller,
10451-
30,
10446+
60,
1045210447
|| {
1045310448
Ok(get_burn_height() > burn_height_before
1045410449
&& rl2_proposals.load(Ordering::SeqCst) > proposals_before_2

0 commit comments

Comments
 (0)