Skip to content

Commit 331dc94

Browse files
committed
feat: wait to build block if min gap won't be met
* ci: disable unneeded microblocks tests * test: remove blanket 2 sec wait for nakamoto btc blocks
1 parent 2c6aad8 commit 331dc94

File tree

3 files changed

+49
-27
lines changed

3 files changed

+49
-27
lines changed

.github/workflows/bitcoin-tests.yml

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ jobs:
3232
- tests::bitcoin_regtest::bitcoind_integration_test
3333
- tests::integrations::integration_test_get_info
3434
- tests::neon_integrations::antientropy_integration_test
35-
- tests::neon_integrations::bad_microblock_pubkey
3635
- tests::neon_integrations::bitcoind_forking_test
3736
- tests::neon_integrations::bitcoind_integration_test
3837
- tests::neon_integrations::block_large_tx_integration_test
@@ -43,21 +42,26 @@ jobs:
4342
- tests::neon_integrations::fuzzed_median_fee_rate_estimation_test_window10
4443
- tests::neon_integrations::fuzzed_median_fee_rate_estimation_test_window5
4544
- tests::neon_integrations::liquid_ustx_integration
46-
- tests::neon_integrations::microblock_fork_poison_integration_test
47-
- tests::neon_integrations::microblock_integration_test
45+
# Microblock tests that are no longer needed on every CI run
46+
# (microblocks are unsupported starting in Epoch 2.5)
47+
# - tests::neon_integrations::bad_microblock_pubkey
48+
# - tests::neon_integrations::microblock_fork_poison_integration_test
49+
# - tests::neon_integrations::microblock_integration_test
50+
# - tests::neon_integrations::microblock_limit_hit_integration_test
51+
# - tests::neon_integrations::test_problematic_microblocks_are_not_mined
52+
# - tests::neon_integrations::test_problematic_microblocks_are_not_relayed_or_stored
53+
# - tests::neon_integrations::size_overflow_unconfirmed_invalid_stream_microblocks_integration_test
54+
# - tests::neon_integrations::size_overflow_unconfirmed_microblocks_integration_test
55+
# - tests::neon_integrations::size_overflow_unconfirmed_stream_microblocks_integration_test
56+
# - tests::neon_integrations::runtime_overflow_unconfirmed_microblocks_integration_test
4857
# Disable this flaky test. Microblocks are no longer supported anyways.
4958
# - tests::neon_integrations::microblock_large_tx_integration_test_FLAKY
50-
- tests::neon_integrations::microblock_limit_hit_integration_test
5159
- tests::neon_integrations::miner_submit_twice
5260
- tests::neon_integrations::mining_events_integration_test
5361
- tests::neon_integrations::pox_integration_test
5462
- tests::neon_integrations::push_boot_receipts
55-
- tests::neon_integrations::runtime_overflow_unconfirmed_microblocks_integration_test
5663
- tests::neon_integrations::should_fix_2771
5764
- tests::neon_integrations::size_check_integration_test
58-
- tests::neon_integrations::size_overflow_unconfirmed_invalid_stream_microblocks_integration_test
59-
- tests::neon_integrations::size_overflow_unconfirmed_microblocks_integration_test
60-
- tests::neon_integrations::size_overflow_unconfirmed_stream_microblocks_integration_test
6165
- tests::neon_integrations::stx_delegate_btc_integration_test
6266
- tests::neon_integrations::stx_transfer_btc_integration_test
6367
- tests::neon_integrations::stack_stx_burn_op_test
@@ -66,8 +70,6 @@ jobs:
6670
- tests::neon_integrations::test_flash_block_skip_tenure
6771
- tests::neon_integrations::test_problematic_blocks_are_not_mined
6872
- tests::neon_integrations::test_problematic_blocks_are_not_relayed_or_stored
69-
- tests::neon_integrations::test_problematic_microblocks_are_not_mined
70-
- tests::neon_integrations::test_problematic_microblocks_are_not_relayed_or_stored
7173
- tests::neon_integrations::test_problematic_txs_are_not_stored
7274
- tests::neon_integrations::use_latest_tip_integration_test
7375
- tests::neon_integrations::confirm_unparsed_ongoing_ops
@@ -90,6 +92,7 @@ jobs:
9092
- tests::nakamoto_integrations::follower_bootup
9193
- tests::nakamoto_integrations::forked_tenure_is_ignored
9294
- tests::nakamoto_integrations::nakamoto_attempt_time
95+
- tests::nakamoto_integrations::skip_mining_long_tx
9396
- tests::signer::v0::block_proposal_rejection
9497
- tests::signer::v0::miner_gather_signatures
9598
- tests::signer::v0::end_of_tenure

