If there's a failure, we reset the state to the last * valid channel */
| 1663 | /* If there's a failure, we reset the state to the last |
| 1664 | * valid channel */ |
| 1665 | static void revert_channel_state(struct state *state) |
| 1666 | { |
| 1667 | struct tx_state *tx_state = state->tx_state; |
| 1668 | struct amount_sat total; |
| 1669 | struct amount_msat our_msats; |
| 1670 | enum side opener = state->our_role == TX_INITIATOR ? LOCAL : REMOTE; |
| 1671 | const struct channel_type *type; |
| 1672 | |
| 1673 | /* We've already checked this */ |
| 1674 | if (!amount_sat_add(&total, tx_state->opener_funding, |
| 1675 | tx_state->accepter_funding)) |
| 1676 | abort(); |
| 1677 | |
| 1678 | /* We've already checked this */ |
| 1679 | if (!amount_sat_to_msat(&our_msats, |
| 1680 | state->our_role == TX_INITIATOR ? |
| 1681 | tx_state->opener_funding : |
| 1682 | tx_state->accepter_funding)) |
| 1683 | abort(); |
| 1684 | |
| 1685 | tal_free(state->channel); |
| 1686 | type = default_channel_type(NULL, |
| 1687 | state->our_features, state->their_features); |
| 1688 | state->channel = new_initial_channel(state, |
| 1689 | &state->channel_id, |
| 1690 | &tx_state->funding, |
| 1691 | state->minimum_depth, |
| 1692 | take(new_height_states(NULL, opener, |
| 1693 | &tx_state->blockheight)), |
| 1694 | tx_state->lease_expiry, |
| 1695 | total, |
| 1696 | our_msats, |
| 1697 | take(new_fee_states( |
| 1698 | NULL, opener, |
| 1699 | &state->feerate_per_kw_commitment)), |
| 1700 | &tx_state->localconf, |
| 1701 | &tx_state->remoteconf, |
| 1702 | &state->our_points, |
| 1703 | &state->their_points, |
| 1704 | &state->our_funding_pubkey, |
| 1705 | &state->their_funding_pubkey, |
| 1706 | take(type), |
| 1707 | feature_offered(state->their_features, |
| 1708 | OPT_LARGE_CHANNELS), |
| 1709 | opener); |
| 1710 | } |
| 1711 | |
| 1712 | /* Returns NULL on negotation failure; reason given as *err_reason |
| 1713 | * In case that negotiation_aborted called, *err_reason set NULL */ |
no test coverage detected