| 674 | } |
| 675 | |
| 676 | static char *check_balances(const tal_t *ctx, |
| 677 | struct state *state, |
| 678 | struct tx_state *tx_state, |
| 679 | struct wally_psbt *psbt, |
| 680 | u32 feerate_per_kw_funding) |
| 681 | { |
| 682 | struct amount_sat initiator_inputs, initiator_outs, |
| 683 | accepter_inputs, accepter_outs, |
| 684 | tot_input_amt, tot_output_amt, |
| 685 | initiator_fee, accepter_fee, |
| 686 | initiator_diff, accepter_diff; |
| 687 | |
| 688 | bool ok; |
| 689 | u32 funding_outnum = psbt->num_outputs; |
| 690 | size_t accepter_weight = 0; |
| 691 | |
| 692 | |
| 693 | /* BOLT #2: |
| 694 | * |
| 695 | * The *initiator* is responsible for paying the fees for the |
| 696 | * following fields, to be referred to as the `common fields`. |
| 697 | * - version |
| 698 | * - segwit marker + flag |
| 699 | * - input count |
| 700 | * - output count |
| 701 | * - locktime |
| 702 | */ |
| 703 | size_t initiator_weight = |
| 704 | bitcoin_tx_core_weight(psbt->num_inputs, |
| 705 | psbt->num_outputs); |
| 706 | |
| 707 | u8 *funding_wscript = |
| 708 | bitcoin_redeem_2of2(tmpctx, |
| 709 | &state->our_funding_pubkey, |
| 710 | &state->their_funding_pubkey); |
| 711 | |
| 712 | /* |
| 713 | * BOLT #2: |
| 714 | * The receiving node: ... |
| 715 | * - MUST fail the negotiation if: ... |
| 716 | * - there are more than 252 inputs |
| 717 | */ |
| 718 | if (tx_state->psbt->num_inputs > MAX_FUNDING_INPUTS) |
| 719 | return tal_fmt(ctx, |
| 720 | "Too many inputs. Have %zu," |
| 721 | " Max allowed %u", |
| 722 | tx_state->psbt->num_inputs, |
| 723 | MAX_FUNDING_INPUTS); |
| 724 | /* |
| 725 | * BOLT #2: |
| 726 | * The receiving node: ... |
| 727 | * - MUST fail the negotiation if: ... |
| 728 | * - there are more than 252 outputs |
| 729 | */ |
| 730 | if (tx_state->psbt->num_outputs > MAX_FUNDING_OUTPUTS) |
| 731 | return tal_fmt(ctx, "Too many inputs. Have %zu," |
| 732 | " Max allowed %u", |
| 733 | tx_state->psbt->num_outputs, |
no test coverage detected