Skip to content

Commit

Permalink
fixup! inflights: use ctx for making new ones
Browse files Browse the repository at this point in the history
  • Loading branch information
niftynei committed May 12, 2023
1 parent 4ea0f03 commit 9c93a37
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
17 changes: 9 additions & 8 deletions channeld/channeld.c
Original file line number Diff line number Diff line change
Expand Up @@ -3324,16 +3324,17 @@ static void resume_splice_negotiation(struct peer *peer,
send_channel_update(peer, 0);
}

static struct inflight *append_inflight(struct peer *peer)
static struct inflight *init_inflights(const tal_t *ctx, struct peer *peer)
{
if (!peer->splice_state.inflights)
peer->splice_state.inflights = tal_arr(peer, struct inflight *, 0);
struct inflight *inf;

size_t len = tal_count(peer->splice_state.inflights);
if (!peer->splice_state.inflights)
peer->splice_state.inflights = tal_arr(ctx, struct inflight *, 0);

tal_resize(&peer->splice_state.inflights, len + 1);
inf = tal(peer->splice_state.inflights, struct inflight);

return peer->splice_state.inflights[len];
tal_arr_expand(&peer->splice_state.inflights, inf);
return inf;
}

/* ACCEPTER side of the splice. Here we handle all the accepter's steps for the
Expand Down Expand Up @@ -3464,7 +3465,7 @@ static void splice_accepter(struct peer *peer, const u8 *inmsg)
master_wait_sync_reply(tmpctx, peer, take(msg),
WIRE_CHANNELD_GOT_INFLIGHT);

new_inflight = append_inflight(peer);
new_inflight = init_inflights(peer, peer);

psbt_txid(tmpctx, ictx->current_psbt, &new_inflight->outpoint.txid, NULL);
new_inflight->outpoint = outpoint;
Expand Down Expand Up @@ -3719,7 +3720,7 @@ static void splice_initiator_user_finalized(struct peer *peer)
master_wait_sync_reply(tmpctx, peer, take(outmsg),
WIRE_CHANNELD_GOT_INFLIGHT);

new_inflight = append_inflight(peer);
new_inflight = init_inflights(peer, peer);

psbt_txid(tmpctx, ictx->current_psbt, &new_inflight->outpoint.txid, NULL);
new_inflight->outpoint.n = chan_output_index;
Expand Down
24 changes: 14 additions & 10 deletions lightningd/channel_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -1262,7 +1262,7 @@ bool peer_start_channeld(struct channel *channel,
secp256k1_ecdsa_signature *remote_ann_node_sig, *remote_ann_bitcoin_sig;
struct penalty_base *pbases;
struct channel_inflight *inflight;
struct inflight *inflights;
struct inflight **inflights;
struct bitcoin_txid txid;

hsmfd = hsm_get_client_fd(ld, &channel->peer->id,
Expand Down Expand Up @@ -1364,15 +1364,19 @@ bool peer_start_channeld(struct channel *channel,
return false;
}

inflights = tal_arr(tmpctx, struct inflight, 0);
inflights = tal_arr(tmpctx, struct inflight *, 0);
list_for_each(&channel->inflights, inflight, list) {
struct inflight infcopy;
infcopy.outpoint = inflight->funding->outpoint;
infcopy.amnt = inflight->funding->total_funds;
infcopy.splice_amnt = inflight->funding->splice_amnt;
infcopy.last_tx = inflight->last_tx;
infcopy.last_sig = inflight->last_sig;
infcopy.i_am_initiator = inflight->i_am_initiator;
struct inflight *infcopy = tal(inflights, struct inflight);

infcopy->outpoint = inflight->funding->outpoint;
infcopy->amnt = inflight->funding->total_funds;
infcopy->splice_amnt = inflight->funding->splice_amnt;
infcopy->last_tx = tal_dup(infcopy, struct bitcoin_tx, inflight->last_tx);
infcopy->last_sig = inflight->last_sig;
infcopy->i_am_initiator = inflight->i_am_initiator;
tal_wally_start();
wally_psbt_clone_alloc(inflight->funding_psbt, 0, &infcopy->psbt);
tal_wally_end_onto(infcopy, infcopy->psbt, struct wally_psbt);
tal_arr_expand(&inflights, infcopy);
}

Expand Down Expand Up @@ -1446,7 +1450,7 @@ bool peer_start_channeld(struct channel *channel,
pbases,
reestablish_only,
channel->channel_update,
cast_const2(const struct inflight **, &inflights));
cast_const2(const struct inflight **, inflights));

/* We don't expect a response: we are triggered by funding_depth_cb. */
subd_send_msg(channel->owner, take(initmsg));
Expand Down

0 comments on commit 9c93a37

Please sign in to comment.