Skip to content

Commit fa6a6b7

Browse files
committed
refactor: add check_nakamoto_no_missing_blocks func
This function can be used to check for missing burn blocks, ignoring a block missing during the transition to epoch 3.0.
1 parent f3f49a4 commit fa6a6b7

File tree

1 file changed

+23
-35
lines changed

1 file changed

+23
-35
lines changed

testnet/stacks-node/src/tests/nakamoto_integrations.rs

Lines changed: 23 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
use std::collections::{BTreeMap, HashMap, HashSet};
17+
use std::ops::RangeBounds;
1718
use std::sync::atomic::{AtomicU64, Ordering};
1819
use std::sync::mpsc::{channel, Receiver, Sender};
1920
use std::sync::{Arc, Mutex};
@@ -1488,6 +1489,26 @@ fn wait_for_first_naka_block_commit(timeout_secs: u64, naka_commits_submitted: &
14881489
}
14891490
}
14901491

1492+
// Check for missing burn blocks in `range`, but allow for a missed block at
1493+
// the epoch 3 transition. Panic if any other blocks are missing.
1494+
fn check_nakamoto_no_missing_blocks(conf: &Config, range: impl RangeBounds<u64>) {
1495+
let epoch_3 = &conf.burnchain.epochs.as_ref().unwrap()[StacksEpochId::Epoch30];
1496+
let missing = test_observer::get_missing_burn_blocks(range).unwrap();
1497+
let missing_is_error: Vec<_> = missing
1498+
.into_iter()
1499+
.filter(|&i| {
1500+
(i != epoch_3.start_height - 1) || {
1501+
warn!("Missing burn block {} at epoch 3 transition", i);
1502+
false
1503+
}
1504+
})
1505+
.collect();
1506+
1507+
if !missing_is_error.is_empty() {
1508+
panic!("Missing the following burn blocks: {missing_is_error:?}");
1509+
}
1510+
}
1511+
14911512
#[test]
14921513
#[ignore]
14931514
/// This test spins up a nakamoto-neon node.
@@ -1689,27 +1710,8 @@ fn simple_neon_integration() {
16891710
assert!(tip.stacks_block_height >= block_height_pre_3_0 + 30);
16901711

16911712
// Check that we aren't missing burn blocks (except during the Nakamoto transition)
1692-
let epoch_3 = &naka_conf.burnchain.epochs.unwrap()[StacksEpochId::Epoch30];
16931713
let bhh = u64::from(tip.burn_header_height);
1694-
let missing = test_observer::get_missing_burn_blocks(220..=bhh).unwrap();
1695-
1696-
// This test was flaky because it was sometimes missing burn block 230, which is right at the Nakamoto transition
1697-
// So it was possible to miss a burn block during the transition
1698-
// But I don't think it matters at this point since the Nakamoto transition has already happened on mainnet
1699-
// So just print a warning instead, don't count it as an error
1700-
let missing_is_error: Vec<_> = missing
1701-
.into_iter()
1702-
.filter(|&i| {
1703-
(i != epoch_3.start_height - 1) || {
1704-
warn!("Missing burn block {} at epoch 3 transition", i);
1705-
false
1706-
}
1707-
})
1708-
.collect();
1709-
1710-
if !missing_is_error.is_empty() {
1711-
panic!("Missing the following burn blocks: {missing_is_error:?}");
1712-
}
1714+
check_nakamoto_no_missing_blocks(&naka_conf, 220..=bhh);
17131715

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

1010810110
// Check that we aren't missing burn blocks (except during the Nakamoto transition)
10109-
let epoch_3 = &naka_conf.burnchain.epochs.unwrap()[StacksEpochId::Epoch30];
1011010111
let bhh = u64::from(tip.burn_header_height);
10111-
let missing = test_observer::get_missing_burn_blocks(220..=bhh).unwrap();
10112-
let missing_is_error: Vec<_> = missing
10113-
.into_iter()
10114-
.filter(|&i| {
10115-
(i != epoch_3.start_height - 1) || {
10116-
warn!("Missing burn block {} at epoch 3 transition", i);
10117-
false
10118-
}
10119-
})
10120-
.collect();
10121-
10122-
if !missing_is_error.is_empty() {
10123-
panic!("Missing the following burn blocks: {missing_is_error:?}");
10124-
}
10112+
check_nakamoto_no_missing_blocks(&naka_conf, 220..=bhh);
1012510113

1012610114
check_nakamoto_empty_block_heuristics();
1012710115

0 commit comments

Comments
 (0)