Browse Source

commit_tx: update HTLC-tx fees to match latest BOLT.

As per lightning-rfc BOLT #3 ec99f893f320e8c88f564c1c8566f3454f0f1f5f:
"fixed htlc weight calculation"

Reported-by: Fabrice Drouin <fabrice.drouin@acinq.fr>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 8 years ago
parent
commit
726e7226c4
  1. 8
      lightningd/commit_tx.c
  2. 27
      lightningd/test/run-commit_tx.c

8
lightningd/commit_tx.c

@ -55,10 +55,10 @@ u64 htlc_timeout_fee(u64 feerate_per_kw)
*
* The fee for an HTLC-timeout transaction MUST BE calculated to match:
*
* 1. Multiply `feerate-per-kw` by 634 and divide by 1000 (rounding
* 1. Multiply `feerate-per-kw` by 635 and divide by 1000 (rounding
* down).
*/
return feerate_per_kw * 634 / 1000;
return feerate_per_kw * 635 / 1000;
}
u64 htlc_success_fee(u64 feerate_per_kw)
@ -67,10 +67,10 @@ u64 htlc_success_fee(u64 feerate_per_kw)
*
* The fee for an HTLC-success transaction MUST BE calculated to match:
*
* 1. Multiply `feerate-per-kw` by 671 and divide by 1000 (rounding
* 1. Multiply `feerate-per-kw` by 673 and divide by 1000 (rounding
* down).
*/
return feerate_per_kw * 671 / 1000;
return feerate_per_kw * 673 / 1000;
}
static const struct htlc **untrimmed(const tal_t *ctx,

27
lightningd/test/run-commit_tx.c

@ -10,6 +10,7 @@ static bool print_superverbose;
#include <bitcoin/preimage.h>
#include <bitcoin/privkey.h>
#include <bitcoin/pubkey.h>
#include <ccan/array_size/array_size.h>
#include <ccan/str/hex/hex.h>
#include <type_to_string.h>
@ -317,22 +318,14 @@ static u64 increase(u64 feerate_per_kw)
#else
static u64 increase(u64 feerate_per_kw)
{
switch (feerate_per_kw) {
case 0:
return 679;
case 679:
return 2169;
case 2169:
return 2295;
case 2295:
return 3873;
case 3873:
return 5150;
case 5150:
return 9651181;
default:
abort();
}
const u64 rates[] = { 0, 677, 2162, 2292, 3867, 5134, 9651181 };
size_t i;
for (i = 0; i < ARRAY_SIZE(rates); i++)
if (rates[i] == feerate_per_kw)
return rates[i+1];
abort();
}
#endif
@ -715,7 +708,7 @@ int main(void)
&x_remote_secretkey,
&remotekey,
&local_revocation_key,
feerate_per_kw,
feerate_per_kw-1,
htlc_map);
printf("\n"

Loading…
Cancel
Save