From d76fd81902c218a9a1544f54b01d3fae176bf02f Mon Sep 17 00:00:00 2001 From: Jeff Bencin Date: Thu, 18 Apr 2024 17:07:16 -0400 Subject: [PATCH] feat: Add `nakamoto_attempt_time_ms` to control Nakamoto miner --- docs/mining.md | 6 +++-- testnet/stacks-node/src/config.rs | 27 +++++++++++++++++++ .../stacks-node/src/nakamoto_node/miner.rs | 11 ++------ 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/docs/mining.md b/docs/mining.md index 8b824924f..891358af0 100644 --- a/docs/mining.md +++ b/docs/mining.md @@ -3,7 +3,7 @@ Stacks tokens (STX) are mined by transferring BTC via PoX. To run as a miner, you should make sure to add the following config fields to your config file: -``` +```toml [node] # Run as a miner miner = True @@ -25,6 +25,8 @@ first_attempt_time_ms = 1000 subsequent_attempt_time_ms = 60000 # Time to spend mining a microblock, in milliseconds. microblock_attempt_time_ms = 30000 +# Time to spend mining a Nakamoto block, in milliseconds. +nakamoto_attempt_time_ms = 10000 ``` You can verify that your node is operating as a miner by checking its log output @@ -40,7 +42,7 @@ INFO [1630127492.062652] [testnet/stacks-node/src/run_loop/neon.rs:164] [main] U Fee and cost estimators can be configured via the config section `[fee_estimation]`: -``` +```toml [fee_estimation] cost_estimator = naive_pessimistic fee_estimator = fuzzed_weighted_median_fee_rate diff --git a/testnet/stacks-node/src/config.rs b/testnet/stacks-node/src/config.rs index 54b5aa839..368b52731 100644 --- a/testnet/stacks-node/src/config.rs +++ b/testnet/stacks-node/src/config.rs @@ -1194,6 +1194,26 @@ impl Config { self.events_observers.len() > 0 } + pub fn make_nakamoto_block_builder_settings( + &self, + miner_status: Arc>, + ) -> BlockBuilderSettings { + let miner_config = self.get_miner_config(); + BlockBuilderSettings { + max_miner_time_ms: miner_config.nakamoto_attempt_time_ms, + mempool_settings: MemPoolWalkSettings { + max_walk_time_ms: miner_config.nakamoto_attempt_time_ms, + consider_no_estimate_tx_prob: miner_config.probability_pick_no_estimate_tx, + nonce_cache_size: miner_config.nonce_cache_size, + candidate_retry_cache_size: miner_config.candidate_retry_cache_size, + txs_to_consider: miner_config.txs_to_consider, + filter_origins: miner_config.filter_origins, + }, + miner_status, + confirm_microblocks: false, + } + } + pub fn make_block_builder_settings( &self, attempt: u64, @@ -2162,6 +2182,8 @@ pub struct MinerConfig { pub first_attempt_time_ms: u64, pub subsequent_attempt_time_ms: u64, pub microblock_attempt_time_ms: u64, + /// Max time to assemble Nakamoto block + pub nakamoto_attempt_time_ms: u64, pub probability_pick_no_estimate_tx: u8, pub block_reward_recipient: Option, /// If possible, mine with a p2wpkh address @@ -2212,6 +2234,7 @@ impl Default for MinerConfig { first_attempt_time_ms: 10, subsequent_attempt_time_ms: 120_000, microblock_attempt_time_ms: 30_000, + nakamoto_attempt_time_ms: 10_000, probability_pick_no_estimate_tx: 25, block_reward_recipient: None, segwit: false, @@ -2537,6 +2560,7 @@ pub struct MinerConfigFile { pub first_attempt_time_ms: Option, pub subsequent_attempt_time_ms: Option, pub microblock_attempt_time_ms: Option, + pub nakamoto_attempt_time_ms: Option, pub probability_pick_no_estimate_tx: Option, pub block_reward_recipient: Option, pub segwit: Option, @@ -2570,6 +2594,9 @@ impl MinerConfigFile { microblock_attempt_time_ms: self .microblock_attempt_time_ms .unwrap_or(miner_default_config.microblock_attempt_time_ms), + nakamoto_attempt_time_ms: self + .nakamoto_attempt_time_ms + .unwrap_or(miner_default_config.nakamoto_attempt_time_ms), probability_pick_no_estimate_tx: self .probability_pick_no_estimate_tx .unwrap_or(miner_default_config.probability_pick_no_estimate_tx), diff --git a/testnet/stacks-node/src/nakamoto_node/miner.rs b/testnet/stacks-node/src/nakamoto_node/miner.rs index 3a976aecc..a75b89772 100644 --- a/testnet/stacks-node/src/nakamoto_node/miner.rs +++ b/testnet/stacks-node/src/nakamoto_node/miner.rs @@ -802,10 +802,6 @@ impl BlockMinerThread { parent_block_info.stacks_parent_header.microblock_tail = None; - let block_num = u64::try_from(self.mined_blocks.len()) - .map_err(|_| NakamotoNodeError::UnexpectedChainState)? - .saturating_add(1); - let signer_transactions = self.get_signer_transactions(&mut chain_state, &burn_db, &stackerdbs)?; @@ -818,11 +814,8 @@ impl BlockMinerThread { &self.burn_block.consensus_hash, self.burn_block.total_burn, tenure_start_info, - self.config.make_block_builder_settings( - block_num, - false, - self.globals.get_miner_status(), - ), + self.config + .make_nakamoto_block_builder_settings(self.globals.get_miner_status()), // we'll invoke the event dispatcher ourselves so that it calculates the // correct signer_sighash for `process_mined_nakamoto_block_event` Some(&self.event_dispatcher),