Skip to content

Commit c5e98db

Browse files
committed
Introduce AnchorChannelsConfig
.. allowing to configure the per-channel emergency reserve as well as some trusted peers for which we won't maintain any reserve.
1 parent 9990e51 commit c5e98db

File tree

3 files changed

+97
-1
lines changed

3 files changed

+97
-1
lines changed

bindings/ldk_node.udl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ dictionary Config {
1515
sequence<PublicKey> trusted_peers_0conf;
1616
u64 probing_liquidity_limit_multiplier;
1717
LogLevel log_level;
18+
AnchorChannelsConfig? anchor_channels_config;
19+
};
20+
21+
dictionary AnchorChannelsConfig {
22+
sequence<PublicKey> trusted_peers_no_reserve;
23+
u64 per_channel_reserve_sats;
1824
};
1925

2026
interface Builder {

src/config.rs

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const DEFAULT_LDK_WALLET_SYNC_INTERVAL_SECS: u64 = 30;
1515
const DEFAULT_FEE_RATE_CACHE_UPDATE_INTERVAL_SECS: u64 = 60 * 10;
1616
const DEFAULT_PROBING_LIQUIDITY_LIMIT_MULTIPLIER: u64 = 3;
1717
const DEFAULT_LOG_LEVEL: LogLevel = LogLevel::Debug;
18+
const DEFAULT_ANCHOR_PER_CHANNEL_RESERVE_SATS: u64 = 25_000;
1819

1920
// The 'stop gap' parameter used by BDK's wallet sync. This seems to configure the threshold
2021
// 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;
6263
/// | `trusted_peers_0conf` | [] |
6364
/// | `probing_liquidity_limit_multiplier` | 3 |
6465
/// | `log_level` | Debug |
66+
/// | `anchor_channels_config` | Some(..) |
67+
///
68+
/// See [`AnchorChannelsConfig`] for more information on its respective default values.
6569
///
6670
/// [`Node`]: crate::Node
6771
pub struct Config {
@@ -104,6 +108,21 @@ pub struct Config {
104108
///
105109
/// Any messages below this level will be excluded from the logs.
106110
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`, new channels will have Anchors enabled, i.e., will be negotiated with the
117+
/// `option_anchors_zero_fee_htlc_tx` channel type. If set to `None`, new channels will be
118+
/// negotiated with the legacy `option_static_remotekey` channel type.
119+
///
120+
/// **Note:** If set to `None` *after* some Anchor channels have already been
121+
/// opened, no dedicated emergency on-chain reserve will be maintained for these channels,
122+
/// which can be dangerous if only insufficient funds are available at the time of channel
123+
/// closure. We *will* however still try to get the Anchor spending transactions confirmed
124+
/// on-chain with the funds available.
125+
pub anchor_channels_config: Option<AnchorChannelsConfig>,
107126
}
108127

109128
impl Default for Config {
@@ -120,6 +139,77 @@ impl Default for Config {
120139
trusted_peers_0conf: Vec::new(),
121140
probing_liquidity_limit_multiplier: DEFAULT_PROBING_LIQUIDITY_LIMIT_MULTIPLIER,
122141
log_level: DEFAULT_LOG_LEVEL,
142+
anchor_channels_config: Some(AnchorChannelsConfig::default()),
143+
}
144+
}
145+
}
146+
147+
/// Configuration options pertaining to 'Anchor' channels, i.e., channels for which the
148+
/// `option_anchors_zero_fee_htlc_tx` channel type is negotiated.
149+
///
150+
/// Prior to the introduction of Anchor channels, the on-chain fees paying for the transactions
151+
/// issued on channel closure were pre-determined and locked-in at the time of the channel
152+
/// opening. This required to estimate what fee rate would be sufficient to still have the
153+
/// closing transactions be spendable on-chain (i.e., not be considered dust). This legacy
154+
/// design of pre-anchor channels proved inadequate in the unpredictable, often turbulent, fee
155+
/// markets we experience today.
156+
///
157+
/// In contrast, Anchor channels allow to determine an adequate fee
158+
/// rate *at the time of channel closure*, making them much more robust in the face of fee spikes.
159+
/// In turn, they require to maintain a reserve of on-chain funds to have the channel closure
160+
/// transactions confirmed on-chain, at least if the channel counterparty can't be trusted to do
161+
/// this for us.
162+
///
163+
/// See [BOLT 3] for more technical details on Anchor channels.
164+
///
165+
///
166+
/// ### Defaults
167+
///
168+
/// | Parameter | Value |
169+
/// |----------------------------|--------|
170+
/// | `trusted_peers_no_reserve` | [] |
171+
/// | `per_channel_reserve_sats` | 25000 |
172+
///
173+
///
174+
/// [BOLT 3]: https://github.com/lightning/bolts/blob/master/03-transactions.md#htlc-timeout-and-htlc-success-transactions
175+
#[derive(Debug, Clone)]
176+
pub struct AnchorChannelsConfig {
177+
/// A list of peers that we trust to get the required channel closing transactions confirmed
178+
/// on-chain.
179+
///
180+
/// Channels with these peers won't count towards the retained on-chain reserve and we won't
181+
/// take any action to get the required transactions confirmed ourselves.
182+
///
183+
/// **Note:** Trusting the channel counterparty to take the necessary actions to get the
184+
/// required Anchor spending and HTLC transactions confirmed on-chain is potentially insecure
185+
/// as the channel may not be closed if they refuse to do so, potentially leaving the user
186+
/// funds stuck *or* even allow the counterparty to steal any in-flight funds after the
187+
/// corresponding HTLCs time out.
188+
pub trusted_peers_no_reserve: Vec<PublicKey>,
189+
/// The amount of satoshis per channel we keep as an emergency reserve in our on-chain wallet
190+
/// in order to have the required Anchor output spending and HTLC transactions confirmed when
191+
/// the channel is closed.
192+
///
193+
/// If the channel peer is not marked as trusted via
194+
/// [`AnchorChannelsConfig::trusted_peers_no_reserve`], we will always try to spend the Anchor
195+
/// outputs with *any* on-chain funds available, i.e., the total reserve value as well as any
196+
/// spendable funds available in the on-chain wallet. Therefore, this per-channel multiplier is
197+
/// really a emergencey reserve that we maintain at all time to reduce reduce the risk of
198+
/// insufficient funds at time of a channel closure. To this end, we will refuse to open
199+
/// outbound or accept inbound channels if we don't have sufficient on-chain funds availble to
200+
/// cover the additional reserve requirement.
201+
///
202+
/// **Note:** Depending on the fee market at the time of closure, this reserve amount might or
203+
/// might not suffice to successfully spend the Anchor output and have the HTLC transactions
204+
/// confirmed on-chain, i.e., you may want to adjust this value accordingly.
205+
pub per_channel_reserve_sats: u64,
206+
}
207+
208+
impl Default for AnchorChannelsConfig {
209+
fn default() -> Self {
210+
Self {
211+
trusted_peers_no_reserve: Vec::new(),
212+
per_channel_reserve_sats: DEFAULT_ANCHOR_PER_CHANNEL_RESERVE_SATS,
123213
}
124214
}
125215
}

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ pub use lightning;
103103
pub use lightning_invoice;
104104

105105
pub use balance::{BalanceDetails, LightningBalance, PendingSweepBalance};
106-
pub use config::{default_config, Config};
106+
pub use config::{default_config, AnchorChannelsConfig, Config};
107107
pub use error::Error as NodeError;
108108
use error::Error;
109109

0 commit comments

Comments
 (0)