Skip to content

Commit 88c291a

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 93011c3 commit 88c291a

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
@@ -331,6 +331,21 @@ pub enum ClosureReason {
331331
FundingBatchClosure,
332332
/// One of our HTLCs timed out in a channel, causing us to force close the channel.
333333
HTLCsTimedOut,
334+
/// Our peer provided a feerate which violated our required minimum (fetched from our
335+
/// [`FeeEstimator`] either as [`ConfirmationTarget::MinAllowedAnchorChannelRemoteFee`] or
336+
/// [`ConfirmationTarget::MinAllowedNonAnchorChannelRemoteFee`]).
337+
///
338+
/// [`FeeEstimator`]: crate::chain::chaininterface::FeeEstimator
339+
/// [`ConfirmationTarget::MinAllowedAnchorChannelRemoteFee`]: crate::chain::chaininterface::ConfirmationTarget::MinAllowedAnchorChannelRemoteFee
340+
/// [`ConfirmationTarget::MinAllowedNonAnchorChannelRemoteFee`]: crate::chain::chaininterface::ConfirmationTarget::MinAllowedNonAnchorChannelRemoteFee
341+
PeerFeerateTooLow {
342+
/// The feerate on our channel set by our peer.
343+
peer_feerate_sat_per_kw: u32,
344+
/// The required feerate we enforce, from our [`FeeEstimator`].
345+
///
346+
/// [`FeeEstimator`]: crate::chain::chaininterface::FeeEstimator
347+
required_feerate_sat_per_kw: u32,
348+
},
334349
}
335350

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

378402
/// 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
@@ -3512,7 +3512,12 @@ impl<SP: Deref> Channel<SP> where
35123512
return Ok(());
35133513
}
35143514
}
3515-
return Err(ChannelError::close(format!("Peer's feerate much too low. Actual: {}. Our expected lower limit: {}", feerate_per_kw, lower_limit)));
3515+
return Err(ChannelError::Close((format!(
3516+
"Peer's feerate much too low. Actual: {}. Our expected lower limit: {}", feerate_per_kw, lower_limit
3517+
), ClosureReason::PeerFeerateTooLow {
3518+
peer_feerate_sat_per_kw: feerate_per_kw,
3519+
required_feerate_sat_per_kw: lower_limit,
3520+
})));
35163521
}
35173522
Ok(())
35183523
}

lightning/src/ln/functional_tests.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -10408,9 +10408,9 @@ fn accept_busted_but_better_fee() {
1040810408
match events[0] {
1040910409
MessageSendEvent::UpdateHTLCs { updates: msgs::CommitmentUpdate { ref update_fee, .. }, .. } => {
1041010410
nodes[1].node.handle_update_fee(&nodes[0].node.get_our_node_id(), update_fee.as_ref().unwrap());
10411-
check_closed_event!(nodes[1], 1, ClosureReason::ProcessingError {
10412-
err: "Peer's feerate much too low. Actual: 1000. Our expected lower limit: 5000".to_owned() },
10413-
[nodes[0].node.get_our_node_id()], 100000);
10411+
check_closed_event!(nodes[1], 1, ClosureReason::PeerFeerateTooLow {
10412+
peer_feerate_sat_per_kw: 1000, required_feerate_sat_per_kw: 5000,
10413+
}, [nodes[0].node.get_our_node_id()], 100000);
1041410414
check_closed_broadcast!(nodes[1], true);
1041510415
check_added_monitors!(nodes[1], 1);
1041610416
},

0 commit comments

Comments
 (0)