Merge pull request #2382 from dunxen/2077-followups
authorMatt Corallo <649246+TheBlueMatt@users.noreply.github.com>
Thu, 20 Jul 2023 21:40:04 +0000 (21:40 +0000)
committerGitHub <noreply@github.com>
Thu, 20 Jul 2023 21:40:04 +0000 (21:40 +0000)
Address outstanding 2077 feedback

lightning/src/chain/chaininterface.rs
lightning/src/chain/onchaintx.rs
lightning/src/util/logger.rs
lightning/src/util/macro_logger.rs

index 6073ed61aaf0cc88beea1c899b687fbb407fbc93..913fa007d378e91ba5666e3d34ae11c15010ce13 100644 (file)
@@ -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 {
index beb0dfc10353eabe0b9339fd67bdca22f988edae..6ac4973a74441de88461576d26c9f8b69545d1c8 100644 (file)
@@ -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())));
                                                }
                                        }
index 722a81f7ab665b15961363a1f064377718e36dd3..dbca9b785e85dfbaf3c68253e7e47b91225c6bdc 100644 (file)
@@ -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, "]")?;
index 4703bcdb32a2a00719f4d7a5eb1edd37aa2d75ec..e79980370342ff01920fe5a37b4423719a228ac7 100644 (file)
@@ -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)
        }
 }