Add user configurable csv delay encumbering channel refund output,
[rust-lightning] / src / util / config.rs
index f3b574b93fba6c40389761994cb92cddb1b3480a..5b805d45e478ca0ed73392a5cbac91d1561478b4 100644 (file)
@@ -1,6 +1,8 @@
 //! Various user-configurable channel limits and settings which ChannelManager
 //! applies for you.
 
+use ln::channelmanager::{BREAKDOWN_TIMEOUT, MAX_LOCAL_BREAKDOWN_TIMEOUT};
+
 /// Top-level config which holds ChannelHandshakeLimits and ChannelConfig.
 #[derive(Clone, Debug)]
 pub struct UserConfig {
@@ -30,6 +32,18 @@ pub struct ChannelHandshakeConfig {
        /// Applied only for inbound channels (see ChannelHandshakeLimits::max_minimum_depth for the
        /// equivalent limit applied to outbound channels).
        pub minimum_depth: u32,
+       /// Set to the amount of time we require our counterparty to wait to claim their money.
+       ///
+       /// It's one of the main parameter of our security model. We (or one of our watchtowers) MUST
+       /// be online to check for peer having broadcast a revoked transaction to steal our funds
+       /// at least once every our_to_self_delay blocks.
+       /// Default is BREAKDOWN_TIMEOUT, we enforce it as a minimum at channel opening so you can
+       /// tweak config to ask for more security, not less.
+       ///
+       /// Meanwhile, asking for a too high delay, we bother peer to freeze funds for nothing in
+       /// case of an honest unilateral channel close, which implicitly decrease the economic value of
+       /// our channel.
+       pub our_to_self_delay: u16,
 }
 
 impl ChannelHandshakeConfig {
@@ -37,6 +51,7 @@ impl ChannelHandshakeConfig {
        pub fn new() -> ChannelHandshakeConfig {
                ChannelHandshakeConfig {
                        minimum_depth: 6,
+                       our_to_self_delay: BREAKDOWN_TIMEOUT,
                }
        }
 }
@@ -88,6 +103,13 @@ pub struct ChannelHandshakeLimits {
        /// Defaults to true to make the default that no announced channels are possible (which is
        /// appropriate for any nodes which are not online very reliably).
        pub force_announced_channel_preference: bool,
+       /// Set to the amount of time we're willing to wait to claim money back to us.
+       ///
+       /// Not checking this value would be a security issue, as our peer would be able to set it to
+       /// max relative lock-time (a year) and we would "lose" money as it would be locked for a long time.
+       /// Default is MAX_LOCAL_BREAKDOWN_TIMEOUT, which we also enforce as a maximum value
+       /// so you can tweak config to reduce the loss of having useless locked funds (if your peer accepts)
+       pub their_to_self_delay: u16
 }
 
 impl ChannelHandshakeLimits {
@@ -107,6 +129,7 @@ impl ChannelHandshakeLimits {
                        max_dust_limit_satoshis: <u64>::max_value(),
                        max_minimum_depth: 144,
                        force_announced_channel_preference: true,
+                       their_to_self_delay: MAX_LOCAL_BREAKDOWN_TIMEOUT,
                }
        }
 }
@@ -129,6 +152,14 @@ pub struct ChannelConfig {
        ///
        /// This cannot be changed after the initial channel handshake.
        pub announced_channel: bool,
+       /// Set to commit to an upfront shutdown_pubkey at channel opening. In case of mutual
+       /// closing, the other peer will check that our closing transction output is encumbered
+       /// by the provided script.
+       ///
+       /// We set it by default as this ensure greater security to the user funds.
+       ///
+       /// This cannot be changed after channel opening.
+       pub commit_upfront_shutdown_pubkey: bool
 }
 
 impl ChannelConfig {
@@ -137,12 +168,14 @@ impl ChannelConfig {
                ChannelConfig {
                        fee_proportional_millionths: 0,
                        announced_channel: false,
+                       commit_upfront_shutdown_pubkey: true,
                }
        }
 }
 
 //Add write and readable traits to channelconfig
-impl_writeable!(ChannelConfig, 8+1, {
+impl_writeable!(ChannelConfig, 8+1+1, {
        fee_proportional_millionths,
-       announced_channel
+       announced_channel,
+       commit_upfront_shutdown_pubkey
 });