From ed86f2dd1da370fe2dbf7db475afc41b218cbc5f Mon Sep 17 00:00:00 2001 From: Duke Date: Thu, 12 Sep 2024 00:21:56 -0400 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. Ported from ZEC commit e2cd1b761fe556bc6d61849346902c3611530307 --- src/main.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index ae5e27916..169124334 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -33,6 +33,7 @@ #include "net.h" #include "netmessagemaker.h" #include "pow.h" +#include "time.h" #include "script/interpreter.h" #include "txdb.h" #include "txmempool.h" @@ -4333,7 +4334,15 @@ bool ActivateBestChain(bool fSkipdpow, CValidationState &state, CBlock *pblock) CBlockIndex *pindexMostWork = NULL; const CChainParams& chainParams = Params(); 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. 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. + // + boost::this_thread::sleep_for(boost::chrono::microseconds(200)); if (ShutdownRequested()) break;