diff --git a/lightningd/commit_tx.c b/lightningd/commit_tx.c index 0a697c8c5..e24e35624 100644 --- a/lightningd/commit_tx.c +++ b/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, diff --git a/lightningd/test/run-commit_tx.c b/lightningd/test/run-commit_tx.c index c759cadb0..1facf58a4 100644 --- a/lightningd/test/run-commit_tx.c +++ b/lightningd/test/run-commit_tx.c @@ -10,6 +10,7 @@ static bool print_superverbose; #include #include #include +#include #include #include @@ -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"