MCPcopy Create free account
hub / github.com/ElementsProject/lightning / check_balances

Function check_balances

openingd/dualopend.c:572–863  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

570}
571
572static char *check_balances(const tal_t *ctx,
573 struct state *state,
574 struct tx_state *tx_state,
575 struct wally_psbt *psbt,
576 u32 feerate_per_kw_funding)
577{
578 struct amount_sat initiator_inputs, initiator_outs,
579 accepter_inputs, accepter_outs,
580 tot_input_amt, tot_output_amt,
581 initiator_fee, accepter_fee,
582 initiator_diff, accepter_diff;
583
584 bool ok;
585 u32 funding_outnum = psbt->num_outputs;
586 size_t accepter_weight = 0;
587
588
589 /* BOLT-f53ca2301232db780843e894f55d95d512f297f9 #2:
590 *
591 * The *initiator* is responsible for paying the fees for the
592 * following fields, to be referred to as the `common fields`.
593 * - version
594 * - segwit marker + flag
595 * - input count
596 * - output count
597 * - locktime
598 */
599 size_t initiator_weight =
600 bitcoin_tx_core_weight(psbt->num_inputs,
601 psbt->num_outputs);
602
603 u8 *funding_wscript =
604 bitcoin_redeem_2of2(tmpctx,
605 &state->our_funding_pubkey,
606 &state->their_funding_pubkey);
607
608 /*
609 * BOLT-f53ca2301232db780843e894f55d95d512f297f9 #2:
610 * The receiving node: ...
611 * - MUST fail the negotiation if: ...
612 * - there are more than 252 inputs
613 */
614 if (tx_state->psbt->num_inputs > MAX_FUNDING_INPUTS)
615 negotiation_failed(state, "Too many inputs. Have %zu,"
616 " Max allowed %zu",
617 tx_state->psbt->num_inputs,
618 MAX_FUNDING_INPUTS);
619 /*
620 * BOLT-f53ca2301232db780843e894f55d95d512f297f9 #2:
621 * The receiving node: ...
622 * - MUST fail the negotiation if: ...
623 * - there are more than 252 outputs
624 */
625 if (tx_state->psbt->num_outputs > MAX_FUNDING_OUTPUTS)
626 negotiation_failed(state, "Too many inputs. Have %zu,"
627 " Max allowed %zu",
628 tx_state->psbt->num_outputs,
629 MAX_FUNDING_OUTPUTS);

Callers 2

accepter_commitsFunction · 0.70
opener_commitsFunction · 0.70

Calls 15

bitcoin_tx_core_weightFunction · 0.85
bitcoin_redeem_2of2Function · 0.85
find_txoutFunction · 0.85
psbt_output_get_amountFunction · 0.85
is_dustFunction · 0.85
is_openersFunction · 0.85
psbt_input_weightFunction · 0.85
psbt_output_weightFunction · 0.85
negotiation_failedFunction · 0.70
scriptpubkey_p2wshFunction · 0.50
amount_sat_addFunction · 0.50
amount_sat_eqFunction · 0.50

Tested by

no test coverage detected