Skip to content

Commit f1ab771

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 f1ab771

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

lightning/src/ln/channel.rs

+6-1
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,11 @@ impl<Signer: Sign> Channel<Signer> {
44914491
self.config.options.max_dust_htlc_exposure_msat
44924492
}
44934493

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

lightning/src/ln/channelmanager.rs

+8-2
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.get_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

+1
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

lightning/src/util/config.rs

+9-1
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,14 @@ 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, (default_value, 5_000_000)),
353+
(8, force_close_avoidance_max_fee_satoshis, (default_value, 1000)),
354+
});
355+
348356
/// Legacy version of [`ChannelConfig`] that stored the static
349357
/// [`ChannelHandshakeConfig::announced_channel`] and
350358
/// [`ChannelHandshakeConfig::commit_upfront_shutdown_pubkey`] fields.

0 commit comments

Comments
 (0)