Skip to content

Commit ae946dd

Browse files
committed
test: finish deadlock test
1 parent c973bea commit ae946dd

File tree

1 file changed

+26
-19
lines changed
  • stackslib/src/chainstate/nakamoto/coordinator

1 file changed

+26
-19
lines changed

stackslib/src/chainstate/nakamoto/coordinator/tests.rs

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2495,33 +2495,40 @@ fn process_next_nakamoto_block_deadlock() {
24952495
info!("Creating peer");
24962496

24972497
let mut peer = boot_plan.boot_into_nakamoto_peer(vec![], None);
2498+
let (chainstate, _) = &mut peer
2499+
.stacks_node
2500+
.as_mut()
2501+
.unwrap()
2502+
.chainstate
2503+
.reopen()
2504+
.unwrap();
24982505

24992506
// Lock the sortdb
25002507
info!(" ------------------------------- TRYING TO LOCK THE SORTDB");
25012508
let mut sortition_db = peer.sortdb().reopen().unwrap();
25022509
let sort_tx = sortition_db.tx_begin().unwrap();
2510+
info!(" ------------------------------- SORTDB LOCKED");
25032511

2504-
// Start another thread that opens the sortdb, waits 10s, then tries to
2505-
// lock the chainstate db. This should cause a deadlock if the block
2506-
// processing is not acquiring the locks in the correct order.
2507-
info!(" ------------------------------- SPAWNING BLOCKER THREAD");
2508-
let blocker_thread = std::thread::spawn(move || {
2509-
// Wait a bit, to ensure the tenure will have grabbed any locks it needs
2510-
std::thread::sleep(std::time::Duration::from_secs(10));
2512+
let miner_thread = std::thread::spawn(move || {
2513+
info!(" ------------------------------- MINING TENURE");
2514+
let (block, burn_height, ..) =
2515+
peer.single_block_tenure(&private_key, |_| {}, |_| {}, |_| true);
2516+
peer.try_process_block(&block).unwrap();
2517+
info!(" ------------------------------- TENURE MINED");
2518+
});
25112519

2512-
// Lock the chainstate db
2513-
info!(" ------------------------------- TRYING TO LOCK THE CHAINSTATE");
2514-
let chainstate = &mut peer.stacks_node.as_mut().unwrap().chainstate;
2515-
let (chainstate_tx, _) = chainstate.chainstate_tx_begin().unwrap();
2520+
// Wait a bit, to ensure the tenure will have grabbed any locks it needs
2521+
std::thread::sleep(std::time::Duration::from_secs(10));
25162522

2517-
info!(" ------------------------------- SORTDB AND CHAINSTATE LOCKED");
2518-
info!(" ------------------------------- BLOCKER THREAD FINISHED");
2519-
});
2523+
// Lock the chainstate db
2524+
info!(" ------------------------------- TRYING TO LOCK THE CHAINSTATE");
2525+
let chainstate_tx = chainstate.chainstate_tx_begin().unwrap();
25202526

2521-
info!(" ------------------------------- MINING TENURE");
2522-
let (block, burn_height, ..) = peer.single_block_tenure(&private_key, |_| {}, |_| {}, |_| true);
2523-
info!(" ------------------------------- TENURE MINED");
2527+
info!(" ------------------------------- SORTDB AND CHAINSTATE LOCKED");
2528+
drop(chainstate_tx);
2529+
drop(sort_tx);
2530+
info!(" ------------------------------- MAIN THREAD FINISHED");
25242531

2525-
// Wait for the blocker thread to finish
2526-
blocker_thread.join().unwrap();
2532+
// Wait for the blocker and miner threads to finish
2533+
miner_thread.join().unwrap();
25272534
}

0 commit comments

Comments
 (0)