diff --git a/common/initial_commit_tx.c b/common/initial_commit_tx.c index 361575ee0..a314e9c19 100644 --- a/common/initial_commit_tx.c +++ b/common/initial_commit_tx.c @@ -6,7 +6,6 @@ #include #include #include -#include #include /* BOLT #3: diff --git a/common/initial_commit_tx.h b/common/initial_commit_tx.h index 92dccd099..2b75e4d2a 100644 --- a/common/initial_commit_tx.h +++ b/common/initial_commit_tx.h @@ -6,6 +6,7 @@ #include #include #include +#include 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