Fix chain tip data race and corrupt rest response
Summary:
https://github.com/bitcoin/bitcoin/pull/25077/commits/fa530bcb9c13b58ab1b2068b48aa3fff910e2f87
Add ChainstateManager::GetMutex(), an alias for ::cs_main
https://github.com/bitcoin/bitcoin/pull/25077/commits/fa97a528d6382a0163d5aa7d37ecbf93579b8186
Fix UB/data-race in RPCNotifyBlockChange
ActiveTip() is *not* thread-safe, as the required ::cs_main lock will be
released as ActiveChainstate() returns.ActiveTip() is an alias for ActiveChainstate().m_chain.Tip(), so m_chain
may be involved in a data-race (UB).
https://github.com/bitcoin/bitcoin/pull/25077/commits/fac15ff673f0d6f84ea1eaae855597da02b0e510
Fix logical race in rest_getutxos
Calling ActiveHeight() and ActiveTip() subsequently without holding the
::cs_main lock over both calls may result in a height that does not
correspond to the tip due to a race.Fix this by holding the lock.
https://github.com/bitcoin/bitcoin/pull/25077/commits/fac04cb6ba1d032587bd02eab2247fd655a548cd
refactor: Add lock annotations to Active* methods
This is a refactor, putting the burden to think about thread safety to
the caller. Otherwise, there is a risk that the caller will assume
thread safety where none exists, as is evident in the previous two
commits.
This is a backport of core#25077
Depends on D14642
Test Plan:
with debug & tsan
ninja all check-all
Reviewers: #bitcoin_abc, Fabien
Reviewed By: #bitcoin_abc, Fabien
Subscribers: Fabien
Differential Revision: https://reviews.bitcoinabc.org/D14643