Skip to content

Commit

Permalink
Merge pull request #2423 from wpaulino/2403-fixups
Browse files Browse the repository at this point in the history
PR #2403 fixups
  • Loading branch information
TheBlueMatt committed Jul 19, 2023
2 parents 2e86a59 + c7d84d8 commit 8a8f29a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
5 changes: 5 additions & 0 deletions lightning/src/chain/chaininterface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,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 {
Expand Down
11 changes: 6 additions & 5 deletions lightning/src/chain/onchaintx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -633,11 +633,12 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
.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())));
}
}
Expand Down
11 changes: 4 additions & 7 deletions lightning/src/util/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,18 +173,15 @@ impl<'a> core::fmt::Display for DebugBytes<'a> {
///
/// 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, "]")?;
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/util/macro_logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::util::logger::DebugBytes;

macro_rules! log_iter {
($obj: expr) => {
$crate::util::logger::DebugIter(core::cell::RefCell::new($obj))
$crate::util::logger::DebugIter($obj)
}
}

Expand Down

0 comments on commit 8a8f29a

Please sign in to comment.