mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-06-03 16:02:34 +02:00
Merge 12965 via scriptthreads-27+knots
This commit is contained in:
commit
1c0147ac12
@ -182,6 +182,7 @@ public:
|
||||
}
|
||||
|
||||
bool HasThreads() const { return !m_worker_threads.empty(); }
|
||||
size_t ThreadCount() const { return m_worker_threads.size(); }
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -1497,6 +1497,69 @@ static RPCHelpMan verifychain()
|
||||
};
|
||||
}
|
||||
|
||||
static RPCHelpMan scriptthreadsinfo()
|
||||
{
|
||||
return RPCHelpMan{"scriptthreadsinfo",
|
||||
"\nShow information about the script verification threads.\n",
|
||||
{},
|
||||
RPCResult{
|
||||
RPCResult::Type::OBJ, "", "",
|
||||
{
|
||||
{RPCResult::Type::BOOL, "enabled", "true if script verification threads are enabled (see setscriptthreadsenabled)."},
|
||||
{RPCResult::Type::NUM, "num_script_check_threads", "The total number of script verification threads, when enabled."},
|
||||
},
|
||||
},
|
||||
RPCExamples{
|
||||
HelpExampleCli("scriptthreadsinfo", "")
|
||||
+ HelpExampleRpc("scriptthreadsinfo", "")
|
||||
},
|
||||
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
||||
{
|
||||
ChainstateManager& chainman = EnsureAnyChainman(request.context);
|
||||
UniValue ret(UniValue::VOBJ);
|
||||
size_t thread_count{chainman.m_script_check_queue_enabled ? chainman.GetCheckQueue().ThreadCount() : 0};
|
||||
ret.pushKV("enabled", (bool)thread_count);
|
||||
ret.pushKV("num_script_check_threads", (int64_t)thread_count + 1);
|
||||
return ret;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
static RPCHelpMan setscriptthreadsenabled()
|
||||
{
|
||||
return RPCHelpMan{"setscriptthreadsenabled",
|
||||
"\nDisable/enable script verification threads, thereby reducing CPU usage on multicore systems on demand.\n"
|
||||
"Disabling script verification threads may result in a significant slow-down during synchronisation.\n"
|
||||
"Has no effect on single core machines or if started with -par=<-<numcores>\n",
|
||||
{
|
||||
{"state", RPCArg::Type::BOOL, RPCArg::Optional::NO, "false if script verification threads should be disabled (true for re-enabling)"},
|
||||
},
|
||||
RPCResult{RPCResult::Type::NONE, "", ""},
|
||||
RPCExamples{
|
||||
HelpExampleCli("setscriptthreadsenabled", "false")
|
||||
+ HelpExampleRpc("setscriptthreadsenabled", "false")
|
||||
},
|
||||
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
||||
{
|
||||
ChainstateManager& chainman = EnsureAnyChainman(request.context);
|
||||
LOCK(cs_main);
|
||||
|
||||
const bool parallel_script_checks{request.params[0].get_bool()};
|
||||
if (parallel_script_checks) {
|
||||
if (!chainman.GetCheckQueue().HasThreads()) {
|
||||
throw JSONRPCError(RPC_MISC_ERROR, "Script verification threads are disabled (single core machine or -par=<-<numcores>)");
|
||||
}
|
||||
|
||||
chainman.m_script_check_queue_enabled = true;
|
||||
} else {
|
||||
chainman.m_script_check_queue_enabled = false;
|
||||
}
|
||||
|
||||
return NullUniValue;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
static void SoftForkDescPushBack(const CBlockIndex* blockindex, UniValue& softforks, const ChainstateManager& chainman, Consensus::BuriedDeployment dep)
|
||||
{
|
||||
// For buried deployments.
|
||||
@ -3428,6 +3491,8 @@ void RegisterBlockchainRPCCommands(CRPCTable& t)
|
||||
{"blockchain", &setprunelock},
|
||||
{"blockchain", &pruneblockchain},
|
||||
{"blockchain", &verifychain},
|
||||
{"blockchain", &scriptthreadsinfo},
|
||||
{"blockchain", &setscriptthreadsenabled},
|
||||
{"blockchain", &preciousblock},
|
||||
{"blockchain", &scantxoutset},
|
||||
{"blockchain", &scanblocks},
|
||||
|
@ -313,6 +313,7 @@ static const CRPCConvertParam vRPCConvertParams[] =
|
||||
{ "echojson", 9, "arg9" },
|
||||
{ "rescanblockchain", 0, "start_height"},
|
||||
{ "rescanblockchain", 1, "stop_height"},
|
||||
{ "setscriptthreadsenabled", 0, "state"},
|
||||
{ "createwallet", 1, "disable_private_keys"},
|
||||
{ "createwallet", 2, "blank"},
|
||||
{ "createwallet", 4, "avoid_reuse"},
|
||||
|
@ -169,11 +169,13 @@ const std::vector<std::string> RPC_COMMANDS_SAFE_FOR_FUZZING{
|
||||
"reconsiderblock",
|
||||
"scanblocks",
|
||||
"scantxoutset",
|
||||
"scriptthreadsinfo",
|
||||
"sendmsgtopeer", // when no peers are connected, no p2p message is sent
|
||||
"sendrawtransaction",
|
||||
"setmocktime",
|
||||
"setnetworkactive",
|
||||
"setprunelock",
|
||||
"setscriptthreadsenabled",
|
||||
"signmessagewithprivkey",
|
||||
"signrawtransactionwithkey",
|
||||
"submitblock",
|
||||
|
@ -2196,7 +2196,7 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
|
||||
|
||||
uint256 block_hash{block.GetHash()};
|
||||
assert(*pindex->phashBlock == block_hash);
|
||||
const bool parallel_script_checks{m_chainman.GetCheckQueue().HasThreads()};
|
||||
const bool parallel_script_checks{m_chainman.m_script_check_queue_enabled && m_chainman.GetCheckQueue().HasThreads()};
|
||||
|
||||
const auto time_start{SteadyClock::now()};
|
||||
const CChainParams& params{m_chainman.GetParams()};
|
||||
|
@ -1271,6 +1271,7 @@ public:
|
||||
//! nullopt.
|
||||
std::optional<int> GetSnapshotBaseHeight() const EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
|
||||
|
||||
bool m_script_check_queue_enabled{true};
|
||||
CCheckQueue<CScriptCheck>& GetCheckQueue() { return m_script_check_queue; }
|
||||
|
||||
~ChainstateManager();
|
||||
|
Loading…
Reference in New Issue
Block a user