Browse Source

lightningd/commit_tx: support for printing out actual tx fees.

This was included in the lightningnetwork/lightning-rfc#105 update
to the test vectors, and it's a good idea.  Takes a bit of work to
calculate (particularly, being aware of rounding issues).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 8 years ago
parent
commit
8d01eeeef5
  1. 17
      lightningd/commit_tx.c
  2. 4
      lightningd/test/run-commit_tx.c

17
lightningd/commit_tx.c

@ -231,6 +231,23 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx,
subtract_fee(funder, side, base_fee_msat,
&self_pay_msat, &other_pay_msat);
#ifdef PRINT_ACTUAL_FEE
{
u64 satoshis_out = 0;
for (i = n = 0; i < tal_count(htlcs); i++) {
if (!trim(htlcs[i], feerate_per_kw, dust_limit_satoshis,
side))
satoshis_out += htlcs[i]->msatoshi / 1000;
}
if (self_pay_msat / 1000 >= dust_limit_satoshis)
satoshis_out += self_pay_msat / 1000;
if (other_pay_msat / 1000 >= dust_limit_satoshis)
satoshis_out += other_pay_msat / 1000;
SUPERVERBOSE("# actual commitment transaction fee = %"PRIu64"\n",
funding_satoshis - satoshis_out);
}
#endif
/* Worst-case sizing: both to-local and to-remote outputs. */
tx = bitcoin_tx(ctx, 1, untrimmed + 2);

4
lightningd/test/run-commit_tx.c

@ -5,6 +5,7 @@
static bool print_superverbose;
#define SUPERVERBOSE(...) \
do { if (print_superverbose) printf(__VA_ARGS__); } while(0)
#define PRINT_ACTUAL_FEE
#include "../commit_tx.c"
#include "../htlc_tx.c"
#include <bitcoin/preimage.h>
@ -15,6 +16,9 @@ static bool print_superverbose;
#include <ccan/str/hex/hex.h>
#include <type_to_string.h>
/* Turn this on to brute-force fee values */
/*#define DEBUG */
static struct sha256 sha256_from_hex(const char *hex)
{
struct sha256 sha256;

Loading…
Cancel
Save