Skip to content

Commit c41c880

Browse files
committed
Test commit for CI
1 parent 057982b commit c41c880

File tree

5 files changed

+213
-28
lines changed

5 files changed

+213
-28
lines changed

bitcoin/psbt.c

+9-6
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,15 @@ struct wally_psbt *create_psbt(const tal_t *ctx, size_t num_inputs, size_t num_o
3838

3939
struct wally_psbt *clone_psbt(const tal_t *ctx, const struct wally_psbt *psbt)
4040
{
41-
struct wally_psbt *clone;
42-
tal_wally_start();
43-
if (wally_psbt_clone_alloc(psbt, 0, &clone) != WALLY_OK)
44-
abort();
45-
tal_wally_end_onto(ctx, clone, struct wally_psbt);
46-
return clone;
41+
struct wally_psbt *result;
42+
size_t bytes_written;
43+
const u8 *psbt_bytes;
44+
45+
psbt_bytes = psbt_get_bytes(NULL, psbt, &bytes_written);
46+
result = psbt_from_bytes(ctx, psbt_bytes, bytes_written);
47+
tal_free(psbt_bytes);
48+
49+
return result;
4750
}
4851

4952
struct wally_psbt *new_psbt(const tal_t *ctx, const struct wally_tx *wtx)

channeld/channeld.c

+109-20
Original file line numberDiff line numberDiff line change
@@ -3610,8 +3610,9 @@ static void resume_splice_negotiation(struct peer *peer,
36103610
" Most likely you are missing"
36113611
" signatures.");
36123612

3613-
psbt_finalize_input(current_psbt, in,
3614-
inws[j++]);
3613+
tal_wally_start();
3614+
psbt_finalize_input(current_psbt, in, inws[j++]);
3615+
tal_wally_end(current_psbt);
36153616
}
36163617

36173618
final_tx = bitcoin_tx_with_psbt(tmpctx, current_psbt);
@@ -3654,6 +3655,17 @@ static void resume_splice_negotiation(struct peer *peer,
36543655
new_output_index);
36553656
wire_sync_write(MASTER_FD, take(msg));
36563657
}
3658+
3659+
size_t dummy;
3660+
psbt_get_bytes(NULL, inflight->psbt, &dummy);
3661+
psbt_get_bytes(NULL, current_psbt, &dummy);
3662+
clone_psbt(NULL, inflight->psbt);
3663+
clone_psbt(NULL, current_psbt);
3664+
assert(inflight->psbt == current_psbt);
3665+
3666+
struct wally_psbt *copy = inflight->psbt;
3667+
inflight->psbt = clone_psbt(inflight, inflight->psbt);
3668+
free(copy);
36573669
}
36583670

36593671
static struct inflight *inflights_new(struct peer *peer)
@@ -3841,7 +3853,7 @@ static void splice_accepter(struct peer *peer, const u8 *inmsg)
38413853
funding_feerate_perkw,
38423854
both_amount,
38433855
peer->splicing->accepter_relative,
3844-
ictx->current_psbt,
3856+
clone_psbt(tmpctx, ictx->current_psbt),
38453857
false,
38463858
peer->splicing->force_sign_first);
38473859

@@ -3862,15 +3874,34 @@ static void splice_accepter(struct peer *peer, const u8 *inmsg)
38623874
new_inflight->force_sign_first = peer->splicing->force_sign_first;
38633875
new_inflight->is_locked = false;
38643876

