mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 23:24:27 +01:00
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>
This commit is contained in:
@@ -55,10 +55,10 @@ u64 htlc_timeout_fee(u64 feerate_per_kw)
|
|||||||
*
|
*
|
||||||
* The fee for an HTLC-timeout transaction MUST BE calculated to match:
|
* 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).
|
* down).
|
||||||
*/
|
*/
|
||||||
return feerate_per_kw * 634 / 1000;
|
return feerate_per_kw * 635 / 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 htlc_success_fee(u64 feerate_per_kw)
|
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:
|
* 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).
|
* down).
|
||||||
*/
|
*/
|
||||||
return feerate_per_kw * 671 / 1000;
|
return feerate_per_kw * 673 / 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct htlc **untrimmed(const tal_t *ctx,
|
static const struct htlc **untrimmed(const tal_t *ctx,
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ static bool print_superverbose;
|
|||||||
#include <bitcoin/preimage.h>
|
#include <bitcoin/preimage.h>
|
||||||
#include <bitcoin/privkey.h>
|
#include <bitcoin/privkey.h>
|
||||||
#include <bitcoin/pubkey.h>
|
#include <bitcoin/pubkey.h>
|
||||||
|
#include <ccan/array_size/array_size.h>
|
||||||
#include <ccan/str/hex/hex.h>
|
#include <ccan/str/hex/hex.h>
|
||||||
#include <type_to_string.h>
|
#include <type_to_string.h>
|
||||||
|
|
||||||
@@ -317,22 +318,14 @@ static u64 increase(u64 feerate_per_kw)
|
|||||||
#else
|
#else
|
||||||
static u64 increase(u64 feerate_per_kw)
|
static u64 increase(u64 feerate_per_kw)
|
||||||
{
|
{
|
||||||
switch (feerate_per_kw) {
|
const u64 rates[] = { 0, 677, 2162, 2292, 3867, 5134, 9651181 };
|
||||||
case 0:
|
size_t i;
|
||||||
return 679;
|
|
||||||
case 679:
|
for (i = 0; i < ARRAY_SIZE(rates); i++)
|
||||||
return 2169;
|
if (rates[i] == feerate_per_kw)
|
||||||
case 2169:
|
return rates[i+1];
|
||||||
return 2295;
|
|
||||||
case 2295:
|
|
||||||
return 3873;
|
|
||||||
case 3873:
|
|
||||||
return 5150;
|
|
||||||
case 5150:
|
|
||||||
return 9651181;
|
|
||||||
default:
|
|
||||||
abort();
|
abort();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -715,7 +708,7 @@ int main(void)
|
|||||||
&x_remote_secretkey,
|
&x_remote_secretkey,
|
||||||
&remotekey,
|
&remotekey,
|
||||||
&local_revocation_key,
|
&local_revocation_key,
|
||||||
feerate_per_kw,
|
feerate_per_kw-1,
|
||||||
htlc_map);
|
htlc_map);
|
||||||
|
|
||||||
printf("\n"
|
printf("\n"
|
||||||
|
|||||||
Reference in New Issue
Block a user