mirror of
https://github.com/alexgo-io/stacks-puppet-node.git
synced 2026-01-12 16:53:21 +08:00
feat: Add nakamoto_attempt_time_ms to control Nakamoto miner
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -1194,6 +1194,26 @@ impl Config {
|
||||
self.events_observers.len() > 0
|
||||
}
|
||||
|
||||
pub fn make_nakamoto_block_builder_settings(
|
||||
&self,
|
||||
miner_status: Arc<Mutex<MinerStatus>>,
|
||||
) -> 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<PrincipalData>,
|
||||
/// 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<u64>,
|
||||
pub subsequent_attempt_time_ms: Option<u64>,
|
||||
pub microblock_attempt_time_ms: Option<u64>,
|
||||
pub nakamoto_attempt_time_ms: Option<u64>,
|
||||
pub probability_pick_no_estimate_tx: Option<u8>,
|
||||
pub block_reward_recipient: Option<String>,
|
||||
pub segwit: Option<bool>,
|
||||
@@ -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),
|
||||
|
||||
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user