0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-05 10:17:30 -05:00
bitcoin-bitcoin-core/src/test/util
MarcoFalke 7003b6ab24
Merge bitcoin/bitcoin#24138: index: Commit MuHash and best block together for coinstatsindex
691d45fdc8 Add coinstatsindex_unclean_shutdown test (Ryan Ofsky)
eb6cc05da3 index: Commit DB_MUHASH and DB_BEST_BLOCK to disk together (Martin Zumsande)

Pull request description:

  Fixes #24076

  Coinstatsindex currently writes the MuHash (`DB_MUHASH`) to disk in `CoinStatsIndex::WriteBlock()` and `CoinStatsIndex::ReverseBlock()`, but the best synced block is written in `BaseIndex::Commit()`. These are called at different points in time, both during the ThreadSync phase, and also after the initial sync is finished and validation callbacks (`BlockConnected()` vs `ChainStateFlushed()`) perform the syncing.

  As a result, the index DB is temporarily in an inconsistent state, and if bitcoind is terminated uncleanly (so that there is no time to call `Commit()` by receiving an interrupt or by flushing the chainstate) this leads to problems:
  On the next startup, `Init()` will read the best block and a MuHash that corresponds to a different (higher) block. Indexing will  be picked up at the the best block processing some blocks again, but since MuHash is a rolling hash, it will process some utxos twice and the muhashes for all future blocks will be wrong, as was observed in #24076.

  Fix this by always committing `DB_MUHASH` together with `DB_BEST_BLOCK`.

  Note that the block data for the index is still written at different times, but this does not corrupt the index - at worst, these entries will be processed another time and overwritten after an unclean shutdown and restart.

ACKs for top commit:
  ryanofsky:
    Code review ACK 691d45fdc8. Only change since last review is adding test
  fjahr:
    ACK 691d45fdc8

Tree-SHA512: e1c3b5f06fa4baacd1b070abb0f8111fe2ea4a001ca8b8bf892e96597cf8b5d5ea10fa8fb837cfbf46648f052c742d912add4ce26d4406294fc5fc20809a0e1b
2022-03-09 11:43:13 +01:00
..
blockfilter.cpp Require CBlockIndex::GetBlockPos() to hold mutex cs_main 2022-01-25 20:43:12 +01:00
blockfilter.h
chainstate.h Add src/node/* code to node:: namespace 2022-01-06 22:14:16 -05:00
logging.cpp scripted-diff: Bump copyright headers 2021-12-30 19:36:57 +02:00
logging.h scripted-diff: Bump copyright headers 2020-12-31 09:45:41 +01:00
mining.cpp Add src/node/* code to node:: namespace 2022-01-06 22:14:16 -05:00
mining.h Add src/node/* code to node:: namespace 2022-01-06 22:14:16 -05:00
net.cpp scripted-diff: Bump copyright headers 2021-12-30 19:36:57 +02:00
net.h Merge bitcoin/bitcoin#21879: refactor: wrap accept() and extend usage of Sock 2022-01-05 15:32:53 +01:00
README.md doc: Add documentation for new test/lib 2019-11-06 11:56:53 -05:00
script.cpp fuzz: [refactor] Use IsValidFlagCombination in signature_checker fuzz target 2021-03-30 10:42:45 +02:00
script.h fuzz: [refactor] Use IsValidFlagCombination in signature_checker fuzz target 2021-03-30 10:42:45 +02:00
setup_common.cpp validation, refactoring: remove ChainstateManager::Reset() 2022-02-09 18:04:54 +01:00
setup_common.h test: parse the command line arguments in unit tests 2022-01-11 11:53:30 +01:00
str.cpp
str.h [test] move string helper functions into test library 2019-11-25 01:33:17 +01:00
transaction_utils.cpp scripted-diff: Bump copyright headers 2020-04-16 13:33:09 -04:00
transaction_utils.h scripted-diff: TxoutType C++11 scoped enum class 2020-06-21 06:41:55 -04:00
validation.cpp Add coinstatsindex_unclean_shutdown test 2022-02-25 16:06:27 -05:00
validation.h Add coinstatsindex_unclean_shutdown test 2022-02-25 16:06:27 -05:00
wallet.cpp Add src/wallet/* code to wallet:: namespace 2022-01-06 22:14:16 -05:00
wallet.h Add src/wallet/* code to wallet:: namespace 2022-01-06 22:14:16 -05:00

Test library

This contains files for the test library, which is used by the test binaries (unit tests, benchmarks, fuzzers, gui tests).

Generally, the files in this folder should be well-separated modules. New code should be added to existing modules or (when in doubt) a new module should be created.

The utilities in here are compiled into a library, which does not hold any state. However, the main file setup_common defines the common test setup for all test binaries. The test binaries will handle the global state when they instantiate the BasicTestingSetup (or one of its derived classes).