Skip to content

Commit ab9fe62

Browse files
committed
Add and update high priority feerate in Channel
To find the maximum dust exposure as a multiplier of the current high priority feerate, we keep an updated record of the feerate inside of the channel.
1 parent aee967a commit ab9fe62

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

lightning/src/ln/channel.rs

+15
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,10 @@ pub(super) struct Channel<Signer: ChannelSigner> {
601601
next_holder_htlc_id: u64,
602602
next_counterparty_htlc_id: u64,
603603
feerate_per_kw: u32,
604+
/// We keep an updated high priority feerate in order to calculate the max dust
605+
/// exposure limit if [`ChannelConfig::max_dust_htlc_exposure_multiplier_thousandths`]
606+
/// is set.
607+
high_priority_feerate_per_kw: Option<u32>,
604608

605609
/// The timestamp set on our latest `channel_update` message for this channel. It is updated
606610
/// when the channel is updated in ways which may impact the `channel_update` message or when a
@@ -1018,6 +1022,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
10181022
debug_assert!(channel_type.is_subset(&channelmanager::provided_channel_type_features(&config)));
10191023

10201024
let feerate = fee_estimator.bounded_sat_per_1000_weight(ConfirmationTarget::Normal);
1025+
let high_priority_feerate = fee_estimator.bounded_sat_per_1000_weight(ConfirmationTarget::HighPriority);
10211026

10221027
let value_to_self_msat = channel_value_satoshis * 1000 - push_msat;
10231028
let commitment_tx_fee = Self::commit_tx_fee_msat(feerate, MIN_AFFORDABLE_HTLC_COUNT, channel_type.requires_anchors_zero_fee_htlc_tx());
@@ -1114,6 +1119,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
11141119
channel_creation_height: current_chain_height,
11151120

11161121
feerate_per_kw: feerate,
1122+
high_priority_feerate_per_kw: Some(high_priority_feerate),
11171123
counterparty_dust_limit_satoshis: 0,
11181124
holder_dust_limit_satoshis: MIN_CHAN_DUST_LIMIT_SATOSHIS,
11191125
counterparty_max_htlc_value_in_flight_msat: 0,
@@ -1470,6 +1476,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
14701476
channel_creation_height: current_chain_height,
14711477

14721478
feerate_per_kw: msg.feerate_per_kw,
1479+
high_priority_feerate_per_kw: Some(fee_estimator.bounded_sat_per_1000_weight(ConfirmationTarget::HighPriority)),
14731480
channel_value_satoshis: msg.funding_satoshis,
14741481
counterparty_dust_limit_satoshis: msg.dust_limit_satoshis,
14751482
holder_dust_limit_satoshis: MIN_CHAN_DUST_LIMIT_SATOSHIS,
@@ -4962,6 +4969,11 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
49624969
self.config.options.max_dust_htlc_exposure_msat
49634970
}
49644971

4972+
/// Sets the channel's high priority feerate per kw.
4973+
pub fn update_high_priority_feerate(&mut self, high_priority_feerate_per_kw: u32) {
4974+
self.high_priority_feerate_per_kw = Some(high_priority_feerate_per_kw);
4975+
}
4976+
49654977
/// Returns the previous [`ChannelConfig`] applied to this channel, if any.
49664978
pub fn prev_config(&self) -> Option<ChannelConfig> {
49674979
self.prev_config.map(|prev_config| prev_config.0)
@@ -7046,6 +7058,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
70467058
let mut holder_max_accepted_htlcs: Option<u16> = None;
70477059

70487060
let mut pending_monitor_updates = Some(Vec::new());
7061+
let mut high_priority_feerate_per_kw = None;
70497062

70507063
read_tlv_fields!(reader, {
70517064
(0, announcement_sigs, option),
@@ -7070,6 +7083,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
70707083
(29, temporary_channel_id, option),
70717084
(31, channel_pending_event_emitted, option),
70727085
(33, pending_monitor_updates, vec_type),
7086+
(35, high_priority_feerate_per_kw, option),
70737087
});
70747088

70757089
let (channel_keys_id, holder_signer) = if let Some(channel_keys_id) = channel_keys_id {
@@ -7172,6 +7186,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
71727186
next_counterparty_htlc_id,
71737187
update_time_counter,
71747188
feerate_per_kw,
7189+
high_priority_feerate_per_kw,
71757190

71767191
#[cfg(debug_assertions)]
71777192
holder_max_commitment_tx_output: Mutex::new((0, 0)),

lightning/src/ln/channelmanager.rs

+2
Original file line numberDiff line numberDiff line change
@@ -4008,6 +4008,7 @@ where
40084008
let mut should_persist = self.process_background_events();
40094009

40104010
let new_feerate = self.fee_estimator.bounded_sat_per_1000_weight(ConfirmationTarget::Normal);
4011+
let new_high_priority_feerate = self.fee_estimator.bounded_sat_per_1000_weight(ConfirmationTarget::HighPriority);
40114012

40124013
let mut handle_errors: Vec<(Result<(), _>, _)> = Vec::new();
40134014
let mut timed_out_mpp_htlcs = Vec::new();
@@ -4020,6 +4021,7 @@ where
40204021
let pending_msg_events = &mut peer_state.pending_msg_events;
40214022
let counterparty_node_id = *counterparty_node_id;
40224023
peer_state.channel_by_id.retain(|chan_id, chan| {
4024+
chan.update_high_priority_feerate(new_high_priority_feerate);
40234025
let chan_needs_persist = self.update_channel_fee(chan_id, chan, new_feerate);
40244026
if chan_needs_persist == NotifyOption::DoPersist { should_persist = NotifyOption::DoPersist; }
40254027

0 commit comments

Comments
 (0)