Skip to content

Commit d2de91d

Browse files
committed
splice: Update commit sigs to use dynamic remote funding pubkey.
Update the sending and receiving of commit sigs to use dyniamic funding pubkeys incase our remote peer rotates theirs during a splice. Changelog-None
1 parent d05f820 commit d2de91d

File tree

1 file changed

+35
-16
lines changed

1 file changed

+35
-16
lines changed

channeld/channeld.c

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,7 +1136,8 @@ static u8 *send_commit_part(const tal_t *ctx,
11361136
u64 remote_index,
11371137
const struct pubkey *remote_per_commit,
11381138
struct local_anchor_info **anchor,
1139-
u16 batch_size)
1139+
u16 batch_size,
1140+
struct pubkey remote_funding_pubkey)
11401141
{
11411142
u8 *msg;
11421143
struct bitcoin_signature commit_sig, *htlc_sigs;
@@ -1146,6 +1147,9 @@ static u8 *send_commit_part(const tal_t *ctx,
11461147
struct wally_tx_output *direct_outputs[NUM_SIDES];
11471148
struct penalty_base *pbase;
11481149
int local_anchor_outnum;
1150+
struct pubkey funding_pubkeys[NUM_SIDES] =
1151+
{ peer->channel->funding_pubkey[LOCAL],
1152+
remote_funding_pubkey };
11491153
struct tlv_commitment_signed_tlvs *cs_tlv
11501154
= tlv_commitment_signed_tlvs_new(tmpctx);
11511155

@@ -1172,11 +1176,11 @@ static u8 *send_commit_part(const tal_t *ctx,
11721176
peer->channel, remote_per_commit,
11731177
remote_index, REMOTE,
11741178
splice_amnt, remote_splice_amnt, &local_anchor_outnum,
1175-
NULL);
1179+
funding_pubkeys);
11761180
htlc_sigs =
11771181
calc_commitsigs(tmpctx, peer, txs, funding_wscript, htlc_map,
11781182
remote_index, remote_per_commit, &commit_sig,
1179-
peer->channel->funding_pubkey[REMOTE]);
1183+
remote_funding_pubkey);
11801184

11811185
if (direct_outputs[LOCAL] != NULL) {
11821186
pbase = penalty_base_new(tmpctx, remote_index,
@@ -1356,7 +1360,8 @@ static void send_commit(struct peer *peer)
13561360
peer->channel->funding_sats, changed_htlcs,
13571361
true, 0, 0, peer->next_index[REMOTE],
13581362
&peer->remote_per_commit, &local_anchor,
1359-
batch_size);
1363+
batch_size,
1364+
peer->channel->funding_pubkey[REMOTE]);
13601365
if (local_anchor)
13611366
tal_arr_expand(&anchors_info, *local_anchor);
13621367

