Fixes #16028.
Problem description:
LockAnnotation lock(::cs_main)
is a guarantee to the compiler thread analysis that ::cs_main
is locked (when it couldn’t be determined otherwise).
Despite being annotated with the locking guarantee …
… getTipLocator()
reads chainActive
(via ::ChainActive()
) without holding cs_main
.
This can be verified by adding the following AssertLockHeld(cs_main)
:
0$ git diff
1diff --git a/src/interfaces/chain.cpp b/src/interfaces/chain.cpp
2index 59623284d..9fc693a0f 100644
3--- a/src/interfaces/chain.cpp
4+++ b/src/interfaces/chain.cpp
5@@ -134,6 +134,7 @@ class LockImpl : public Chain::Lock
6 CBlockLocator getTipLocator() override
7 {
8 LockAnnotation lock(::cs_main);
9+ AssertLockHeld(::cs_main);
10 return ::ChainActive().GetLocator();
11 }
12 Optional<int> findLocatorFork(const CBlockLocator& locator) override
13$ make check
14../build-aux/test-driver: line 107: 12881 Aborted "$@" > $log_file 2>&1
15FAIL: qt/test/test_bitcoin-qt