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

@@ -24,6 +24,26 @@ size_t commit_tx_num_untrimmed(const struct htlc **htlcs,
bool option_anchor_outputs,
enum side side);
/**
* commit_tx_amount_trimmed: what's the sum of trimmed htlc amounts?
* @htlcs: tal_arr of HTLCs
* @feerate_per_kw: feerate to use
* @dust_limit: dust limit below which to trim outputs.
* @option_anchor_outputs: does option_anchor_outputs apply to this channel?
* @side: from which side's point of view
* @amt: returned, total value trimmed from this commitment
*
* We need @side because HTLC fees are different for offered and
* received HTLCs.
*
* Returns false if unable to calculate amount trimmed.
*/
bool commit_tx_amount_trimmed(const struct htlc **htlcs,
u32 feerate_per_kw,
struct amount_sat dust_limit,
bool option_anchor_outputs,
enum side side,
struct amount_msat *amt);
/**
* commit_tx: create (unsigned) commitment tx to spend the funding tx output
* @ctx: context to allocate transaction and @htlc_map from.