Skip to content

Commit 71deeab

Browse files
committed
CRC: use ms precision for min_block_time config option
Signed-off-by: Jacinta Ferrant <[email protected]>
1 parent 24c425f commit 71deeab

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

testnet/stacks-node/src/config.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ pub const OP_TX_ANY_ESTIM_SIZE: u64 = fmax!(
8686
const DEFAULT_MAX_RBF_RATE: u64 = 150; // 1.5x
8787
const DEFAULT_RBF_FEE_RATE_INCREMENT: u64 = 5;
8888
const INV_REWARD_CYCLES_TESTNET: u64 = 6;
89-
const DEFAULT_MINIMUM_GAP_SECS: u64 = 1;
89+
const DEFAULT_MINIMUM_GAP_MS: u64 = 1000;
9090

9191
#[derive(Clone, Deserialize, Default, Debug)]
9292
pub struct ConfigFile {
@@ -2359,9 +2359,9 @@ pub struct MinerConfig {
23592359
pub wait_on_signers: Duration,
23602360
/// Whether to mock sign in Epoch 2.5 through the .miners and .signers contracts. This is used for testing purposes in Epoch 2.5 only.
23612361
pub pre_nakamoto_mock_signing: bool,
2362-
/// The minimum gap to wait between blocks in seconds. The value must be greater than or equal to 1 second because if a block is mined
2362+
/// The minimum gap to wait between blocks in milliseconds. The value must be greater than or equal to 1000 ms because if a block is mined
23632363
/// within the same second as its parent, it will be rejected by the signers.
2364-
pub min_block_time_gap_secs: u64,
2364+
pub min_block_time_gap_ms: u64,
23652365
}
23662366

23672367
impl Default for MinerConfig {
@@ -2393,7 +2393,7 @@ impl Default for MinerConfig {
23932393
// TODO: update to a sane value based on stackerdb benchmarking
23942394
wait_on_signers: Duration::from_secs(200),
23952395
pre_nakamoto_mock_signing: false, // Should only default true if mining key is set
2396-
min_block_time_gap_secs: DEFAULT_MINIMUM_GAP_SECS,
2396+
min_block_time_gap_ms: DEFAULT_MINIMUM_GAP_MS,
23972397
}
23982398
}
23992399
}
@@ -2744,7 +2744,7 @@ pub struct MinerConfigFile {
27442744
pub max_reorg_depth: Option<u64>,
27452745
pub wait_on_signers_ms: Option<u64>,
27462746
pub pre_nakamoto_mock_signing: Option<bool>,
2747-
pub min_block_time_gap_secs: Option<u64>,
2747+
pub min_block_time_gap_ms: Option<u64>,
27482748
}
27492749

27502750
impl MinerConfigFile {
@@ -2856,12 +2856,12 @@ impl MinerConfigFile {
28562856
pre_nakamoto_mock_signing: self
28572857
.pre_nakamoto_mock_signing
28582858
.unwrap_or(pre_nakamoto_mock_signing), // Should only default true if mining key is set
2859-
min_block_time_gap_secs: self.min_block_time_gap_secs.map(|secs| if secs < DEFAULT_MINIMUM_GAP_SECS {
2860-
warn!("miner.min_block_time_gap_secs is less than the minimum allowed value of {DEFAULT_MINIMUM_GAP_SECS} secs. Using the default value instead.");
2861-
DEFAULT_MINIMUM_GAP_SECS
2859+
min_block_time_gap_ms: self.min_block_time_gap_ms.map(|ms| if ms < DEFAULT_MINIMUM_GAP_MS {
2860+
warn!("miner.min_block_time_gap_ms is less than the minimum allowed value of {DEFAULT_MINIMUM_GAP_MS} ms. Using the default value instead.");
2861+
DEFAULT_MINIMUM_GAP_MS
28622862
} else {
2863-
secs
2864-
}).unwrap_or(miner_default_config.min_block_time_gap_secs),
2863+
ms
2864+
}).unwrap_or(miner_default_config.min_block_time_gap_ms),
28652865
})
28662866
}
28672867
}

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ use stacks::chainstate::stacks::{
4545
use stacks::net::p2p::NetworkHandle;
4646
use stacks::net::stackerdb::StackerDBs;
4747
use stacks::net::{NakamotoBlocksData, StacksMessageType};
48-
use stacks::util::get_epoch_time_secs;
4948
use stacks::util::secp256k1::MessageSignature;
49+
use stacks::util::{get_epoch_time_secs, sleep_ms};
5050
use stacks_common::codec::read_next;
5151
use stacks_common::types::chainstate::{StacksAddress, StacksBlockId};
5252
use stacks_common::types::{PrivateKey, StacksEpochId};
@@ -1051,16 +1051,17 @@ impl BlockMinerThread {
10511051
let mut chain_state = neon_node::open_chainstate_with_faults(&self.config)
10521052
.expect("FATAL: could not open chainstate DB");
10531053
let parent_block_info = self.load_block_parent_info(&mut burn_db, &mut chain_state)?;
1054-
let time_since_parent_secs = get_epoch_time_secs()
1055-
.saturating_sub(parent_block_info.stacks_parent_header.burn_header_timestamp);
1056-
if time_since_parent_secs < self.config.miner.min_block_time_gap_secs {
1057-
let wait_secs = self
1054+
let time_since_parent_ms = get_epoch_time_secs()
1055+
.saturating_sub(parent_block_info.stacks_parent_header.burn_header_timestamp)
1056+
/ 1000;
1057+
if time_since_parent_ms < self.config.miner.min_block_time_gap_ms {
1058+
let wait_ms = self
10581059
.config
10591060
.miner
1060-
.min_block_time_gap_secs
1061-
.saturating_sub(time_since_parent_secs);
1062-
info!("Waiting {wait_secs} seconds before mining a new block.");
1063-
std::thread::sleep(Duration::from_secs(wait_secs));
1061+
.min_block_time_gap_ms
1062+
.saturating_sub(time_since_parent_ms);
1063+
info!("Waiting {wait_ms} ms before mining a new block.");
1064+
sleep_ms(wait_ms);
10641065
}
10651066
Ok(())
10661067
}

0 commit comments

Comments
 (0)