diff --git a/lightningd/commit_tx.c b/lightningd/commit_tx.c index d2353c80e..d80194b09 100644 --- a/lightningd/commit_tx.c +++ b/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); diff --git a/lightningd/test/run-commit_tx.c b/lightningd/test/run-commit_tx.c index 9f742ea32..85a19116a 100644 --- a/lightningd/test/run-commit_tx.c +++ b/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 @@ -15,6 +16,9 @@ static bool print_superverbose; #include #include +/* Turn this on to brute-force fee values */ +/*#define DEBUG */ + static struct sha256 sha256_from_hex(const char *hex) { struct sha256 sha256;