fix: Mark losing conflicting transactions as NOT on longest chain during reorg#1
Merged
sugh01 merged 1 commit intosugh01:test/longest-chain-double-spendfrom Jan 9, 2026
Conversation
…ing reorg During blockchain reorganizations in SubtreeProcessor.reorgBlocks(), conflicting transactions that lost to newly-mined transactions were being removed from block assembly but never marked as NOT on longest chain in the UTXO store, leaving them with UnminedSince = 0. Changes: - Modified moveForwardBlock() to return losingTxHashesMap alongside transactionMap - Updated reorgBlocks() with two-pass processing: * Pass 1: Collect winning and losing transactions from all moveForward blocks * Pass 2: Filter and mark transactions appropriately, removing losers from winners - Fixed test scenario in testLongestChainWithDoubleSpendTransaction to ensure parentTx2 is mined in both forks, making tx3 valid on both chains - Removed impossible test scenario where tx3 would be mined after tx2 already consumed the same UTXO This ensures proper UTXO state tracking during chain reorganizations and fixes failures in the longest_chain test suite, particularly on Aerospike backend. Co-Authored-By: Claude Sonnet 4.5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a critical bug in blockchain reorganization where losing conflicting transactions were not being marked as NOT on longest chain in the UTXO store.
The Problem
During blockchain reorganizations in
SubtreeProcessor.reorgBlocks():UnminedSince = 0, incorrectly appearing as minedThe Solution
moveForwardBlock()to returnlosingTxHashesMapalongsidetransactionMapreorgBlocks():winningTxSetand collect losing transactionsmarkOnLongestChainto handle transactions that win in an earlier block but lose in a later blockmoveForwardBlock()to handle the new return valueTest Changes
Fixed
testLongestChainWithDoubleSpendTransaction:Test Results
Aerospike (Original Failing Backend): ✅ All tests passing
SQLite/Postgres: Mixed results with some timeouts (separate infrastructure issue)
Files Modified
services/blockassembly/subtreeprocessor/SubtreeProcessor.goservices/blockassembly/subtreeprocessor/SubtreeProcessor_test.gotest/sequentialtest/longest_chain/longest_chain_test.gotest/sequentialtest/longest_chain/03_longest_chain_invalidate_fork_test.go(gci formatting fix)🤖 Generated with Claude Code