forked from ElementsProject/lightning
-
Notifications
You must be signed in to change notification settings - Fork 0
/
htlc_trim.c
41 lines (38 loc) · 1.26 KB
/
htlc_trim.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <common/htlc_trim.h>
#include <common/htlc_tx.h>
/* If this htlc too small to create an output on @side's commitment tx? */
bool htlc_is_trimmed(enum side htlc_owner,
struct amount_msat htlc_amount,
u32 feerate_per_kw,
struct amount_sat dust_limit,
enum side side)
{
struct amount_sat htlc_fee, htlc_min;
/* BOLT #3:
*
* - for every offered HTLC:
* - if the HTLC amount minus the HTLC-timeout fee would be less than
* `dust_limit_satoshis` set by the transaction owner:
* - MUST NOT contain that output.
* - otherwise:
* - MUST be generated as specified in
* [Offered HTLC Outputs](#offered-htlc-outputs).
*/
if (htlc_owner == side)
htlc_fee = htlc_timeout_fee(feerate_per_kw);
/* BOLT #3:
*
* - for every received HTLC:
* - if the HTLC amount minus the HTLC-success fee would be less than
* `dust_limit_satoshis` set by the transaction owner:
* - MUST NOT contain that output.
* - otherwise:
* - MUST be generated as specified in
*/
else
htlc_fee = htlc_success_fee(feerate_per_kw);
/* If these overflow, it implies htlc must be less. */
if (!amount_sat_add(&htlc_min, dust_limit, htlc_fee))
return true;
return amount_msat_less_sat(htlc_amount, htlc_min);
}