HomePhabricator

Release cs_main during InvalidateBlock iterations

Description

Release cs_main during InvalidateBlock iterations

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 241b2c7):
https://github.com/bitcoin/bitcoin/pull/15402/commits/9bb32eb571a846b66ed3bac493f55cee11a3a1b9

Release cs_main during InvalidateBlock iterations

Depends on D4758

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-all
  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, Fabien

Reviewed By: #bitcoin_abc, deadalnix, Fabien

Subscribers: Fabien

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

Details

Provenance
Pieter Wuille <pieter.wuille@gmail.com>Authored on Feb 14 2019, 00:37
fpelliccioniCommitted on Jan 14 2020, 16:05
fpelliccioniPushed on Jan 14 2020, 16:09
Reviewer
Restricted Project
Differential Revision
D4802: Release cs_main during InvalidateBlock iterations
Parents
rSTAGING9096e76f01e5: Call InvalidateBlock without cs_main held
Branches
Unknown
Tags
Unknown
References
tag: phabricator/base/15462, tag: phabricator/base/15461, tag: phabricator/base/15453