| 97 | } |
| 98 | |
| 99 | struct bitcoin_tx *commit_tx(const tal_t *ctx, |
| 100 | const struct bitcoin_outpoint *funding, |
| 101 | struct amount_sat funding_sats, |
| 102 | const struct pubkey *local_funding_key, |
| 103 | const struct pubkey *remote_funding_key, |
| 104 | enum side opener, |
| 105 | u16 to_self_delay, |
| 106 | u32 lease_expiry, |
| 107 | u32 blockheight, |
| 108 | const struct keyset *keyset, |
| 109 | u32 feerate_per_kw, |
| 110 | struct amount_sat dust_limit, |
| 111 | struct amount_msat self_pay, |
| 112 | struct amount_msat other_pay, |
| 113 | const struct htlc **htlcs, |
| 114 | const struct htlc ***htlcmap, |
| 115 | struct wally_tx_output *direct_outputs[NUM_SIDES], |
| 116 | u64 obscured_commitment_number, |
| 117 | bool option_anchor_outputs, |
| 118 | enum side side) |
| 119 | { |
| 120 | struct amount_sat base_fee; |
| 121 | struct amount_msat total_pay; |
| 122 | struct bitcoin_tx *tx; |
| 123 | size_t n, untrimmed; |
| 124 | /* Is this the lessor ? */ |
| 125 | enum side lessor = !opener; |
| 126 | u32 *cltvs; |
| 127 | bool to_local, to_remote; |
| 128 | struct htlc *dummy_to_local = (struct htlc *)0x01, |
| 129 | *dummy_to_remote = (struct htlc *)0x02; |
| 130 | const u8 *funding_wscript = bitcoin_redeem_2of2(tmpctx, |
| 131 | local_funding_key, |
| 132 | remote_funding_key); |
| 133 | u32 csv_lock = lease_expiry > blockheight ? |
| 134 | lease_expiry - blockheight : 1; |
| 135 | |
| 136 | if (!amount_msat_add(&total_pay, self_pay, other_pay)) |
| 137 | abort(); |
| 138 | assert(!amount_msat_greater_sat(total_pay, funding_sats)); |
| 139 | |
| 140 | /* BOLT #3: |
| 141 | * |
| 142 | * 1. Calculate which committed HTLCs need to be trimmed (see |
| 143 | * [Trimmed Outputs](#trimmed-outputs)). |
| 144 | */ |
| 145 | untrimmed = commit_tx_num_untrimmed(htlcs, |
| 146 | feerate_per_kw, |
| 147 | dust_limit, |
| 148 | option_anchor_outputs, |
| 149 | side); |
| 150 | |
| 151 | /* BOLT #3: |
| 152 | * |
| 153 | * 2. Calculate the base [commitment transaction |
| 154 | * fee](#fee-calculation). |
| 155 | */ |
| 156 | base_fee = commit_tx_base_fee(feerate_per_kw, untrimmed, |