Skip to content

Commit

Permalink
channeld: Adjust the feerate security margin profile
Browse files Browse the repository at this point in the history
The feerate security margin is a multiplicative factor applied to the
feerate of some transactions in order to guarantee that the
transaction remains publishable and has a sufficient chance of being
confirmed, that we can base some of our decisions on that.

The multiplicative factor is >=1 and was so far a constant 2. This
might have been sensible in the low-fee environment, where the fees
are expected to oscillate, and almost guaranteeing that we will
eventually have rising feerates but in high-fee environments that is
no longer the case, and the 100% margin that the multiplicator 2
brings is excessive. We therefore opt to start out with 100%, then
linearly interpolate up to a given maxfeerate (which does not have to
be a real feerate ever reached, it just indicates the feerate after
which we apply the constant 10% margin.

Fixes ElementsProject#6974
Closes ElementsProject#6976
  • Loading branch information
cdecker committed Feb 21, 2024
1 parent a3d7f05 commit 472c1b4
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion channeld/full_channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -560,9 +560,29 @@ static bool local_opener_has_fee_headroom(const struct channel *channel,
option_anchors_zero_fee_htlc_tx,
committed, adding, removing);

/* Scale the feerate up by a margin. This ensures that we have
* some leeway even in rising fees. The calculation starts
* with a 100% margin at very low fees, since they are likely
* to rise, and can do so quickly, whereas on the higher fee
* side, asking for a 100% margin is excessive, so ask for a
* 10% margin. In-between these two regions we interpolate
* linearly. Notice that minfeerate and maxfeerate are just
* the markers of the linear interpolation, they don't have
* to correspond to actual feerates seen in the network.
*
* See [CLN6974] for details and discussion.
*
* [CLN6974]: https://github.com/ElementsProject/lightning/issues/6974
*/
u64 minfeerate = 253, maxfeerate = 45000,
min = feerate - minfeerate > maxfeerate ? maxfeerate
: feerate - minfeerate;
double marginperc = 1 - min / (maxfeerate * 1.1);
u64 marginrate = 1 + marginperc;

/* Now, how much would it cost us if feerate increases 100% and we added
* another HTLC? */
fee = commit_tx_base_fee(2 * feerate, untrimmed + 1,
fee = commit_tx_base_fee(marginrate, untrimmed + 1,
option_anchor_outputs,
option_anchors_zero_fee_htlc_tx);
if (amount_msat_greater_eq_sat(remainder, fee))
Expand Down

0 comments on commit 472c1b4

Please sign in to comment.