Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Make CCheckQueue RAII-styled #18731

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
refactor: Drop g_parallel_script_checks global
  • Loading branch information
hebasto committed Sep 24, 2020
commit 56d40da18fb60641c6dd683f77837cd32c0e24dd
3 changes: 0 additions & 3 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1305,9 +1305,6 @@ bool AppInitMain(const util::Ref& context, NodeContext& node, interfaces::BlockA
script_threads = std::min(script_threads, MAX_SCRIPTCHECK_THREADS);

LogPrintf("Script verification uses %d additional threads\n", script_threads);
if (script_threads >= 1) {
g_parallel_script_checks = true;
}

assert(!node.scheduler);
node.scheduler = MakeUnique<CScheduler>();
Expand Down
3 changes: 1 addition & 2 deletions src/test/util/setup_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,8 @@ TestingSetup::TestingSetup(const std::string& chainName, const std::vector<const
m_node.mempool = MakeUnique<CTxMemPool>(&::feeEstimator);
m_node.mempool->setSanityCheck(1.0);

// Start script-checking threads. Set g_parallel_script_checks to true so they are used.
// Start script-checking threads.
constexpr int script_check_threads = 2;
g_parallel_script_checks = true;
m_node.chainman = &::g_chainman;
m_node.chainman->InitializeChainstate(*m_node.mempool, uint256(), script_check_threads);
::ChainstateActive().InitCoinsDB(
Expand Down
6 changes: 3 additions & 3 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ CBlockIndex *pindexBestHeader = nullptr;
Mutex g_best_block_mutex;
std::condition_variable g_best_block_cv;
uint256 g_best_block;
bool g_parallel_script_checks{false};
std::atomic_bool fImporting(false);
std::atomic_bool fReindex(false);
bool fHavePruned = false;
Expand Down Expand Up @@ -1266,6 +1265,7 @@ void CoinsViews::InitCache()
CChainState::CChainState(CTxMemPool& mempool, BlockManager& blockman, uint256 from_snapshot_blockhash, int script_check_worker_threads)
: m_blockman(blockman),
m_mempool(mempool),
m_parallel_script_checks{script_check_worker_threads > 0},
m_script_check_queue{MakeUnique<CCheckQueue<CScriptCheck>>(128 /* batch size */, script_check_worker_threads)},
m_from_snapshot_blockhash(from_snapshot_blockhash)
{
Expand Down Expand Up @@ -2119,7 +2119,7 @@ bool CChainState::ConnectBlock(const CBlock& block, BlockValidationState& state,
// in multiple threads). Preallocate the vector size so a new allocation
// doesn't invalidate pointers into the vector, and keep txsdata in scope
// for as long as `control`.
CCheckQueueControl<CScriptCheck> control(fScriptChecks && g_parallel_script_checks ? m_script_check_queue.get() : nullptr);
CCheckQueueControl<CScriptCheck> control(fScriptChecks && m_parallel_script_checks ? m_script_check_queue.get() : nullptr);
std::vector<PrecomputedTransactionData> txsdata(block.vtx.size());

std::vector<int> prevheights;
Expand Down Expand Up @@ -2178,7 +2178,7 @@ bool CChainState::ConnectBlock(const CBlock& block, BlockValidationState& state,
std::vector<CScriptCheck> vChecks;
bool fCacheResults = fJustCheck; /* Don't cache results if we're actually connecting blocks (still consult the cache, though) */
TxValidationState tx_state;
if (fScriptChecks && !CheckInputScripts(tx, tx_state, view, flags, fCacheResults, fCacheResults, txsdata[i], g_parallel_script_checks ? &vChecks : nullptr)) {
if (fScriptChecks && !CheckInputScripts(tx, tx_state, view, flags, fCacheResults, fCacheResults, txsdata[i], m_parallel_script_checks ? &vChecks : nullptr)) {
// Any transaction validation failure in ConnectBlock is a block consensus failure
state.Invalid(BlockValidationResult::BLOCK_CONSENSUS,
tx_state.GetRejectReason(), tx_state.GetDebugMessage());
Expand Down
7 changes: 3 additions & 4 deletions src/validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,6 @@ extern std::condition_variable g_best_block_cv;
extern uint256 g_best_block;
extern std::atomic_bool fImporting;
extern std::atomic_bool fReindex;
/** Whether there are dedicated script-checking threads running.
* False indicates all script checking is done on the main threadMessageHandler thread.
*/
extern bool g_parallel_script_checks;
extern bool fRequireStandard;
extern bool fCheckBlockIndex;
extern bool fCheckpointsEnabled;
Expand Down Expand Up @@ -542,6 +538,9 @@ class CChainState {
//! Manages the UTXO set, which is a reflection of the contents of `m_chain`.
std::unique_ptr<CoinsViews> m_coins_views;

//! Whether there are dedicated script-checking worker threads running.
//! False indicates all script checking is done on the main threadMessageHandler thread.
const bool m_parallel_script_checks;
const std::unique_ptr<CCheckQueue<CScriptCheck>> m_script_check_queue;

public:
Expand Down