Page MenuHomePhabricator

init: add missing cs_main lock
ClosedPublic

Authored by PiRK on Oct 16 2023, 06:17.

Details

Reviewers
Fabien
Group Reviewers
Restricted Project
Commits
rABC47e002683420: 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

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

PiRK requested review of this revision.Oct 16 2023, 06:17
This revision is now accepted and ready to land.Oct 16 2023, 08:03
This revision was automatically updated to reflect the committed changes.