Skip to content

Commit ae18e3c

Browse files
authored
Merge pull request #4795 from stacks-network/feat/next-initiative-delay-config
feat: add a next_initiative_delay config
2 parents 83d338d + 6fcb7d9 commit ae18e3c

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

testnet/stacks-node/src/config.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1795,6 +1795,13 @@ pub struct NodeConfig {
17951795
pub max_microblocks: u64,
17961796
pub wait_time_for_microblocks: u64,
17971797
pub wait_time_for_blocks: u64,
1798+
/// Controls how frequently, in milliseconds, the nakamoto miner's relay thread acts on its own initiative
1799+
/// (as opposed to responding to an event from the networking thread, etc.). This is roughly
1800+
/// how frequently the miner checks if a new burnchain block has been processed.
1801+
///
1802+
/// Default value of 10 seconds is reasonable in mainnet (where bitcoin blocks are ~10 minutes),
1803+
/// but environments where burn blocks are more frequent may want to decrease this value.
1804+
pub next_initiative_delay: u64,
17981805
pub prometheus_bind: Option<String>,
17991806
pub marf_cache_strategy: Option<String>,
18001807
pub marf_defer_hashing: bool,
@@ -2080,6 +2087,7 @@ impl Default for NodeConfig {
20802087
max_microblocks: u16::MAX as u64,
20812088
wait_time_for_microblocks: 30_000,
20822089
wait_time_for_blocks: 30_000,
2090+
next_initiative_delay: 10_000,
20832091
prometheus_bind: None,
20842092
marf_cache_strategy: None,
20852093
marf_defer_hashing: true,
@@ -2530,6 +2538,7 @@ pub struct NodeConfigFile {
25302538
pub max_microblocks: Option<u64>,
25312539
pub wait_time_for_microblocks: Option<u64>,
25322540
pub wait_time_for_blocks: Option<u64>,
2541+
pub next_initiative_delay: Option<u64>,
25332542
pub prometheus_bind: Option<String>,
25342543
pub marf_cache_strategy: Option<String>,
25352544
pub marf_defer_hashing: Option<bool>,
@@ -2590,6 +2599,9 @@ impl NodeConfigFile {
25902599
wait_time_for_blocks: self
25912600
.wait_time_for_blocks
25922601
.unwrap_or(default_node_config.wait_time_for_blocks),
2602+
next_initiative_delay: self
2603+
.next_initiative_delay
2604+
.unwrap_or(default_node_config.next_initiative_delay),
25932605
prometheus_bind: self.prometheus_bind,
25942606
marf_cache_strategy: self.marf_cache_strategy,
25952607
marf_defer_hashing: self

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,10 @@ impl RelayerThread {
190190

191191
let bitcoin_controller = BitcoinRegtestController::new_dummy(config.clone());
192192

193+
let next_initiative_delay = config.node.next_initiative_delay;
194+
193195
RelayerThread {
194-
config: config,
196+
config,
195197
sortdb,
196198
chainstate,
197199
mempool,
@@ -215,7 +217,7 @@ impl RelayerThread {
215217

216218
miner_thread: None,
217219
is_miner,
218-
next_initiative: Instant::now() + Duration::from_secs(10),
220+
next_initiative: Instant::now() + Duration::from_millis(next_initiative_delay),
219221
last_committed: None,
220222
}
221223
}
@@ -819,10 +821,12 @@ impl RelayerThread {
819821
pub fn main(mut self, relay_rcv: Receiver<RelayerDirective>) {
820822
debug!("relayer thread ID is {:?}", std::thread::current().id());
821823

822-
self.next_initiative = Instant::now() + Duration::from_secs(10);
824+
self.next_initiative =
825+
Instant::now() + Duration::from_millis(self.config.node.next_initiative_delay);
823826
while self.globals.keep_running() {
824827
let directive = if Instant::now() >= self.next_initiative {
825-
self.next_initiative = Instant::now() + Duration::from_secs(10);
828+
self.next_initiative =
829+
Instant::now() + Duration::from_millis(self.config.node.next_initiative_delay);
826830
self.initiative()
827831
} else {
828832
None

0 commit comments

Comments
 (0)