From: Matt Corallo Date: Sun, 5 May 2024 23:21:13 +0000 (+0000) Subject: Add a new `ClosureReason::PeerFeerateTooLow` X-Git-Tag: v0.0.124-beta~88^2~3 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=88c291a9bc6df5aa9d2253182a2c934e56c3cfad;p=rust-lightning Add a new `ClosureReason::PeerFeerateTooLow` 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. --- diff --git a/lightning/src/events/mod.rs b/lightning/src/events/mod.rs index 45ed895ad..f054a50ce 100644 --- a/lightning/src/events/mod.rs +++ b/lightning/src/events/mod.rs @@ -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`]. diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs index c1294af6a..488141fa8 100644 --- a/lightning/src/ln/channel.rs +++ b/lightning/src/ln/channel.rs @@ -3512,7 +3512,12 @@ impl Channel 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(()) } diff --git a/lightning/src/ln/functional_tests.rs b/lightning/src/ln/functional_tests.rs index 5c9d8f269..1e31e52cb 100644 --- a/lightning/src/ln/functional_tests.rs +++ b/lightning/src/ln/functional_tests.rs @@ -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); },