1 //! Various user-configurable channel limits and settings which ChannelManager
4 /// Top-level config which holds ChannelHandshakeLimits and ChannelConfig.
5 #[derive(Clone, Debug)]
6 pub struct UserConfig {
7 /// Limits applied during channel creation.
8 pub channel_limits: ChannelHandshakeLimits,
9 /// Channel config which affects behavior during channel lifetime.
10 pub channel_options: ChannelConfig,
14 /// Provides sane defaults for most configurations (but with 0 relay fees!)
17 channel_limits: ChannelHandshakeLimits::new(),
18 channel_options: ChannelConfig::new(),
23 /// Optional channel limits which are applied during channel creation.
25 /// These limits are only applied to our counterparty's limits, not our own.
27 /// Use 0/<type>::max_value() as appropriate to skip checking.
28 #[derive(Copy, Clone, Debug)]
29 pub struct ChannelHandshakeLimits {
30 /// Minimum allowed satoshis when a channel is funded, this is supplied by the sender and so
31 /// only applies to inbound channels.
32 pub min_funding_satoshis: u64,
33 /// The remote node sets a limit on the minimum size of HTLCs we can send to them. This allows
34 /// you to limit the maximum minimum-size they can require.
35 pub max_htlc_minimum_msat: u64,
36 /// The remote node sets a limit on the maximum value of pending HTLCs to them at any given
37 /// time to limit their funds exposure to HTLCs. This allows you to set a minimum such value.
38 pub min_max_htlc_value_in_flight_msat: u64,
39 /// The remote node will require we keep a certain amount in direct payment to ourselves at all
40 /// time, ensuring that we are able to be punished if we broadcast an old state. This allows to
41 /// you limit the amount which we will have to keep to ourselves (and cannot use for HTLCs).
42 pub max_channel_reserve_satoshis: u64,
43 /// The remote node sets a limit on the maximum number of pending HTLCs to them at any given
44 /// time. This allows you to set a minimum such value.
45 pub min_max_accepted_htlcs: u16,
46 /// Outputs below a certain value will not be added to on-chain transactions. The dust value is
47 /// required to always be higher than this value so this only applies to HTLC outputs (and
48 /// potentially to-self outputs before any payments have been made).
49 /// Thus, HTLCs below this amount plus HTLC transaction fees are not enforceable on-chain.
50 /// This setting allows you to set a minimum dust limit for their commitment transactions,
51 /// reflecting the reality that tiny outputs are not considered standard transactions and will
52 /// not propagate through the Bitcoin network.
53 /// Defaults to 546, or the current dust limit on the Bitcoin network.
54 pub min_dust_limit_satoshis: u64,
55 /// Maximum allowed threshold above which outputs will not be generated in their commitment
57 /// HTLCs below this amount plus HTLC transaction fees are not enforceable on-chain.
58 pub max_dust_limit_satoshis: u64,
59 /// Before a channel is usable the funding transaction will need to be confirmed by at least a
60 /// certain number of blocks, specified by the node which is not the funder (as the funder can
61 /// assume they aren't going to double-spend themselves).
62 /// This config allows you to set a limit on the maximum amount of time to wait. Defaults to
63 /// 144 blocks or roughly one day and only applies to outbound channels.
64 pub max_minimum_depth: u32,
65 /// Set to force the incoming channel to match our announced channel preference in
67 /// Defaults to true to make the default that no announced channels are possible (which is
68 /// appropriate for any nodes which are not online very reliably).
69 pub force_announced_channel_preference: bool,
72 impl ChannelHandshakeLimits {
73 /// Provides sane defaults for most configurations.
75 /// Most additional limits are disabled except those with which specify a default in individual
76 /// field documentation. Note that this may result in barely-usable channels, but since they
77 /// are applied mostly only to incoming channels that's not much of a problem.
78 pub fn new() -> Self {
79 ChannelHandshakeLimits {
80 min_funding_satoshis: 0,
81 max_htlc_minimum_msat: <u64>::max_value(),
82 min_max_htlc_value_in_flight_msat: 0,
83 max_channel_reserve_satoshis: <u64>::max_value(),
84 min_max_accepted_htlcs: 0,
85 min_dust_limit_satoshis: 546,
86 max_dust_limit_satoshis: <u64>::max_value(),
87 max_minimum_depth: 144,
88 force_announced_channel_preference: true,
93 /// Options which apply on a per-channel basis and may change at runtime or based on negotiation
94 /// with our counterparty.
95 #[derive(Copy, Clone, Debug)]
96 pub struct ChannelConfig {
97 /// Amount (in millionths of a satoshi) the channel will charge per transferred satoshi.
98 /// This may be allowed to change at runtime in a later update, however doing so must result in
99 /// update messages sent to notify all nodes of our updated relay fee.
100 pub fee_proportional_millionths: u32,
101 /// Set to announce the channel publicly and notify all nodes that they can route via this
104 /// This should only be set to true for nodes which expect to be online reliably.
106 /// As the node which funds a channel picks this value this will only apply for new outbound
107 /// channels unless ChannelHandshakeLimits::force_announced_channel_preferences is set.
109 /// This cannot be changed after the initial channel handshake.
110 pub announced_channel: bool,
114 /// Provides sane defaults for most configurations (but with zero relay fees!).
115 pub fn new() -> Self {
117 fee_proportional_millionths: 0,
118 announced_channel: false,
123 //Add write and readable traits to channelconfig
124 impl_writeable!(ChannelConfig, 8+1, {
125 fee_proportional_millionths,