/// 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 {
.compute_package_feerate(fee_estimator, conf_target, force_feerate_bump);
if let Some(input_amount_sat) = output.funding_amount {
let fee_sat = input_amount_sat - tx.output.iter().map(|output| output.value).sum::<u64>();
- if compute_feerate_sat_per_1000_weight(fee_sat, tx.weight() as u64) >=
- package_target_feerate_sat_per_1000_weight
- {
- log_debug!(logger, "Commitment transaction {} already meets required feerate {} sat/kW",
- tx.txid(), package_target_feerate_sat_per_1000_weight);
+ let commitment_tx_feerate_sat_per_1000_weight =
+ compute_feerate_sat_per_1000_weight(fee_sat, tx.weight() as u64);
+ if commitment_tx_feerate_sat_per_1000_weight >= package_target_feerate_sat_per_1000_weight {
+ log_debug!(logger, "Pre-signed {} already has feerate {} sat/kW above required {} sat/kW",
+ log_tx!(tx), commitment_tx_feerate_sat_per_1000_weight,
+ package_target_feerate_sat_per_1000_weight);
return Some((new_timer, 0, OnchainClaim::Tx(tx.clone())));
}
}
///
/// This is not exported to bindings users as fmt can't be used in C
#[doc(hidden)]
-pub struct DebugIter<T: fmt::Display, I: core::iter::Iterator<Item = T> + Clone>(pub core::cell::RefCell<I>);
+pub struct DebugIter<T: fmt::Display, I: core::iter::Iterator<Item = T> + Clone>(pub I);
impl<T: fmt::Display, I: core::iter::Iterator<Item = T> + Clone> fmt::Display for DebugIter<T, I> {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
- use core::ops::DerefMut;
write!(f, "[")?;
- let iter_ref = self.0.clone();
- let mut iter = iter_ref.borrow_mut();
- for item in iter.deref_mut() {
+ let mut iter = self.0.clone();
+ if let Some(item) = iter.next() {
write!(f, "{}", item)?;
- break;
}
- for item in iter.deref_mut() {
+ while let Some(item) = iter.next() {
write!(f, ", {}", item)?;
}
write!(f, "]")?;
macro_rules! log_iter {
($obj: expr) => {
- $crate::util::logger::DebugIter(core::cell::RefCell::new($obj))
+ $crate::util::logger::DebugIter($obj)
}
}