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.
This commit is contained in:
Matt Corallo 2024-05-05 23:21:13 +00:00
parent 93011c377c
commit 88c291a9bc
3 changed files with 33 additions and 4 deletions

View 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`].

View 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(())
}

View 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);
},