Skip to content

Commit

Permalink
policy: add a function to get the virtual transaction size
Browse files Browse the repository at this point in the history
It's very useful to Bitcoin applications, and especially "L2" ones, to
effectively compute feerates. Currently (and this is very unlikely to
change) bitcoind nodes compute the virtual size as a rounded-up division
of the size in witness units by 4, with a penalty for transactions that
are essentially >5% full of sigops.

Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
  • Loading branch information
darosior committed May 12, 2021
1 parent f5d6bdf commit 9995ce3
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/policy/mod.rs
Expand Up @@ -42,3 +42,9 @@ pub const DEFAULT_BYTES_PER_SIGOP: u32 = 20;
/// The minimum feerate, in sats per kilo-virtualbyte, for defining dust. An output is considered
/// dust if spending it under this feerate would cost more in fee.
pub const DUST_RELAY_TX_FEE: u32 = 3000;

/// The virtual transaction size, as computed by default by bitcoind node.
pub fn get_virtual_tx_size(weight: i64, n_sigops: i64) -> i64 {
(cmp::max(weight, n_sigops * DEFAULT_BYTES_PER_SIGOP as i64) + WITNESS_SCALE_FACTOR as i64 - 1)
/ WITNESS_SCALE_FACTOR as i64
}

0 comments on commit 9995ce3

Please sign in to comment.