Browse Source

mfc-df: only add outputs for v1 outs; go to openchannel_update if v2s

We only have output scripts for v1 protocols after the
fundchannel_start/openchannel_init round. We need to add them before
we get into the openchannel_update rounds, however, so we do that here.
fix-mocks
niftynei 4 years ago
committed by neil saitug
parent
commit
c90a19f739
  1. 41
      plugins/spender/multifundchannel.c
  2. 4
      plugins/spender/openchannel.c
  3. 4
      plugins/spender/openchannel.h

41
plugins/spender/multifundchannel.c

@ -1196,6 +1196,9 @@ perform_funding_tx_finalize(struct multifundchannel_command *mfc)
{
struct multifundchannel_destination **deck;
char *content = tal_strdup(tmpctx, "");
size_t v1_dest_count = dest_count(mfc, FUND_CHANNEL);
size_t v2_dest_count = dest_count(mfc, OPEN_CHANNEL);
size_t i, deck_i;
plugin_log(mfc->cmd->plugin, LOG_DBG,
"mfc %"PRIu64": Creating funding tx.",
@ -1203,15 +1206,23 @@ perform_funding_tx_finalize(struct multifundchannel_command *mfc)
/* Construct a deck of destinations. */
deck = tal_arr(tmpctx, struct multifundchannel_destination *,
tal_count(mfc->destinations) + mfc->change_needed);
for (size_t i = 0; i < tal_count(mfc->destinations); ++i)
deck[i] = &mfc->destinations[i];
v1_dest_count + mfc->change_needed);
deck_i = 0;
for (i = 0; i < tal_count(mfc->destinations); i++) {
if (mfc->destinations[i].protocol == OPEN_CHANNEL)
continue;
assert(deck_i < tal_count(deck));
deck[deck_i++] = &mfc->destinations[i];
}
/* Add a NULL into the deck as a proxy for change output, if
* needed. */
if (mfc->change_needed)
deck[tal_count(mfc->destinations)] = NULL;
deck[v1_dest_count] = NULL;
/* Fisher-Yates shuffle. */
for (size_t i = tal_count(deck); i > 1; --i) {
for (i = tal_count(deck); i > 1; --i) {
size_t j = pseudorand(i);
if (j == i - 1)
continue;
@ -1221,7 +1232,7 @@ perform_funding_tx_finalize(struct multifundchannel_command *mfc)
deck[i - 1] = tmp;
}
/* Now that we have the outputs shuffled, add outputs to the PSBT. */
/* Now that we have our outputs shuffled, add outputs to the PSBT. */
for (unsigned int outnum = 0; outnum < tal_count(deck); ++outnum) {
if (outnum != 0)
tal_append_fmt(&content, ", ");
@ -1233,6 +1244,9 @@ perform_funding_tx_finalize(struct multifundchannel_command *mfc)
dest->funding_script,
dest->amount,
outnum);
/* The actual output index will be based on the
* serial_id if this contains any v2 outputs */
if (v2_dest_count == 0)
dest->outnum = outnum;
tal_append_fmt(&content, "%s: %s",
type_to_string(tmpctx, struct node_id,
@ -1254,6 +1268,21 @@ perform_funding_tx_finalize(struct multifundchannel_command *mfc)
}
}
if (v2_dest_count > 0) {
/* Add serial_ids to all the new outputs */
psbt_add_serials(mfc->psbt, TX_INITIATOR);
/* Now we stash the 'mfc' command, so when/if
* signature notifications start coming
* in, we'll catch them. */
register_mfc(mfc);
/* Take a side-quest to finish filling out
* the funding tx */
return perform_openchannel_update(mfc);
}
/* We've only got v1 destinations, move onward */
/* Elements requires a fee output. */
psbt_elements_normalize_fees(mfc->psbt);

4
plugins/spender/openchannel.c

@ -14,21 +14,19 @@
static struct list_head mfc_commands;
/* unused for now, will return soon!
static void
destroy_mfc(struct multifundchannel_command *mfc)
{
list_del(&mfc->list);
}
static void register_mfc(struct multifundchannel_command *mfc)
void register_mfc(struct multifundchannel_command *mfc)
{
assert(mfc);
list_add_tail(&mfc_commands, &mfc->list);
tal_add_destructor(mfc, &destroy_mfc);
}
*/
static struct multifundchannel_destination *
find_dest_by_channel_id(struct channel_id *cid)

4
plugins/spender/openchannel.h

@ -8,6 +8,10 @@ struct wally_psbt;
extern const struct plugin_notification openchannel_notifs[];
extern const size_t num_openchannel_notifs;
/* register_mfc - Register to listen for incoming
* peer signature notifications */
void register_mfc(struct multifundchannel_command *mfc);
struct command_result *
openchannel_init_dest(struct multifundchannel_destination *dest);

Loading…
Cancel
Save