]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Add a new `ClosureReason::PeerFeerateTooLow`
authorMatt Corallo <git@bluematt.me>
Sun, 5 May 2024 23:21:13 +0000 (23:21 +0000)
committerMatt Corallo <git@bluematt.me>
Mon, 10 Jun 2024 15:12:28 +0000 (15:12 +0000)
Closure due to feerate disagreements are a specific closure reason
which admins can understand and tune their config (in the form of
their `FeeEstimator`) to avoid, so having a separate
`ClosureReason` for it is useful.

lightning/src/events/mod.rs
lightning/src/ln/channel.rs
lightning/src/ln/functional_tests.rs

index 45ed895ade7a0f9010c07a3bc7de73e1e1dd6913..f054a50ceb807298f37bddd690ef1a4d29a81384 100644 (file)
@@ -331,6 +331,21 @@ pub enum ClosureReason {
        FundingBatchClosure,
        /// One of our HTLCs timed out in a channel, causing us to force close the channel.
        HTLCsTimedOut,
+       /// Our peer provided a feerate which violated our required minimum (fetched from our
+       /// [`FeeEstimator`] either as [`ConfirmationTarget::MinAllowedAnchorChannelRemoteFee`] or
+       /// [`ConfirmationTarget::MinAllowedNonAnchorChannelRemoteFee`]).
+       ///
+       /// [`FeeEstimator`]: crate::chain::chaininterface::FeeEstimator
+       /// [`ConfirmationTarget::MinAllowedAnchorChannelRemoteFee`]: crate::chain::chaininterface::ConfirmationTarget::MinAllowedAnchorChannelRemoteFee
+       /// [`ConfirmationTarget::MinAllowedNonAnchorChannelRemoteFee`]: crate::chain::chaininterface::ConfirmationTarget::MinAllowedNonAnchorChannelRemoteFee
+       PeerFeerateTooLow {
+               /// The feerate on our channel set by our peer.
+               peer_feerate_sat_per_kw: u32,
+               /// The required feerate we enforce, from our [`FeeEstimator`].
+               ///
+               /// [`FeeEstimator`]: crate::chain::chaininterface::FeeEstimator
+               required_feerate_sat_per_kw: u32,
+       },
 }
 
 impl core::fmt::Display for ClosureReason {
@@ -355,6 +370,11 @@ impl core::fmt::Display for ClosureReason {
                        ClosureReason::CounterpartyCoopClosedUnfundedChannel => f.write_str("the peer requested the unfunded channel be closed"),
                        ClosureReason::FundingBatchClosure => f.write_str("another channel in the same funding batch closed"),
                        ClosureReason::HTLCsTimedOut => f.write_str("htlcs on the channel timed out"),
+                       ClosureReason::PeerFeerateTooLow { peer_feerate_sat_per_kw, required_feerate_sat_per_kw } =>
+                               f.write_fmt(format_args!(
+                                       "peer provided a feerate ({} sat/kw) which was below our lower bound ({} sat/kw)",
+                                       peer_feerate_sat_per_kw, required_feerate_sat_per_kw,
+                               )),
                }
        }
 }
@@ -373,6 +393,10 @@ impl_writeable_tlv_based_enum_upgradable!(ClosureReason,
        (17, CounterpartyInitiatedCooperativeClosure) => {},
        (19, LocallyInitiatedCooperativeClosure) => {},
        (21, HTLCsTimedOut) => {},
+       (23, PeerFeerateTooLow) => {
+               (0, peer_feerate_sat_per_kw, required),
+               (2, required_feerate_sat_per_kw, required),
+       },
 );
 
 /// Intended destination of a failed HTLC as indicated in [`Event::HTLCHandlingFailed`].
index c1294af6a73c776636fe982688a294851345bfc2..488141fa8fa300fc65812209036aa99e591a7753 100644 (file)
@@ -3512,7 +3512,12 @@ impl<SP: Deref> Channel<SP> where
                                        return Ok(());
                                }
                        }
-                       return Err(ChannelError::close(format!("Peer's feerate much too low. Actual: {}. Our expected lower limit: {}", feerate_per_kw, lower_limit)));
+                       return Err(ChannelError::Close((format!(
+                               "Peer's feerate much too low. Actual: {}. Our expected lower limit: {}", feerate_per_kw, lower_limit
+                       ), ClosureReason::PeerFeerateTooLow {
+                               peer_feerate_sat_per_kw: feerate_per_kw,
+                               required_feerate_sat_per_kw: lower_limit,
+                       })));
                }
                Ok(())
        }
index 5c9d8f269b196c278ed7d2f8ac3233825bb41e1c..1e31e52cbf0431ed0657e9ff571639cd06b615da 100644 (file)
@@ -10408,9 +10408,9 @@ fn accept_busted_but_better_fee() {
        match events[0] {
                MessageSendEvent::UpdateHTLCs { updates: msgs::CommitmentUpdate { ref update_fee, .. }, .. } => {
                        nodes[1].node.handle_update_fee(&nodes[0].node.get_our_node_id(), update_fee.as_ref().unwrap());
-                       check_closed_event!(nodes[1], 1, ClosureReason::ProcessingError {
-                               err: "Peer's feerate much too low. Actual: 1000. Our expected lower limit: 5000".to_owned() },
-                               [nodes[0].node.get_our_node_id()], 100000);
+                       check_closed_event!(nodes[1], 1, ClosureReason::PeerFeerateTooLow {
+                               peer_feerate_sat_per_kw: 1000, required_feerate_sat_per_kw: 5000,
+                       }, [nodes[0].node.get_our_node_id()], 100000);
                        check_closed_broadcast!(nodes[1], true);
                        check_added_monitors!(nodes[1], 1);
                },