Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

commands: add weights before converting to vbytes #734

Merged
merged 1 commit into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,14 @@ fn sanity_check_psbt(
}

// Check the feerate isn't insane.
let tx_vb = (tx.vsize() + spent_desc.max_sat_vbytes() * tx.input.len()) as u64;
// Add weights together before converting to vbytes to avoid rounding up multiple times
// 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(descriptors::WITNESS_FACTOR as u64 - 1)
.unwrap()
.checked_div(descriptors::WITNESS_FACTOR as u64)
.unwrap();
let feerate_sats_vb = abs_fee
.checked_div(tx_vb)
.ok_or(CommandError::InsaneFees(InsaneFeeInfo::InvalidFeerate))?;
Expand Down
2 changes: 1 addition & 1 deletion src/descriptors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub use keys::*;
pub mod analysis;
pub use analysis::*;

const WITNESS_FACTOR: usize = 4;
pub const WITNESS_FACTOR: usize = 4;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the future we should avoid rolling our own constant and instead use rust-bitcoin's.


#[derive(Debug)]
pub enum LianaDescError {
Expand Down
Loading