Skip to content

Commit 9ea0643

Browse files
ddustinrustyrussell
authored andcommitted
channeld: Move counting code to its own function
Counting remote inputs needing sigs can be in its own method
1 parent 1403bbf commit 9ea0643

File tree

1 file changed

+26
-24
lines changed

1 file changed

+26
-24
lines changed

channeld/channeld.c

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3490,6 +3490,29 @@ static void update_view_from_inflights(struct peer *peer)
34903490
}
34913491
}
34923492

3493+
static size_t count_inputs_with_exclusions(struct wally_psbt *psbt,
3494+
enum tx_role role_to_ignore,
3495+
u32 input_index_to_ignore)
3496+
{
3497+
size_t result = 0;
3498+
for (size_t i = 0; i < psbt->num_inputs; i++) {
3499+
struct wally_psbt_input *in = &psbt->inputs[i];
3500+
u64 in_serial;
3501+
3502+
if (!psbt_get_serial_id(&in->unknowns, &in_serial))
3503+
status_broken("PSBT input %zu missing serial_id"
3504+
" %s", i, fmt_wally_psbt(tmpctx, psbt));
3505+
if (in_serial % 2 == role_to_ignore)
3506+
continue;
3507+
3508+
if (i == input_index_to_ignore)
3509+
continue;
3510+
3511+
result++;
3512+
}
3513+
return result;
3514+
}
3515+
34933516
/* Called to finish an ongoing splice OR on restart from channel_reestablish. */
34943517
static void resume_splice_negotiation(struct peer *peer,
34953518
bool send_commitments,
@@ -3520,7 +3543,6 @@ static void resume_splice_negotiation(struct peer *peer,
35203543
const u8 *msg_received;
35213544
struct witness **inws;
35223545
struct bitcoin_signature *their_sig;
3523-
size_t remote_inputs_needing_sigs;
35243546

35253547
if (peer->splicing) {
35263548
inws = peer->splicing->inws;
@@ -3767,28 +3789,6 @@ static void resume_splice_negotiation(struct peer *peer,
37673789
" received",
37683790
tal_count(inws) - current_psbt->num_inputs);
37693791

3770-
remote_inputs_needing_sigs = 0;
3771-
for (size_t i = 0; i < current_psbt->num_inputs; i++) {
3772-
struct wally_psbt_input *in =
3773-
&current_psbt->inputs[i];
3774-
u64 in_serial;
3775-
3776-
if (!psbt_get_serial_id(&in->unknowns, &in_serial)) {
3777-
status_broken("PSBT input %zu missing serial_id"
3778-
" %s", i,
3779-
fmt_wally_psbt(tmpctx,
3780-
current_psbt));
3781-
return;
3782-
}
3783-
if (in_serial % 2 == our_role)
3784-
continue;
3785-
3786-
if (i == splice_funding_index)
3787-
continue;
3788-
3789-
remote_inputs_needing_sigs++;
3790-
}
3791-
37923792
/* We put the PSBT + sigs all together */
37933793
for (size_t j = 0, i = 0; i < current_psbt->num_inputs; i++) {
37943794
struct wally_psbt_input *in =
@@ -3817,7 +3817,9 @@ static void resume_splice_negotiation(struct peer *peer,
38173817
" remote inputs needing sigs"
38183818
" and you sent %zu witness"
38193819
" bundles.",
3820-
remote_inputs_needing_sigs,
3820+
count_inputs_with_exclusions(current_psbt,
3821+
our_role,
3822+
splice_funding_index),
38213823
tal_count(inws));
38223824
}
38233825

0 commit comments

Comments
 (0)