Repository navigation
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #628 +/- ##
==========================================
+ Coverage 81.69% 81.90% +0.21%
==========================================
Files 25 25
Lines 6265 6300 +35
Branches 299 302 +3
==========================================
+ Hits 5118 5160 +42
+ Misses 1041 1035 -6
+ Partials 106 105 -1
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:
|
Thanks for the review and tACK Totally agree on And then for coin selection Q, this PR only addresses recipient amounts and initial fee calculations so I’m leaving #53 open for the remaining cases like coin selection. |
muawiya1
left a comment
There was a problem hiding this comment.
tACK 9df73a1
I reviewed the PR, and all the PR's tests passed locally on my macOS. To confirm the bug on master, I added 4 separate tests covering recipient and fee overflows since the PR's tests uses a new error variant (AmountOverflow) that does not exist on master, all tests failed on master and passed on the PR branch locally.
THanks! |
I reproduced cases where explicit algorithms (LargestFirst, OldestFirst, SingleRandomDraw) panic in debug builds and silently wrap in release builds when fee calculations overflow. In release, this results in an incorrect InsufficientFunds.needed value. These cases use extreme fee rates. The default algorithm also panics on UTXO values above i64::MAX. One option is to introduce a Another option is to keep the existing API and map arithmetic overflow to There's also |
| impl core::error::Error for MiniscriptPsbtError {} | ||
|
|
||
| #[derive(Debug)] | ||
| #[non_exhaustive] |
There was a problem hiding this comment.
In rust-bitcoin this is a policy: https://github.com/rust-bitcoin/rust-bitcoin/blob/master/docs/policy.md#errors (first bullet point) Should we adopt it too?
There was a problem hiding this comment.
I think so!
I'll keep the change here focused on CreateTxError, but:
|
tACK 9df73a1 I ran the tests and everything passed locally. I also tested master and this branch in both debug and release mode. I noticed something on master that this PR fixes. if you build a transaction with With this PR, both debug and release builds handle it correctly and return |
Description
Addresses the recipient and initial fee overflow cases from #53 "All across the crate, unchecked arithmetic is used. The unchecked arithmetic routines of rust-bitcoin's Amount type will panic if the result of an operation overflows. This is an issue for externally-provided values, such as for instance recipient amounts or fees” by using checked arithmetic in
create_txand returnsCreateTxError::AmountOverflowincluding for targets aboveAmount::MAX_MONEY.Notes to the reviewers
The
Amount::MAX_MONEYcap is there because a recipient ofAmount::MAX - 100at 1 sat/vB passes the checked additions and still panics inside coin selection. Targets aboveMAX_MONEYthat previously returnedInsufficientFundsnow returnAmountOverflow.Foreign UTXOs with extreme values, coin selection internals, and
PsbtUtils::fee_amount(#558, #559) can still panic and are out of scope here, so #53 should stay open.And then thinking about the direction for
TxBuilderis this worth landing on master and a 3.x version?Changelog notice
CreateTxError::AmountOverflowreturned on recipient or fee overflow and for targets aboveAmount::MAX_MONEYwhich previously returnedInsufficientFunds.CreateTxErroris also now#[non_exhaustive], a breaking change.Before submitting