@@ -3610,8 +3610,9 @@ static void resume_splice_negotiation(struct peer *peer,
3610
3610
" Most likely you are missing"
3611
3611
" signatures." );
3612
3612
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 );
3615
3616
}
3616
3617
3617
3618
final_tx = bitcoin_tx_with_psbt (tmpctx , current_psbt );
@@ -3654,6 +3655,17 @@ static void resume_splice_negotiation(struct peer *peer,
3654
3655
new_output_index );
3655
3656
wire_sync_write (MASTER_FD , take (msg ));
3656
3657
}
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 );
3657
3669
}
3658
3670
3659
3671
static struct inflight * inflights_new (struct peer * peer )
@@ -3841,7 +3853,7 @@ static void splice_accepter(struct peer *peer, const u8 *inmsg)
3841
3853
funding_feerate_perkw ,
3842
3854
both_amount ,
3843
3855
peer -> splicing -> accepter_relative ,
3844
- ictx -> current_psbt ,
3856
+ clone_psbt ( tmpctx , ictx -> current_psbt ) ,
3845
3857
false,
3846
3858
peer -> splicing -> force_sign_first );
3847
3859
@@ -3862,15 +3874,34 @@ static void splice_accepter(struct peer *peer, const u8 *inmsg)
3862
3874
new_inflight -> force_sign_first = peer -> splicing -> force_sign_first ;
3863
3875
new_inflight -> is_locked = false;
3864
3876
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 ,
3866
3881
outpoint .n , splice_funding_index );
3882
+
3883
+ psbt_get_bytes (NULL , new_inflight -> psbt , & dummy );
3884
+
3867
3885
update_hsmd_with_splice (peer , new_inflight , our_role , current_push_val );
3868
3886
3887
+ psbt_get_bytes (NULL , new_inflight -> psbt , & dummy );
3888
+
3869
3889
update_view_from_inflights (peer );
3870
3890
3891
+ psbt_get_bytes (NULL , new_inflight -> psbt , & dummy );
3892
+
3871
3893
peer -> splice_state -> count ++ ;
3872
3894
3895
+ psbt_get_bytes (NULL , new_inflight -> psbt , & dummy );
3896
+
3873
3897
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 );
3874
3905
}
3875
3906
3876
3907
/* 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)
3992
4023
char * error ;
3993
4024
u32 chan_output_index , splice_funding_index ;
3994
4025
struct wally_psbt_output * new_chan_output ;
4026
+ struct wally_psbt * psbt ;
3995
4027
struct inflight * new_inflight ;
3996
4028
struct bitcoin_txid current_psbt_txid ;
3997
4029
struct amount_sat both_amount ;
@@ -4003,7 +4035,7 @@ static void splice_initiator_user_finalized(struct peer *peer)
4003
4035
/* We must loading the funding tx as our previous utxo */
4004
4036
prev_tx = bitcoin_tx_from_txid (peer , peer -> channel -> funding .txid );
4005
4037
4006
- ictx = new_interactivetx_context (tmpctx , our_role ,
4038
+ ictx = new_interactivetx_context (NULL , our_role ,
4007
4039
peer -> pps , peer -> channel_id );
4008
4040
4009
4041
ictx -> next_update_fn = next_splice_step ;
@@ -4015,60 +4047,82 @@ static void splice_initiator_user_finalized(struct peer *peer)
4015
4047
ictx -> tx_add_input_count = peer -> splicing -> tx_add_input_count ;
4016
4048
ictx -> tx_add_output_count = peer -> splicing -> tx_add_output_count ;
4017
4049
4050
+ clone_psbt (NULL , ictx -> current_psbt );
4051
+
4018
4052
ictx -> shared_outpoint = tal (ictx , struct bitcoin_outpoint );
4019
4053
* ictx -> shared_outpoint = peer -> channel -> funding ;
4020
4054
ictx -> funding_tx = prev_tx ;
4021
4055
4022
- error = process_interactivetx_updates (tmpctx , ictx ,
4056
+ clone_psbt (NULL , ictx -> current_psbt );
4057
+
4058
+ error = process_interactivetx_updates (ictx , ictx ,
4023
4059
& peer -> splicing -> received_tx_complete ,
4024
4060
& abort_msg );
4025
4061
if (error )
4026
4062
peer_failed_warn (peer -> pps , & peer -> channel_id ,
4027
4063
"Splice interactivetx error: %s" , error );
4028
4064
4065
+ clone_psbt (NULL , ictx -> current_psbt ); // dustin
4066
+
4029
4067
check_tx_abort (peer , abort_msg );
4030
4068
4069
+ psbt = ictx -> current_psbt ;
4070
+
4071
+ clone_psbt (NULL , psbt );
4072
+
4031
4073
/* With pause_when_complete fase, this assert should never fail */
4032
4074
assert (peer -> splicing -> received_tx_complete );
4033
4075
peer -> splicing -> sent_tx_complete = true;
4034
4076
4035
- psbt_sort_by_serial_id ( ictx -> current_psbt );
4077
+ clone_psbt ( NULL , psbt );
4036
4078
4037
- new_chan_output = find_channel_output (peer , ictx -> current_psbt ,
4079
+ new_chan_output = find_channel_output (peer , psbt ,
4038
4080
& chan_output_index ,
4039
4081
& peer -> splicing -> remote_funding_pubkey );
4082
+
4083
+ clone_psbt (NULL , psbt );
4040
4084
4041
- splice_funding_index = find_channel_funding_input (ictx -> current_psbt ,
4085
+ splice_funding_index = find_channel_funding_input (psbt ,
4042
4086
& peer -> channel -> funding );
4087
+
4088
+ clone_psbt (NULL , psbt ); // lisa
4043
4089
4044
- both_amount = check_balances (peer , our_role , ictx -> current_psbt ,
4090
+ both_amount = check_balances (peer , our_role , psbt ,
4045
4091
chan_output_index , splice_funding_index );
4046
4092
new_chan_output -> amount = both_amount .satoshis ; /* Raw: type conv */
4093
+
4094
+ clone_psbt (NULL , psbt );
4047
4095
4048
- psbt_elements_normalize_fees (ictx -> current_psbt );
4096
+ psbt_elements_normalize_fees (psbt );
4097
+
4098
+ clone_psbt (NULL , psbt );
4049
4099
4050
4100
status_debug ("Splice adding inflight: %s" ,
4051
- fmt_wally_psbt (tmpctx , ictx -> current_psbt ));
4101
+ fmt_wally_psbt (tmpctx , psbt ));
4052
4102
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 );
4054
4106
4055
- outmsg = towire_channeld_add_inflight (tmpctx ,
4107
+ outmsg = towire_channeld_add_inflight (NULL ,
4056
4108
& peer -> splicing -> remote_funding_pubkey ,
4057
4109
& current_psbt_txid ,
4058
4110
chan_output_index ,
4059
4111
peer -> splicing -> feerate_per_kw ,
4060
4112
amount_sat (new_chan_output -> amount ),
4061
4113
peer -> splicing -> opener_relative ,
4062
- ictx -> current_psbt ,
4114
+ psbt ,
4063
4115
true,
4064
4116
peer -> splicing -> force_sign_first );
4117
+
4118
+ clone_psbt (NULL , psbt );
4065
4119
4066
4120
master_wait_sync_reply (tmpctx , peer , take (outmsg ),
4067
4121
WIRE_CHANNELD_GOT_INFLIGHT );
4068
4122
4069
4123
new_inflight = inflights_new (peer );
4070
4124
4071
- psbt_txid (tmpctx , ictx -> current_psbt , & new_inflight -> outpoint .txid ,
4125
+ psbt_txid (new_inflight , psbt , & new_inflight -> outpoint .txid ,
4072
4126
NULL );
4073
4127
new_inflight -> remote_funding = peer -> splicing -> remote_funding_pubkey ;
4074
4128
new_inflight -> outpoint .n = chan_output_index ;
@@ -4084,7 +4138,7 @@ static void splice_initiator_user_finalized(struct peer *peer)
4084
4138
* normal in-memory copy of the psbt: peer->splicing/ictx->current_psbt.
4085
4139
* Since we have to support using the inflight psbt anyway, we default
4086
4140
* to it. */
4087
- new_inflight -> psbt = clone_psbt (new_inflight , ictx -> current_psbt );
4141
+ new_inflight -> psbt = clone_psbt (new_inflight , psbt );
4088
4142
4089
4143
current_push_val = relative_splice_balance_fundee (peer , our_role ,
4090
4144
new_inflight -> psbt ,
@@ -4113,14 +4167,32 @@ static void splice_initiator_user_finalized(struct peer *peer)
4113
4167
sign_first = do_i_sign_first (peer , new_inflight -> psbt , our_role ,
4114
4168
peer -> splicing -> force_sign_first );
4115
4169
4170
+ assert (new_inflight -> psbt );
4171
+
4116
4172
if (!sign_first )
4117
4173
resume_splice_negotiation (peer , false, false, false, true);
4118
4174
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
+
4119
4183
outmsg = towire_channeld_splice_confirmed_update (NULL ,
4120
4184
new_inflight -> psbt ,
4121
4185
true,
4122
4186
!sign_first );
4123
4187
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 );
4124
4196
}
4125
4197
4126
4198
/* 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)
4141
4213
return ;
4142
4214
}
4143
4215
4144
- ictx = new_interactivetx_context (tmpctx , TX_INITIATOR ,
4216
+ ictx = new_interactivetx_context (NULL , TX_INITIATOR ,
4145
4217
peer -> pps , peer -> channel_id );
4146
4218
4147
4219
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)
4152
4224
" splice when not in"
4153
4225
" splice mode." );
4154
4226
wire_sync_write (MASTER_FD , take (msg ));
4227
+ tal_free (ictx );
4155
4228
return ;
4156
4229
4157
4230
}
@@ -4177,10 +4250,11 @@ static void splice_initiator_user_update(struct peer *peer, const u8 *inmsg)
4177
4250
if (!interactivetx_has_changes (ictx , ictx -> desired_psbt )) {
4178
4251
splice_initiator_user_finalized (peer );
4179
4252
tal_steal (last_inflight (peer ), last_inflight (peer )-> psbt );
4253
+ tal_free (ictx );
4180
4254
return ;
4181
4255
}
4182
4256
4183
- error = process_interactivetx_updates (tmpctx , ictx ,
4257
+ error = process_interactivetx_updates (ictx , ictx ,
4184
4258
& peer -> splicing -> received_tx_complete ,
4185
4259
& abort_msg );
4186
4260
if (error )
@@ -4201,9 +4275,10 @@ static void splice_initiator_user_update(struct peer *peer, const u8 *inmsg)
4201
4275
4202
4276
/* Peer may have modified our PSBT so we return it to the user here */
4203
4277
outmsg = towire_channeld_splice_confirmed_update (NULL ,
4204
- ictx -> current_psbt ,
4278
+ peer -> splicing -> current_psbt ,
4205
4279
false, false);
4206
4280
wire_sync_write (MASTER_FD , take (outmsg ));
4281
+ tal_free (ictx );
4207
4282
}
4208
4283
4209
4284
/* 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)
4285
4360
inflight -> force_sign_first );
4286
4361
4287
4362
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 );
4288
4370
}
4289
4371
4290
4372
/* This occurs once our 'stfu' transition was successful. */
@@ -5650,15 +5732,22 @@ static void handle_funding_depth(struct peer *peer, const u8 *msg)
5650
5732
5651
5733
for (size_t i = 0 ; i < tal_count (peer -> splice_state -> inflights ); i ++ ) {
5652
5734
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 );
5653
5739
if (bitcoin_txid_eq (& inflight -> outpoint .txid ,
5654
5740
& txid )) {
5655
5741
inflight -> is_locked = true;
5656
5742
assert (inflight -> psbt );
5743
+ psbt_get_bytes (NULL , inflight -> psbt , & dummy );
5657
5744
msg = towire_channeld_update_inflight (NULL ,
5658
5745
inflight -> psbt ,
5659
5746
NULL ,
5660
5747
NULL ,
5661
5748
inflight -> is_locked );
5749
+
5750
+ psbt_get_bytes (NULL , inflight -> psbt , & dummy );
5662
5751
wire_sync_write (MASTER_FD , take (msg ));
5663
5752
}
5664
5753
}
0 commit comments