Skip to content

Commit d991a45

Browse files
committed
Test commit for CI
1 parent 4fca656 commit d991a45

File tree

3 files changed

+108
-17
lines changed

3 files changed

+108
-17
lines changed

channeld/channeld.c

+43-15
Original file line numberDiff line numberDiff line change
@@ -3992,6 +3992,7 @@ static void splice_initiator_user_finalized(struct peer *peer)
39923992
char *error;
39933993
u32 chan_output_index, splice_funding_index;
39943994
struct wally_psbt_output *new_chan_output;
3995+
struct wally_psbt *psbt;
39953996
struct inflight *new_inflight;
39963997
struct bitcoin_txid current_psbt_txid;
39973998
struct amount_sat both_amount;
@@ -4003,7 +4004,7 @@ static void splice_initiator_user_finalized(struct peer *peer)
40034004
/* We must loading the funding tx as our previous utxo */
40044005
prev_tx = bitcoin_tx_from_txid(peer, peer->channel->funding.txid);
40054006

4006-
ictx = new_interactivetx_context(tmpctx, our_role,
4007+
ictx = new_interactivetx_context(NULL, our_role,
40074008
peer->pps, peer->channel_id);
40084009

40094010
ictx->next_update_fn = next_splice_step;
@@ -4015,60 +4016,82 @@ static void splice_initiator_user_finalized(struct peer *peer)
40154016
ictx->tx_add_input_count = peer->splicing->tx_add_input_count;
40164017
ictx->tx_add_output_count = peer->splicing->tx_add_output_count;
40174018

4019+
clone_psbt(NULL, ictx->current_psbt);
4020+
40184021
ictx->shared_outpoint = tal(ictx, struct bitcoin_outpoint);
40194022
*ictx->shared_outpoint = peer->channel->funding;
40204023
ictx->funding_tx = prev_tx;
40214024

4022-
error = process_interactivetx_updates(tmpctx, ictx,
4025+
clone_psbt(NULL, ictx->current_psbt);
4026+
4027+
error = process_interactivetx_updates(ictx, ictx,
40234028
&peer->splicing->received_tx_complete,
40244029
&abort_msg);
40254030
if (error)
40264031
peer_failed_warn(peer->pps, &peer->channel_id,
40274032
"Splice interactivetx error: %s", error);
40284033

4034+
clone_psbt(NULL, ictx->current_psbt);
4035+
40294036
check_tx_abort(peer, abort_msg);
40304037

4038+
psbt = ictx->current_psbt;
4039+
4040+
clone_psbt(NULL, psbt);
4041+
40314042
/* With pause_when_complete fase, this assert should never fail */
40324043
assert(peer->splicing->received_tx_complete);
40334044
peer->splicing->sent_tx_complete = true;
40344045

4035-
psbt_sort_by_serial_id(ictx->current_psbt);
4046+
clone_psbt(NULL, psbt);
40364047

4037-
new_chan_output = find_channel_output(peer, ictx->current_psbt,
4048+
new_chan_output = find_channel_output(peer, psbt,
40384049
&chan_output_index,
40394050
&peer->splicing->remote_funding_pubkey);
4051+
4052+
clone_psbt(NULL, psbt);
40404053

4041-
splice_funding_index = find_channel_funding_input(ictx->current_psbt,
4054+
splice_funding_index = find_channel_funding_input(psbt,
40424055
&peer->channel->funding);
4056+
4057+
clone_psbt(NULL, psbt);
40434058

4044-
both_amount = check_balances(peer, our_role, ictx->current_psbt,
4059+
both_amount = check_balances(peer, our_role, psbt,
40454060
chan_output_index, splice_funding_index);
40464061
new_chan_output->amount = both_amount.satoshis; /* Raw: type conv */
4062+
4063+
clone_psbt(NULL, psbt);
40474064

4048-
psbt_elements_normalize_fees(ictx->current_psbt);
4065+
psbt_elements_normalize_fees(psbt);
4066+
4067+
clone_psbt(NULL, psbt);
40494068

40504069
status_debug("Splice adding inflight: %s",
4051-
fmt_wally_psbt(tmpctx, ictx->current_psbt));
4070+
fmt_wally_psbt(tmpctx, psbt));
40524071

4053-
psbt_txid(tmpctx, ictx->current_psbt, &current_psbt_txid, NULL);
4072+
psbt_txid(ictx, psbt, &current_psbt_txid, NULL);
4073+
4074+
clone_psbt(NULL, psbt);
40544075

4055-
outmsg = towire_channeld_add_inflight(tmpctx,
4076+
outmsg = towire_channeld_add_inflight(NULL,
40564077
&peer->splicing->remote_funding_pubkey,
40574078
&current_psbt_txid,
40584079
chan_output_index,
40594080
peer->splicing->feerate_per_kw,
40604081
amount_sat(new_chan_output->amount),
40614082
peer->splicing->opener_relative,
4062-
ictx->current_psbt,
4083+
psbt,
40634084
true,
40644085
peer->splicing->force_sign_first);
4086+
4087+
clone_psbt(NULL, psbt);
40654088

40664089
master_wait_sync_reply(tmpctx, peer, take(outmsg),
40674090
WIRE_CHANNELD_GOT_INFLIGHT);
40684091

40694092
new_inflight = inflights_new(peer);
40704093

4071-
psbt_txid(tmpctx, ictx->current_psbt, &new_inflight->outpoint.txid,
4094+
psbt_txid(new_inflight, psbt, &new_inflight->outpoint.txid,
40724095
NULL);
40734096
new_inflight->remote_funding = peer->splicing->remote_funding_pubkey;
40744097
new_inflight->outpoint.n = chan_output_index;
@@ -4084,7 +4107,7 @@ static void splice_initiator_user_finalized(struct peer *peer)
40844107
* normal in-memory copy of the psbt: peer->splicing/ictx->current_psbt.
40854108
* Since we have to support using the inflight psbt anyway, we default
40864109
* to it. */
4087-
new_inflight->psbt = clone_psbt(new_inflight, ictx->current_psbt);
4110+
new_inflight->psbt = clone_psbt(new_inflight, psbt); // wally_psbt_clone_alloc fails here
40884111

40894112
current_push_val = relative_splice_balance_fundee(peer, our_role,
40904113
new_inflight->psbt,
@@ -4121,6 +4144,8 @@ static void splice_initiator_user_finalized(struct peer *peer)
41214144
true,
41224145
!sign_first);
41234146
wire_sync_write(MASTER_FD, take(outmsg));
4147+
4148+
tal_free(ictx);
41244149
}
41254150

41264151
/* During a splice the user may call splice_update mulitple times adding
@@ -4141,7 +4166,7 @@ static void splice_initiator_user_update(struct peer *peer, const u8 *inmsg)
41414166
return;
41424167
}
41434168

4144-
ictx = new_interactivetx_context(tmpctx, TX_INITIATOR,
4169+
ictx = new_interactivetx_context(NULL, TX_INITIATOR,
41454170
peer->pps, peer->channel_id);
41464171

41474172
if (!fromwire_channeld_splice_update(ictx, inmsg, &ictx->desired_psbt))
@@ -4152,6 +4177,7 @@ static void splice_initiator_user_update(struct peer *peer, const u8 *inmsg)
41524177
" splice when not in"
41534178
" splice mode.");
41544179
wire_sync_write(MASTER_FD, take(msg));
4180+
tal_free(ictx);
41554181
return;
41564182

41574183
}
@@ -4175,10 +4201,11 @@ static void splice_initiator_user_update(struct peer *peer, const u8 *inmsg)
41754201
if (!interactivetx_has_changes(ictx, ictx->desired_psbt)) {
41764202
splice_initiator_user_finalized(peer);
41774203
tal_steal(last_inflight(peer), last_inflight(peer)->psbt);
4204+
tal_free(ictx);
41784205
return;
41794206
}
41804207

4181-
error = process_interactivetx_updates(tmpctx, ictx,
4208+
error = process_interactivetx_updates(ictx, ictx,
41824209
&peer->splicing->received_tx_complete,
41834210
&abort_msg);
41844211
if (error)
@@ -4199,6 +4226,7 @@ static void splice_initiator_user_update(struct peer *peer, const u8 *inmsg)
41994226
ictx->current_psbt,
42004227
false, false);
42014228
wire_sync_write(MASTER_FD, take(outmsg));
4229+
tal_free(ictx);
42024230
}
42034231

42044232
/* This occurs when the user has signed the final version of the PSBT. At this

common/interactivetx.c

+49-2
Original file line numberDiff line numberDiff line change
@@ -391,26 +391,48 @@ char *process_interactivetx_updates(const tal_t *ctx,
391391
if (received_tx_complete)
392392
they_complete = *received_tx_complete;
393393

394-
/* Build change_set and handle PSBT variables */
395-
ictx->change_set = tal_free(ictx->change_set);
394+
if (ictx->current_psbt)
395+
clone_psbt(NULL, ictx->current_psbt);
396+
if (ictx->desired_psbt)
397+
clone_psbt(NULL, ictx->desired_psbt);
396398

397399
/* Call next_update_fn or default to 'desired_psbt' */
398400
next_psbt = ictx->next_update_fn(ictx, ictx);
399401

402+
if (ictx->current_psbt)
403+
clone_psbt(NULL, ictx->current_psbt);
404+
if (ictx->desired_psbt)
405+
clone_psbt(NULL, ictx->desired_psbt);
406+
400407
/* Returning NULL from next_update_fn is the same as using `current_psbt`
401408
* with no changes -- both indicate no changes */
402409
if (!next_psbt)
403410
next_psbt = ictx->current_psbt;
404411

412+
if (ictx->current_psbt)
413+
clone_psbt(NULL, ictx->current_psbt);
414+
if (ictx->desired_psbt)
415+
clone_psbt(NULL, ictx->desired_psbt);
416+
405417
ictx->change_set = get_changes(ctx, ictx, next_psbt);
406418

419+
if (ictx->current_psbt)
420+
clone_psbt(NULL, ictx->current_psbt); // this fails
421+
if (ictx->desired_psbt)
422+
clone_psbt(NULL, ictx->desired_psbt);
423+
407424
/* If current_psbt and next_psbt are the same, dont double free it!
408425
* Otherwise we advance `current_psbt` to `next_psbt` and begin
409426
* processing the change set in `ictx->change_set` */
410427
if (ictx->current_psbt != next_psbt) {
411428
ictx->current_psbt = next_psbt;
412429
}
413430

431+
if (ictx->current_psbt)
432+
clone_psbt(NULL, ictx->current_psbt);
433+
if (ictx->desired_psbt)
434+
clone_psbt(NULL, ictx->desired_psbt);
435+
414436
/* As initiator we always start with a single send to start it off */
415437
if (ictx->our_role == TX_INITIATOR) {
416438
error = send_next(ctx, ictx, &we_complete);
@@ -423,6 +445,11 @@ char *process_interactivetx_updates(const tal_t *ctx,
423445
}
424446
}
425447

448+
if (ictx->current_psbt)
449+
clone_psbt(NULL, ictx->current_psbt);
450+
if (ictx->desired_psbt)
451+
clone_psbt(NULL, ictx->desired_psbt);
452+
426453
/* Loop through tx update turns with peer */
427454
while (!(we_complete && they_complete)) {
428455
struct channel_id cid;
@@ -436,10 +463,20 @@ char *process_interactivetx_updates(const tal_t *ctx,
436463
if (received_tx_complete)
437464
*received_tx_complete = false;
438465

466+
if (ictx->current_psbt)
467+
clone_psbt(NULL, ictx->current_psbt);
468+
if (ictx->desired_psbt)
469+
clone_psbt(NULL, ictx->desired_psbt);
470+
439471
msg = read_next_msg(ctx, ictx, &error);
440472
if (error)
441473
return error;
442474

475+
if (ictx->current_psbt)
476+
clone_psbt(NULL, ictx->current_psbt);
477+
if (ictx->desired_psbt)
478+
clone_psbt(NULL, ictx->desired_psbt);
479+
443480
t = fromwire_peektype(msg);
444481
switch (t) {
445482
case WIRE_TX_ADD_INPUT: {
@@ -800,8 +837,18 @@ char *process_interactivetx_updates(const tal_t *ctx,
800837
send_next(ctx, ictx, &we_complete);
801838
}
802839

840+
if (ictx->current_psbt)
841+
clone_psbt(NULL, ictx->current_psbt);
842+
if (ictx->desired_psbt)
843+
clone_psbt(NULL, ictx->desired_psbt);
844+
803845
/* Sort psbt! */
804846
psbt_sort_by_serial_id(ictx->current_psbt);
805847

848+
if (ictx->current_psbt)
849+
clone_psbt(NULL, ictx->current_psbt);
850+
if (ictx->desired_psbt)
851+
clone_psbt(NULL, ictx->desired_psbt);
852+
806853
return NULL;
807854
}

common/psbt_open.c

+16
Original file line numberDiff line numberDiff line change
@@ -280,11 +280,24 @@ struct psbt_changeset *psbt_get_changeset(const tal_t *ctx,
280280
size_t i = 0, j = 0;
281281
struct psbt_changeset *set;
282282

283+
clone_psbt(NULL, orig);
284+
clone_psbt(NULL, new);
285+
283286
psbt_sort_by_serial_id(orig);
287+
288+
clone_psbt(NULL, orig);
289+
clone_psbt(NULL, new);
290+
284291
psbt_sort_by_serial_id(new);
285292

293+
clone_psbt(NULL, orig);
294+
clone_psbt(NULL, new);
295+
286296
set = new_changeset(ctx);
287297

298+
clone_psbt(NULL, orig);
299+
clone_psbt(NULL, new);
300+
288301
/* Find the input diff */
289302
while (i < orig->num_inputs || j < new->num_inputs) {
290303
if (i >= orig->num_inputs) {
@@ -352,6 +365,9 @@ struct psbt_changeset *psbt_get_changeset(const tal_t *ctx,
352365
i++;
353366
j++;
354367
}
368+
369+
clone_psbt(NULL, orig);
370+
clone_psbt(NULL, new);
355371

356372
return set;
357373
}

0 commit comments

Comments
 (0)