From e7c90c57e7b5ee20a2c523706cc4ea9957594857 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Thu, 12 Jun 2025 10:58:50 +1000 Subject: [PATCH] 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 --- bitcoin/src/psbt/mod.rs | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/bitcoin/src/psbt/mod.rs b/bitcoin/src/psbt/mod.rs index 40153c460..20c2c6c04 100644 --- a/bitcoin/src/psbt/mod.rs +++ b/bitcoin/src/psbt/mod.rs @@ -20,7 +20,6 @@ use std::collections::{HashMap, HashSet}; use internals::write_err; use secp256k1::{Keypair, Message, Secp256k1, Signing, Verification}; -use units::NumOpResult; use crate::bip32::{self, DerivationPath, KeySource, Xpriv, Xpub}; use crate::crypto::key::{PrivateKey, PublicKey}; @@ -206,18 +205,12 @@ impl Psbt { // Note: Move prevents usage of &self from now on. let tx = self.internal_extract_tx(); - // Now that the extracted Transaction is made, decide how to return it. - match fee / tx.weight() { - NumOpResult::Valid(fee_rate) => { - // Prefer to return an AbsurdFeeRate error when both trigger. - if fee_rate > max_fee_rate { - return Err(ExtractTxError::AbsurdFeeRate { fee_rate, tx }); - } - } - NumOpResult::Error(_) => unreachable!("weight() is always non-zero"), + let fee_rate = (fee / tx.weight()).unwrap_or(FeeRate::MAX); + if fee_rate > max_fee_rate { + Err(ExtractTxError::AbsurdFeeRate { fee_rate, tx }) + } else { + Ok(tx) } - - Ok(tx) } /// Combines this [`Psbt`] with `other` PSBT as described by BIP 174.