Skip to content

Commit fee7a9a

Browse files
committed
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.
1 parent f8caf60 commit fee7a9a

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

lightning/src/events/mod.rs

+24
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,21 @@ pub enum ClosureReason {
330330
FundingBatchClosure,
331331
/// One of our HTLCs timed out in a channel, causing us to force close the channel.
332332
HTLCsTimedOut,
333+
/// Our peer provided a feerate which violated our required minimum (fetched from our
334+
/// [`FeeEstimator`] either as [`ConfirmationTarget::MinAllowedAnchorChannelRemoteFee`] or
335+
/// [`ConfirmationTarget::MinAllowedNonAnchorChannelRemoteFee`]).
336+
///
337+
/// [`FeeEstimator`]: crate::chain::chaininterface::FeeEstimator
338+
/// [`ConfirmationTarget::MinAllowedAnchorChannelRemoteFee`]: crate::chain::chaininterface::ConfirmationTarget::MinAllowedAnchorChannelRemoteFee
339+
/// [`ConfirmationTarget::MinAllowedNonAnchorChannelRemoteFee`]: crate::chain::chaininterface::ConfirmationTarget::MinAllowedNonAnchorChannelRemoteFee
340+
PeerFeerateTooLow {
341+
/// The feerate on our channel set by our peer.
342+
peer_feerate_sat_per_kw: u32,
343+
/// The required feerate we enforce, from our [`FeeEstimator`].
344+
///
345+
/// [`FeeEstimator`]: crate::chain::chaininterface::FeeEstimator
346+
required_feerate_sat_per_kw: u32,
347+
},
333348
}
334349

335350
impl core::fmt::Display for ClosureReason {
@@ -354,6 +369,11 @@ impl core::fmt::Display for ClosureReason {
354369
ClosureReason::CounterpartyCoopClosedUnfundedChannel => f.write_str("the peer requested the unfunded channel be closed"),
355370
ClosureReason::FundingBatchClosure => f.write_str("another channel in the same funding batch closed"),
356371
ClosureReason::HTLCsTimedOut => f.write_str("htlcs on the channel timed out"),
372+
ClosureReason::PeerFeerateTooLow { peer_feerate_sat_per_kw, required_feerate_sat_per_kw } =>
373+
f.write_fmt(format_args!(
374+
"peer provided a feerate ({} sat/kw) which was below our lower bound ({} sat/kw)",
375+
peer_feerate_sat_per_kw, required_feerate_sat_per_kw,
376+
)),
357377
}
358378
}
359379
}
@@ -372,6 +392,10 @@ impl_writeable_tlv_based_enum_upgradable!(ClosureReason,
372392
(17, CounterpartyInitiatedCooperativeClosure) => {},
373393
(19, LocallyInitiatedCooperativeClosure) => {},
374394
(21, HTLCsTimedOut) => {},
395+
(23, PeerFeerateTooLow) => {
396+
(0, peer_feerate_sat_per_kw, required),
397+
(2, required_feerate_sat_per_kw, required),
398+
},
375399
);
376400

377401
/// Intended destination of a failed HTLC as indicated in [`Event::HTLCHandlingFailed`].

lightning/src/ln/channel.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -3640,7 +3640,12 @@ impl<SP: Deref> Channel<SP> where
36403640
return Ok(());
36413641
}
36423642
}
3643-
return Err(ChannelError::close(format!("Peer's feerate much too low. Actual: {}. Our expected lower limit: {}", feerate_per_kw, lower_limit)));
3643+
return Err(ChannelError::Close((format!(
3644+
"Peer's feerate much too low. Actual: {}. Our expected lower limit: {}", feerate_per_kw, lower_limit
3645+
), ClosureReason::PeerFeerateTooLow {
3646+
peer_feerate_sat_per_kw: feerate_per_kw,
3647+
required_feerate_sat_per_kw: lower_limit,
3648+
})));
36443649
}
36453650
Ok(())
36463651
}

lightning/src/ln/functional_tests.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -10224,9 +10224,9 @@ fn accept_busted_but_better_fee() {
1022410224
match events[0] {
1022510225
MessageSendEvent::UpdateHTLCs { updates: msgs::CommitmentUpdate { ref update_fee, .. }, .. } => {
1022610226
nodes[1].node.handle_update_fee(&nodes[0].node.get_our_node_id(), update_fee.as_ref().unwrap());
10227-
check_closed_event!(nodes[1], 1, ClosureReason::ProcessingError {
10228-
err: "Peer's feerate much too low. Actual: 1000. Our expected lower limit: 5000".to_owned() },
10229-
[nodes[0].node.get_our_node_id()], 100000);
10227+
check_closed_event!(nodes[1], 1, ClosureReason::PeerFeerateTooLow {
10228+
peer_feerate_sat_per_kw: 1000, required_feerate_sat_per_kw: 5000,
10229+
}, [nodes[0].node.get_our_node_id()], 100000);
1023010230
check_closed_broadcast!(nodes[1], true);
1023110231
check_added_monitors!(nodes[1], 1);
1023210232
},

0 commit comments

Comments
 (0)