Skip to content

Commit

Permalink
feat: add a next_initiative_delay config
Browse files Browse the repository at this point in the history
  • Loading branch information
hugocaillard committed May 2, 2024
1 parent a7ef54e commit 2a7f237
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
6 changes: 6 additions & 0 deletions testnet/stacks-node/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1730,6 +1730,7 @@ pub struct NodeConfig {
pub max_microblocks: u64,
pub wait_time_for_microblocks: u64,
pub wait_time_for_blocks: u64,
pub next_initiative_delay: u64,
pub prometheus_bind: Option<String>,
pub marf_cache_strategy: Option<String>,
pub marf_defer_hashing: bool,
Expand Down Expand Up @@ -2015,6 +2016,7 @@ impl Default for NodeConfig {
max_microblocks: u16::MAX as u64,
wait_time_for_microblocks: 30_000,
wait_time_for_blocks: 30_000,
next_initiative_delay: 10_000,
prometheus_bind: None,
marf_cache_strategy: None,
marf_defer_hashing: true,
Expand Down Expand Up @@ -2462,6 +2464,7 @@ pub struct NodeConfigFile {
pub max_microblocks: Option<u64>,
pub wait_time_for_microblocks: Option<u64>,
pub wait_time_for_blocks: Option<u64>,
pub next_initiative_delay: Option<u64>,
pub prometheus_bind: Option<String>,
pub marf_cache_strategy: Option<String>,
pub marf_defer_hashing: Option<bool>,
Expand Down Expand Up @@ -2522,6 +2525,9 @@ impl NodeConfigFile {
wait_time_for_blocks: self
.wait_time_for_blocks
.unwrap_or(default_node_config.wait_time_for_blocks),
next_initiative_delay: self
.next_initiative_delay
.unwrap_or(default_node_config.next_initiative_delay),
prometheus_bind: self.prometheus_bind,
marf_cache_strategy: self.marf_cache_strategy,
marf_defer_hashing: self
Expand Down
12 changes: 8 additions & 4 deletions testnet/stacks-node/src/nakamoto_node/relayer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,10 @@ impl RelayerThread {

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

let next_initiative_delay = config.node.next_initiative_delay;

RelayerThread {
config: config,
config,
sortdb,
chainstate,
mempool,
Expand All @@ -210,7 +212,7 @@ impl RelayerThread {

miner_thread: None,
is_miner,
next_initiative: Instant::now() + Duration::from_secs(4),
next_initiative: Instant::now() + Duration::from_millis(next_initiative_delay),
last_committed: None,
}
}
Expand Down Expand Up @@ -804,10 +806,12 @@ impl RelayerThread {
pub fn main(mut self, relay_rcv: Receiver<RelayerDirective>) {
debug!("relayer thread ID is {:?}", std::thread::current().id());

self.next_initiative = Instant::now() + Duration::from_secs(4);
self.next_initiative =
Instant::now() + Duration::from_millis(self.config.node.next_initiative_delay);
while self.globals.keep_running() {
let directive = if Instant::now() >= self.next_initiative {
self.next_initiative = Instant::now() + Duration::from_secs(4);
self.next_initiative =
Instant::now() + Duration::from_millis(self.config.node.next_initiative_delay);
self.initiative()
} else {
None
Expand Down

0 comments on commit 2a7f237

Please sign in to comment.