From a99b76f26958829c2b9ca4ffa5b1d81912b8acc7 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Mon, 4 Dec 2017 18:25:57 -0500 Subject: Require no cs_main lock for ProcessNewBlock/ActivateBestChain This requires the removal of some very liberal (incorrect) cs_mains sprinkled in some tests. It adds some chainActive.Tip() races, but the tests are all single-threaded anyway. --- src/validation.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/validation.cpp') diff --git a/src/validation.cpp b/src/validation.cpp index 75c40b22fc..71a51c499c 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -2559,6 +2559,7 @@ bool CChainState::ActivateBestChain(CValidationState &state, const CChainParams& // far from a guarantee. Things in the P2P/RPC will often end up calling // us in the middle of ProcessNewBlock - do not assume pblock is set // sanely for performance or correctness! + AssertLockNotHeld(cs_main); CBlockIndex *pindexMostWork = nullptr; CBlockIndex *pindexNewTip = nullptr; @@ -3383,6 +3384,8 @@ bool CChainState::AcceptBlock(const std::shared_ptr& pblock, CVali bool ProcessNewBlock(const CChainParams& chainparams, const std::shared_ptr pblock, bool fForceProcessing, bool *fNewBlock) { + AssertLockNotHeld(cs_main); + { CBlockIndex *pindex = nullptr; if (fNewBlock) *fNewBlock = false; -- cgit v1.2.3 From 36137497f1e2b3324ca84550f4f295dcd605d1fa Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Mon, 4 Dec 2017 18:57:55 -0500 Subject: Block ActivateBestChain to empty validationinterface queue --- src/validation.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/validation.cpp') diff --git a/src/validation.cpp b/src/validation.cpp index 71a51c499c..23ce6509d5 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -40,6 +40,7 @@ #include #include +#include #include #include @@ -2566,6 +2567,18 @@ bool CChainState::ActivateBestChain(CValidationState &state, const CChainParams& int nStopAtHeight = gArgs.GetArg("-stopatheight", DEFAULT_STOPATHEIGHT); do { boost::this_thread::interruption_point(); + + if (GetMainSignals().CallbacksPending() > 10) { + // Block until the validation queue drains. This should largely + // never happen in normal operation, however may happen during + // reindex, causing memory blowup if we run too far ahead. + std::promise promise; + CallFunctionInValidationInterfaceQueue([&promise] { + promise.set_value(); + }); + promise.get_future().wait(); + } + if (ShutdownRequested()) break; -- cgit v1.2.3 From 97d2b09c124e6e5803f7fd4503348d9710d1260f Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Sun, 24 Dec 2017 12:13:13 -0500 Subject: Add helper to wait for validation interface queue to catch up --- src/validation.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'src/validation.cpp') diff --git a/src/validation.cpp b/src/validation.cpp index 23ce6509d5..1c024ce2ae 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -2572,11 +2572,7 @@ bool CChainState::ActivateBestChain(CValidationState &state, const CChainParams& // Block until the validation queue drains. This should largely // never happen in normal operation, however may happen during // reindex, causing memory blowup if we run too far ahead. - std::promise promise; - CallFunctionInValidationInterfaceQueue([&promise] { - promise.set_value(); - }); - promise.get_future().wait(); + SyncWithValidationInterfaceQueue(); } if (ShutdownRequested()) -- cgit v1.2.3