Returns NULL on negotation failure; reason given as *err_reason. * If we call negotiation_failed internally, reason will be NULL */
| 2367 | /* Returns NULL on negotation failure; reason given as *err_reason. |
| 2368 | * If we call negotiation_failed internally, reason will be NULL */ |
| 2369 | static u8 *opener_commits(struct state *state, |
| 2370 | struct tx_state *tx_state, |
| 2371 | struct amount_sat total, |
| 2372 | char **err_reason) |
| 2373 | { |
| 2374 | struct channel_id cid; |
| 2375 | struct amount_msat our_msats; |
| 2376 | struct wally_tx_output *direct_outputs[NUM_SIDES]; |
| 2377 | struct penalty_base *pbase; |
| 2378 | struct bitcoin_tx *remote_commit, *local_commit; |
| 2379 | struct bitcoin_signature remote_sig, local_sig; |
| 2380 | secp256k1_ecdsa_signature *htlc_sigs; |
| 2381 | const u8 *wscript; |
| 2382 | u8 *msg; |
| 2383 | char *error; |
| 2384 | struct amount_msat their_msats; |
| 2385 | const struct channel_type *type; |
| 2386 | |
| 2387 | wscript = bitcoin_redeem_2of2(tmpctx, &state->our_funding_pubkey, |
| 2388 | &state->their_funding_pubkey); |
| 2389 | psbt_txid(NULL, tx_state->psbt, &tx_state->funding.txid, NULL); |
| 2390 | |
| 2391 | /* Figure out the txout */ |
| 2392 | if (!find_txout(tx_state->psbt, scriptpubkey_p2wsh(tmpctx, wscript), |
| 2393 | &tx_state->funding.n)) { |
| 2394 | *err_reason = tal_fmt(tmpctx, "Expected output %s not" |
| 2395 | " found on funding tx %s", |
| 2396 | tal_hex(tmpctx, |
| 2397 | scriptpubkey_p2wsh(tmpctx, |
| 2398 | wscript)), |
| 2399 | type_to_string(tmpctx, |
| 2400 | struct wally_psbt, |
| 2401 | tx_state->psbt)); |
| 2402 | return NULL; |
| 2403 | } |
| 2404 | |
| 2405 | error = check_balances(tmpctx, state, tx_state, |
| 2406 | tx_state->psbt, |
| 2407 | tx_state->feerate_per_kw_funding); |
| 2408 | if (error) { |
| 2409 | *err_reason = tal_fmt(tmpctx, "Insufficiently funded funding " |
| 2410 | "tx, %s. %s", error, |
| 2411 | type_to_string(tmpctx, |
| 2412 | struct wally_psbt, |
| 2413 | tx_state->psbt)); |
| 2414 | return NULL; |
| 2415 | } |
| 2416 | |
| 2417 | if (!amount_sat_to_msat(&our_msats, tx_state->opener_funding)) { |
| 2418 | status_failed(STATUS_FAIL_INTERNAL_ERROR, |
| 2419 | "Rounding error, can't convert opener_funding %s" |
| 2420 | " to msats", |
| 2421 | type_to_string(tmpctx, struct amount_sat, |
| 2422 | &tx_state->opener_funding)); |
| 2423 | return NULL; |
| 2424 | } |
| 2425 | |
| 2426 | if (!amount_sat_to_msat(&their_msats, tx_state->accepter_funding)) { |
no test coverage detected