Skip to content

Commit a056ec1

Browse files
niftyneiddustin
authored andcommitted
fixup! inflights: use ctx for making new ones
1 parent 05dd51d commit a056ec1

File tree

2 files changed

+23
-18
lines changed

2 files changed

+23
-18
lines changed

channeld/channeld.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3324,16 +3324,17 @@ static void resume_splice_negotiation(struct peer *peer,
33243324
send_channel_update(peer, 0);
33253325
}
33263326

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

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

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

3336-
return peer->splice_state.inflights[len];
3336+
tal_arr_expand(&peer->splice_state.inflights, inf);
3337+
return inf;
33373338
}
33383339

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

3467-
new_inflight = append_inflight(peer);
3468+
new_inflight = init_inflights(peer, peer);
34683469

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

3722-
new_inflight = append_inflight(peer);
3723+
new_inflight = init_inflights(peer, peer);
37233724

37243725
psbt_txid(tmpctx, ictx->current_psbt, &new_inflight->outpoint.txid, NULL);
37253726
new_inflight->outpoint.n = chan_output_index;

lightningd/channel_control.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,7 +1262,7 @@ bool peer_start_channeld(struct channel *channel,
12621262
secp256k1_ecdsa_signature *remote_ann_node_sig, *remote_ann_bitcoin_sig;
12631263
struct penalty_base *pbases;
12641264
struct channel_inflight *inflight;
1265-
struct inflight *inflights;
1265+
struct inflight **inflights;
12661266
struct bitcoin_txid txid;
12671267

12681268
hsmfd = hsm_get_client_fd(ld, &channel->peer->id,
@@ -1364,15 +1364,19 @@ bool peer_start_channeld(struct channel *channel,
13641364
return false;
13651365
}
13661366

1367-
inflights = tal_arr(tmpctx, struct inflight, 0);
1367+
inflights = tal_arr(tmpctx, struct inflight *, 0);
13681368
list_for_each(&channel->inflights, inflight, list) {
1369-
struct inflight infcopy;
1370-
infcopy.outpoint = inflight->funding->outpoint;
1371-
infcopy.amnt = inflight->funding->total_funds;
1372-
infcopy.splice_amnt = inflight->funding->splice_amnt;
1373-
infcopy.last_tx = inflight->last_tx;
1374-
infcopy.last_sig = inflight->last_sig;
1375-
infcopy.i_am_initiator = inflight->i_am_initiator;
1369+
struct inflight *infcopy = tal(inflights, struct inflight);
1370+
1371+
infcopy->outpoint = inflight->funding->outpoint;
1372+
infcopy->amnt = inflight->funding->total_funds;
1373+
infcopy->splice_amnt = inflight->funding->splice_amnt;
1374+
infcopy->last_tx = tal_dup(infcopy, struct bitcoin_tx, inflight->last_tx);
1375+
infcopy->last_sig = inflight->last_sig;
1376+
infcopy->i_am_initiator = inflight->i_am_initiator;
1377+
tal_wally_start();
1378+
wally_psbt_clone_alloc(inflight->funding_psbt, 0, &infcopy->psbt);
1379+
tal_wally_end_onto(infcopy, infcopy->psbt, struct wally_psbt);
13761380
tal_arr_expand(&inflights, infcopy);
13771381
}
13781382

@@ -1446,7 +1450,7 @@ bool peer_start_channeld(struct channel *channel,
14461450
pbases,
14471451
reestablish_only,
14481452
channel->channel_update,
1449-
cast_const2(const struct inflight **, &inflights));
1453+
cast_const2(const struct inflight **, inflights));
14501454

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

0 commit comments

Comments
 (0)