Add comprehensive txindex reorg test coverage
Motivation
This PR adds a new functional test feature_txindex_reorg.py to improve test coverage for the transaction index (-txindex) behavior during chain reorganizations. Currently, while txindex functionality is tested in various scenarios, there is limited coverage specifically focused on its behavior during deep reorgs, concurrent access patterns, and edge cases that could affect reliability.
The transaction index is a critical component for applications that need to look up historical transactions without knowing their block location. Ensuring its consistency and reliability during chain reorganizations is essential for:
- Block explorers and indexing services
- Applications using
getrawtransactionwithout blockhash - Historical transaction analysis tools
- Services relying on transaction lookup performance
Changes
This PR introduces a single new test file and registers it in the test runner:
test/functional/feature_txindex_reorg.py(new): Comprehensive test suite for txindex reorg scenariostest/functional/test_runner.py(modified): Registers the new test
Test Coverage
The new test covers five critical scenarios:
1. Txindex Consistency After Deep Reorg
- Creates transactions on the main chain
- Triggers a deep reorganization (10+ blocks)
- Verifies that txindex correctly updates to reflect the new chain state
- Ensures reorged-out transactions are properly handled
2. Transaction Lookups After Reorg
- Tests
getrawtransactionwith and without blockhash parameter - Validates that transactions remain findable after reorg
- Verifies correct behavior when transactions move to mempool
- Tests node without txindex for comparison
3. Txindex Rebuild After Corruption
- Simulates txindex corruption scenario
- Tests recovery using
-reindexflag - Verifies all transactions are correctly re-indexed
- Ensures no data loss during rebuild process
4. Concurrent Txindex Queries During Reorg
- Tests thread-safe concurrent access to txindex
- Performs multiple simultaneous transaction lookups
- Executes blockchain operations while queries are running
- Validates that concurrent access doesn’t cause crashes or inconsistencies
5. Txindex with Assumeutxo Scenarios
- Tests txindex behavior in assumeutxo-like scenarios
- Validates transaction lookups across snapshot boundaries
- Ensures txindex works correctly with invalidateblock/reconsiderblock
- Verifies consistency when blocks are invalidated around snapshot points
Testing
The test has been successfully executed:
0$ test/functional/test_runner.py feature_txindex_reorg
1✓ feature_txindex_reorg.py passed (Duration: 3s)
All test scenarios pass without errors, and the test follows Bitcoin Core’s functional test framework conventions.
Code Quality
The implementation follows all contributing guidelines:
- ✅ Follows naming convention (
feature_*.py) - ✅ Uses
BitcoinTestFrameworkbase class - ✅ Includes comprehensive docstring explaining test purpose
- ✅ Uses proper logging with
self.log.info() - ✅ Follows PEP-8 style guidelines
- ✅ Uses f-strings for formatting
- ✅ Includes MIT license header
- ✅ Properly handles node connections and synchronization
- ✅ Uses
sync_txindex()utility for proper index synchronization
Benefits
This test provides several benefits:
- Improved Coverage: Fills gaps in txindex testing, particularly around reorg scenarios
- Regression Prevention: Catches potential bugs in txindex reorg handling
- Documentation: Serves as documentation for expected txindex behavior during reorgs
- Confidence: Increases confidence in txindex reliability for production use
- Future-Proofing: Ensures txindex works correctly with features like assumeutxo
Notes
- The test is designed to be deterministic and should not be flaky
- Runtime is approximately 3 seconds on standard hardware
- No external dependencies required beyond standard test framework
- Test can be run individually or as part of the full test suite
Checklist
- New test added with clear documentation
- Test passes locally
- Test registered in test_runner.py
- Follows code style guidelines
- Commit message follows conventions
- No breaking changes
- Test is deterministic and not flaky
Contribution by Gittensor, learn more at https://gittensor.io/