X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fchain%2Fchaininterface.rs;h=913fa007d378e91ba5666e3d34ae11c15010ce13;hb=61cf75265ebff493af5a04550a5ff8b250f3b2f6;hp=4204d714f1b12be5a7a1a04fed5092746562c827;hpb=db3d58c586b9f2972414a07b09980db710428c7a;p=rust-lightning diff --git a/lightning/src/chain/chaininterface.rs b/lightning/src/chain/chaininterface.rs index 4204d714..913fa007 100644 --- a/lightning/src/chain/chaininterface.rs +++ b/lightning/src/chain/chaininterface.rs @@ -14,9 +14,18 @@ //! disconnections, transaction broadcasting, and feerate information requests. use core::{cmp, ops::Deref}; +use core::convert::TryInto; use bitcoin::blockdata::transaction::Transaction; +// TODO: Define typed abstraction over feerates to handle their conversions. +pub(crate) fn compute_feerate_sat_per_1000_weight(fee_sat: u64, weight: u64) -> u32 { + (fee_sat * 1000 / weight).try_into().unwrap_or(u32::max_value()) +} +pub(crate) const fn fee_for_weight(feerate_sat_per_1000_weight: u32, weight: u64) -> u64 { + ((feerate_sat_per_1000_weight as u64 * weight) + 1000 - 1) / 1000 +} + /// An interface to send a transaction to the Bitcoin network. pub trait BroadcasterInterface { /// Sends a list of transactions out to (hopefully) be mined. @@ -59,6 +68,11 @@ pub enum ConfirmationTarget { /// A trait which should be implemented to provide feerate information on a number of time /// horizons. /// +/// If access to a local mempool is not feasible, feerate estimates should be fetched from a set of +/// third-parties hosting them. Note that this enables them to affect the propagation of your +/// pre-signed transactions at any time and therefore endangers the safety of channels funds. It +/// should be considered carefully as a deployment. +/// /// Note that all of the functions implemented here *must* be reentrant-safe (obviously - they're /// called from inside the library in response to chain events, P2P events, or timer events). pub trait FeeEstimator {