fix(panic): Log a warning instead of panicking for unused mining configs (#7290)
* Logs warning for unused mining config * add conditional serialization of the mining section * rustfmt * Simplify mining::Config argument passing * Simplify mining config argument passing in start.rs --------- Co-authored-by: Alfredo Garcia <oxarbitrage@gmail.com> Co-authored-by: teor <teor@riseup.net>
This commit is contained in:
parent
e58000f07f
commit
2b81d845ea
|
@ -4,6 +4,8 @@ use std::net::SocketAddr;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
pub mod mining;
|
||||||
|
|
||||||
/// RPC configuration section.
|
/// RPC configuration section.
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
#[serde(deny_unknown_fields, default)]
|
#[serde(deny_unknown_fields, default)]
|
||||||
|
|
|
@ -39,3 +39,16 @@ impl Default for Config {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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")]
|
||||||
|
return false;
|
||||||
|
#[cfg(not(feature = "getblocktemplate-rpcs"))]
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
|
@ -55,7 +55,6 @@ use crate::methods::{
|
||||||
height_from_signed_int, GetBlockHash, MISSING_BLOCK_ERROR_CODE,
|
height_from_signed_int, GetBlockHash, MISSING_BLOCK_ERROR_CODE,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub mod config;
|
|
||||||
pub mod constants;
|
pub mod constants;
|
||||||
pub mod get_block_template;
|
pub mod get_block_template;
|
||||||
pub mod types;
|
pub mod types;
|
||||||
|
@ -315,7 +314,7 @@ where
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub fn new(
|
pub fn new(
|
||||||
network: Network,
|
network: Network,
|
||||||
mining_config: config::Config,
|
mining_config: crate::config::mining::Config,
|
||||||
mempool: Buffer<Mempool, mempool::Request>,
|
mempool: Buffer<Mempool, mempool::Request>,
|
||||||
state: State,
|
state: State,
|
||||||
latest_chain_tip: Tip,
|
latest_chain_tip: Tip,
|
||||||
|
|
|
@ -36,9 +36,7 @@ use zebra_test::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::methods::{
|
use crate::methods::{
|
||||||
get_block_template_rpcs::{
|
get_block_template_rpcs::types::{
|
||||||
self,
|
|
||||||
types::{
|
|
||||||
get_block_template::{self, GetBlockTemplateRequestMode},
|
get_block_template::{self, GetBlockTemplateRequestMode},
|
||||||
get_mining_info,
|
get_mining_info,
|
||||||
hex_data::HexData,
|
hex_data::HexData,
|
||||||
|
@ -48,7 +46,6 @@ use crate::methods::{
|
||||||
subsidy::BlockSubsidy,
|
subsidy::BlockSubsidy,
|
||||||
unified_address, validate_address, z_validate_address,
|
unified_address, validate_address, z_validate_address,
|
||||||
},
|
},
|
||||||
},
|
|
||||||
tests::{snapshot::EXCESSIVE_BLOCK_HEIGHT, utils::fake_history_tree},
|
tests::{snapshot::EXCESSIVE_BLOCK_HEIGHT, utils::fake_history_tree},
|
||||||
GetBlockHash, GetBlockTemplateRpc, GetBlockTemplateRpcImpl,
|
GetBlockHash, GetBlockTemplateRpc, GetBlockTemplateRpcImpl,
|
||||||
};
|
};
|
||||||
|
@ -100,7 +97,7 @@ pub async fn test_responses<State, ReadState>(
|
||||||
let mut mock_sync_status = MockSyncStatus::default();
|
let mut mock_sync_status = MockSyncStatus::default();
|
||||||
mock_sync_status.set_is_close_to_tip(true);
|
mock_sync_status.set_is_close_to_tip(true);
|
||||||
|
|
||||||
let mining_config = get_block_template_rpcs::config::Config {
|
let mining_config = crate::config::mining::Config {
|
||||||
miner_address: Some(transparent::Address::from_script_hash(network, [0xad; 20])),
|
miner_address: Some(transparent::Address::from_script_hash(network, [0xad; 20])),
|
||||||
extra_coinbase_data: None,
|
extra_coinbase_data: None,
|
||||||
debug_like_zcashd: true,
|
debug_like_zcashd: true,
|
||||||
|
|
|
@ -1203,7 +1203,6 @@ async fn rpc_getblocktemplate_mining_address(use_p2pkh: bool) {
|
||||||
|
|
||||||
use crate::methods::{
|
use crate::methods::{
|
||||||
get_block_template_rpcs::{
|
get_block_template_rpcs::{
|
||||||
config::Config,
|
|
||||||
constants::{
|
constants::{
|
||||||
GET_BLOCK_TEMPLATE_CAPABILITIES_FIELD, GET_BLOCK_TEMPLATE_MUTABLE_FIELD,
|
GET_BLOCK_TEMPLATE_CAPABILITIES_FIELD, GET_BLOCK_TEMPLATE_MUTABLE_FIELD,
|
||||||
GET_BLOCK_TEMPLATE_NONCE_RANGE_FIELD,
|
GET_BLOCK_TEMPLATE_NONCE_RANGE_FIELD,
|
||||||
|
@ -1229,7 +1228,7 @@ async fn rpc_getblocktemplate_mining_address(use_p2pkh: bool) {
|
||||||
true => Some(transparent::Address::from_pub_key_hash(Mainnet, [0x7e; 20])),
|
true => Some(transparent::Address::from_pub_key_hash(Mainnet, [0x7e; 20])),
|
||||||
};
|
};
|
||||||
|
|
||||||
let mining_config = Config {
|
let mining_config = crate::config::mining::Config {
|
||||||
miner_address,
|
miner_address,
|
||||||
extra_coinbase_data: None,
|
extra_coinbase_data: None,
|
||||||
debug_like_zcashd: true,
|
debug_like_zcashd: true,
|
||||||
|
@ -1668,9 +1667,7 @@ async fn rpc_getdifficulty() {
|
||||||
|
|
||||||
use zebra_state::{GetBlockTemplateChainInfo, ReadRequest, ReadResponse};
|
use zebra_state::{GetBlockTemplateChainInfo, ReadRequest, ReadResponse};
|
||||||
|
|
||||||
use crate::methods::{
|
use crate::{config::mining::Config, methods::tests::utils::fake_history_tree};
|
||||||
get_block_template_rpcs::config::Config, tests::utils::fake_history_tree,
|
|
||||||
};
|
|
||||||
|
|
||||||
let _init_guard = zebra_test::init();
|
let _init_guard = zebra_test::init();
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ use crate::{
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(feature = "getblocktemplate-rpcs")]
|
#[cfg(feature = "getblocktemplate-rpcs")]
|
||||||
use crate::methods::{get_block_template_rpcs, GetBlockTemplateRpc, GetBlockTemplateRpcImpl};
|
use crate::methods::{GetBlockTemplateRpc, GetBlockTemplateRpcImpl};
|
||||||
|
|
||||||
pub mod http_request_compatibility;
|
pub mod http_request_compatibility;
|
||||||
pub mod rpc_call_compatibility;
|
pub mod rpc_call_compatibility;
|
||||||
|
@ -95,11 +95,7 @@ impl RpcServer {
|
||||||
AddressBook,
|
AddressBook,
|
||||||
>(
|
>(
|
||||||
config: Config,
|
config: Config,
|
||||||
#[cfg(feature = "getblocktemplate-rpcs")]
|
mining_config: crate::config::mining::Config,
|
||||||
mining_config: get_block_template_rpcs::config::Config,
|
|
||||||
#[cfg(not(feature = "getblocktemplate-rpcs"))]
|
|
||||||
#[allow(unused_variables)]
|
|
||||||
mining_config: (),
|
|
||||||
build_version: VersionString,
|
build_version: VersionString,
|
||||||
user_agent: UserAgentString,
|
user_agent: UserAgentString,
|
||||||
mempool: Buffer<Mempool, mempool::Request>,
|
mempool: Buffer<Mempool, mempool::Request>,
|
||||||
|
|
|
@ -208,13 +208,18 @@ impl StartCmd {
|
||||||
// And give it time to clear its queue
|
// And give it time to clear its queue
|
||||||
tokio::task::yield_now().await;
|
tokio::task::yield_now().await;
|
||||||
|
|
||||||
|
#[cfg(not(feature = "getblocktemplate-rpcs"))]
|
||||||
|
if config.mining != zebra_rpc::config::mining::Config::default() {
|
||||||
|
warn!(
|
||||||
|
"Unused mining section in config,\
|
||||||
|
compile with 'getblocktemplate-rpcs' feature to use mining RPCs"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// Launch RPC server
|
// Launch RPC server
|
||||||
let (rpc_task_handle, rpc_tx_queue_task_handle, rpc_server) = RpcServer::spawn(
|
let (rpc_task_handle, rpc_tx_queue_task_handle, rpc_server) = RpcServer::spawn(
|
||||||
config.rpc.clone(),
|
config.rpc.clone(),
|
||||||
#[cfg(feature = "getblocktemplate-rpcs")]
|
|
||||||
config.mining.clone(),
|
config.mining.clone(),
|
||||||
#[cfg(not(feature = "getblocktemplate-rpcs"))]
|
|
||||||
(),
|
|
||||||
build_version(),
|
build_version(),
|
||||||
user_agent(),
|
user_agent(),
|
||||||
mempool.clone(),
|
mempool.clone(),
|
||||||
|
|
|
@ -38,7 +38,7 @@ pub struct ZebradConfig {
|
||||||
/// RPC configuration
|
/// RPC configuration
|
||||||
pub rpc: zebra_rpc::config::Config,
|
pub rpc: zebra_rpc::config::Config,
|
||||||
|
|
||||||
#[cfg(feature = "getblocktemplate-rpcs")]
|
#[serde(skip_serializing_if = "zebra_rpc::config::mining::Config::skip_getblocktemplate")]
|
||||||
/// Mining configuration
|
/// Mining configuration
|
||||||
pub mining: zebra_rpc::methods::get_block_template_rpcs::config::Config,
|
pub mining: zebra_rpc::config::mining::Config,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue