@@ -1307,6 +1307,97 @@ fn bitcoind_forking_test() {
13071307 // but we're able to keep on mining
13081308 assert_eq ! ( account. nonce, 3 ) ;
13091309
1310+ // Let's create another fork, deeper
1311+ let burn_header_hash_to_fork = btc_regtest_controller. get_block_hash ( 206 ) ;
1312+ btc_regtest_controller. invalidate_block ( & burn_header_hash_to_fork) ;
1313+ btc_regtest_controller. build_next_block ( 10 ) ;
1314+
1315+ thread:: sleep ( Duration :: from_secs ( 5 ) ) ;
1316+ next_block_and_wait ( & mut btc_regtest_controller, & blocks_processed) ;
1317+
1318+ let account = get_account ( & http_origin, & miner_account) ;
1319+ assert_eq ! ( account. balance, 0 ) ;
1320+ assert_eq ! ( account. nonce, 3 ) ;
1321+
1322+ next_block_and_wait ( & mut btc_regtest_controller, & blocks_processed) ;
1323+
1324+ let account = get_account ( & http_origin, & miner_account) ;
1325+ assert_eq ! ( account. balance, 0 ) ;
1326+ // but we're able to keep on mining
1327+ assert_eq ! ( account. nonce, 3 ) ;
1328+
1329+ channel. stop_chains_coordinator ( ) ;
1330+ }
1331+
1332+ #[ test]
1333+ #[ ignore]
1334+ fn should_fix_2771 ( ) {
1335+ if env:: var ( "BITCOIND_TEST" ) != Ok ( "1" . into ( ) ) {
1336+ return ;
1337+ }
1338+
1339+ let ( conf, miner_account) = neon_integration_test_conf ( ) ;
1340+
1341+ let mut btcd_controller = BitcoinCoreController :: new ( conf. clone ( ) ) ;
1342+ btcd_controller
1343+ . start_bitcoind ( )
1344+ . map_err ( |_e| ( ) )
1345+ . expect ( "Failed starting bitcoind" ) ;
1346+
1347+ let mut btc_regtest_controller = BitcoinRegtestController :: new ( conf. clone ( ) , None ) ;
1348+
1349+ btc_regtest_controller. bootstrap_chain ( 201 ) ;
1350+
1351+ eprintln ! ( "Chain bootstrapped..." ) ;
1352+
1353+ let mut run_loop = neon:: RunLoop :: new ( conf) ;
1354+ let blocks_processed = run_loop. get_blocks_processed_arc ( ) ;
1355+
1356+ let channel = run_loop. get_coordinator_channel ( ) . unwrap ( ) ;
1357+
1358+ thread:: spawn ( move || run_loop. start ( None , 0 ) ) ;
1359+
1360+ // give the run loop some time to start up!
1361+ wait_for_runloop ( & blocks_processed) ;
1362+
1363+ // first block wakes up the run loop
1364+ next_block_and_wait ( & mut btc_regtest_controller, & blocks_processed) ;
1365+
1366+ // first block will hold our VRF registration
1367+ next_block_and_wait ( & mut btc_regtest_controller, & blocks_processed) ;
1368+
1369+ let mut sort_height = channel. get_sortitions_processed ( ) ;
1370+ eprintln ! ( "Sort height: {}" , sort_height) ;
1371+
1372+ while sort_height < 210 {
1373+ next_block_and_wait ( & mut btc_regtest_controller, & blocks_processed) ;
1374+ sort_height = channel. get_sortitions_processed ( ) ;
1375+ eprintln ! ( "Sort height: {}" , sort_height) ;
1376+ }
1377+
1378+ // okay, let's figure out the burn block we want to fork away.
1379+ let reorg_height = 208 ;
1380+ warn ! ( "Will trigger re-org at block {}" , reorg_height) ;
1381+ let burn_header_hash_to_fork = btc_regtest_controller. get_block_hash ( reorg_height) ;
1382+ btc_regtest_controller. invalidate_block ( & burn_header_hash_to_fork) ;
1383+ btc_regtest_controller. build_next_block ( 1 ) ;
1384+ thread:: sleep ( Duration :: from_secs ( 5 ) ) ;
1385+
1386+ // The test here consists in producing a canonical chain with 210 blocks.
1387+ // Once done, we invalidate the block 208, and instead of rebuilding directly
1388+ // a longer fork with N blocks (as done in the bitcoind_forking_test)
1389+ // we slowly add some more blocks.
1390+ // Without the patch, this behavior ends up crashing the node with errors like:
1391+ // WARN [1626791307.078061] [src/chainstate/coordinator/mod.rs:535] [chains-coordinator] ChainsCoordinator: could not retrieve block burnhash=40bdbf0dda349642bdf4dd30dd31af4f0c9979ce12a7c17485245d0a6ddd970b
1392+ // WARN [1626791307.078098] [src/chainstate/coordinator/mod.rs:308] [chains-coordinator] Error processing new burn block: NonContiguousBurnchainBlock(UnknownBlock(40bdbf0dda349642bdf4dd30dd31af4f0c9979ce12a7c17485245d0a6ddd970b))
1393+ // And the burnchain db ends up in the same state we ended up while investigating 2771.
1394+ // With this patch, the node is able to entirely register this new canonical fork, and then able to make progress and finish successfully.
1395+ while sort_height < 213 {
1396+ next_block_and_wait ( & mut btc_regtest_controller, & blocks_processed) ;
1397+ sort_height = channel. get_sortitions_processed ( ) ;
1398+ eprintln ! ( "Sort height: {}" , sort_height) ;
1399+ }
1400+
13101401 channel. stop_chains_coordinator ( ) ;
13111402}
13121403
0 commit comments