Skip to content

Commit b652750

Browse files
committed
splice: Add hsmd_next_funding_pubkey
1 parent 9ebc2f5 commit b652750

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

hsmd/hsmd.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,7 @@ static struct io_plan *handle_client(struct io_conn *conn, struct client *c)
655655
case WIRE_HSMD_NEW_CHANNEL:
656656
case WIRE_HSMD_SETUP_CHANNEL:
657657
case WIRE_HSMD_SYNC_OUTPOINT:
658+
case WIRE_HSMD_NEXT_FUNDING_PUBKEY:
658659
case WIRE_HSMD_SIGN_COMMITMENT_TX:
659660
case WIRE_HSMD_VALIDATE_COMMITMENT_TX:
660661
case WIRE_HSMD_VALIDATE_REVOCATION:
@@ -701,6 +702,7 @@ static struct io_plan *handle_client(struct io_conn *conn, struct client *c)
701702
case WIRE_HSMD_NEW_CHANNEL_REPLY:
702703
case WIRE_HSMD_SETUP_CHANNEL_REPLY:
703704
case WIRE_HSMD_SYNC_OUTPOINT_REPLY:
705+
case WIRE_HSMD_NEXT_FUNDING_PUBKEY_REPLY:
704706
case WIRE_HSMD_NODE_ANNOUNCEMENT_SIG_REPLY:
705707
case WIRE_HSMD_SIGN_WITHDRAWAL_REPLY:
706708
case WIRE_HSMD_SIGN_INVOICE_REPLY:

hsmd/hsmd_wire.csv

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,17 @@ msgdata,hsmd_sync_outpoint,funding_outpoint,bitcoin_outpoint,
9797
# No value returned
9898
msgtype,hsmd_sync_outpoint_reply,132
9999

100+
# Sent to derive the next funding pubkey (for splicing)
101+
msgtype,hsmd_next_funding_pubkey,34
102+
msgdata,hsmd_next_funding_pubkey,peerid,node_id,
103+
msgdata,hsmd_next_funding_pubkey,dbid,u64,
104+
msgdata,hsmd_next_funding_pubkey,funding_txid,bitcoin_txid,
105+
msgdata,hsmd_next_funding_pubkey,funding_txout,u32,
106+
107+
# Returns the next funding pubkey for a splice
108+
msgtype,hsmd_next_funding_pubkey_reply,134
109+
msgdata,hsmd_next_funding_pubkey_reply,next_funding_pubkey,pubkey,
110+
100111
# Return signature for a funding tx.
101112
#include <common/utxo.h>
102113

hsmd/libhsmd.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ bool hsmd_check_client_capabilities(struct hsmd_client *client,
122122
case WIRE_HSMD_SIGN_INVOICE:
123123
case WIRE_HSMD_SIGN_COMMITMENT_TX:
124124
case WIRE_HSMD_GET_CHANNEL_BASEPOINTS:
125+
case WIRE_HSMD_NEXT_FUNDING_PUBKEY:
125126
case WIRE_HSMD_DEV_MEMLEAK:
126127
case WIRE_HSMD_SIGN_MESSAGE:
127128
case WIRE_HSMD_GET_OUTPUT_SCRIPTPUBKEY:
@@ -162,6 +163,7 @@ bool hsmd_check_client_capabilities(struct hsmd_client *client,
162163
case WIRE_HSMD_GET_PER_COMMITMENT_POINT_REPLY:
163164
case WIRE_HSMD_CHECK_FUTURE_SECRET_REPLY:
164165
case WIRE_HSMD_GET_CHANNEL_BASEPOINTS_REPLY:
166+
case WIRE_HSMD_NEXT_FUNDING_PUBKEY_REPLY:
165167
case WIRE_HSMD_DEV_MEMLEAK_REPLY:
166168
case WIRE_HSMD_SIGN_MESSAGE_REPLY:
167169
case WIRE_HSMD_GET_OUTPUT_SCRIPTPUBKEY_REPLY:
@@ -397,6 +399,27 @@ static u8 *handle_sync_outpoint(struct hsmd_client *c, const u8 *msg_in)
397399
return towire_hsmd_setup_channel_reply(NULL);
398400
}
399401

402+
/* ~Return the funding pubkey for the next splice */
403+
static u8 *handle_next_funding_pubkey(struct hsmd_client *c, const u8 *msg_in)
404+
{
405+
struct node_id peer_id;
406+
u64 dbid;
407+
struct bitcoin_txid funding_txid;
408+
u32 funding_txout;
409+
struct secret seed;
410+
struct pubkey funding_pubkey;
411+
412+
if (!fromwire_hsmd_next_funding_pubkey(msg_in, &peer_id, &dbid,
413+
&funding_txid, &funding_txout))
414+
return hsmd_status_malformed_request(c, msg_in);
415+
416+
// TODO actually rotate the funding pubkey
417+
get_channel_seed(&peer_id, dbid, &seed);
418+
derive_basepoints(&seed, &funding_pubkey, NULL, NULL, NULL);
419+
420+
return towire_hsmd_setup_channel_reply(NULL);
421+
}
422+
400423
/*~ For almost every wallet tx we use the BIP32 seed, but not for onchain
401424
* unilateral closes from a peer: they (may) have an output to us using a
402425
* public key based on the channel basepoints. It's a bit spammy to spend
@@ -1926,6 +1949,8 @@ u8 *hsmd_handle_client_message(const tal_t *ctx, struct hsmd_client *client,
19261949
return handle_setup_channel(client, msg);
19271950
case WIRE_HSMD_SYNC_OUTPOINT:
19281951
return handle_sync_outpoint(client, msg);
1952+
case WIRE_HSMD_NEXT_FUNDING_PUBKEY:
1953+
return handle_next_funding_pubkey(client, msg);
19291954
case WIRE_HSMD_GET_OUTPUT_SCRIPTPUBKEY:
19301955
return handle_get_output_scriptpubkey(client, msg);
19311956
case WIRE_HSMD_CHECK_FUTURE_SECRET:
@@ -2004,6 +2029,7 @@ u8 *hsmd_handle_client_message(const tal_t *ctx, struct hsmd_client *client,
20042029
case WIRE_HSMD_NEW_CHANNEL_REPLY:
20052030
case WIRE_HSMD_SETUP_CHANNEL_REPLY:
20062031
case WIRE_HSMD_SYNC_OUTPOINT_REPLY:
2032+
case WIRE_HSMD_NEXT_FUNDING_PUBKEY_REPLY:
20072033
case WIRE_HSMD_NODE_ANNOUNCEMENT_SIG_REPLY:
20082034
case WIRE_HSMD_SIGN_WITHDRAWAL_REPLY:
20092035
case WIRE_HSMD_SIGN_INVOICE_REPLY:

0 commit comments

Comments
 (0)