channeld: Adjust the feerate security margin profile

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 #6974
Closes #6976
This commit is contained in:
Christian Decker 2024-02-11 11:14:34 +01:00
parent 1e023a171d
commit 48c6551734

View File

@ -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))