mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 05:12:45 +01:00
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>
This commit is contained in:
parent
29d6004efc
commit
8d01eeeef5
@ -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);
|
||||
|
||||
|
@ -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…
Reference in New Issue
Block a user