3865-
current_push_val = relative_splice_balance_fundee(peer, our_role,ictx->current_psbt,
3877+
size_t dummy;
3878+
psbt_get_bytes(NULL, new_inflight->psbt, &dummy);
3879+
3880+
current_push_val = relative_splice_balance_fundee(peer, our_role, ictx->current_psbt,
38663881
outpoint.n, splice_funding_index);
3882+
3883+
psbt_get_bytes(NULL, new_inflight->psbt, &dummy);
3884+
38673885
update_hsmd_with_splice(peer, new_inflight, our_role, current_push_val);
38683886

3887+
psbt_get_bytes(NULL, new_inflight->psbt, &dummy);
3888+
38693889
update_view_from_inflights(peer);
38703890

3891+
psbt_get_bytes(NULL, new_inflight->psbt, &dummy);
3892+
38713893
peer->splice_state->count++;
38723894

3895+
psbt_get_bytes(NULL, new_inflight->psbt, &dummy);
3896+
38733897
resume_splice_negotiation(peer, true, true, true, true);
3898+
3899+
psbt_get_bytes(NULL, new_inflight->psbt, &dummy);
3900+
3901+
new_inflight->psbt = clone_psbt(new_inflight, ictx->current_psbt);
3902+
clean_tmpctx();
3903+
3904+
psbt_get_bytes(NULL, new_inflight->psbt, &dummy);
38743905
}
38753906

38763907
/* splice_initiator runs when splice_ack is received by the other side. It
@@ -3992,6 +4023,7 @@ static void splice_initiator_user_finalized(struct peer *peer)
39924023
char *error;
39934024
u32 chan_output_index, splice_funding_index;
39944025
struct wally_psbt_output *new_chan_output;
4026+
struct wally_psbt *psbt;
39954027
struct inflight *new_inflight;
39964028
struct bitcoin_txid current_psbt_txid;
39974029
struct amount_sat both_amount;
@@ -4003,7 +4035,7 @@ static void splice_initiator_user_finalized(struct peer *peer)
40034035
/* We must loading the funding tx as our previous utxo */
40044036
prev_tx = bitcoin_tx_from_txid(peer, peer->channel->funding.txid);
40054037

