From 4843cc6ec431cc79e05b302fa3e5bdd6738d2fde Mon Sep 17 00:00:00 2001 From: Jude Nelson Date: Tue, 31 Aug 2021 18:44:39 -0400 Subject: [PATCH] refactor: create block builder settings should be a function of the config --- testnet/stacks-node/src/config.rs | 25 ++++++++++++++++++++++ testnet/stacks-node/src/neon_node.rs | 31 +++------------------------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/testnet/stacks-node/src/config.rs b/testnet/stacks-node/src/config.rs index fd145c166..cd7b11a49 100644 --- a/testnet/stacks-node/src/config.rs +++ b/testnet/stacks-node/src/config.rs @@ -7,6 +7,8 @@ use rand::RngCore; use stacks::burnchains::bitcoin::BitcoinNetworkType; use stacks::burnchains::{MagicBytes, BLOCKSTACK_MAGIC_MAINNET}; +use stacks::chainstate::stacks::miner::BlockBuilderSettings; +use stacks::core::mempool::MemPoolWalkSettings; use stacks::core::{ BLOCK_LIMIT_MAINNET, CHAIN_ID_MAINNET, CHAIN_ID_TESTNET, HELIUM_BLOCK_LIMIT, PEER_VERSION_MAINNET, PEER_VERSION_TESTNET, @@ -828,6 +830,29 @@ impl Config { pub fn is_node_event_driven(&self) -> bool { self.events_observers.len() > 0 } + + pub fn make_block_builder_settings(&self, attempt: u64) -> BlockBuilderSettings { + BlockBuilderSettings { + execution_cost: self.block_limit.clone(), + max_miner_time_ms: if attempt <= 1 { + // first attempt to mine a block -- do so right away + self.miner.first_attempt_time_ms + } else { + // second or later attempt to mine a block -- give it some time + self.miner.subsequent_attempt_time_ms + }, + mempool_settings: MemPoolWalkSettings { + min_tx_fee: self.miner.min_tx_fee, + max_walk_time_ms: if attempt <= 1 { + // first attempt to mine a block -- do so right away + self.miner.first_attempt_time_ms + } else { + // second or later attempt to mine a block -- give it some time + self.miner.subsequent_attempt_time_ms + }, + }, + } + } } impl std::default::Default for Config { diff --git a/testnet/stacks-node/src/neon_node.rs b/testnet/stacks-node/src/neon_node.rs index c12ce29df..a5d32466f 100644 --- a/testnet/stacks-node/src/neon_node.rs +++ b/testnet/stacks-node/src/neon_node.rs @@ -36,7 +36,6 @@ use stacks::chainstate::stacks::{ }; use stacks::codec::StacksMessageCodec; use stacks::core::mempool::MemPoolDB; -use stacks::core::mempool::MemPoolWalkSettings; use stacks::core::FIRST_BURNCHAIN_CONSENSUS_HASH; use stacks::monitoring::{increment_stx_blocks_mined_counter, update_active_miners_count_gauge}; use stacks::net::{ @@ -157,30 +156,6 @@ struct MiningTenureInformation { coinbase_nonce: u64, } -/// Generate the block-builder settings from the node config -fn make_block_builder_settings(config: &Config, attempt: u64) -> BlockBuilderSettings { - BlockBuilderSettings { - execution_cost: config.block_limit.clone(), - max_miner_time_ms: if attempt <= 1 { - // first attempt to mine a block -- do so right away - config.miner.first_attempt_time_ms - } else { - // second or later attempt to mine a block -- give it some time - config.miner.subsequent_attempt_time_ms - }, - mempool_settings: MemPoolWalkSettings { - min_tx_fee: config.miner.min_tx_fee, - max_walk_time_ms: if attempt <= 1 { - // first attempt to mine a block -- do so right away - config.miner.first_attempt_time_ms - } else { - // second or later attempt to mine a block -- give it some time - config.miner.subsequent_attempt_time_ms - }, - }, - } -} - /// Process artifacts from the tenure. /// At this point, we're modifying the chainstate, and merging the artifacts from the previous tenure. fn inner_process_tenure( @@ -459,7 +434,7 @@ fn try_mine_microblock( last_mined: 0, quantity: 0, cost_so_far: cost_so_far, - settings: make_block_builder_settings(config, 2), + settings: config.make_block_builder_settings(2), }); } Ok(None) => { @@ -1851,7 +1826,7 @@ impl InitializedNeonNode { vrf_proof.clone(), mblock_pubkey_hash, &coinbase_tx, - make_block_builder_settings(&config, (last_mined_blocks.len() + 1) as u64), + config.make_block_builder_settings((last_mined_blocks.len() + 1) as u64), Some(event_observer), ) { Ok(block) => block, @@ -1891,7 +1866,7 @@ impl InitializedNeonNode { vrf_proof.clone(), mblock_pubkey_hash, &coinbase_tx, - make_block_builder_settings(&config, (last_mined_blocks.len() + 1) as u64), + config.make_block_builder_settings((last_mined_blocks.len() + 1) as u64), Some(event_observer), ) { Ok(block) => block,