This PR replaces the goto statement in bitcoin-chainstate by encapsulating resources into a dedicated Epilogue class.
I’ve bumped into it while reviewing #25722.
Key Changes:
- Encapsulated ValidationSignalsandChainstateManagercleanup into an RAII Epilogue class to replace the goto-based cleanup logic.
- Split bitcoin-chainstatelogic into a header to enable isolated testing and clarity.
- Introduced basic tests to ensure normal execution completes successfully in regtest, and cleanup code is called in both success and failure scenarios.
How to test it manually:
- cmake -B build -DCMAKE_BUILD_TYPE=Debug -DBUILD_UTIL_CHAINSTATE=OFF && cmake --build build -j$(nproc) && ctest --test-dir build -j$(nproc)- should not contain- bitcoin_chainstate_tests
- cmake -B build -DCMAKE_BUILD_TYPE=Debug -DBUILD_UTIL_CHAINSTATE=ON && cmake --build build -j$(nproc) && ctest --test-dir build -j$(nproc)- should contain a passing- bitcoin_chainstate_tests
- cmake -B build -DCMAKE_BUILD_TYPE=Debug -DBUILD_UTIL_CHAINSTATE=ON && cmake --build build -j$(nproc) && ./build/src/bitcoin-chainstate your-bitcoin-datadir- should work the same as before (needs an extra newline at the end to exit)