HomePhabricator

Call RewindBlockIndex without cs_main held

Description

Call RewindBlockIndex without cs_main held

Summary:
This PR makes a number of improvements to the InvalidateBlock (invalidateblock RPC) and RewindBlockIndex functions, primarily around breaking up their long-term cs_main holding. In addition:

  • They're made safely interruptible (bitcoind can be shutdown, and no progress in either will be lost, though if incomplete, invalidateblock won't continue after restart and will need to be called again)
  • The validation queue is prevented from overflowing (meaning invalidateblock on a very old block will not drive bitcoind OOM) (see #14289).
  • invalidateblock won't bother to move transactions back into the mempool after 10 blocks (optimization).

Partial Backport of Bitcoin Core PR15402 (commit 880ce7d):
https://github.com/bitcoin/bitcoin/commit/880ce7d46b51835c00d77a366ec28f54a05239df

Modified version of "Call RewindBlockIndex without cs_main held"

RewindBlockIndex function was removed on D4728, but the locks were moved in`AppInitMain` function.

Test Plan:

  1. Build with Clang in Debug mode:
CXX=clang++ CC=clang cmake .. -D CMAKE_CXX_FLAGS="-Werror=thread-safety-analysis" -GNinja -DCMAKE_BUILD_TYPE=Debug
ninja check
  1. Verify that the compiler has not emitted a thread-safety warning.
  2. Run the node: ./src/bitcoind -regtest
  3. Verify that text similar to "Assertion failed: lock ... not held ..." is not printed on stderr.

Reviewers: #bitcoin_abc, deadalnix, markblundeberg

Reviewed By: #bitcoin_abc, markblundeberg

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

Details

Committed
fpelliccioniJan 14 2020, 15:18
Pushed
fpelliccioniJan 14 2020, 15:18
Reviewer
Restricted Project
Differential Revision
D4757: Call RewindBlockIndex without cs_main held
Parents
rABCbe651fb90eb6: [wallet] Support creating a blank wallet
Branches
Unknown
Tags
Unknown

Event Timeline