0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-10 10:52:31 -05:00
bitcoin-bitcoin-core/src/index
fanquake 4175c332b9
Merge bitcoin/bitcoin#26215: index: Improve BaseIndex::BlockUntilSyncedToCurrentChain reliability
8891949bdc index: Improve BaseIndex::BlockUntilSyncedToCurrentChain reliability (Ryan Ofsky)

Pull request description:

  Since commit f08c9fb0c6 from PR https://github.com/bitcoin/bitcoin/pull/21726, index  `BlockUntilSyncedToCurrentChain` behavior has been less reliable, and there has also been a race condition in the `coinstatsindex_initial_sync` unit test.

  It seems better for `BlockUntilSyncedToCurrentChain` to actually wait for the last connected block to be fully processed, than to be able to return before prune locks are set, so this switches the order of `m_best_block_index = block;` and `UpdatePruneLock` statements in `SetBestBlockIndex` to make it more reliable.

  Also since commit f08c9fb0c6, there has been a race condition in the `coinstatsindex_initial_sync` test. Before that commit, the atomic index best block pointer `m_best_block_index` was updated as the last step of `BaseIndex::BlockConnected`, so `BlockUntilSyncedToCurrentChain` could safely be used in tests to wait for the last `BlockConnected` notification to be finished before stopping and destroying the index.  But after that commit, calling `BlockUntilSyncedToCurrentChain` is no longer sufficient, and there is a race between the test shutdown code which destroys the index object and the new code introduced in that commit calling `AllowPrune()` and `GetName()` on the index object. Reproducibility instructions for this are in https://github.com/bitcoin/bitcoin/issues/25365#issuecomment-1259744133

  This commit fixes the `coinstatsindex_initial_sync` race condition, even though it will require an additional change to silence TSAN false positives, https://github.com/bitcoin/bitcoin/pull/26188, after it is fixed. So this partially addresses but does not resolve the bug reporting TSAN errors https://github.com/bitcoin/bitcoin/issues/25365.

  There is no known race condition outside of test code currently, because the bitcoind `Shutdown` function calls `FlushBackgroundCallbacks` not `BlockUntilSyncedToCurrentChain` to safely shut down.

  Co-authored-by: vasild
  Co-authored-by: MarcoFalke

ACKs for top commit:
  mzumsande:
    re-ACK 8891949bdc

Tree-SHA512: 52e29e3772a0c92873c54e5ffb31dd66a909b68a2031b7585713cd1d976811289c98bd9bb41679a8689062f03be4f97bb8368696e789caa4607c2fd8b1fe289b
2022-10-10 14:23:00 +08:00
..
base.cpp index: Improve BaseIndex::BlockUntilSyncedToCurrentChain reliability 2022-10-05 11:06:58 -04:00
base.h refactor: use std::string for index names 2022-09-13 19:10:41 +01:00
blockfilterindex.cpp refactor: use std::string for index names 2022-09-13 19:10:41 +01:00
blockfilterindex.h refactor: move DEFAULT_BLOCKFILTERINDEX from val to blockfilterindex 2022-10-03 18:19:40 +01:00
coinstatsindex.cpp refactor: use std::string for index names 2022-09-13 19:10:41 +01:00
coinstatsindex.h refactor: move DEFAULT_COINSTATSINDEX from validation to coinstatsindex 2022-10-03 18:19:39 +01:00
disktxpos.h scripted-diff: Bump copyright headers 2020-12-31 09:45:41 +01:00
txindex.cpp refactor: use std::string for index names 2022-09-13 19:10:41 +01:00
txindex.h refactor: move DEFAULT_TXINDEX from validation to txindex 2022-10-03 18:19:39 +01:00