fix(wallet): return error instead of panicking on invalid current_height#449
Open
none34829 wants to merge 2 commits intobitcoindevkit:masterfrom
Open
fix(wallet): return error instead of panicking on invalid current_height#449none34829 wants to merge 2 commits intobitcoindevkit:masterfrom
none34829 wants to merge 2 commits intobitcoindevkit:masterfrom
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #449 +/- ##
==========================================
- Coverage 80.21% 80.16% -0.05%
==========================================
Files 24 24
Lines 5347 5350 +3
Branches 242 242
==========================================
Hits 4289 4289
- Misses 980 983 +3
Partials 78 78
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 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
Closes #49.
TxBuilder::current_heightand the fallback tochain.tip().height()increate_txboth calledabsolute::LockTime::from_height(h).expect(...), which panics wheneverh >= 500_000_000. The Wizardsardine audit flagged this because it lets a remote Electrum/Esplora server crash the wallet by reporting a tip height at or above that threshold — panics on externally-provided input are unsafe for a library.This PR replaces the panics with a typed error:
TxParams.current_heightnow stores a rawu32instead of an already-validatedabsolute::LockTime, so the builder setter no longer has to validate in a position where it can't return aResult.Wallet::create_txperforms theu32 -> LockTimeconversion in one place, mapping theConversionErrorto a newCreateTxError::InvalidCurrentHeight(u32)variant via?.TxBuilder::current_height) and the implicit-fallback path (chain tip) now flow through the same validation and surface the same error.Notes to the reviewers
TxParams.current_heightis crate-private (pub(crate)) so there's no external API break there. TheTxBuilder::current_heightpublic signature is unchanged.CreateTxErroris technically an additive change, but it is an enum so downstream exhaustive matches would need to be updated.CreateTxErroris not marked#[non_exhaustive], which is tracked separately in Consider making all error enum variants#[non_exhaustive]#239.Changelog notice
Wallet::create_txnow returnsCreateTxError::InvalidCurrentHeightinstead of panicking whenTxBuilder::current_heightor the fallback chain tip height is>= 500_000_000.Checklists
All Submissions:
just pbefore pushing (140 lib tests + 118 wallet + 22 fee_bump + 10 persisted + 13 descriptor_macro + 54 doctests all pass; clippy clean; fmt clean; cargo doc clean)Bugfixes: