Merge pull request #6424 from str4d/sideport-reindex-lock-contention-fix-5.4.1

Sleep for 200µs before each `ActivateBestChainStep` call
This commit is contained in:
Kris Nuttycombe 2023-02-10 15:40:51 -07:00 committed by GitHub
commit 8707a8e9f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 1 deletions

View File

@ -27,6 +27,7 @@
#include "policy/policy.h"
#include "pow.h"
#include "reverse_iterator.h"
#include "time.h"
#include "txmempool.h"
#include "ui_interface.h"
#include "undo.h"
@ -4386,7 +4387,17 @@ bool ActivateBestChain(CValidationState& state, const CChainParams& chainparams,
CBlockIndex *pindexMostWork = NULL;
CBlockIndex *pindexNewTip = NULL;
do {
boost::this_thread::interruption_point();
// Sleep briefly to allow other threads a chance at grabbing cs_main if
// we are connecting a long chain of blocks and would otherwise hold the
// lock almost continuously. As of 2023-02-03 the Zcash mainnet chain is
// around height 1,972,000; the total time slept here while activating
// the best chain from genesis to that height is ~6.6 minutes. This helps
// the internal wallet, if it is enabled, to keep up with the connected
// blocks, reducing the overall time until the node becomes usable.
//
// This is defined to be an interruption point.
// <https://www.boost.org/doc/libs/1_81_0/doc/html/thread/thread_management.html#interruption_points>
boost::this_thread::sleep_for(boost::chrono::microseconds(200));
bool fInitialDownload;
int nNewHeight;