Skip to content

Commit 726e722

Browse files
committed
commit_tx: update HTLC-tx fees to match latest BOLT.
As per lightning-rfc BOLT #3 ec99f89: "fixed htlc weight calculation" Reported-by: Fabrice Drouin <[email protected]> Signed-off-by: Rusty Russell <[email protected]>
1 parent 35909ba commit 726e722

File tree

2 files changed

+14
-21
lines changed

2 files changed

+14
-21
lines changed

lightningd/commit_tx.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ u64 htlc_timeout_fee(u64 feerate_per_kw)
5555
*
5656
* The fee for an HTLC-timeout transaction MUST BE calculated to match:
5757
*
58-
* 1. Multiply `feerate-per-kw` by 634 and divide by 1000 (rounding
58+
* 1. Multiply `feerate-per-kw` by 635 and divide by 1000 (rounding
5959
* down).
6060
*/
61-
return feerate_per_kw * 634 / 1000;
61+
return feerate_per_kw * 635 / 1000;
6262
}
6363

6464
u64 htlc_success_fee(u64 feerate_per_kw)
@@ -67,10 +67,10 @@ u64 htlc_success_fee(u64 feerate_per_kw)
6767
*
6868
* The fee for an HTLC-success transaction MUST BE calculated to match:
6969
*
70-
* 1. Multiply `feerate-per-kw` by 671 and divide by 1000 (rounding
70+
* 1. Multiply `feerate-per-kw` by 673 and divide by 1000 (rounding
7171
* down).
7272
*/
73-
return feerate_per_kw * 671 / 1000;
73+
return feerate_per_kw * 673 / 1000;
7474
}
7575

7676
static const struct htlc **untrimmed(const tal_t *ctx,

lightningd/test/run-commit_tx.c

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ static bool print_superverbose;
1010
#include <bitcoin/preimage.h>
1111
#include <bitcoin/privkey.h>
1212
#include <bitcoin/pubkey.h>
13+
#include <ccan/array_size/array_size.h>
1314
#include <ccan/str/hex/hex.h>
1415
#include <type_to_string.h>
1516

@@ -317,22 +318,14 @@ static u64 increase(u64 feerate_per_kw)
317318
#else
318319
static u64 increase(u64 feerate_per_kw)
319320
{
320-
switch (feerate_per_kw) {
321-
case 0:
322-
return 679;
323-
case 679:
324-
return 2169;
325-
case 2169:
326-
return 2295;
327-
case 2295:
328-
return 3873;
329-
case 3873:
330-
return 5150;
331-
case 5150:
332-
return 9651181;
333-
default:
334-
abort();
335-
}
321+
const u64 rates[] = { 0, 677, 2162, 2292, 3867, 5134, 9651181 };
322+
size_t i;
323+
324+
for (i = 0; i < ARRAY_SIZE(rates); i++)
325+
if (rates[i] == feerate_per_kw)
326+
return rates[i+1];
327+
328+
abort();
336329
}
337330
#endif
338331

@@ -715,7 +708,7 @@ int main(void)
715708
&x_remote_secretkey,
716709
&remotekey,
717710
&local_revocation_key,
718-
feerate_per_kw,
711+
feerate_per_kw-1,
719712
htlc_map);
720713

721714
printf("\n"

0 commit comments

Comments
 (0)