Skip to content

Commit e7c90c5

Browse files
committed
Remove reachable unreachable call in psbt
A bunch of changes have been implemented lately in the fee calculation logic. As a result of this a at once time `unreachable` statement is now reachable - bad rust-bitcoin devs, no biscuit. Saturate to `FeeRate::MAX` when calculating the fee rate, check against the limit arg, and win. Co-developed-by: Andrew Poelstra <[email protected]>
1 parent c736e73 commit e7c90c5

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

bitcoin/src/psbt/mod.rs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use std::collections::{HashMap, HashSet};
2020

2121
use internals::write_err;
2222
use secp256k1::{Keypair, Message, Secp256k1, Signing, Verification};
23-
use units::NumOpResult;
2423

2524
use crate::bip32::{self, DerivationPath, KeySource, Xpriv, Xpub};
2625
use crate::crypto::key::{PrivateKey, PublicKey};
@@ -206,18 +205,12 @@ impl Psbt {
206205
// Note: Move prevents usage of &self from now on.
207206
let tx = self.internal_extract_tx();
208207

209-
// Now that the extracted Transaction is made, decide how to return it.
210-
match fee / tx.weight() {
211-
NumOpResult::Valid(fee_rate) => {
212-
// Prefer to return an AbsurdFeeRate error when both trigger.
213-
if fee_rate > max_fee_rate {
214-
return Err(ExtractTxError::AbsurdFeeRate { fee_rate, tx });
215-
}
216-
}
217-
NumOpResult::Error(_) => unreachable!("weight() is always non-zero"),
208+
let fee_rate = (fee / tx.weight()).unwrap_or(FeeRate::MAX);
209+
if fee_rate > max_fee_rate {
210+
Err(ExtractTxError::AbsurdFeeRate { fee_rate, tx })
211+
} else {
212+
Ok(tx)
218213
}
219-
220-
Ok(tx)
221214
}
222215

223216
/// Combines this [`Psbt`] with `other` PSBT as described by BIP 174.

0 commit comments

Comments
 (0)