From b4db228aa18f69bd3bc50b4d16c5b63df9960742 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 4 Apr 2018 05:50:57 +0930 Subject: [PATCH] onchaind: add BOLT 3 comment for fee calculations. Signed-off-by: Rusty Russell --- onchaind/onchain.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/onchaind/onchain.c b/onchaind/onchain.c index 84b4c4552..6fc65fcda 100644 --- a/onchaind/onchain.c +++ b/onchaind/onchain.c @@ -110,6 +110,18 @@ static u64 grind_htlc_tx_fee(struct bitcoin_tx *tx, u64 input_amount = *tx->input[0].amount; for (u64 i = min_possible_feerate; i <= max_possible_feerate; i++) { + /* BOLT #3: + * + * The fee for an HTLC-timeout transaction: + * - MUST BE calculated to match: + * 1. Multiply `feerate_per_kw` by 663 and divide by 1000 + * (rounding down). + * + * The fee for an HTLC-success transaction: + * - MUST BE calculated to match: + * 1. Multiply `feerate_per_kw` by 703 and divide by 1000 + * (rounding down). + */ u64 fee = i * multiplier / 1000; if (fee > input_amount)