fix: use validateTransaction instead of isConsistentOrThrow in Wallet…#294
fix: use validateTransaction instead of isConsistentOrThrow in Wallet…#294HashEngineering wants to merge 1 commit intomasterfrom
Conversation
📝 WalkthroughWalkthroughThe Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ast-grep (0.41.0)core/src/main/java/org/bitcoinj/wallet/Wallet.javaThanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
core/src/main/java/org/bitcoinj/wallet/Wallet.java (1)
1990-2005:⚠️ Potential issue | 🔴 Critical
validateTransaction()drops the multi-pool invariant thatisConsistentOrThrow()enforced.
isConsistentOrThrow()did more than validate spent/unspent outputs: it also detected the same tx appearing in multiple pools by comparing the summed pool sizes withgetTransactions(true).size(). This replacement skips that entirely, so a tx can now live inspentandpendingsimultaneously and still pass validation, which weakens the safeguard exercised bycore/src/test/java/org/bitcoinj/wallet/WalletTest.java:683-712.Proposed fix
protected boolean validateTransaction(Transaction tx) { lock.readLock().lock(); try { Sha256Hash txHash = tx.getTxId(); + EnumSet<Pool> pools = getContainingPools(tx); + if (pools.size() > 1) { + throw new IllegalStateException("Transaction appears in multiple pools: " + txHash + " " + pools); + } // Determine which pool the transaction is in and validate accordingly. // Pending/dead transactions are intentionally not checked here: their outputs // may all be spent by other pending/conflict transactions, which is valid. // This mirrors the behaviour of isConsistentOrThrow() which only checks🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@core/src/main/java/org/bitcoinj/wallet/Wallet.java` around lines 1990 - 2005, The new validateTransaction() implementation removed the multi-pool uniqueness check that isConsistentOrThrow() enforced, allowing a tx to appear in multiple pools; restore that invariant by adding a check in validateTransaction() (the method shown) that verifies the total number of unique transactions across all pools equals getTransactions(true).size() (or equivalently detect duplicates across spent, unspent, pending, dead maps) and throw an IllegalStateException if a transaction is present in more than one pool; locate the pools referenced (spent, unspent, pending, dead) and perform the uniqueness/size comparison or duplicate detection before returning so the same safeguard the WalletTest expects is re-established.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@core/src/main/java/org/bitcoinj/wallet/Wallet.java`:
- Around line 1990-2005: The new validateTransaction() implementation removed
the multi-pool uniqueness check that isConsistentOrThrow() enforced, allowing a
tx to appear in multiple pools; restore that invariant by adding a check in
validateTransaction() (the method shown) that verifies the total number of
unique transactions across all pools equals getTransactions(true).size() (or
equivalently detect duplicates across spent, unspent, pending, dead maps) and
throw an IllegalStateException if a transaction is present in more than one
pool; locate the pools referenced (spent, unspent, pending, dead) and perform
the uniqueness/size comparison or duplicate detection before returning so the
same safeguard the WalletTest expects is re-established.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 735e3208-6f4c-4f5e-ac54-0054e9c5de8f
📒 Files selected for processing (1)
core/src/main/java/org/bitcoinj/wallet/Wallet.java
….receive
Issue being fixed or feature implemented
What was done?
How Has This Been Tested?
Breaking Changes
Checklist:
For repository code-owners and collaborators only
Summary by CodeRabbit