From: Wilmer Paulino Date: Tue, 14 Jun 2022 23:40:12 +0000 (-0700) Subject: Expose ChannelConfig within ChannelDetails X-Git-Tag: v0.0.109~10^2~4 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=dfd56793a77fa92ed36f6951dcb4e93c250376c4;p=rust-lightning 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. --- diff --git a/fuzz/src/router.rs b/fuzz/src/router.rs index 21fb2dc1..84afb91f 100644 --- a/fuzz/src/router.rs +++ b/fuzz/src/router.rs @@ -235,6 +235,7 @@ pub fn do_test(data: &[u8], out: Out) { next_outbound_htlc_limit_msat: capacity.saturating_mul(1000), inbound_htlc_minimum_msat: None, inbound_htlc_maximum_msat: None, + config: None, }); } Some(&first_hops_vec[..]) diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs index 9b47770f..846bfd01 100644 --- a/lightning/src/ln/channel.rs +++ b/lightning/src/ln/channel.rs @@ -39,7 +39,7 @@ use util::events::ClosureReason; use util::ser::{Readable, ReadableArgs, Writeable, Writer, VecWriter}; use util::logger::Logger; use util::errors::APIError; -use util::config::{UserConfig, LegacyChannelConfig, ChannelHandshakeConfig, ChannelHandshakeLimits}; +use util::config::{UserConfig, ChannelConfig, LegacyChannelConfig, ChannelHandshakeConfig, ChannelHandshakeLimits}; use util::scid_utils::scid_from_parts; use io; @@ -4491,6 +4491,12 @@ impl Channel { self.config.options.max_dust_htlc_exposure_msat } + + /// Returns the current [`ChannelConfig`] applied to the channel. + pub fn config(&self) -> ChannelConfig { + self.config.options + } + pub fn get_feerate(&self) -> u32 { self.feerate_per_kw } diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index cf593068..6913e1f7 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -51,7 +51,7 @@ use ln::onion_utils; use ln::msgs::{ChannelMessageHandler, DecodeError, LightningError, MAX_VALUE_MSAT, OptionalField}; use ln::wire::Encode; use chain::keysinterface::{Sign, KeysInterface, KeysManager, InMemorySigner, Recipient}; -use util::config::UserConfig; +use util::config::{UserConfig, ChannelConfig}; use util::events::{EventHandler, EventsProvider, MessageSendEvent, MessageSendEventsProvider, ClosureReason}; use util::{byte_utils, events}; use util::scid_utils::fake_scid; @@ -1095,6 +1095,10 @@ pub struct ChannelDetails { pub inbound_htlc_minimum_msat: Option, /// The largest value HTLC (in msat) we currently will accept, for this channel. pub inbound_htlc_maximum_msat: Option, + /// Set of configurable parameters that affect channel operation. + /// + /// This field is only `None` for `ChannelDetails` objects serialized prior to LDK 0.0.109. + pub config: Option, } impl ChannelDetails { @@ -1759,7 +1763,8 @@ impl ChannelMana is_usable: channel.is_live(), is_public: channel.should_announce(), inbound_htlc_minimum_msat: Some(channel.get_holder_htlc_minimum_msat()), - inbound_htlc_maximum_msat: channel.get_holder_htlc_maximum_msat() + inbound_htlc_maximum_msat: channel.get_holder_htlc_maximum_msat(), + config: Some(channel.config()), }); } } @@ -6089,6 +6094,7 @@ impl_writeable_tlv_based!(ChannelDetails, { (4, counterparty, required), (5, outbound_scid_alias, option), (6, funding_txo, option), + (7, config, option), (8, short_channel_id, option), (10, channel_value_satoshis, required), (12, unspendable_punishment_reserve, option), diff --git a/lightning/src/routing/router.rs b/lightning/src/routing/router.rs index 2c25b277..634282d6 100644 --- a/lightning/src/routing/router.rs +++ b/lightning/src/routing/router.rs @@ -1937,6 +1937,7 @@ mod tests { is_usable: true, is_public: true, inbound_htlc_minimum_msat: None, inbound_htlc_maximum_msat: None, + config: None, } } @@ -5806,6 +5807,7 @@ mod benches { is_public: true, inbound_htlc_minimum_msat: None, inbound_htlc_maximum_msat: None, + config: None, } } diff --git a/lightning/src/util/config.rs b/lightning/src/util/config.rs index a76f7162..be7accc1 100644 --- a/lightning/src/util/config.rs +++ b/lightning/src/util/config.rs @@ -249,7 +249,7 @@ impl Default for ChannelHandshakeLimits { /// Options which apply on a per-channel basis and may change at runtime or based on negotiation /// with our counterparty. -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq)] pub struct ChannelConfig { /// Amount (in millionths of a satoshi) charged per satoshi for payments forwarded outbound /// over the channel. @@ -345,6 +345,17 @@ impl Default for ChannelConfig { } } +impl_writeable_tlv_based!(ChannelConfig, { + (0, forwarding_fee_proportional_millionths, required), + (2, forwarding_fee_base_msat, required), + (4, cltv_expiry_delta, required), + (6, max_dust_htlc_exposure_msat, required), + // ChannelConfig serialized this field with a required type of 8 prior to the introduction of + // LegacyChannelConfig. To make sure that serialization is not compatible with this one, we use + // the next required type of 10, which if seen by the old serialization will always fail. + (10, force_close_avoidance_max_fee_satoshis, required), +}); + /// Legacy version of [`ChannelConfig`] that stored the static /// [`ChannelHandshakeConfig::announced_channel`] and /// [`ChannelHandshakeConfig::commit_upfront_shutdown_pubkey`] fields.