Skip to content

Commit

Permalink
Test commit for CI
Browse files Browse the repository at this point in the history
  • Loading branch information
ddustin committed Feb 7, 2025
1 parent 4fca656 commit 3644ed4
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 17 deletions.
58 changes: 43 additions & 15 deletions channeld/channeld.c
Original file line number Diff line number Diff line change
Expand Up @@ -3992,6 +3992,7 @@ static void splice_initiator_user_finalized(struct peer *peer)
char *error;
u32 chan_output_index, splice_funding_index;
struct wally_psbt_output *new_chan_output;
struct wally_psbt *psbt;
struct inflight *new_inflight;
struct bitcoin_txid current_psbt_txid;
struct amount_sat both_amount;
Expand All @@ -4003,7 +4004,7 @@ static void splice_initiator_user_finalized(struct peer *peer)
/* We must loading the funding tx as our previous utxo */
prev_tx = bitcoin_tx_from_txid(peer, peer->channel->funding.txid);

ictx = new_interactivetx_context(tmpctx, our_role,
ictx = new_interactivetx_context(NULL, our_role,
peer->pps, peer->channel_id);

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

clone_psbt(NULL, ictx->current_psbt);

ictx->shared_outpoint = tal(ictx, struct bitcoin_outpoint);
*ictx->shared_outpoint = peer->channel->funding;
ictx->funding_tx = prev_tx;

error = process_interactivetx_updates(tmpctx, ictx,
clone_psbt(NULL, ictx->current_psbt);

error = process_interactivetx_updates(ictx, ictx,
&peer->splicing->received_tx_complete,
&abort_msg);
if (error)
peer_failed_warn(peer->pps, &peer->channel_id,
"Splice interactivetx error: %s", error);

clone_psbt(NULL, ictx->current_psbt);

check_tx_abort(peer, abort_msg);

psbt = ictx->current_psbt;

clone_psbt(NULL, psbt);

/* With pause_when_complete fase, this assert should never fail */
assert(peer->splicing->received_tx_complete);
peer->splicing->sent_tx_complete = true;

psbt_sort_by_serial_id(ictx->current_psbt);
clone_psbt(NULL, psbt);

new_chan_output = find_channel_output(peer, ictx->current_psbt,
new_chan_output = find_channel_output(peer, psbt,
&chan_output_index,
&peer->splicing->remote_funding_pubkey);

clone_psbt(NULL, psbt);

splice_funding_index = find_channel_funding_input(ictx->current_psbt,
splice_funding_index = find_channel_funding_input(psbt,
&peer->channel->funding);

clone_psbt(NULL, psbt);

both_amount = check_balances(peer, our_role, ictx->current_psbt,
both_amount = check_balances(peer, our_role, psbt,
chan_output_index, splice_funding_index);
new_chan_output->amount = both_amount.satoshis; /* Raw: type conv */

clone_psbt(NULL, psbt);

psbt_elements_normalize_fees(ictx->current_psbt);
psbt_elements_normalize_fees(psbt);

clone_psbt(NULL, psbt);

status_debug("Splice adding inflight: %s",
fmt_wally_psbt(tmpctx, ictx->current_psbt));
fmt_wally_psbt(tmpctx, psbt));

psbt_txid(tmpctx, ictx->current_psbt, &current_psbt_txid, NULL);
psbt_txid(ictx, psbt, &current_psbt_txid, NULL);

clone_psbt(NULL, psbt);

outmsg = towire_channeld_add_inflight(tmpctx,
outmsg = towire_channeld_add_inflight(NULL,
&peer->splicing->remote_funding_pubkey,
&current_psbt_txid,
chan_output_index,
peer->splicing->feerate_per_kw,
amount_sat(new_chan_output->amount),
peer->splicing->opener_relative,
ictx->current_psbt,
psbt,
true,
peer->splicing->force_sign_first);

clone_psbt(NULL, psbt);

master_wait_sync_reply(tmpctx, peer, take(outmsg),
WIRE_CHANNELD_GOT_INFLIGHT);

new_inflight = inflights_new(peer);

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

current_push_val = relative_splice_balance_fundee(peer, our_role,
new_inflight->psbt,
Expand Down Expand Up @@ -4121,6 +4144,8 @@ static void splice_initiator_user_finalized(struct peer *peer)
true,
!sign_first);
wire_sync_write(MASTER_FD, take(outmsg));

tal_free(ictx);
}

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

ictx = new_interactivetx_context(tmpctx, TX_INITIATOR,
ictx = new_interactivetx_context(NULL, TX_INITIATOR,
peer->pps, peer->channel_id);

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

}
Expand All @@ -4175,10 +4201,11 @@ static void splice_initiator_user_update(struct peer *peer, const u8 *inmsg)
if (!interactivetx_has_changes(ictx, ictx->desired_psbt)) {
splice_initiator_user_finalized(peer);
tal_steal(last_inflight(peer), last_inflight(peer)->psbt);
tal_free(ictx);
return;
}

error = process_interactivetx_updates(tmpctx, ictx,
error = process_interactivetx_updates(ictx, ictx,
&peer->splicing->received_tx_complete,
&abort_msg);
if (error)
Expand All @@ -4199,6 +4226,7 @@ static void splice_initiator_user_update(struct peer *peer, const u8 *inmsg)
ictx->current_psbt,
false, false);
wire_sync_write(MASTER_FD, take(outmsg));
tal_free(ictx);
}

/* This occurs when the user has signed the final version of the PSBT. At this
Expand Down
31 changes: 29 additions & 2 deletions common/interactivetx.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,26 +391,38 @@ char *process_interactivetx_updates(const tal_t *ctx,
if (received_tx_complete)
they_complete = *received_tx_complete;

/* Build change_set and handle PSBT variables */
ictx->change_set = tal_free(ictx->change_set);
clone_psbt(NULL, ictx->current_psbt);
clone_psbt(NULL, ictx->desired_psbt);

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

clone_psbt(NULL, ictx->current_psbt);
clone_psbt(NULL, ictx->desired_psbt);

/* Returning NULL from next_update_fn is the same as using `current_psbt`
* with no changes -- both indicate no changes */
if (!next_psbt)
next_psbt = ictx->current_psbt;

clone_psbt(NULL, ictx->current_psbt);
clone_psbt(NULL, ictx->desired_psbt);

ictx->change_set = get_changes(ctx, ictx, next_psbt);

clone_psbt(NULL, ictx->current_psbt);
clone_psbt(NULL, ictx->desired_psbt);

/* If current_psbt and next_psbt are the same, dont double free it!
* Otherwise we advance `current_psbt` to `next_psbt` and begin
* processing the change set in `ictx->change_set` */
if (ictx->current_psbt != next_psbt) {
ictx->current_psbt = next_psbt;
}

clone_psbt(NULL, ictx->current_psbt);
clone_psbt(NULL, ictx->desired_psbt);

/* As initiator we always start with a single send to start it off */
if (ictx->our_role == TX_INITIATOR) {
error = send_next(ctx, ictx, &we_complete);
Expand All @@ -423,6 +435,9 @@ char *process_interactivetx_updates(const tal_t *ctx,
}
}

clone_psbt(NULL, ictx->current_psbt);
clone_psbt(NULL, ictx->desired_psbt);

/* Loop through tx update turns with peer */
while (!(we_complete && they_complete)) {
struct channel_id cid;
Expand All @@ -436,10 +451,16 @@ char *process_interactivetx_updates(const tal_t *ctx,
if (received_tx_complete)
*received_tx_complete = false;

clone_psbt(NULL, ictx->current_psbt);
clone_psbt(NULL, ictx->desired_psbt);

msg = read_next_msg(ctx, ictx, &error);
if (error)
return error;

clone_psbt(NULL, ictx->current_psbt);
clone_psbt(NULL, ictx->desired_psbt);

t = fromwire_peektype(msg);
switch (t) {
case WIRE_TX_ADD_INPUT: {
Expand Down Expand Up @@ -800,8 +821,14 @@ char *process_interactivetx_updates(const tal_t *ctx,
send_next(ctx, ictx, &we_complete);
}

clone_psbt(NULL, ictx->current_psbt);
clone_psbt(NULL, ictx->desired_psbt);

/* Sort psbt! */
psbt_sort_by_serial_id(ictx->current_psbt);

clone_psbt(NULL, ictx->current_psbt);
clone_psbt(NULL, ictx->desired_psbt);

return NULL;
}

0 comments on commit 3644ed4

Please sign in to comment.