Repository navigation
fix(chain): return false for untracked indices in SpkTxOutIndex::is_used - #2445
Open
bhuvan-somisetty wants to merge 1 commit into
Open
bhuvan-somisetty wants to merge 1 commit into
bhuvan-somisetty wants to merge 1 commit into
Conversation
Previously, `SpkTxOutIndex::is_used` checked `!self.unused.contains(index)`. Because `self.unused` only tracks indices that were explicitly added to the index, any untracked index was absent from `self.unused`, causing `is_used` to evaluate to `true`. Check `self.spks.contains_key(index)` in `is_used` to ensure untracked indices return `false`. Also update documentation and add unit tests for `SpkTxOutIndex` and `KeychainTxOutIndex`. Closes bitcoindevkit#2444 Signed-off-by: bhuvan-somisetty <somisettybhuvan5@gmail.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2445 +/- ##
==========================================
+ Coverage 83.25% 83.30% +0.04%
==========================================
Files 31 31
Lines 6236 6236
Branches 293 294 +1
==========================================
+ Hits 5192 5195 +3
+ Misses 976 973 -3
Partials 68 68
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Description
Fixes an issue where
SpkTxOutIndex::is_usedreturnstruefor an index that was never tracked or added to the index (e.g. on an empty index or querying an unrevealed keychain derivation index inKeychainTxOutIndex::is_used).is_usedpreviously checked!self.unused.contains(index). Becauseself.unusedonly tracks indices that were explicitly added to the index, any index that has never been tracked is absent fromself.unused, causingis_usedto evaluate totrue.This PR updates
SpkTxOutIndex::is_usedto verifyself.spks.contains_key(index) && !self.unused.contains(index), matching the guard already present inunmark_used. It also adds documentation and unit tests for bothSpkTxOutIndexandKeychainTxOutIndex.Closes #2444.
Notes to the reviewers
SpkTxOutIndex::unmark_usedalready explicitly checksif !self.spks.contains_key(index) { return false; }. Applyingself.spks.contains_key(index)tois_usedbrings full symmetry between both methods and preserves the invariant that untracked indices are not considered used.test_spk_txout_index.rsandtest_keychain_txout_index.rs.Changelog notice
SpkTxOutIndex::is_usedreturningtruefor untracked script pubkey indices.Checklists
All Submissions:
Bugfixes: