Skip to content

Commit dfd5679

Browse files
committed
Expose ChannelConfig within ChannelDetails
As we prepare to expose an API to update a channel's ChannelConfig, we'll also want to expose this struct to consumers such that they have insights into the current ChannelConfig applied for each channel.
1 parent 8fce6a1 commit dfd5679

File tree

5 files changed

+30
-4
lines changed

5 files changed

+30
-4
lines changed

fuzz/src/router.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
235235
next_outbound_htlc_limit_msat: capacity.saturating_mul(1000),
236236
inbound_htlc_minimum_msat: None,
237237
inbound_htlc_maximum_msat: None,
238+
config: None,
238239
});
239240
}
240241
Some(&first_hops_vec[..])

lightning/src/ln/channel.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use util::events::ClosureReason;
3939
use util::ser::{Readable, ReadableArgs, Writeable, Writer, VecWriter};
4040
use util::logger::Logger;
4141
use util::errors::APIError;
42-
use util::config::{UserConfig, LegacyChannelConfig, ChannelHandshakeConfig, ChannelHandshakeLimits};
42+
use util::config::{UserConfig, ChannelConfig, LegacyChannelConfig, ChannelHandshakeConfig, ChannelHandshakeLimits};
4343
use util::scid_utils::scid_from_parts;
4444

4545
use io;
@@ -4491,6 +4491,12 @@ impl<Signer: Sign> Channel<Signer> {
44914491
self.config.options.max_dust_htlc_exposure_msat
44924492
}
44934493

4494+
4495+
/// Returns the current [`ChannelConfig`] applied to the channel.
4496+
pub fn config(&self) -> ChannelConfig {
4497+
self.config.options
4498+
}
4499+
44944500
pub fn get_feerate(&self) -> u32 {
44954501
self.feerate_per_kw
44964502
}

lightning/src/ln/channelmanager.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ use ln::onion_utils;
5151
use ln::msgs::{ChannelMessageHandler, DecodeError, LightningError, MAX_VALUE_MSAT, OptionalField};
5252
use ln::wire::Encode;
5353
use chain::keysinterface::{Sign, KeysInterface, KeysManager, InMemorySigner, Recipient};
54-
use util::config::UserConfig;
54+
use util::config::{UserConfig, ChannelConfig};
5555
use util::events::{EventHandler, EventsProvider, MessageSendEvent, MessageSendEventsProvider, ClosureReason};
5656
use util::{byte_utils, events};
5757
use util::scid_utils::fake_scid;
@@ -1095,6 +1095,10 @@ pub struct ChannelDetails {
10951095
pub inbound_htlc_minimum_msat: Option<u64>,
10961096
/// The largest value HTLC (in msat) we currently will accept, for this channel.
10971097
pub inbound_htlc_maximum_msat: Option<u64>,
1098+
/// Set of configurable parameters that affect channel operation.
1099+
///
1100+
/// This field is only `None` for `ChannelDetails` objects serialized prior to LDK 0.0.109.
1101+
pub config: Option<ChannelConfig>,
10981102
}
10991103

11001104
impl ChannelDetails {
@@ -1759,7 +1763,8 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
17591763
is_usable: channel.is_live(),
17601764
is_public: channel.should_announce(),
17611765
inbound_htlc_minimum_msat: Some(channel.get_holder_htlc_minimum_msat()),
1762-
inbound_htlc_maximum_msat: channel.get_holder_htlc_maximum_msat()
1766+
inbound_htlc_maximum_msat: channel.get_holder_htlc_maximum_msat(),
1767+
config: Some(channel.config()),
17631768
});
17641769
}
17651770
}
@@ -6089,6 +6094,7 @@ impl_writeable_tlv_based!(ChannelDetails, {
60896094
(4, counterparty, required),
60906095
(5, outbound_scid_alias, option),
60916096
(6, funding_txo, option),
6097+
(7, config, option),
60926098
(8, short_channel_id, option),
60936099
(10, channel_value_satoshis, required),
60946100
(12, unspendable_punishment_reserve, option),

lightning/src/routing/router.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1937,6 +1937,7 @@ mod tests {
19371937
is_usable: true, is_public: true,
19381938
inbound_htlc_minimum_msat: None,
19391939
inbound_htlc_maximum_msat: None,
1940+
config: None,
19401941
}
19411942
}
19421943

@@ -5806,6 +5807,7 @@ mod benches {
58065807
is_public: true,
58075808
inbound_htlc_minimum_msat: None,
58085809
inbound_htlc_maximum_msat: None,
5810+
config: None,
58095811
}
58105812
}
58115813

lightning/src/util/config.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ impl Default for ChannelHandshakeLimits {
249249

250250
/// Options which apply on a per-channel basis and may change at runtime or based on negotiation
251251
/// with our counterparty.
252-
#[derive(Copy, Clone, Debug)]
252+
#[derive(Copy, Clone, Debug, PartialEq)]
253253
pub struct ChannelConfig {
254254
/// Amount (in millionths of a satoshi) charged per satoshi for payments forwarded outbound
255255
/// over the channel.
@@ -345,6 +345,17 @@ impl Default for ChannelConfig {
345345
}
346346
}
347347

348+
impl_writeable_tlv_based!(ChannelConfig, {
349+
(0, forwarding_fee_proportional_millionths, required),
350+
(2, forwarding_fee_base_msat, required),
351+
(4, cltv_expiry_delta, required),
352+
(6, max_dust_htlc_exposure_msat, required),
353+
// ChannelConfig serialized this field with a required type of 8 prior to the introduction of
354+
// LegacyChannelConfig. To make sure that serialization is not compatible with this one, we use
355+
// the next required type of 10, which if seen by the old serialization will always fail.
356+
(10, force_close_avoidance_max_fee_satoshis, required),
357+
});
358+
348359
/// Legacy version of [`ChannelConfig`] that stored the static
349360
/// [`ChannelHandshakeConfig::announced_channel`] and
350361
/// [`ChannelHandshakeConfig::commit_upfront_shutdown_pubkey`] fields.

0 commit comments

Comments
 (0)