testnet/stacks-node/src/nakamoto_node/miner.rs

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ use stacks::chainstate::stacks::{
4040
use stacks::net::p2p::NetworkHandle;
4141
use stacks::net::stackerdb::StackerDBs;
4242
use stacks::net::{NakamotoBlocksData, StacksMessageType};
43+
use stacks::util::get_epoch_time_secs;
4344
use stacks::util::secp256k1::MessageSignature;
4445
use stacks_common::types::chainstate::{StacksAddress, StacksBlockId};
4546
use stacks_common::types::{PrivateKey, StacksEpochId};
@@ -949,6 +950,29 @@ impl BlockMinerThread {
949950
Some(vrf_proof)
950951
}
951952

953+
fn validate_timestamp_info(
954+
&self,
955+
current_timestamp_secs: u64,
956+
stacks_parent_header: &StacksHeaderInfo,
957+
) -> bool {
958+
let parent_timestamp = match stacks_parent_header.anchored_header.as_stacks_nakamoto() {
959+
Some(naka_header) => naka_header.timestamp,
960+
None => stacks_parent_header.burn_header_timestamp,
961+
};
962+
let time_since_parent_ms = current_timestamp_secs.saturating_sub(parent_timestamp) * 1000;
963+
if time_since_parent_ms < self.config.miner.min_time_between_blocks_ms {
964+
debug!("Parent block mined {time_since_parent_ms} ms ago. Required minimum gap between blocks is {} ms", self.config.miner.min_time_between_blocks_ms;
965+
"current_timestamp" => current_timestamp_secs,
966+
"parent_block_id" => %stacks_parent_header.index_block_hash(),
967+
"parent_block_height" => stacks_parent_header.stacks_block_height,
968+
"parent_block_timestamp" => stacks_parent_header.burn_header_timestamp,
969+
);
970+
false
971+
} else {
972+
true
973+
}
974+
}
975+
952976
/// Check that the provided block is not mined too quickly after the parent block.
953977
/// This is to ensure that the signers do not reject the block due to the block being mined within the same second as the parent block.
954978
fn validate_timestamp(&self, x: &NakamotoBlock) -> Result<bool, NakamotoNodeError> {
@@ -970,22 +994,7 @@ impl BlockMinerThread {
970994
);
971995
NakamotoNodeError::ParentNotFound
972996
})?;
973-
let current_timestamp = x.header.timestamp;
974-
let parent_timestamp = match stacks_parent_header.anchored_header.as_stacks_nakamoto() {
975-
Some(naka_header) => naka_header.timestamp,
976-
None => stacks_parent_header.burn_header_timestamp,
977-
};
978-
let time_since_parent_ms = current_timestamp.saturating_sub(parent_timestamp) * 1000;
979-
if time_since_parent_ms < self.config.miner.min_time_between_blocks_ms {
980-
debug!("Parent block mined {time_since_parent_ms} ms ago. Required minimum gap between blocks is {} ms", self.config.miner.min_time_between_blocks_ms;
981-
"current_timestamp" => current_timestamp,
982-
"parent_block_id" => %stacks_parent_header.index_block_hash(),
983-
"parent_block_height" => stacks_parent_header.stacks_block_height,
984-
"parent_block_timestamp" => stacks_parent_header.burn_header_timestamp,
985-
);
986-
return Ok(false);
987-
}
988-
Ok(true)
997+
Ok(self.validate_timestamp_info(x.header.timestamp, &stacks_parent_header))
989998
}
990999

9911000
// TODO: add tests from mutation testing results #4869
@@ -1042,6 +1051,17 @@ impl BlockMinerThread {
10421051

10431052
let signer_bitvec_len = reward_set.rewarded_addresses.len().try_into().ok();
10441053

1054+
if !self.validate_timestamp_info(
1055+
get_epoch_time_secs(),
1056+
&parent_block_info.stacks_parent_header,
1057+
) {
1058+
// treat a too-soon-to-mine block as an interrupt: this will let the caller sleep and then re-evaluate
1059+
// all the pre-mining checks (burnchain tip changes, signal interrupts, etc.)
1060+
return Err(NakamotoNodeError::MiningFailure(
1061+
ChainstateError::MinerAborted,
1062+
));
1063+
}
1064+
10451065
// build the block itself
10461066
let (mut block, consumed, size, tx_events) = NakamotoBlockBuilder::build_nakamoto_block(
10471067
&chain_state,

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,6 @@ pub fn next_block_and_wait_for_commits(
728728
(0..commits_before.len()).map(|_| None).collect();
729729
let mut commit_sent_time: Vec<Option<Instant>> =
730730
(0..commits_before.len()).map(|_| None).collect();
731-
sleep_ms(2000); // Make sure that the proposed stacks block has a different timestamp than its parent
732731
next_block_and(btc_controller, timeout_secs, || {
733732
for i in 0..commits_submitted.len() {
734733
let commits_sent = commits_submitted[i].load(Ordering::SeqCst);

0 commit comments

Comments
 (0)