diff --git a/src/policy/mod.rs b/src/policy/mod.rs index e6cdc26e9f..02efa58b1d 100644 --- a/src/policy/mod.rs +++ b/src/policy/mod.rs @@ -23,7 +23,8 @@ //! //! These values were taken from bitcoind v0.21.1 (194b9b8792d9b0798fdb570b79fa51f1d1f5ebaf). -use super::blockdata::constants::MAX_BLOCK_SIGOPS_COST; +use super::blockdata::constants::{MAX_BLOCK_SIGOPS_COST, WITNESS_SCALE_FACTOR}; +use std::cmp; /// Maximum weight of a transaction for it to be relayed by most nodes on the network pub const MAX_STANDARD_TX_WEIGHT: u32 = 400_000; @@ -52,3 +53,9 @@ pub const DEFAULT_MIN_RELAY_TX_FEE: u32 = 1_000; /// Default number of hours for an unconfirmed transaction to expire in most of the network nodes' /// mempools. pub const DEFAULT_MEMPOOL_EXPIRY: u32 = 336; + +/// 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 +}