@@ -15,6 +15,7 @@ const DEFAULT_LDK_WALLET_SYNC_INTERVAL_SECS: u64 = 30;
15
15
const DEFAULT_FEE_RATE_CACHE_UPDATE_INTERVAL_SECS : u64 = 60 * 10 ;
16
16
const DEFAULT_PROBING_LIQUIDITY_LIMIT_MULTIPLIER : u64 = 3 ;
17
17
const DEFAULT_LOG_LEVEL : LogLevel = LogLevel :: Debug ;
18
+ const DEFAULT_ANCHOR_PER_CHANNEL_RESERVE_SATS : u64 = 25_000 ;
18
19
19
20
// The 'stop gap' parameter used by BDK's wallet sync. This seems to configure the threshold
20
21
// number of derivation indexes after which BDK stops looking for new scripts belonging to the wallet.
@@ -62,6 +63,9 @@ pub(crate) const WALLET_KEYS_SEED_LEN: usize = 64;
62
63
/// | `trusted_peers_0conf` | [] |
63
64
/// | `probing_liquidity_limit_multiplier` | 3 |
64
65
/// | `log_level` | Debug |
66
+ /// | `anchor_channels_config` | Some(..) |
67
+ ///
68
+ /// See [`AnchorChannelsConfig`] for more information on its respective default values.
65
69
///
66
70
/// [`Node`]: crate::Node
67
71
pub struct Config {
@@ -104,6 +108,23 @@ pub struct Config {
104
108
///
105
109
/// Any messages below this level will be excluded from the logs.
106
110
pub log_level : LogLevel ,
111
+ /// Configuration options pertaining to Anchor channels, i.e., channels for which the
112
+ /// `option_anchors_zero_fee_htlc_tx` channel type is negotiated.
113
+ ///
114
+ /// Please refer to [`AnchorChannelsConfig`] for further information on Anchor channels.
115
+ ///
116
+ /// If set to `Some`, we'll try to open new channels with Anchors enabled, i.e., new channels
117
+ /// will be negotiated with the `option_anchors_zero_fee_htlc_tx` channel type if supported by
118
+ /// the counterparty. Note that this won't prevent us from opening non-Anchor channels if the
119
+ /// counterparty doesn't support `option_anchors_zero_fee_htlc_tx`. If set to `None`, new
120
+ /// channels will be negotiated with the legacy `option_static_remotekey` channel type only.
121
+ ///
122
+ /// **Note:** If set to `None` *after* some Anchor channels have already been
123
+ /// opened, no dedicated emergency on-chain reserve will be maintained for these channels,
124
+ /// which can be dangerous if only insufficient funds are available at the time of channel
125
+ /// closure. We *will* however still try to get the Anchor spending transactions confirmed
126
+ /// on-chain with the funds available.
127
+ pub anchor_channels_config : Option < AnchorChannelsConfig > ,
107
128
}
108
129
109
130
impl Default for Config {
@@ -120,6 +141,78 @@ impl Default for Config {
120
141
trusted_peers_0conf : Vec :: new ( ) ,
121
142
probing_liquidity_limit_multiplier : DEFAULT_PROBING_LIQUIDITY_LIMIT_MULTIPLIER ,
122
143
log_level : DEFAULT_LOG_LEVEL ,
144
+ anchor_channels_config : Some ( AnchorChannelsConfig :: default ( ) ) ,
145
+ }
146
+ }
147
+ }
148
+
149
+ /// Configuration options pertaining to 'Anchor' channels, i.e., channels for which the
150
+ /// `option_anchors_zero_fee_htlc_tx` channel type is negotiated.
151
+ ///
152
+ /// Prior to the introduction of Anchor channels, the on-chain fees paying for the transactions
153
+ /// issued on channel closure were pre-determined and locked-in at the time of the channel
154
+ /// opening. This required to estimate what fee rate would be sufficient to still have the
155
+ /// closing transactions be spendable on-chain (i.e., not be considered dust). This legacy
156
+ /// design of pre-anchor channels proved inadequate in the unpredictable, often turbulent, fee
157
+ /// markets we experience today.
158
+ ///
159
+ /// In contrast, Anchor channels allow to determine an adequate fee rate *at the time of channel
160
+ /// closure*, making them much more robust in the face of fee spikes. In turn, they require to
161
+ /// maintain a reserve of on-chain funds to have the channel closure transactions confirmed
162
+ /// on-chain, at least if the channel counterparty can't be trusted to do this for us.
163
+ ///
164
+ /// See [BOLT 3] for more technical details on Anchor channels.
165
+ ///
166
+ ///
167
+ /// ### Defaults
168
+ ///
169
+ /// | Parameter | Value |
170
+ /// |----------------------------|--------|
171
+ /// | `trusted_peers_no_reserve` | [] |
172
+ /// | `per_channel_reserve_sats` | 25000 |
173
+ ///
174
+ ///
175
+ /// [BOLT 3]: https://github.com/lightning/bolts/blob/master/03-transactions.md#htlc-timeout-and-htlc-success-transactions
176
+ #[ derive( Debug , Clone ) ]
177
+ pub struct AnchorChannelsConfig {
178
+ /// A list of peers that we trust to get the required channel closing transactions confirmed
179
+ /// on-chain.
180
+ ///
181
+ /// Channels with these peers won't count towards the retained on-chain reserve and we won't
182
+ /// take any action to get the required transactions confirmed ourselves.
183
+ ///
184
+ /// **Note:** Trusting the channel counterparty to take the necessary actions to get the
185
+ /// required Anchor spending and HTLC transactions confirmed on-chain is potentially insecure
186
+ /// as the channel may not be closed if they refuse to do so, potentially leaving the user
187
+ /// funds stuck *or* even allow the counterparty to steal any in-flight funds after the
188
+ /// corresponding HTLCs time out.
189
+ pub trusted_peers_no_reserve : Vec < PublicKey > ,
190
+ /// The amount of satoshis per anchors-negotiated channel with an untrusted peer that we keep
191
+ /// as an emergency reserve in our on-chain wallet.
192
+ ///
193
+ /// This allows for having the required Anchor output spending and HTLC transactions confirmed
194
+ /// when the channel is closed.
195
+ ///
196
+ /// If the channel peer is not marked as trusted via
197
+ /// [`AnchorChannelsConfig::trusted_peers_no_reserve`], we will always try to spend the Anchor
198
+ /// outputs with *any* on-chain funds available, i.e., the total reserve value as well as any
199
+ /// spendable funds available in the on-chain wallet. Therefore, this per-channel multiplier is
200
+ /// really a emergencey reserve that we maintain at all time to reduce reduce the risk of
201
+ /// insufficient funds at time of a channel closure. To this end, we will refuse to open
202
+ /// outbound or accept inbound channels if we don't have sufficient on-chain funds availble to
203
+ /// cover the additional reserve requirement.
204
+ ///
205
+ /// **Note:** Depending on the fee market at the time of closure, this reserve amount might or
206
+ /// might not suffice to successfully spend the Anchor output and have the HTLC transactions
207
+ /// confirmed on-chain, i.e., you may want to adjust this value accordingly.
208
+ pub per_channel_reserve_sats : u64 ,
209
+ }
210
+
211
+ impl Default for AnchorChannelsConfig {
212
+ fn default ( ) -> Self {
213
+ Self {
214
+ trusted_peers_no_reserve : Vec :: new ( ) ,
215
+ per_channel_reserve_sats : DEFAULT_ANCHOR_PER_CHANNEL_RESERVE_SATS ,
123
216
}
124
217
}
125
218
}
0 commit comments