4006-
ictx = new_interactivetx_context(tmpctx, our_role,
4038+
ictx = new_interactivetx_context(NULL, our_role,
40074039
peer->pps, peer->channel_id);
40084040

40094041
ictx->next_update_fn = next_splice_step;
@@ -4015,60 +4047,82 @@ static void splice_initiator_user_finalized(struct peer *peer)
40154047
ictx->tx_add_input_count = peer->splicing->tx_add_input_count;
40164048
ictx->tx_add_output_count = peer->splicing->tx_add_output_count;
40174049

4050+
clone_psbt(NULL, ictx->current_psbt);
4051+
40184052
ictx->shared_outpoint = tal(ictx, struct bitcoin_outpoint);
40194053
*ictx->shared_outpoint = peer->channel->funding;
40204054
ictx->funding_tx = prev_tx;
40214055

4022-
error = process_interactivetx_updates(tmpctx, ictx,
4056+
clone_psbt(NULL, ictx->current_psbt);
4057+
4058+
error = process_interactivetx_updates(ictx, ictx,
40234059
&peer->splicing->received_tx_complete,
40244060
&abort_msg);
40254061
if (error)
40264062
peer_failed_warn(peer->pps, &peer->channel_id,
40274063
"Splice interactivetx error: %s", error);
40284064

4065+
clone_psbt(NULL, ictx->current_psbt); // dustin
4066+
40294067
check_tx_abort(peer, abort_msg);
40304068

4069+
psbt = ictx->current_psbt;
4070+
4071+
clone_psbt(NULL, psbt);
4072+
40314073
/* With pause_when_complete fase, this assert should never fail */
40324074
assert(peer->splicing->received_tx_complete);
40334075
peer->splicing->sent_tx_complete = true;
40344076

4035-
psbt_sort_by_serial_id(ictx->current_psbt);
4077+
clone_psbt(NULL, psbt);
40364078

4037-
new_chan_output = find_channel_output(peer, ictx->current_psbt,
4079+
new_chan_output = find_channel_output(peer, psbt,
40384080
&chan_output_index,
40394081
&peer->splicing->remote_funding_pubkey);
4082+
4083+
clone_psbt(NULL, psbt);
40404084

4041-
splice_funding_index = find_channel_funding_input(ictx->current_psbt,
4085+
splice_funding_index = find_channel_funding_input(psbt,
40424086
&peer->channel->funding);
4087+
4088+
clone_psbt(NULL, psbt); // lisa
40434089

4044-
both_amount = check_balances(peer, our_role, ictx->current_psbt,
4090+
both_amount = check_balances(peer, our_role, psbt,
40454091
chan_output_index, splice_funding_index);
40464092
new_chan_output->amount = both_amount.satoshis; /* Raw: type conv */
4093+
4094+
clone_psbt(NULL, psbt);
40474095

4048-
psbt_elements_normalize_fees(ictx->current_psbt);
4096+
psbt_elements_normalize_fees(psbt);
4097+
4098+
clone_psbt(NULL, psbt);
40494099

40504100
status_debug("Splice adding inflight: %s",
4051-
fmt_wally_psbt(tmpctx, ictx->current_psbt));
4101+
fmt_wally_psbt(tmpctx, psbt));
40524102

4053-
psbt_txid(tmpctx, ictx->current_psbt, &current_psbt_txid, NULL);
4103+
psbt_txid(ictx, psbt, &current_psbt_txid, NULL);
4104+
4105+
clone_psbt(NULL, psbt);
40544106

4055-
outmsg = towire_channeld_add_inflight(tmpctx,
4107+
outmsg = towire_channeld_add_inflight(NULL,
40564108
&peer->splicing->remote_funding_pubkey,
40574109
&current_psbt_txid,
40584110
chan_output_index,
40594111
peer->splicing->feerate_per_kw,
40604112
amount_sat(new_chan_output->amount),
40614113
peer->splicing->opener_relative,
4062-
ictx->current_psbt,
4114+
psbt,
40634115
true,
40644116
peer->splicing->force_sign_first);
4117+
4118+
clone_psbt(NULL, psbt);
40654119

40664120
master_wait_sync_reply(tmpctx, peer, take(outmsg),
40674121
WIRE_CHANNELD_GOT_INFLIGHT);
40684122

40694123
new_inflight = inflights_new(peer);
40704124

4071-
psbt_txid(tmpctx, ictx->current_psbt, &new_inflight->outpoint.txid,
4125+
psbt_txid(new_inflight, psbt, &new_inflight->outpoint.txid,
40724126
NULL);
40734127
new_inflight->remote_funding = peer->splicing->remote_funding_pubkey;
40744128
new_inflight->outpoint.n = chan_output_index;
@@ -4084,7 +4138,7 @@ static void splice_initiator_user_finalized(struct peer *peer)
40844138
* normal in-memory copy of the psbt: peer->splicing/ictx->current_psbt.
40854139
* Since we have to support using the inflight psbt anyway, we default
40864140
* to it. */
4087-
new_inflight->psbt = clone_psbt(new_inflight, ictx->current_psbt);
4141+
new_inflight->psbt = clone_psbt(new_inflight, psbt);
40884142

40894143
current_push_val = relative_splice_balance_fundee(peer, our_role,
40904144
new_inflight->psbt,
@@ -4113,14 +4167,32 @@ static void splice_initiator_user_finalized(struct peer *peer)
41134167
sign_first = do_i_sign_first(peer, new_inflight->psbt, our_role,
41144168
peer->splicing->force_sign_first);
41154169

4170+
assert(new_inflight->psbt);
4171+
41164172
if (!sign_first)
41174173
resume_splice_negotiation(peer, false, false, false, true);
41184174

4175+
size_t dummy;
4176+
psbt_get_bytes(NULL, new_inflight->psbt, &dummy);
4177+
4178+
assert(new_inflight->psbt);
4179+
struct wally_psbt *old_psbt = new_inflight->psbt;
4180+
new_inflight->psbt = clone_psbt(new_inflight, new_inflight->psbt);
4181+
tal_free(old_psbt);
4182+
41194183
outmsg = towire_channeld_splice_confirmed_update(NULL,
41204184
new_inflight->psbt,
41214185
true,
41224186
!sign_first);
41234187
wire_sync_write(MASTER_FD, take(outmsg));
4188+
4189+
tal_free(ictx);
4190+
4191+
psbt_get_bytes(NULL, new_inflight->psbt, &dummy);
4192+
4193+
clean_tmpctx();
4194+
4195+
psbt_get_bytes(NULL, new_inflight->psbt, &dummy);
41244196
}
41254197

41264198
/* During a splice the user may call splice_update mulitple times adding
@@ -4141,7 +4213,7 @@ static void splice_initiator_user_update(struct peer *peer, const u8 *inmsg)
41414213
return;
41424214
}
41434215

4144-
ictx = new_interactivetx_context(tmpctx, TX_INITIATOR,
4216+
ictx = new_interactivetx_context(NULL, TX_INITIATOR,
41454217
peer->pps, peer->channel_id);
41464218

41474219
if (!fromwire_channeld_splice_update(ictx, inmsg, &ictx->desired_psbt))
@@ -4152,6 +4224,7 @@ static void splice_initiator_user_update(struct peer *peer, const u8 *inmsg)
41524224
" splice when not in"
41534225
" splice mode.");
41544226
wire_sync_write(MASTER_FD, take(msg));
4227+
tal_free(ictx);
41554228
return;
41564229

41574230
}
@@ -4177,10 +4250,11 @@ static void splice_initiator_user_update(struct peer *peer, const u8 *inmsg)
41774250
if (!interactivetx_has_changes(ictx, ictx->desired_psbt)) {
41784251
splice_initiator_user_finalized(peer);
41794252
tal_steal(last_inflight(peer), last_inflight(peer)->psbt);
4253+
tal_free(ictx);
41804254
return;
41814255
}
41824256

4183-
error = process_interactivetx_updates(tmpctx, ictx,
4257+
error = process_interactivetx_updates(ictx, ictx,
41844258
&peer->splicing->received_tx_complete,
41854259
&abort_msg);
41864260
if (error)
@@ -4201,9 +4275,10 @@ static void splice_initiator_user_update(struct peer *peer, const u8 *inmsg)
42014275

42024276
/* Peer may have modified our PSBT so we return it to the user here */
42034277
outmsg = towire_channeld_splice_confirmed_update(NULL,
4204-
ictx->current_psbt,
4278+
peer->splicing->current_psbt,
42054279
false, false);
42064280
wire_sync_write(MASTER_FD, take(outmsg));
4281+
tal_free(ictx);
42074282
}
42084283

42094284
/* This occurs when the user has signed the final version of the PSBT. At this
@@ -4285,6 +4360,13 @@ static void splice_initiator_user_signed(struct peer *peer, const u8 *inmsg)
42854360
inflight->force_sign_first);
42864361

42874362
resume_splice_negotiation(peer, false, false, true, sign_first);
4363+
4364+
size_t dummy;
4365+
psbt_get_bytes(NULL, inflight->psbt, &dummy);
4366+
4367+
clean_tmpctx();
4368+
4369+
psbt_get_bytes(NULL, inflight->psbt, &dummy);
42884370
}
42894371

42904372
/* This occurs once our 'stfu' transition was successful. */
@@ -5650,15 +5732,22 @@ static void handle_funding_depth(struct peer *peer, const u8 *msg)
56505732

56515733
for (size_t i = 0; i < tal_count(peer->splice_state->inflights); i++) {
56525734
struct inflight *inflight = peer->splice_state->inflights[i];
5735+
size_t dummy;
5736+
psbt_get_bytes(NULL, inflight->psbt, &dummy);
5737+
psbt_get_bytes(NULL, inflight->psbt, &dummy);
5738+
psbt_get_bytes(NULL, inflight->psbt, &dummy);
56535739
if (bitcoin_txid_eq(&inflight->outpoint.txid,
56545740
&txid)) {
56555741
inflight->is_locked = true;
56565742
assert(inflight->psbt);
5743+
psbt_get_bytes(NULL, inflight->psbt, &dummy);
56575744
msg = towire_channeld_update_inflight(NULL,
56585745
inflight->psbt,
56595746
NULL,
56605747
NULL,
56615748
inflight->is_locked);
5749+
5750+
psbt_get_bytes(NULL, inflight->psbt, &dummy);
56625751
wire_sync_write(MASTER_FD, take(msg));
56635752
}
56645753
}

0 commit comments

Comments
 (0)