Returns NULL if can't generate a key for this channel (Shouldn't happen) */
| 1555 | |
| 1556 | /* Returns NULL if can't generate a key for this channel (Shouldn't happen) */ |
| 1557 | static struct channel_inflight * |
| 1558 | wallet_commit_channel(struct lightningd *ld, |
| 1559 | struct channel *channel, |
| 1560 | const struct bitcoin_outpoint *funding, |
| 1561 | struct amount_sat total_funding, |
| 1562 | struct amount_sat our_funding, |
| 1563 | struct channel_info *channel_info, |
| 1564 | u32 funding_feerate, |
| 1565 | u32 commitment_feerate, |
| 1566 | const u8 *our_upfront_shutdown_script, |
| 1567 | const u8 *remote_upfront_shutdown_script, |
| 1568 | struct wally_psbt *psbt STEALS, |
| 1569 | const struct amount_sat lease_amt, |
| 1570 | const u32 lease_blockheight_start, |
| 1571 | const u32 lease_expiry, |
| 1572 | const struct amount_sat lease_fee, |
| 1573 | secp256k1_ecdsa_signature *lease_commit_sig STEALS, |
| 1574 | const u32 lease_chan_max_msat, |
| 1575 | const u16 lease_chan_max_ppt, |
| 1576 | const struct channel_type *type) |
| 1577 | { |
| 1578 | struct amount_msat our_msat, lease_fee_msat; |
| 1579 | struct channel_inflight *inflight; |
| 1580 | bool anysegwit = !chainparams->is_elements && feature_negotiated(channel->peer->ld->our_features, |
| 1581 | channel->peer->their_features, |
| 1582 | OPT_SHUTDOWN_ANYSEGWIT); |
| 1583 | bool was_important; |
| 1584 | |
| 1585 | if (!amount_sat_to_msat(&our_msat, our_funding)) { |
| 1586 | log_broken(channel->log, "Unable to convert funds"); |
| 1587 | return NULL; |
| 1588 | } |
| 1589 | |
| 1590 | if (!amount_sat_to_msat(&lease_fee_msat, lease_fee)) { |
| 1591 | log_broken(channel->log, "Unable to convert lease fee"); |
| 1592 | return NULL; |
| 1593 | } |
| 1594 | |
| 1595 | /* Get a key to use for closing outputs from this tx. Prefer |
| 1596 | * P2TR, but we'll use BECH32 for older peers (but always P2TR |
| 1597 | * for our own onchian spends, if any). */ |
| 1598 | |
| 1599 | channel->final_key_idx = wallet_get_newindex(ld, anysegwit ? ADDR_P2TR : (ADDR_BECH32|ADDR_P2TR)); |
| 1600 | if (channel->final_key_idx == -1) { |
| 1601 | log_broken(channel->log, "Can't get final key index"); |
| 1602 | return NULL; |
| 1603 | } |
| 1604 | |
| 1605 | /* Does peer currently have an important channel? */ |
| 1606 | was_important = peer_any_channel(channel->peer, |
| 1607 | channel_important_filter, NULL, NULL); |
| 1608 | |
| 1609 | assert(channel->state == DUALOPEND_OPEN_INIT); |
| 1610 | log_info(channel->log, "State changed from %s to %s", |
| 1611 | channel_state_name(channel), |
| 1612 | channel_state_str(DUALOPEND_OPEN_COMMIT_READY)); |
| 1613 | channel->state = DUALOPEND_OPEN_COMMIT_READY; |
| 1614 | tell_connectd_peer_importance(channel->peer, was_important); |
no test coverage detected