-
Notifications
You must be signed in to change notification settings - Fork 38.7k
validation: avoid potential deadlocks in ValidationInterface #15205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
validation: avoid potential deadlocks in ValidationInterface #15205
Conversation
See discussions here: - bitcoin#11722 (review) - bitcoin#13168 (comment)
af05222 to
76d0fa3
Compare
37f3992 to
c024cc9
Compare
|
Restarted appveyor, unrelated error. |
c024cc9 to
5a18208
Compare
|
Pushed an update futureproofing all calls to |
7c01deb to
6f330dc
Compare
Since ActivateBestChain will in certain cases block in order to allow the ValidationInterface queue to drain, it cannot safely be called from within ValidationInterface callbacks. This patch adds assertions preventing that when DEBUG_LOCKORDER. We slightly rework the ValidationInterface class, adding an `AddToProcessQueue()` method that handles scheduling a callback. When the scheduling queue is initiated, we make the thread aware it's managed by ValidationInterface.
Also adds default constructor and destructor to CMainSignals to avoid build errors due to the forward declaration of MainSignalsInstance.
6f330dc to
93e09ee
Compare
|
I've taken @practicalswift's advice on declaration conditional on |
|
We discussed a better approach today on IRC (http://www.erisian.com.au/bitcoin-core-dev/log-2019-01-22.html), which is to conditionally move all |
Currently, the potential for a deadlock exists if
ActivateBestChain()is called from within theValidationInterfacescheduler thread. This is because ABC itself avoids overrunning the VI queue by waiting for it to drain once it has passed a certain depth.To avoid this (or at least disallow it during CI runs), this change introduces thread_local state that gets set to indicate execution on ValidationInterface threads. If we've compiled with
DEBUG_LOCKORDER, calling ABC from within a VI thread throws an exception. A small,necessaryrefactoring onCMainSignalsis included.This changeset also includes a commit from #13168 that limits the platforms where we can rely on the use of thread_local.