dusty-htlcs: enforce limit on dusty htlcs

for every new added htlc, check that adding it won't go over our 'dust
budget' (which assumes a slightly higher than current feerate, as this
prevents sudden feerate changes from overshooting our dust budget)

note that if the feerate changes surpass the limits we've set, we
immediately fail the channel.
This commit is contained in:
niftynei
2021-09-28 14:12:01 -05:00
committed by Christian Decker
parent 42e40c1ced
commit b193eb06d3
8 changed files with 182 additions and 1 deletions

View File

@@ -42,3 +42,15 @@ bool htlc_is_trimmed(enum side htlc_owner,
return true;
return amount_msat_less_sat(htlc_amount, htlc_min);
}
/* Minimum amount of headroom we should use for
* anticipated feerate adjustments */
#define HTLC_FEE_MIN_RANGE 2530
#define max(a, b) ((a) > (b) ? (a) : (b))
u32 htlc_trim_feerate_ceiling(u32 feerate_per_kw)
{
/* Add the greater of 1.25x or 2530 sat/kw */
return max(feerate_per_kw + feerate_per_kw / 4,
feerate_per_kw + HTLC_FEE_MIN_RANGE);
}

View File

@@ -12,4 +12,7 @@ bool htlc_is_trimmed(enum side htlc_owner,
enum side side,
bool option_anchor_outputs);
/* Calculate the our htlc-trimming buffer feerate
* (max(25%, 10s/vbyte) above feerate_per_kw) */
u32 htlc_trim_feerate_ceiling(u32 feerate_per_kw);
#endif /* LIGHTNING_COMMON_HTLC_TRIM_H */