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

Function perform_funding_tx_finalize

plugins/spender/multifundchannel.c:826–934  ·  view source on GitHub ↗

~ The PSBT we are holding currently has no outputs. We now proceed to filling in those outputs now that we know what the funding scriptpubkeys are. First thing we do is to shuffle the outputs. This is needed in order to decorrelate the transaction outputs from the parameters passed into the command. We should assume that the caller of the command might inadvertently leak important privacy data in

Source from the content-addressed store, hash-verified

824of its arguments, so we shuffle the outputs.
825*/
826static struct command_result *
827perform_funding_tx_finalize(struct multifundchannel_command *mfc)
828{
829 struct multifundchannel_destination **deck;
830 char *content = tal_strdup(tmpctx, "");
831 size_t v1_dest_count = dest_count(mfc, FUND_CHANNEL);
832 size_t v2_dest_count = dest_count(mfc, OPEN_CHANNEL);
833 size_t i, deck_i;
834
835 plugin_log(mfc->cmd->plugin, LOG_DBG,
836 "mfc %"PRIu64": Creating funding tx.",
837 mfc->id);
838
839 /* Construct a deck of destinations. */
840 deck = tal_arr(tmpctx, struct multifundchannel_destination *,
841 v1_dest_count + mfc->change_needed);
842
843 deck_i = 0;
844 for (i = 0; i < tal_count(mfc->destinations); i++) {
845 if (is_v2(&mfc->destinations[i]))
846 continue;
847
848 assert(deck_i < tal_count(deck));
849 deck[deck_i++] = &mfc->destinations[i];
850 }
851
852 /* Add a NULL into the deck as a proxy for change output, if
853 * needed. */
854 if (mfc->change_needed)
855 deck[v1_dest_count] = NULL;
856 /* Fisher-Yates shuffle. */
857 for (i = tal_count(deck); i > 1; --i) {
858 size_t j = pseudorand(i);
859 if (j == i - 1)
860 continue;
861 struct multifundchannel_destination *tmp;
862 tmp = deck[j];
863 deck[j] = deck[i - 1];
864 deck[i - 1] = tmp;
865 }
866
867 /* Now that we have our outputs shuffled, add outputs to the PSBT. */
868 for (unsigned int outnum = 0; outnum < tal_count(deck); ++outnum) {
869 if (outnum != 0)
870 tal_append_fmt(&content, ", ");
871 if (deck[outnum]) {
872 /* Funding outpoint. */
873 struct multifundchannel_destination *dest;
874 dest = deck[outnum];
875 (void) psbt_insert_output(mfc->psbt,
876 dest->funding_script,
877 dest->amount,
878 outnum);
879 /* The actual output index will be based on the
880 * serial_id if this contains any v2 outputs */
881 if (v2_dest_count == 0)
882 dest->outnum = outnum;
883 tal_append_fmt(&content, "%s: %s",

Callers 1

after_channel_startFunction · 0.85

Calls 13

dest_countFunction · 0.85
is_v2Function · 0.85
tal_append_fmtFunction · 0.85
psbt_insert_outputFunction · 0.85
psbt_add_serialsFunction · 0.85
register_mfcFunction · 0.85
psbt_txidFunction · 0.85
plugin_logFunction · 0.50
pseudorandFunction · 0.50

Tested by

no test coverage detected