Expose API to update a channel's ChannelConfig
[rust-lightning] / lightning / src / ln / channel.rs
index 846bfd01be843c6c60c4cdfd724bfa9e7301f71a..ab26cea33f092187756a72e42d091952ed98ef7b 100644 (file)
@@ -4491,12 +4491,27 @@ 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
        }
 
+       /// Updates the channel's config. A bool is returned indicating whether the config update
+       /// applied resulted in a new ChannelUpdate message.
+       pub fn update_config(&mut self, config: &ChannelConfig) -> bool {
+               let did_channel_update =
+                       self.config.options.forwarding_fee_proportional_millionths != config.forwarding_fee_proportional_millionths ||
+                       self.config.options.forwarding_fee_base_msat != config.forwarding_fee_base_msat ||
+                       self.config.options.cltv_expiry_delta != config.cltv_expiry_delta;
+               if did_channel_update {
+                       // Update the counter, which backs the ChannelUpdate timestamp, to allow the relay
+                       // policy change to propagate throughout the network.
+                       self.update_time_counter += 1;
+               }
+               self.config.options = *config;
+               did_channel_update
+       }
+
        pub fn get_feerate(&self) -> u32 {
                self.feerate_per_kw
        }