zebra/zebra-rpc/src/config/mining.rs

86 lines
3.4 KiB
Rust
Raw Normal View History

//! Mining config
use serde::{Deserialize, Serialize};
use zebra_chain::transparent;
/// Mining configuration section.
#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
#[serde(deny_unknown_fields, default)]
pub struct Config {
/// The address used for miner payouts.
/// Zebra currently only supports P2SH and P2PKH transparent addresses.
///
/// Zebra sends mining fees and miner rewards to this address in the
/// `getblocktemplate` RPC coinbase transaction.
pub miner_address: Option<transparent::Address>,
feat(mine): Add an internal Zcash miner to Zebra (#8136) * Patch equihash to use the solver branch * Add an internal-miner feature and set up its dependencies * Remove 'Experimental' from mining RPC docs * Fix a nightly clippy::question_mark lint * Move a byte array utility function to zebra-chain * fixup! Add an internal-miner feature and set up its dependencies * Add an equihash::Solution::solve() method with difficulty checks * Check solution is valid before returning it * Add a TODO to check for peers before mining * Move config validation into GetBlockTemplateRpcImpl::new() * fixup! fixup! Add an internal-miner feature and set up its dependencies * Use the same generic constraints for GetBlockTemplateRpcImpl struct and impls * Start adding an internal miner component * Add the miner task to the start command * Add basic miner code * Split out a method to mine one block * Spawn to a blocking thread * Wait until a valid template is available * Handle shutdown * Run mining on low priority threads * Ignore some invalid solutions * Use a difference nonce for each solver thread * Update TODOs * Change the patch into a renamed dependency to simplify crate releases * Clean up instrumentation and TODOs * Make RPC instances cloneable and clean up generics * Make LongPollId Copy so it's easier to use * Add API to restart mining if there's a new block template * Actually restart mining if there's a new block template * Tidy instrumentation * fixup! Move config validation into GetBlockTemplateRpcImpl::new() * fixup! Make RPC instances cloneable and clean up generics * Run the template generator and one miner concurrently * Reduce logging * Fix a bug in getblocktemplate RPC tip change detection * Work around some watch channel change bugs * Rate-limit template changes in the receiver * Run one mining solver per available core * Use updated C code with double-free protection * Update to the latest solver branch * Return and submit all valid solutions * Document what INPUT_LENGTH means * Fix watch channel change detection * Don't return early when a mining task fails * Spawn async miner tasks to avoid cooperative blocking, deadlocks, and improve shutdown responsiveness * Make existing parallelism docs and configs consistent * Add a mining parallelism config * Use the minimum of the configured or available threads for mining * Ignore optional feature fields in tests * Downgrade some frequent logs to debug * Document new zebrad features and tasks * Describe the internal-miner feature in the CHANGELOG * Update dependency to de-duplicate equihash solutions * Use futures::StreamExt instead of TryStreamExt * Fix a panic message typo
2024-01-11 06:41:01 -08:00
/// Mine blocks using Zebra's internal miner, without an external mining pool or equihash solver.
///
/// This experimental feature is only supported on testnet.
/// Mainnet miners should use a mining pool with GPUs or ASICs designed for efficient mining.
///
/// The internal miner is off by default.
#[cfg(feature = "internal-miner")]
pub internal_miner: bool,
/// The number of internal miner threads used by Zebra.
/// These threads are scheduled at low priority.
///
/// The number of threads is limited by the available parallelism reported by the OS.
/// If the number of threads isn't configured, or can't be detected, Zebra uses one thread.
/// This is different from Zebra's other parallelism configs, because mining runs constantly and
/// uses a large amount of memory. (144 MB of RAM and 100% of a core per thread.)
///
/// If the number of threads is set to zero, Zebra disables mining.
/// This matches `zcashd`'s behaviour, but is different from Zebra's other parallelism configs.
#[cfg(feature = "internal-miner")]
pub internal_miner_threads: usize,
/// Extra data to include in coinbase transaction inputs.
/// Limited to around 95 bytes by the consensus rules.
///
/// If this string is hex-encoded, it will be hex-decoded into bytes.
/// Otherwise, it will be UTF-8 encoded into bytes.
pub extra_coinbase_data: Option<String>,
/// Should Zebra's block templates try to imitate `zcashd`?
///
/// This developer-only config is not supported for general use.
pub debug_like_zcashd: bool,
}
impl Default for Config {
fn default() -> Self {
Self {
miner_address: None,
// For now, act like `zcashd` as much as possible.
// TODO: do we want to default to v5 transactions and Zebra coinbase data?
extra_coinbase_data: None,
debug_like_zcashd: true,
feat(mine): Add an internal Zcash miner to Zebra (#8136) * Patch equihash to use the solver branch * Add an internal-miner feature and set up its dependencies * Remove 'Experimental' from mining RPC docs * Fix a nightly clippy::question_mark lint * Move a byte array utility function to zebra-chain * fixup! Add an internal-miner feature and set up its dependencies * Add an equihash::Solution::solve() method with difficulty checks * Check solution is valid before returning it * Add a TODO to check for peers before mining * Move config validation into GetBlockTemplateRpcImpl::new() * fixup! fixup! Add an internal-miner feature and set up its dependencies * Use the same generic constraints for GetBlockTemplateRpcImpl struct and impls * Start adding an internal miner component * Add the miner task to the start command * Add basic miner code * Split out a method to mine one block * Spawn to a blocking thread * Wait until a valid template is available * Handle shutdown * Run mining on low priority threads * Ignore some invalid solutions * Use a difference nonce for each solver thread * Update TODOs * Change the patch into a renamed dependency to simplify crate releases * Clean up instrumentation and TODOs * Make RPC instances cloneable and clean up generics * Make LongPollId Copy so it's easier to use * Add API to restart mining if there's a new block template * Actually restart mining if there's a new block template * Tidy instrumentation * fixup! Move config validation into GetBlockTemplateRpcImpl::new() * fixup! Make RPC instances cloneable and clean up generics * Run the template generator and one miner concurrently * Reduce logging * Fix a bug in getblocktemplate RPC tip change detection * Work around some watch channel change bugs * Rate-limit template changes in the receiver * Run one mining solver per available core * Use updated C code with double-free protection * Update to the latest solver branch * Return and submit all valid solutions * Document what INPUT_LENGTH means * Fix watch channel change detection * Don't return early when a mining task fails * Spawn async miner tasks to avoid cooperative blocking, deadlocks, and improve shutdown responsiveness * Make existing parallelism docs and configs consistent * Add a mining parallelism config * Use the minimum of the configured or available threads for mining * Ignore optional feature fields in tests * Downgrade some frequent logs to debug * Document new zebrad features and tasks * Describe the internal-miner feature in the CHANGELOG * Update dependency to de-duplicate equihash solutions * Use futures::StreamExt instead of TryStreamExt * Fix a panic message typo
2024-01-11 06:41:01 -08:00
// TODO: ignore and warn rather than panicking if these fields are in the config,
// but the feature isn't enabled.
#[cfg(feature = "internal-miner")]
internal_miner: false,
#[cfg(feature = "internal-miner")]
internal_miner_threads: 1,
}
}
}
impl Config {
/// Return true if `getblocktemplate-rpcs` rust feature is not turned on, false otherwise.
///
/// This is used to ignore the mining section of the configuration if the feature is not
/// enabled, allowing us to log a warning when the config found is different from the default.
pub fn skip_getblocktemplate(&self) -> bool {
!cfg!(feature = "getblocktemplate-rpcs")
}
feat(mine): Add an internal Zcash miner to Zebra (#8136) * Patch equihash to use the solver branch * Add an internal-miner feature and set up its dependencies * Remove 'Experimental' from mining RPC docs * Fix a nightly clippy::question_mark lint * Move a byte array utility function to zebra-chain * fixup! Add an internal-miner feature and set up its dependencies * Add an equihash::Solution::solve() method with difficulty checks * Check solution is valid before returning it * Add a TODO to check for peers before mining * Move config validation into GetBlockTemplateRpcImpl::new() * fixup! fixup! Add an internal-miner feature and set up its dependencies * Use the same generic constraints for GetBlockTemplateRpcImpl struct and impls * Start adding an internal miner component * Add the miner task to the start command * Add basic miner code * Split out a method to mine one block * Spawn to a blocking thread * Wait until a valid template is available * Handle shutdown * Run mining on low priority threads * Ignore some invalid solutions * Use a difference nonce for each solver thread * Update TODOs * Change the patch into a renamed dependency to simplify crate releases * Clean up instrumentation and TODOs * Make RPC instances cloneable and clean up generics * Make LongPollId Copy so it's easier to use * Add API to restart mining if there's a new block template * Actually restart mining if there's a new block template * Tidy instrumentation * fixup! Move config validation into GetBlockTemplateRpcImpl::new() * fixup! Make RPC instances cloneable and clean up generics * Run the template generator and one miner concurrently * Reduce logging * Fix a bug in getblocktemplate RPC tip change detection * Work around some watch channel change bugs * Rate-limit template changes in the receiver * Run one mining solver per available core * Use updated C code with double-free protection * Update to the latest solver branch * Return and submit all valid solutions * Document what INPUT_LENGTH means * Fix watch channel change detection * Don't return early when a mining task fails * Spawn async miner tasks to avoid cooperative blocking, deadlocks, and improve shutdown responsiveness * Make existing parallelism docs and configs consistent * Add a mining parallelism config * Use the minimum of the configured or available threads for mining * Ignore optional feature fields in tests * Downgrade some frequent logs to debug * Document new zebrad features and tasks * Describe the internal-miner feature in the CHANGELOG * Update dependency to de-duplicate equihash solutions * Use futures::StreamExt instead of TryStreamExt * Fix a panic message typo
2024-01-11 06:41:01 -08:00
/// Is the internal miner enabled using at least one thread?
#[cfg(feature = "internal-miner")]
pub fn is_internal_miner_enabled(&self) -> bool {
self.internal_miner && self.internal_miner_threads > 0
}
}