| 41 | } |
| 42 | |
| 43 | static struct bitcoin_tx *close_tx(const tal_t *ctx, |
| 44 | const struct chainparams *chainparams, |
| 45 | struct per_peer_state *pps, |
| 46 | const struct channel_id *channel_id, |
| 47 | u32 *local_wallet_index, |
| 48 | const struct ext_key *local_wallet_ext_key, |
| 49 | u8 *scriptpubkey[NUM_SIDES], |
| 50 | const struct bitcoin_outpoint *funding, |
| 51 | struct amount_sat funding_sats, |
| 52 | const u8 *funding_wscript, |
| 53 | const struct amount_sat out[NUM_SIDES], |
| 54 | enum side opener, |
| 55 | struct amount_sat fee, |
| 56 | struct amount_sat dust_limit, |
| 57 | const struct bitcoin_outpoint *wrong_funding) |
| 58 | { |
| 59 | struct bitcoin_tx *tx; |
| 60 | struct amount_sat out_minus_fee[NUM_SIDES]; |
| 61 | |
| 62 | /* BOLT #3: |
| 63 | * ## Legacy Closing Transaction |
| 64 | *... |
| 65 | * ### Requirements |
| 66 | * |
| 67 | * Each node offering a signature: |
| 68 | *... |
| 69 | * - MUST subtract the fee given by `fee_satoshis` from the output to the funder. |
| 70 | */ |
| 71 | out_minus_fee[LOCAL] = out[LOCAL]; |
| 72 | out_minus_fee[REMOTE] = out[REMOTE]; |
| 73 | if (!amount_sat_sub(&out_minus_fee[opener], out[opener], fee)) |
| 74 | peer_failed_warn(pps, channel_id, |
| 75 | "Funder cannot afford fee %s (%s and %s)", |
| 76 | fmt_amount_sat(tmpctx, fee), |
| 77 | fmt_amount_sat(tmpctx, out[LOCAL]), |
| 78 | fmt_amount_sat(tmpctx, out[REMOTE])); |
| 79 | |
| 80 | status_debug("Making close tx at = %s/%s fee %s", |
| 81 | fmt_amount_sat(tmpctx, out[LOCAL]), |
| 82 | fmt_amount_sat(tmpctx, out[REMOTE]), |
| 83 | fmt_amount_sat(tmpctx, fee)); |
| 84 | |
| 85 | /* FIXME: We need to allow this! */ |
| 86 | tx = create_close_tx(ctx, |
| 87 | chainparams, |
| 88 | local_wallet_index, local_wallet_ext_key, |
| 89 | scriptpubkey[LOCAL], scriptpubkey[REMOTE], |
| 90 | funding_wscript, |
| 91 | funding, |
| 92 | funding_sats, |
| 93 | out_minus_fee[LOCAL], |
| 94 | out_minus_fee[REMOTE], |
| 95 | dust_limit); |
| 96 | if (!tx) |
| 97 | peer_failed_err(pps, channel_id, |
| 98 | "Both outputs below dust limit:" |
| 99 | " funding = %s" |
| 100 | " fee = %s" |
no test coverage detected