fix: Race Condition in Block Height and Median Time Validation#96
Conversation
da9e488 to
f59652f
Compare
f59652f to
38d7584
Compare
|
🤖 Claude Code Review Status: Complete Critical Issue Found: The new GetBlockState() implementation does not actually provide atomic snapshot guarantees. In both Aerospike and SQL implementations, the method calls .Load() on two separate atomic variables. See inline comment at stores/utxo/aerospike/aerospike.go:354 for details. Between the first Load() and second Load(), another goroutine could call SetBlockHeight() or SetMedianBlockTime(), causing the returned snapshot to contain mismatched values from different states. This defeats the purpose of the PR. Solution: To achieve true atomicity, consider one of these approaches:
The rest of the PR structure is solid - good test coverage, proper interface design, and consistent implementation across all store types. |
|


Add Atomic BlockState Snapshot to Prevent Race Conditions
Summary
This PR introduces an atomic
BlockStatesnapshot mechanism in the UTXO store to prevent race conditions between block height and median block time reads during transaction validation.Problem
Previously,
GetBlockHeight()andGetMedianBlockTime()were called separately during validation. This created a race condition where:Solution
Introduced
GetBlockState()method that returns an atomic snapshot containing both:Changes
BlockStatestruct andGetBlockState()interface methodGetBlockState()GetBlockState()in all store implementationsGetBlockState()instead of separate callsGetBlockState()instead of deprecated separate callsBenefits
Testing
GetBlockState()mock