Skip to content

Commit

Permalink
chore: add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
lgalabru committed Jul 20, 2021
1 parent 5343c9c commit 17456cf
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
1 change: 1 addition & 0 deletions .github/actions/bitcoin-int-tests/Dockerfile.bitcoin-tests
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ RUN cargo test -- --test-threads 1 --ignored tests::neon_integrations::bitcoind_
RUN cargo test -- --test-threads 1 --ignored tests::neon_integrations::liquid_ustx_integration
RUN cargo test -- --test-threads 1 --ignored tests::neon_integrations::stx_transfer_btc_integration_test
RUN cargo test -- --test-threads 1 --ignored tests::neon_integrations::bitcoind_forking_test
RUN cargo test -- --test-threads 1 --ignored tests::neon_integrations::should_fix_2771
RUN cargo test -- --test-threads 1 --ignored tests::neon_integrations::pox_integration_test
RUN cargo test -- --test-threads 1 --ignored tests::bitcoin_regtest::bitcoind_integration_test
RUN cargo test -- --test-threads 1 --ignored tests::should_succeed_handling_malformed_and_valid_txs
Expand Down
4 changes: 2 additions & 2 deletions src/burnchains/burnchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,7 @@ impl Burnchain {
}

/// Determine if there has been a chain reorg, given our current canonical burnchain tip.
/// Return the new chain tip
/// Return the new chain tip and a boolen signaling the presence of a reorg
fn sync_reorg<I: BurnchainIndexer>(indexer: &mut I) -> Result<(u64, bool), burnchain_error> {
let headers_path = indexer.get_headers_path();

Expand Down Expand Up @@ -1196,7 +1196,7 @@ impl Burnchain {
}
}
let end_height = target_block_height_opt.unwrap_or(0).max(db_height);
info!("Burnchain reorg happened at height {} invalidating chain tip {} but only {} headers presents on canonical chain. Retry in 1s", sync_height, db_height, end_block);
info!("Burnchain reorg happened at height {} invalidating chain tip {} but only {} headers presents on canonical chain. Retry in 2s", sync_height, db_height, end_block);
thread::sleep(Duration::from_millis(2000));
end_block = indexer.sync_headers(sync_height, Some(end_height))?;
}
Expand Down
38 changes: 31 additions & 7 deletions testnet/stacks-node/src/tests/neon_integrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1307,6 +1307,25 @@ fn bitcoind_forking_test() {
// but we're able to keep on mining
assert_eq!(account.nonce, 3);

// Let's create another fork, deeper
let burn_header_hash_to_fork = btc_regtest_controller.get_block_hash(206);
btc_regtest_controller.invalidate_block(&burn_header_hash_to_fork);
btc_regtest_controller.build_next_block(10);

thread::sleep(Duration::from_secs(5));
next_block_and_wait(&mut btc_regtest_controller, &blocks_processed);

let account = get_account(&http_origin, &miner_account);
assert_eq!(account.balance, 0);
assert_eq!(account.nonce, 2);

next_block_and_wait(&mut btc_regtest_controller, &blocks_processed);

let account = get_account(&http_origin, &miner_account);
assert_eq!(account.balance, 0);
// but we're able to keep on mining
assert_eq!(account.nonce, 3);

channel.stop_chains_coordinator();
}

Expand Down Expand Up @@ -1355,19 +1374,24 @@ fn should_fix_2771() {
sort_height = channel.get_sortitions_processed();
eprintln!("Sort height: {}", sort_height);
}
// let's query the miner's account nonce:

eprintln!("Miner account: {}", miner_account);

// okay, let's figure out the burn block we want to fork away.
warn!("Will trigger re-org at block {}", 208);
let burn_header_hash_to_fork = btc_regtest_controller.get_block_hash(208);
let reorg_height = 208;
warn!("Will trigger re-org at block {}", reorg_height);
let burn_header_hash_to_fork = btc_regtest_controller.get_block_hash(reorg_height);
btc_regtest_controller.invalidate_block(&burn_header_hash_to_fork);
btc_regtest_controller.build_next_block(1);
thread::sleep(Duration::from_secs(5));

// We invalidated a fork 210 long, and the new one is 207 blocks long.
// Let's dispatch the blocks one by one, instead of mining 210-207 blocks
// The test here consists in producing a canonical chain with 210 blocks.
// Once done, we invalidate the block 208, and instead of rebuilding directly
// a longer fork with N blocks (at done in the bitcoind_forking_test)
// we slowly add some more blocks.
// Without the patch, this behavior ends up crashing the node with errors like:
// WARN [1626791307.078061] [src/chainstate/coordinator/mod.rs:535] [chains-coordinator] ChainsCoordinator: could not retrieve block burnhash=40bdbf0dda349642bdf4dd30dd31af4f0c9979ce12a7c17485245d0a6ddd970b
// WARN [1626791307.078098] [src/chainstate/coordinator/mod.rs:308] [chains-coordinator] Error processing new burn block: NonContiguousBurnchainBlock(UnknownBlock(40bdbf0dda349642bdf4dd30dd31af4f0c9979ce12a7c17485245d0a6ddd970b))
// And the burnchain db end up in the same state we ended up while investing 2771.
// With this patch, the node is able to entirely register this new canonical fork, and then able to make some progress.
while sort_height < 213 {
next_block_and_wait(&mut btc_regtest_controller, &blocks_processed);
sort_height = channel.get_sortitions_processed();
Expand Down

0 comments on commit 17456cf

Please sign in to comment.