init: add missing cs_main lock
Summary:
BlockManager::m_block_tree_db is protected by cs_main, so take the cs_main lock while accessing it.
The use of the lambda in Assert and the fact that cs_main is a global lock rather than scoped within a class means that clang's thread safety checks don't catch this.
After D14620, the following warning appears when building with clang:
[364/540] Building CXX object src/CMakeFiles/server.dir/init.cpp.o /home/pierre/dev/bitcoin-abc/src/init.cpp:2538:45: warning: passing variable 'm_block_tree_db' by reference requires holding mutex 'cs_main' [-Wthread-safety-reference] *Assert(chainman.m_blockman.m_block_tree_db))}) {
This is a backport of core#24672
Test Plan:
With clang and Debug, with D14620 rebased on this diff:
ninja all check-all
Reviewers: #bitcoin_abc, Fabien
Reviewed By: #bitcoin_abc, Fabien
Differential Revision: https://reviews.bitcoinabc.org/D14641