Sleep for 200us before each ActivateBestChainStep call

This should lower the main thread's likelihood to immediately reacquire
cs_main after dropping it, which should help ThreadNotifyWallets and the
RPC methods to acquire cs_main more quickly.

Co-authored-by: Daira Hopwood <daira@jacaranda.org>
Co-authored-by: Kris Nuttycombe <kris@nutty.land>
This commit is contained in:
Jack Grigg 2023-02-03 23:10:32 +00:00
parent bd2cabf6fd
commit e2cd1b761f
1 changed files with 10 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,15 @@ 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; this sleep adds ~6.6 minutes to the time
// required to activate the best chain from genesis.
//
// This is defined to be an interruption point.
// <https://www.boost.org/doc/libs/1_70_0/doc/html/thread/thread_management.html#interruption_points>
boost::this_thread::sleep_for(boost::chrono::microseconds(200));
bool fInitialDownload;
int nNewHeight;