@@ -2495,33 +2495,40 @@ fn process_next_nakamoto_block_deadlock() {
2495
2495
info ! ( "Creating peer" ) ;
2496
2496
2497
2497
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 ( ) ;
2498
2505
2499
2506
// Lock the sortdb
2500
2507
info ! ( " ------------------------------- TRYING TO LOCK THE SORTDB" ) ;
2501
2508
let mut sortition_db = peer. sortdb ( ) . reopen ( ) . unwrap ( ) ;
2502
2509
let sort_tx = sortition_db. tx_begin ( ) . unwrap ( ) ;
2510
+ info ! ( " ------------------------------- SORTDB LOCKED" ) ;
2503
2511
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
+ } ) ;
2511
2519
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 ) ) ;
2516
2522
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 ( ) ;
2520
2526
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" ) ;
2524
2531
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 ( ) ;
2527
2534
}
0 commit comments