[backport#15402] Prevent callback overruns in InvalidateBlock and RewindBlockIndex
Summary:
https://github.com/bitcoin/bitcoin/pull/15402/commits/9ce9c37004440d6a329874dbf66b51666d497dcb
This thing has been merged (D4803) and reverted (D4959) before. Seems to be working correctly now, with the lock to m_cs_chainstate in ActivateBestChain having a corresponding one in UnwindBlock.
Concludes backport of Core PR15402
Test Plan:
cmake -GNinja -DCMAKE_BUILD_TYPE=Debug ninja check check-functional
also
build without this patch, invalidate block #6 or similarly deep, see that bitcoind memory usage just keeps going up, even past 30% on my 16GB machine. build with this patch and do the same, memory usage stays steady at ~12% no matter how far you disconnect blocks.
Reviewers: #bitcoin_abc, jasonbcox, deadalnix
Reviewed By: #bitcoin_abc, jasonbcox, deadalnix
Subscribers: jasonbcox
Differential Revision: https://reviews.bitcoinabc.org/D7213