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