elements: Fix fee estimation for commitment transactions

Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
Christian Decker 2019-07-02 16:23:07 +02:00 committed by Rusty Russell
parent 557f6063a7
commit e6d5b70e72
2 changed files with 22 additions and 1 deletions

View File

@ -6,7 +6,6 @@
#include <common/permute_tx.h>
#include <common/status.h>
#include <common/type_to_string.h>
#include <common/utils.h>
#include <inttypes.h>
/* BOLT #3:

View File

@ -6,6 +6,7 @@
#include <bitcoin/pubkey.h>
#include <common/amount.h>
#include <common/htlc.h>
#include <common/utils.h>
struct bitcoin_txid;
struct keyset;
@ -42,6 +43,27 @@ static inline struct amount_sat commit_tx_base_fee(u32 feerate_per_kw,
*/
weight += 172 * num_untrimmed_htlcs;
if (is_elements) {
/* Each transaction has surjection and rangeproof (both empty
* for us as long as we use unblinded L-BTC transactions). */
weight += 2 * 4;
/* Inputs have 6 bytes of blank proofs attached. This TX only
* has a single input. */
weight += 6;
/* Each direct output has a bit more weight to it */
weight += (32 + 1 + 1 + 1) * 4 * 2; /* Elements added fields */
/* Each HTLC output also carries a bit more weight */
weight += (32 + 1 + 1 + 1) * 4 * num_untrimmed_htlcs;
/* For elements we also need to add the fee output and the
* overhead for rangeproofs into the mix. */
weight += (8 + 1) * 4; /* Bitcoin style output */
weight += (32 + 1 + 1 + 1) * 4; /* Elements added fields */
}
/* BOLT #3:
*
* 3. Multiply `feerate_per_kw` by `weight`, divide by 1000 (rounding