@@ -1385,7 +1390,8 @@ static void send_commit(struct peer *peer)
13851390
peer->next_index[REMOTE],
13861391
&peer->remote_per_commit,
13871392
&local_anchor,
1388-
batch_size);
1393+
batch_size,
1394+
peer->splice_state->inflights[i]->remote_funding));
13891395
if (local_anchor)
13901396
tal_arr_expand(&anchors_info, *local_anchor);
13911397
}
@@ -1836,6 +1842,7 @@ struct commitsig_info {
18361842
static struct commitsig_info *handle_peer_commit_sig(struct peer *peer,
18371843
const u8 *msg,
18381844
u32 commit_index,
1845+
struct pubkey remote_funding,
18391846
const struct htlc **changed_htlcs,
18401847
s64 splice_amnt,
18411848
s64 remote_splice_amnt,
@@ -1862,6 +1869,9 @@ static struct commitsig_info *handle_peer_commit_sig(struct peer *peer,
18621869
struct channel_id active_id;
18631870
const struct commitsig **commitsigs;
18641871
int remote_anchor_outnum;
1872+
struct pubkey funding_pubkeys[NUM_SIDES] =
1873+
{ peer->channel->funding_pubkey[LOCAL],
1874+
remote_funding };
18651875

18661876
status_debug("handle_peer_commit_sig(splice: %d, remote_splice: %d,"
18671877
" index: %"PRIu64")",
@@ -1948,11 +1958,11 @@ static struct commitsig_info *handle_peer_commit_sig(struct peer *peer,
19481958
local_per_commit,
19491959
local_index, LOCAL, splice_amnt,
19501960
remote_splice_amnt, &remote_anchor_outnum,
1951-
NULL);
1961+
funding_pubkeys);
19521962

19531963
/* Set the commit_sig on the commitment tx psbt */
19541964
if (!psbt_input_set_signature(txs[0]->psbt, 0,
1955-
&peer->channel->funding_pubkey[REMOTE],
1965+
&remote_funding,
19561966
&commit_sig))
19571967
status_failed(STATUS_FAIL_INTERNAL_ERROR,
19581968
"Unable to set signature internally");
@@ -1975,7 +1985,7 @@ static struct commitsig_info *handle_peer_commit_sig(struct peer *peer,
19751985
* `error` and fail the channel.
19761986
*/
19771987
if (!check_tx_sig(txs[0], 0, NULL, funding_wscript,
1978-
&peer->channel->funding_pubkey[REMOTE], &commit_sig)) {
1988+
&remote_funding, &commit_sig)) {
19791989
dump_htlcs(peer->channel, "receiving commit_sig");
19801990
peer_failed_warn(peer->pps, &peer->channel_id,
19811991
"Bad commit_sig signature %"PRIu64" %s for tx"
@@ -1986,8 +1996,7 @@ static struct commitsig_info *handle_peer_commit_sig(struct peer *peer,
19861996
fmt_bitcoin_signature(msg, &commit_sig),
19871997
fmt_bitcoin_tx(msg, txs[0]),
19881998
tal_hex(msg, funding_wscript),
1989-
fmt_pubkey(msg,
1990-
&peer->channel->funding_pubkey[REMOTE]),
1999+
fmt_pubkey(msg, &remote_funding),
19912000
channel_feerate(peer->channel, LOCAL),
19922001
fmt_channel_id(tmpctx, &active_id),
19932002
cs_tlv && cs_tlv->splice_info
@@ -2026,6 +2035,9 @@ static struct commitsig_info *handle_peer_commit_sig(struct peer *peer,
20262035
wscript = bitcoin_tx_output_get_witscript(tmpctx, txs[0],
20272036
txs[i+1]->wtx->inputs[0].index);
20282037

2038+
/* DTODO: How does the htlc sig know the funding pubkey has changed?
2039+
* It probably doesn't even though send_commit_part does! */
2040+
20292041
if (!check_tx_sig(txs[1+i], 0, NULL, wscript,
20302042
&remote_htlckey, &htlc_sigs[i]))
20312043
peer_failed_warn(peer->pps, &peer->channel_id,
@@ -2105,6 +2117,7 @@ static struct commitsig_info *handle_peer_commit_sig(struct peer *peer,
21052117

21062118
/* We purposely just store the last commit msg in result */
21072119
result = handle_peer_commit_sig(peer, splice_msg, i + 1,
2120+
peer->splice_state->inflights[i]->remote_funding,
21082121
changed_htlcs, sub_splice_amnt,
21092122
funding_diff - sub_splice_amnt,
21102123
local_index, local_per_commit,
@@ -2747,7 +2760,8 @@ static struct commitsig *interactive_send_commitments(struct peer *peer,
27472760
next_index_remote - 1,
27482761
&peer->old_remote_per_commit,
27492762
&local_anchor,
2750-
1);
2763+
1,
2764+
inflight->remote_funding));
27512765
}
27522766

27532767
result = NULL;
@@ -2776,6 +2790,7 @@ static struct commitsig *interactive_send_commitments(struct peer *peer,
27762790

27772791
result = handle_peer_commit_sig(peer, msg,
27782792
inflight_index + 1,
2793+
inflight->remote_funding,
27792794
NULL,
27802795
inflight->splice_amnt,
27812796
remote_splice_amnt,
@@ -2804,7 +2819,8 @@ static struct commitsig *interactive_send_commitments(struct peer *peer,
28042819
next_index_remote - 1,
28052820
&peer->old_remote_per_commit,
28062821
&local_anchor,
2807-
1));
2822+
1,
2823+
inflight->remote_funding));
28082824
}
28092825

28102826
/* Sending and receiving splice commit should not increment commit
@@ -4429,8 +4445,9 @@ static void peer_in(struct peer *peer, const u8 *msg)
44294445
handle_peer_add_htlc(peer, msg);
44304446
return;
44314447
case WIRE_COMMITMENT_SIGNED:
4432-
handle_peer_commit_sig(peer, msg, 0, NULL, 0, 0,
4433-
peer->next_index[LOCAL],
4448+
handle_peer_commit_sig(peer, msg, 0,
4449+
peer->channel->funding_pubkey[REMOTE],
4450+
NULL, 0, 0, peer->next_index[LOCAL],
44344451
&peer->next_local_per_commit, false);
44354452
return;
44364453
case WIRE_UPDATE_FEE:
@@ -4665,7 +4682,8 @@ static void resend_commitment(struct peer *peer, struct changed_htlc *last)
46654682
peer->channel->funding_sats, NULL,
46664683
false, 0, 0, peer->next_index[REMOTE] - 1,
46674684
&peer->remote_per_commit,
4668-
&local_anchor, batch_size);
4685+
&local_anchor, batch_size,
4686+
peer->channel->funding_pubkey[REMOTE]);
46694687

46704688
/* Loop over current inflights
46714689
* BOLT-0d8b701614b09c6ee4172b04da2203e73deec7e2 #2:
@@ -4691,7 +4709,8 @@ static void resend_commitment(struct peer *peer, struct changed_htlc *last)
46914709
remote_splice_amnt,
46924710
peer->next_index[REMOTE] - 1,
46934711
&peer->remote_per_commit,
4694-
&local_anchor, batch_size));
4712+
&local_anchor, batch_size,
4713+
peer->splice_state->inflights[i]->remote_funding));
46954714
}
46964715

46974716
for(i = 0; i < tal_count(msgs); i++)

0 commit comments

Comments
 (0)