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};
|
||||
|
||||
pub mod mining;
|
||||
|
||||
/// RPC configuration section.
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[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,
|
||||
};
|
||||
|
||||
pub mod config;
|
||||
pub mod constants;
|
||||
pub mod get_block_template;
|
||||
pub mod types;
|
||||
|
@ -315,7 +314,7 @@ where
|
|||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn new(
|
||||
network: Network,
|
||||
mining_config: config::Config,
|
||||
mining_config: crate::config::mining::Config,
|
||||
mempool: Buffer<Mempool, mempool::Request>,
|
||||
state: State,
|
||||
latest_chain_tip: Tip,
|
||||
|
|
|
@ -36,18 +36,15 @@ use zebra_test::{
|
|||
};
|
||||
|
||||
use crate::methods::{
|
||||
get_block_template_rpcs::{
|
||||
self,
|
||||
types::{
|
||||
get_block_template::{self, GetBlockTemplateRequestMode},
|
||||
get_mining_info,
|
||||
hex_data::HexData,
|
||||
long_poll::{LongPollId, LONG_POLL_ID_LENGTH},
|
||||
peer_info::PeerInfo,
|
||||
submit_block,
|
||||
subsidy::BlockSubsidy,
|
||||
unified_address, validate_address, z_validate_address,
|
||||
},
|
||||
get_block_template_rpcs::types::{
|
||||
get_block_template::{self, GetBlockTemplateRequestMode},
|
||||
get_mining_info,
|
||||
hex_data::HexData,
|
||||
long_poll::{LongPollId, LONG_POLL_ID_LENGTH},
|
||||
peer_info::PeerInfo,
|
||||
submit_block,
|
||||
subsidy::BlockSubsidy,
|
||||
unified_address, validate_address, z_validate_address,
|
||||
},
|
||||
tests::{snapshot::EXCESSIVE_BLOCK_HEIGHT, utils::fake_history_tree},
|
||||
GetBlockHash, GetBlockTemplateRpc, GetBlockTemplateRpcImpl,
|
||||
|
@ -100,7 +97,7 @@ pub async fn test_responses<State, ReadState>(
|
|||
let mut mock_sync_status = MockSyncStatus::default();
|
||||
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])),
|
||||
extra_coinbase_data: None,
|
||||
debug_like_zcashd: true,
|
||||
|
|
|
@ -1203,7 +1203,6 @@ async fn rpc_getblocktemplate_mining_address(use_p2pkh: bool) {
|
|||
|
||||
use crate::methods::{
|
||||
get_block_template_rpcs::{
|
||||
config::Config,
|
||||
constants::{
|
||||
GET_BLOCK_TEMPLATE_CAPABILITIES_FIELD, GET_BLOCK_TEMPLATE_MUTABLE_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])),
|
||||
};
|
||||
|
||||
let mining_config = Config {
|
||||
let mining_config = crate::config::mining::Config {
|
||||
miner_address,
|
||||
extra_coinbase_data: None,
|
||||
debug_like_zcashd: true,
|
||||
|
@ -1668,9 +1667,7 @@ async fn rpc_getdifficulty() {
|
|||
|
||||
use zebra_state::{GetBlockTemplateChainInfo, ReadRequest, ReadResponse};
|
||||
|
||||
use crate::methods::{
|
||||
get_block_template_rpcs::config::Config, tests::utils::fake_history_tree,
|
||||
};
|
||||
use crate::{config::mining::Config, methods::tests::utils::fake_history_tree};
|
||||
|
||||
let _init_guard = zebra_test::init();
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ use crate::{
|
|||
};
|
||||
|
||||
#[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 rpc_call_compatibility;
|
||||
|
@ -95,11 +95,7 @@ impl RpcServer {
|
|||
AddressBook,
|
||||
>(
|
||||
config: Config,
|
||||
#[cfg(feature = "getblocktemplate-rpcs")]
|
||||
mining_config: get_block_template_rpcs::config::Config,
|
||||
#[cfg(not(feature = "getblocktemplate-rpcs"))]
|
||||
#[allow(unused_variables)]
|
||||
mining_config: (),
|
||||
mining_config: crate::config::mining::Config,
|
||||
build_version: VersionString,
|
||||
user_agent: UserAgentString,
|
||||
mempool: Buffer<Mempool, mempool::Request>,
|
||||
|
|
|
@ -208,13 +208,18 @@ impl StartCmd {
|
|||
// And give it time to clear its queue
|
||||
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
|
||||
let (rpc_task_handle, rpc_tx_queue_task_handle, rpc_server) = RpcServer::spawn(
|
||||
config.rpc.clone(),
|
||||
#[cfg(feature = "getblocktemplate-rpcs")]
|
||||
config.mining.clone(),
|
||||
#[cfg(not(feature = "getblocktemplate-rpcs"))]
|
||||
(),
|
||||
build_version(),
|
||||
user_agent(),
|
||||
mempool.clone(),
|
||||
|
|
|
@ -38,7 +38,7 @@ pub struct ZebradConfig {
|
|||
/// RPC configuration
|
||||
pub rpc: zebra_rpc::config::Config,
|
||||
|
||||
#[cfg(feature = "getblocktemplate-rpcs")]
|
||||
#[serde(skip_serializing_if = "zebra_rpc::config::mining::Config::skip_getblocktemplate")]
|
||||
/// 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