HomePhabricator

validation: Guard the active_chainstate with cs_main

Description

validation: Guard the active_chainstate with cs_main

Summary:
This avoids a potential race-condition where a thread is reading the
ChainstateManager::m_active_chainstate pointer while another one is
writing to it. There is no portable guarantee that reading/writing the
pointer is thread-safe.

This is also done in way that mimics ::ChainstateActive(), so the
transition from that function to this method is easy.

This is a backport of core#20749 [1/17]
https://github.com/bitcoin/bitcoin/pull/20749/commits/f92dc6557a153b390a1ae1d0808ff7ed5d02c66e

Depends on D11171

Test Plan:
With debug:
ninja all check-all

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D11172

Details

Provenance
Carl Dong <contact@carldong.me>Authored on Jan 27 2021, 21:20
PiRKCommitted on Mar 16 2022, 09:11
PiRKPushed on Mar 16 2022, 09:11
Reviewer
Restricted Project
Differential Revision
D11172: validation: Guard the active_chainstate with cs_main
Parents
rABC25f5ae14198f: test: Add new ChainTestingSetup and use it
Branches
Unknown
Tags
Unknown