change(mining): Restores parts of the internal-miner feature for use on Regtest (#8506)
* Allow configurable Nu5 activation height on Regtest * Fixes test * removes outdated TODO * Adds `current_with_activation_height()` method and uses it in `Commitment::from_bytes()` * Enables parts of the internal miner for use on Regtest when the solution isn't checked * Update internal miner config field docs
This commit is contained in:
parent
d2d1a18d81
commit
a6569d4881
|
@ -132,7 +132,7 @@ impl Solution {
|
|||
#[cfg(feature = "internal-miner")]
|
||||
#[allow(clippy::unwrap_in_result)]
|
||||
pub fn solve<F>(
|
||||
mut _header: Header,
|
||||
mut header: Header,
|
||||
mut _cancel_fn: F,
|
||||
) -> Result<AtLeastOne<Header>, SolverCancelled>
|
||||
where
|
||||
|
@ -141,8 +141,8 @@ impl Solution {
|
|||
// TODO: Function code was removed as part of https://github.com/ZcashFoundation/zebra/issues/8180
|
||||
// Find the removed code at https://github.com/ZcashFoundation/zebra/blob/v1.5.1/zebra-chain/src/work/equihash.rs#L115-L166
|
||||
// Restore the code when conditions are met. https://github.com/ZcashFoundation/zebra/issues/8183
|
||||
|
||||
Err(SolverCancelled)
|
||||
header.solution = Solution::for_proposal();
|
||||
Ok(AtLeastOne::from_one(header))
|
||||
}
|
||||
|
||||
// TODO: Some methods were removed as part of https://github.com/ZcashFoundation/zebra/issues/8180
|
||||
|
|
|
@ -29,6 +29,17 @@ pub struct Config {
|
|||
///
|
||||
/// This developer-only config is not supported for general use.
|
||||
pub debug_like_zcashd: bool,
|
||||
|
||||
/// Mine blocks using Zebra's internal miner, without an external mining pool or equihash solver.
|
||||
///
|
||||
/// This experimental feature is only supported on regtest as it uses null solutions and skips checking
|
||||
/// for a valid Proof of Work.
|
||||
///
|
||||
/// The internal miner is off by default.
|
||||
// TODO: Restore equihash solver and recommend that Mainnet miners should use a mining pool with
|
||||
// GPUs or ASICs designed for efficient mining.
|
||||
#[cfg(feature = "internal-miner")]
|
||||
pub internal_miner: bool,
|
||||
}
|
||||
|
||||
impl Default for Config {
|
||||
|
@ -42,6 +53,8 @@ impl Default for Config {
|
|||
// TODO: Internal miner config code was removed as part of https://github.com/ZcashFoundation/zebra/issues/8180
|
||||
// Find the removed code at https://github.com/ZcashFoundation/zebra/blob/v1.5.1/zebra-rpc/src/config/mining.rs#L61-L66
|
||||
// Restore the code when conditions are met. https://github.com/ZcashFoundation/zebra/issues/8183
|
||||
#[cfg(feature = "internal-miner")]
|
||||
internal_miner: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -61,6 +74,6 @@ impl Config {
|
|||
// TODO: Changed to return always false so internal miner is never started. Part of https://github.com/ZcashFoundation/zebra/issues/8180
|
||||
// Find the removed code at https://github.com/ZcashFoundation/zebra/blob/v1.5.1/zebra-rpc/src/config/mining.rs#L83
|
||||
// Restore the code when conditions are met. https://github.com/ZcashFoundation/zebra/issues/8183
|
||||
false
|
||||
self.internal_miner
|
||||
}
|
||||
}
|
||||
|
|
|
@ -101,7 +101,7 @@ pub async fn test_responses<State, ReadState>(
|
|||
extra_coinbase_data: None,
|
||||
debug_like_zcashd: true,
|
||||
// TODO: Use default field values when optional features are enabled in tests #8183
|
||||
//..Default::default()
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
// nu5 block height
|
||||
|
|
|
@ -1286,7 +1286,7 @@ async fn rpc_getblocktemplate_mining_address(use_p2pkh: bool) {
|
|||
extra_coinbase_data: None,
|
||||
debug_like_zcashd: true,
|
||||
// TODO: Use default field values when optional features are enabled in tests #8183
|
||||
//..Default::default()
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
// nu5 block height
|
||||
|
@ -1735,7 +1735,7 @@ async fn rpc_getdifficulty() {
|
|||
extra_coinbase_data: None,
|
||||
debug_like_zcashd: true,
|
||||
// TODO: Use default field values when optional features are enabled in tests #8183
|
||||
//..Default::default()
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
// nu5 block height
|
||||
|
|
|
@ -359,7 +359,7 @@ impl StartCmd {
|
|||
address_book,
|
||||
);
|
||||
|
||||
crate::components::miner::spawn_init(&config.mining, rpc)
|
||||
crate::components::miner::spawn_init(&config.network.network, &config.mining, rpc)
|
||||
} else {
|
||||
tokio::spawn(std::future::pending().in_current_span())
|
||||
};
|
||||
|
|
|
@ -16,11 +16,11 @@ use tower::Service;
|
|||
use tracing::{Instrument, Span};
|
||||
|
||||
use zebra_chain::{
|
||||
block::{self, Block},
|
||||
block::{self, Block, Height},
|
||||
chain_sync_status::ChainSyncStatus,
|
||||
chain_tip::ChainTip,
|
||||
diagnostic::task::WaitForPanics,
|
||||
parameters::NetworkUpgrade,
|
||||
parameters::{Network, NetworkUpgrade},
|
||||
serialization::{AtLeastOne, ZcashSerialize},
|
||||
shutdown::is_shutting_down,
|
||||
work::equihash::{Solution, SolverCancelled},
|
||||
|
@ -61,6 +61,7 @@ pub const BLOCK_MINING_WAIT_TIME: Duration = Duration::from_secs(3);
|
|||
///
|
||||
/// See [`run_mining_solver()`] for more details.
|
||||
pub fn spawn_init<Mempool, State, Tip, BlockVerifierRouter, SyncStatus, AddressBook>(
|
||||
network: &Network,
|
||||
config: &Config,
|
||||
rpc: GetBlockTemplateRpcImpl<Mempool, State, Tip, BlockVerifierRouter, SyncStatus, AddressBook>,
|
||||
) -> JoinHandle<Result<(), Report>>
|
||||
|
@ -94,10 +95,11 @@ where
|
|||
SyncStatus: ChainSyncStatus + Clone + Send + Sync + 'static,
|
||||
AddressBook: AddressBookPeers + Clone + Send + Sync + 'static,
|
||||
{
|
||||
let network = network.clone();
|
||||
let config = config.clone();
|
||||
|
||||
// TODO: spawn an entirely new executor here, so mining is isolated from higher priority tasks.
|
||||
tokio::spawn(init(config, rpc).in_current_span())
|
||||
tokio::spawn(init(network, config, rpc).in_current_span())
|
||||
}
|
||||
|
||||
/// Initialize the miner based on its config.
|
||||
|
@ -107,6 +109,7 @@ where
|
|||
///
|
||||
/// See [`run_mining_solver()`] for more details.
|
||||
pub async fn init<Mempool, State, Tip, BlockVerifierRouter, SyncStatus, AddressBook>(
|
||||
network: Network,
|
||||
_config: Config,
|
||||
rpc: GetBlockTemplateRpcImpl<Mempool, State, Tip, BlockVerifierRouter, SyncStatus, AddressBook>,
|
||||
) -> Result<(), Report>
|
||||
|
@ -163,7 +166,7 @@ where
|
|||
let mut abort_handles = Vec::new();
|
||||
|
||||
let template_generator = tokio::task::spawn(
|
||||
generate_block_templates(rpc.clone(), template_sender).in_current_span(),
|
||||
generate_block_templates(network, rpc.clone(), template_sender).in_current_span(),
|
||||
);
|
||||
abort_handles.push(template_generator.abort_handle());
|
||||
let template_generator = template_generator.wait_for_panics();
|
||||
|
@ -217,6 +220,7 @@ pub async fn generate_block_templates<
|
|||
SyncStatus,
|
||||
AddressBook,
|
||||
>(
|
||||
network: Network,
|
||||
rpc: GetBlockTemplateRpcImpl<Mempool, State, Tip, BlockVerifierRouter, SyncStatus, AddressBook>,
|
||||
template_sender: watch::Sender<Option<Arc<Block>>>,
|
||||
) -> Result<(), Report>
|
||||
|
@ -260,11 +264,11 @@ where
|
|||
|
||||
// Shut down the task when all the template receivers are dropped, or Zebra shuts down.
|
||||
while !template_sender.is_closed() && !is_shutting_down() {
|
||||
let template = rpc.get_block_template(Some(parameters.clone())).await;
|
||||
let template: Result<_, _> = rpc.get_block_template(Some(parameters.clone())).await;
|
||||
|
||||
// Wait for the chain to sync so we get a valid template.
|
||||
let Ok(template) = template else {
|
||||
debug!(
|
||||
info!(
|
||||
?BLOCK_TEMPLATE_WAIT_TIME,
|
||||
"waiting for a valid block template",
|
||||
);
|
||||
|
@ -291,8 +295,11 @@ where
|
|||
// Tell the next get_block_template() call to wait until the template has changed.
|
||||
parameters.long_poll_id = Some(template.long_poll_id);
|
||||
|
||||
let block =
|
||||
proposal_block_from_template(&template, TimeSource::CurTime, NetworkUpgrade::Nu5)
|
||||
let block = proposal_block_from_template(
|
||||
&template,
|
||||
TimeSource::CurTime,
|
||||
NetworkUpgrade::current(&network, Height(template.height)),
|
||||
)
|
||||
.expect("unexpected invalid block template");
|
||||
|
||||
// If the template has actually changed, send an updated template.
|
||||
|
|
Loading…
Reference in New Issue