Skip to content

Commit 725a532

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 a8dd213 commit 725a532

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

lightning/src/ln/channel.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,7 @@ pub(super) struct ChannelContext<Signer: ChannelSigner> {
684684
next_holder_htlc_id: u64,
685685
next_counterparty_htlc_id: u64,
686686
feerate_per_kw: u32,
687+
high_priority_feerate_per_kw: Option<u32>,
687688

688689
/// The timestamp set on our latest `channel_update` message for this channel. It is updated
689690
/// when the channel is updated in ways which may impact the `channel_update` message or when a
@@ -1073,6 +1074,11 @@ impl<Signer: ChannelSigner> ChannelContext<Signer> {
10731074
self.config.options.max_dust_htlc_exposure_msat
10741075
}
10751076

1077+
/// Sets the channel's high priority feerate per kw.
1078+
pub fn update_high_priority_feerate(&mut self, high_priority_feerate_per_kw: u32) {
1079+
self.high_priority_feerate_per_kw = Some(high_priority_feerate_per_kw);
1080+
}
1081+
10761082
/// Returns the previous [`ChannelConfig`] applied to this channel, if any.
10771083
pub fn prev_config(&self) -> Option<ChannelConfig> {
10781084
self.prev_config.map(|prev_config| prev_config.0)
@@ -5473,6 +5479,7 @@ impl<Signer: WriteableEcdsaChannelSigner> OutboundV1Channel<Signer> {
54735479
debug_assert!(channel_type.is_subset(&channelmanager::provided_channel_type_features(&config)));
54745480

54755481
let feerate = fee_estimator.bounded_sat_per_1000_weight(ConfirmationTarget::Normal);
5482+
let high_priority_feerate = fee_estimator.bounded_sat_per_1000_weight(ConfirmationTarget::HighPriority);
54765483

54775484
let value_to_self_msat = channel_value_satoshis * 1000 - push_msat;
54785485
let commitment_tx_fee = commit_tx_fee_msat(feerate, MIN_AFFORDABLE_HTLC_COUNT, channel_type.requires_anchors_zero_fee_htlc_tx());
@@ -5570,6 +5577,7 @@ impl<Signer: WriteableEcdsaChannelSigner> OutboundV1Channel<Signer> {
55705577
channel_creation_height: current_chain_height,
55715578

55725579
feerate_per_kw: feerate,
5580+
high_priority_feerate_per_kw: Some(high_priority_feerate),
55735581
counterparty_dust_limit_satoshis: 0,
55745582
holder_dust_limit_satoshis: MIN_CHAN_DUST_LIMIT_SATOSHIS,
55755583
counterparty_max_htlc_value_in_flight_msat: 0,
@@ -6196,6 +6204,7 @@ impl<Signer: WriteableEcdsaChannelSigner> InboundV1Channel<Signer> {
61966204
channel_creation_height: current_chain_height,
61976205

61986206
feerate_per_kw: msg.feerate_per_kw,
6207+
high_priority_feerate_per_kw: Some(fee_estimator.bounded_sat_per_1000_weight(ConfirmationTarget::HighPriority)),
61996208
channel_value_satoshis: msg.funding_satoshis,
62006209
counterparty_dust_limit_satoshis: msg.dust_limit_satoshis,
62016210
holder_dust_limit_satoshis: MIN_CHAN_DUST_LIMIT_SATOSHIS,
@@ -7102,6 +7111,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
71027111
let mut holder_max_accepted_htlcs: Option<u16> = None;
71037112

71047113
let mut pending_monitor_updates = Some(Vec::new());
7114+
let mut high_priority_feerate_per_kw = None;
71057115

71067116
read_tlv_fields!(reader, {
71077117
(0, announcement_sigs, option),
@@ -7126,6 +7136,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
71267136
(29, temporary_channel_id, option),
71277137
(31, channel_pending_event_emitted, option),
71287138
(33, pending_monitor_updates, vec_type),
7139+
(35, high_priority_feerate_per_kw, option),
71297140
});
71307141

71317142
let (channel_keys_id, holder_signer) = if let Some(channel_keys_id) = channel_keys_id {
@@ -7229,6 +7240,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
72297240
next_counterparty_htlc_id,
72307241
update_time_counter,
72317242
feerate_per_kw,
7243+
high_priority_feerate_per_kw,
72327244

72337245
#[cfg(debug_assertions)]
72347246
holder_max_commitment_tx_output: Mutex::new((0, 0)),

lightning/src/ln/channelmanager.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4120,6 +4120,7 @@ where
41204120
let mut should_persist = self.process_background_events();
41214121

41224122
let new_feerate = self.fee_estimator.bounded_sat_per_1000_weight(ConfirmationTarget::Normal);
4123+
let new_high_priority_feerate = self.fee_estimator.bounded_sat_per_1000_weight(ConfirmationTarget::HighPriority);
41234124

41244125
let mut handle_errors: Vec<(Result<(), _>, _)> = Vec::new();
41254126
let mut timed_out_mpp_htlcs = Vec::new();
@@ -4132,6 +4133,7 @@ where
41324133
let pending_msg_events = &mut peer_state.pending_msg_events;
41334134
let counterparty_node_id = *counterparty_node_id;
41344135
peer_state.channel_by_id.retain(|chan_id, chan| {
4136+
chan.context.update_high_priority_feerate(new_high_priority_feerate);
41354137
let chan_needs_persist = self.update_channel_fee(chan_id, chan, new_feerate);
41364138
if chan_needs_persist == NotifyOption::DoPersist { should_persist = NotifyOption::DoPersist; }
41374139

0 commit comments

Comments
 (0)