spend: use helper for unsigned tx max size

This commit is contained in:
jp1ac4 2023-12-14 14:43:49 +00:00
parent af416f6502
commit 927c252d2e
No known key found for this signature in database
GPG Key ID: A7ACD32423568D7B

View File

@ -11,7 +11,6 @@ use miniscript::bitcoin::{
self, self,
absolute::{Height, LockTime}, absolute::{Height, LockTime},
bip32, bip32,
constants::WITNESS_SCALE_FACTOR,
psbt::{Input as PsbtIn, Output as PsbtOut, Psbt}, psbt::{Input as PsbtIn, Output as PsbtOut, Psbt},
secp256k1, secp256k1,
}; };
@ -134,14 +133,7 @@ fn sanity_check_psbt(
} }
// Check the feerate isn't insane. // Check the feerate isn't insane.
// Add weights together before converting to vbytes to avoid rounding up multiple times let tx_vb = spent_desc.unsigned_tx_max_vbytes(tx);
// and increasing the result, which could lead to the feerate in sats/vb falling below 1.
let tx_wu = tx.weight().to_wu() + (spent_desc.max_sat_weight() * tx.input.len()) as u64;
let tx_vb = tx_wu
.checked_add(WITNESS_SCALE_FACTOR as u64 - 1)
.unwrap()
.checked_div(WITNESS_SCALE_FACTOR as u64)
.unwrap();
let feerate_sats_vb = abs_fee let feerate_sats_vb = abs_fee
.checked_div(tx_vb) .checked_div(tx_vb)
.ok_or(SpendCreationError::InsaneFees( .ok_or(SpendCreationError::InsaneFees(