Skip to content

Commit b8fcd03

Browse files
author
Antoine Riard
committed
Add fee-bumping reserves recommendation
1 parent c383f06 commit b8fcd03

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

doc/fee-bumping-reserves.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Fee-Bumping Reserves Recommendations for Anchor Outputs Channels
2+
3+
The Lightning Dev Kit offers the ability to its users to open Lightning [anchor outputs](https://bitcoinops.org/en/topics/anchor-outputs/) channels (`option_anchors_zero_fee_htlc_tx`) with its counterparties.
4+
5+
Under the Lightning security model, commitment and second-stage HTLC transactions (BOLT3's `HTLC-timeout` and `HTLC-preimage` and the corresponding spends on counterparty commitment transaction) must be realized
6+
in a time-sensitive manner if there are pending HTLCs. Lack of chain confirmation before HTLC expiration timelocks can constitute a loss of funds, as the counterparty can claim the HTLC output with a [competing
7+
transaction](https://bitcoinops.org/en/blog/waiting-for-confirmation/#policy-as-an-interface). Failure of confirmation might be provoked by blockspace demand spikes provoked by unrelated Bitcoin on-chain transaction
8+
issuers. Anchor output enables to remedy to this issue by allowing a Lightning node to dynamically adjust the feerate of its commitment and second-stage HTLC transactions in an unilateral way.
9+
10+
However, anchor output channels are requiring from the user the provision and maintenance of fee-bumping reserves to attach feerate increase to the commitment (via a Child-Pay-For-Parent) or the
11+
second-stage HTLC transactions (via `SIGHASH_SINGLE | SIGHASH_ANYONECANPAY`). Those fee-bumping reserves should be a collection of UTXOs, of which the state and signing capabilites should be maintained
12+
on a "hot" host. A "hot" host is a computing machine with 24/7 Internet connectivity as fee-bumping UTXOs might need to be signed as soon there is a pending HTLC. A LDK user can implement management of fee-bumping
13+
reserves through the `CoinSelectionSource` and `WalletSource` traits.
14+
15+
The accumulated satoshis value of the collection of the UTXOs must be maintained to cover sufficient transaction weight surface at high-level of network mempools feerates.
16+
17+
A _predictive_ worst-case `feerate_per_kw` based on historical network mempools traffic must be selected. Predictive worst-case must be understood as the worst-historical network mempools
18+
feerate with an additional safety margin. A factor of 2 is a conservative estimation.
19+
20+
The number of opened anchor outputs channels must be selected, i.e `current_opened_channels`. As of 0.0.116 release, LDK does not have a max number of opened channels enforced by default.
21+
22+
The maximum number of HTLC outputs per-commitment transaction on both directions must be selected, i.e `max_htlc_allsides`. As of 0.0.116 release, LDK has a BOLT3's `max_accepted_htlcs` of
23+
50 (`DEFAULT_MAX_HTLCS`) and the value can be adjusted with the config setting `our_max_accepted_htlcs`. There is no LDK mechanism to limit the number of forward HTLCs (i.e offered HTLC outputs on
24+
a commitment transaction). As such `max_htlc_allsides` is `our_max_accepted_htlcs` + `483` (BOLT3 maximum for outgoing HTLCs).
25+
26+
Each channel included in the `current_opened_channels` set has a combined transaction weight surface computed in the following (according to [BOLT3 annex](https://github.com/lightning/bolts/blob/master/03-transactions.md#appendix-a-expected-weights):
27+
- `a`: 900 WU for the base commitment fields with the 4 outputs (`output_paying_to_remote`, `output_paying_to_local`, `output_anchor`, `output_anchor`) present
28+
- `b`: 172 WU * `max_htlc_allsides`
29+
- `c`: 666 WU * `our_max_accepted_htlcs`
30+
- `d`: 706 WU * 483
31+
32+
If the Lightning node does not accept HTLC routing (i.e incoming HTLCs), the compomnent `c` can be assigned a 0 value.
33+
34+
The sum of `a` + `b` + `c` + `d` is called `max_channel_weight_surface`, a worst-case estimation of the transaction weight surface to fee-bump.
35+
36+
To obtain the amount in satoshis that must be maintained as fee-bumping reserves, the following equation can be resolved:
37+
38+
`current_opened_channel` * `max_channel_weight_surface` * `worst_case_feerate_per_kw` / 1000
39+
40+
The `worst_case_feerate_per_kw` is a conservative estimation of the level of fee-bumping reserves that must be maintained. A Lightning node operator may ponder this level of
41+
reserves with its subjective timevalue cost of the immobilized satoshis capital.
42+
43+
Those fee-bumping reserves recommendations do assume Taproot channel type usage, where the weight of the channel transactions weight are modified due to P2TR scriptpubkeys and corresponding
44+
witness spends.

lightning/src/events/bump_transaction.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,9 @@ pub struct CoinSelection {
438438
/// sign for them. The coin selection method aims to mimic Bitcoin Core's `fundrawtransaction` RPC,
439439
/// which most wallets should be able to satisfy. Otherwise, consider implementing [`WalletSource`],
440440
/// which can provide a default implementation of this trait when used with [`Wallet`].
441+
///
442+
/// The set of UTXOs might represent a level of amount reserves according to the recommendations in
443+
/// `doc/fee-bumping-reserves.md`.
441444
pub trait CoinSelectionSource {
442445
/// Performs coin selection of a set of UTXOs, with at least 1 confirmation each, that are
443446
/// available to spend. Implementations are free to pick their coin selection algorithm of

lightning/src/util/config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ pub struct ChannelHandshakeConfig {
152152
/// If set, we attempt to negotiate the `anchors_zero_fee_htlc_tx`option for all future
153153
/// channels. This feature requires having a reserve of onchain funds readily available to bump
154154
/// transactions in the event of a channel force close to avoid the possibility of losing funds.
155+
/// The level of reserve maintained might follow the recommendations in `doc/fee-bumping-reserves.md`.
155156
///
156157
/// Note that if you wish accept inbound channels with anchor outputs, you must enable
157158
/// [`UserConfig::manually_accept_inbound_channels`] and manually accept them with

0 commit comments

Comments
 (0)