From e2cd1b761fe556bc6d61849346902c3611530307 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Fri, 3 Feb 2023 23:10:32 +0000 Subject: [PATCH] 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 Co-authored-by: Kris Nuttycombe --- src/main.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index cbcaa83c2..838db3871 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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. + // + boost::this_thread::sleep_for(boost::chrono::microseconds(200)); bool fInitialDownload; int nNewHeight;