Disclaimer: I couldn’t reproduce this issue in practice on ext4 and ntfs partitions on a x86 CPU, but I think that this issue should be solved in the long-term.
Basically, CBlockIndex::nStatus
is used to hold a bunch of flags (e.g. whether the block data is currently on the hard drive, or whether the block data was verified at some point in the past). Most of this access is from validation, which happens to hold the cs_main
lock. However, some of the access (e.g. background index threads, or RPC calls) does not take the cs_main
lock, so the access to nStatus
is not guarded for them. In theory, this could turn out to be racy in combination with pruning.
I am not sure how to solve this. Some ideas:
- Put
nStatus
under thecs_main
lock. –> meh, this will affect validation performance when polling on RPC - Make a “read-write-lock” for
nStatus
, similar to::mempool.cs
. I.e. when writingnStatus
, thecs_main
lock and the read lock is taken and when readingnStatus
, only the read lock is taken. Maybe use astd::shared_mutex
? - Any other ideas … !?