Skip to content

Commit

Permalink
refactor: add check_nakamoto_no_missing_blocks func
Browse files Browse the repository at this point in the history
This function can be used to check for missing burn blocks, ignoring a
block missing during the transition to epoch 3.0.
  • Loading branch information
obycode committed Jan 31, 2025
1 parent f3f49a4 commit fa6a6b7
Showing 1 changed file with 23 additions and 35 deletions.
58 changes: 23 additions & 35 deletions testnet/stacks-node/src/tests/nakamoto_integrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
use std::collections::{BTreeMap, HashMap, HashSet};
use std::ops::RangeBounds;
use std::sync::atomic::{AtomicU64, Ordering};
use std::sync::mpsc::{channel, Receiver, Sender};
use std::sync::{Arc, Mutex};
Expand Down Expand Up @@ -1488,6 +1489,26 @@ fn wait_for_first_naka_block_commit(timeout_secs: u64, naka_commits_submitted: &
}
}

// Check for missing burn blocks in `range`, but allow for a missed block at
// the epoch 3 transition. Panic if any other blocks are missing.
fn check_nakamoto_no_missing_blocks(conf: &Config, range: impl RangeBounds<u64>) {
let epoch_3 = &conf.burnchain.epochs.as_ref().unwrap()[StacksEpochId::Epoch30];
let missing = test_observer::get_missing_burn_blocks(range).unwrap();
let missing_is_error: Vec<_> = missing
.into_iter()
.filter(|&i| {
(i != epoch_3.start_height - 1) || {
warn!("Missing burn block {} at epoch 3 transition", i);
false
}
})
.collect();

if !missing_is_error.is_empty() {
panic!("Missing the following burn blocks: {missing_is_error:?}");
}
}

#[test]
#[ignore]
/// This test spins up a nakamoto-neon node.
Expand Down Expand Up @@ -1689,27 +1710,8 @@ fn simple_neon_integration() {
assert!(tip.stacks_block_height >= block_height_pre_3_0 + 30);

// Check that we aren't missing burn blocks (except during the Nakamoto transition)
let epoch_3 = &naka_conf.burnchain.epochs.unwrap()[StacksEpochId::Epoch30];
let bhh = u64::from(tip.burn_header_height);
let missing = test_observer::get_missing_burn_blocks(220..=bhh).unwrap();

// This test was flaky because it was sometimes missing burn block 230, which is right at the Nakamoto transition
// So it was possible to miss a burn block during the transition
// But I don't think it matters at this point since the Nakamoto transition has already happened on mainnet
// So just print a warning instead, don't count it as an error
let missing_is_error: Vec<_> = missing
.into_iter()
.filter(|&i| {
(i != epoch_3.start_height - 1) || {
warn!("Missing burn block {} at epoch 3 transition", i);
false
}
})
.collect();

if !missing_is_error.is_empty() {
panic!("Missing the following burn blocks: {missing_is_error:?}");
}
check_nakamoto_no_missing_blocks(&naka_conf, 220..=bhh);

// make sure prometheus returns an updated number of processed blocks
#[cfg(feature = "monitoring_prom")]
Expand Down Expand Up @@ -10106,22 +10108,8 @@ fn skip_mining_long_tx() {
assert_eq!(sender_1_nonce, 4);

// Check that we aren't missing burn blocks (except during the Nakamoto transition)
let epoch_3 = &naka_conf.burnchain.epochs.unwrap()[StacksEpochId::Epoch30];
let bhh = u64::from(tip.burn_header_height);
let missing = test_observer::get_missing_burn_blocks(220..=bhh).unwrap();
let missing_is_error: Vec<_> = missing
.into_iter()
.filter(|&i| {
(i != epoch_3.start_height - 1) || {
warn!("Missing burn block {} at epoch 3 transition", i);
false
}
})
.collect();

if !missing_is_error.is_empty() {
panic!("Missing the following burn blocks: {missing_is_error:?}");
}
check_nakamoto_no_missing_blocks(&naka_conf, 220..=bhh);

check_nakamoto_empty_block_heuristics();

Expand Down

0 comments on commit fa6a6b7

Please sign in to comment.