Steals fields from uncommitted_channel: returns NULL if can't generate a * key for this channel (shouldn't happen!). */
| 80 | /* Steals fields from uncommitted_channel: returns NULL if can't generate a |
| 81 | * key for this channel (shouldn't happen!). */ |
| 82 | static struct channel * |
| 83 | wallet_commit_channel(struct lightningd *ld, |
| 84 | struct uncommitted_channel *uc, |
| 85 | struct channel_id *cid, |
| 86 | struct bitcoin_tx *remote_commit, |
| 87 | struct bitcoin_signature *remote_commit_sig, |
| 88 | const struct bitcoin_outpoint *funding, |
| 89 | struct amount_sat funding_sats, |
| 90 | struct amount_msat push, |
| 91 | u8 channel_flags, |
| 92 | struct channel_info *channel_info, |
| 93 | u32 feerate, |
| 94 | const u8 *our_upfront_shutdown_script, |
| 95 | const u8 *remote_upfront_shutdown_script, |
| 96 | const struct channel_type *type, |
| 97 | const struct wally_psbt *funding_psbt, |
| 98 | bool withheld) |
| 99 | { |
| 100 | struct channel *channel; |
| 101 | struct amount_msat our_msat; |
| 102 | struct amount_sat local_funding; |
| 103 | s64 final_key_idx; |
| 104 | u64 static_remotekey_start; |
| 105 | u32 lease_start_blockheight = 0; /* No leases on v1 */ |
| 106 | struct timeabs timestamp; |
| 107 | struct channel_stats zero_channel_stats; |
| 108 | enum addrtype addrtype; |
| 109 | struct short_channel_id local_alias; |
| 110 | |
| 111 | /* We can't have any payments yet */ |
| 112 | memset(&zero_channel_stats, 0, sizeof(zero_channel_stats)); |
| 113 | |
| 114 | /* We cannot both be the fundee *and* have a `fundchannel_start` |
| 115 | * command running! |
| 116 | */ |
| 117 | assert(!(uc->got_offer && uc->fc)); |
| 118 | |
| 119 | /* FIXME: P2TR for elements! */ |
| 120 | if (chainparams->is_elements) |
| 121 | addrtype = ADDR_BECH32; |
| 122 | else if (feature_negotiated(ld->our_features, |
| 123 | uc->peer->their_features, |
| 124 | OPT_SHUTDOWN_ANYSEGWIT)) |
| 125 | addrtype = ADDR_P2TR; |
| 126 | else |
| 127 | /* They *may* update to OPT_SHUTDOWN_ANYSEGWIT by the |
| 128 | * time we close, so be prepared for both. */ |
| 129 | addrtype = ADDR_ALL; |
| 130 | |
| 131 | /* Get a key to use for closing outputs from this tx */ |
| 132 | final_key_idx = wallet_get_newindex(ld, addrtype); |
| 133 | if (final_key_idx == -1) { |
| 134 | log_broken(uc->log, "Can't get final key index"); |
| 135 | return NULL; |
| 136 | } |
| 137 | |
| 138 | if (uc->fc) { |
| 139 | if (!amount_sat_sub_msat(&our_msat, funding_sats, push)) { |
no test coverage detected