]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Expose ChannelConfig within ChannelDetails
authorWilmer Paulino <wilmer.paulino@gmail.com>
Tue, 14 Jun 2022 23:40:12 +0000 (16:40 -0700)
committerWilmer Paulino <wilmer.paulino@gmail.com>
Mon, 20 Jun 2022 20:12:28 +0000 (13:12 -0700)
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.

fuzz/src/router.rs
lightning/src/ln/channel.rs
lightning/src/ln/channelmanager.rs
lightning/src/routing/router.rs
lightning/src/util/config.rs

index 21fb2dc152a5fa9aa72f0b79dbca24ef63fad2a3..84afb91f952263fbd39566da37cf8bef17a9d7cc 100644 (file)
@@ -235,6 +235,7 @@ pub fn do_test<Out: test_logger::Output>(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[..])
index 9b47770f120310cce58cc01bc4ab63d1a679b590..846bfd01be843c6c60c4cdfd724bfa9e7301f71a 100644 (file)
@@ -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<Signer: Sign> Channel<Signer> {
                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
        }
index cf593068947478d7060b7603b93f13400e31bda2..6913e1f7ed7ae450ecc463f5374ef3a707cfb26f 100644 (file)
@@ -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<u64>,
        /// The largest value HTLC (in msat) we currently will accept, for this channel.
        pub inbound_htlc_maximum_msat: Option<u64>,
+       /// 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<ChannelConfig>,
 }
 
 impl ChannelDetails {
@@ -1759,7 +1763,8 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> 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),
index 2c25b277f264198a931476ab97ea7e0fac6e7452..634282d6c4b1f202fd0867312fc3dd83fc9b57fb 100644 (file)
@@ -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,
                }
        }
 
index a76f71621011d80b55c02fe898e769055427a808..be7accc18dacfc837d89bddcec937e0e9eb4b349 100644 (file)
@@ -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.