Skip to content

Commit 979583d

Browse files
committed
splice: Add hsmd_next_funding_pubkey
1 parent 098819f commit 979583d

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
@@ -654,6 +654,7 @@ static struct io_plan *handle_client(struct io_conn *conn, struct client *c)
654654

655655
case WIRE_HSMD_NEW_CHANNEL:
656656
case WIRE_HSMD_SETUP_CHANNEL:
657+
case WIRE_HSMD_NEXT_FUNDING_PUBKEY:
657658
case WIRE_HSMD_SIGN_COMMITMENT_TX:
658659
case WIRE_HSMD_VALIDATE_COMMITMENT_TX:
659660
case WIRE_HSMD_VALIDATE_REVOCATION:
@@ -699,6 +700,7 @@ static struct io_plan *handle_client(struct io_conn *conn, struct client *c)
699700
case WIRE_HSMD_CLIENT_HSMFD_REPLY:
700701
case WIRE_HSMD_NEW_CHANNEL_REPLY:
701702
case WIRE_HSMD_SETUP_CHANNEL_REPLY:
703+
case WIRE_HSMD_NEXT_FUNDING_PUBKEY_REPLY:
702704
case WIRE_HSMD_NODE_ANNOUNCEMENT_SIG_REPLY:
703705
case WIRE_HSMD_SIGN_WITHDRAWAL_REPLY:
704706
case WIRE_HSMD_SIGN_INVOICE_REPLY:

hsmd/hsmd_wire.csv

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,17 @@ msgdata,hsmd_setup_channel,channel_type,channel_type,
8989
# No value returned.
9090
msgtype,hsmd_setup_channel_reply,131
9191

92+
# Sent to derive the next funding pubkey (for splicing)
93+
msgtype,hsmd_next_funding_pubkey,34
94+
msgdata,hsmd_next_funding_pubkey,peerid,node_id,
95+
msgdata,hsmd_next_funding_pubkey,dbid,u64,
96+
msgdata,hsmd_next_funding_pubkey,funding_txid,bitcoin_txid,
97+
msgdata,hsmd_next_funding_pubkey,funding_txout,u32,
98+
99+
# Returns the next funding pubkey for a splice
100+
msgtype,hsmd_next_funding_pubkey_reply,134
101+
msgdata,hsmd_next_funding_pubkey_reply,next_funding_pubkey,pubkey,
102+
92103
# Return signature for a funding tx.
93104
#include <common/utxo.h>
94105

hsmd/libhsmd.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ bool hsmd_check_client_capabilities(struct hsmd_client *client,
119119
case WIRE_HSMD_SIGN_INVOICE:
120120
case WIRE_HSMD_SIGN_COMMITMENT_TX:
121121
case WIRE_HSMD_GET_CHANNEL_BASEPOINTS:
122+
case WIRE_HSMD_NEXT_FUNDING_PUBKEY:
122123
case WIRE_HSMD_DEV_MEMLEAK:
123124
case WIRE_HSMD_SIGN_MESSAGE:
124125
case WIRE_HSMD_GET_OUTPUT_SCRIPTPUBKEY:
@@ -158,6 +159,7 @@ bool hsmd_check_client_capabilities(struct hsmd_client *client,
158159
case WIRE_HSMD_GET_PER_COMMITMENT_POINT_REPLY:
159160
case WIRE_HSMD_CHECK_FUTURE_SECRET_REPLY:
160161
case WIRE_HSMD_GET_CHANNEL_BASEPOINTS_REPLY:
162+
case WIRE_HSMD_NEXT_FUNDING_PUBKEY_REPLY:
161163
case WIRE_HSMD_DEV_MEMLEAK_REPLY:
162164
case WIRE_HSMD_SIGN_MESSAGE_REPLY:
163165
case WIRE_HSMD_GET_OUTPUT_SCRIPTPUBKEY_REPLY:
@@ -379,6 +381,27 @@ static u8 *handle_setup_channel(struct hsmd_client *c, const u8 *msg_in)
379381
return towire_hsmd_setup_channel_reply(NULL);
380382
}
381383

384+
/* ~Return the funding pubkey for the next splice */
385+
static u8 *handle_next_funding_pubkey(struct hsmd_client *c, const u8 *msg_in)
386+
{
387+
struct node_id peer_id;
388+
u64 dbid;
389+
struct bitcoin_txid funding_txid;
390+
u32 funding_txout;
391+
struct secret seed;
392+
struct pubkey funding_pubkey;
393+
394+
if (!fromwire_hsmd_next_funding_pubkey(msg_in, &peer_id, &dbid,
395+
&funding_txid, &funding_txout))
396+
return hsmd_status_malformed_request(c, msg_in);
397+
398+
// TODO actually rotate the funding pubkey
399+
get_channel_seed(&peer_id, dbid, &seed);
400+
derive_basepoints(&seed, &funding_pubkey, NULL, NULL, NULL);
401+
402+
return towire_hsmd_setup_channel_reply(NULL);
403+
}
404+
382405
/*~ For almost every wallet tx we use the BIP32 seed, but not for onchain
383406
* unilateral closes from a peer: they (may) have an output to us using a
384407
* public key based on the channel basepoints. It's a bit spammy to spend
@@ -1906,6 +1929,8 @@ u8 *hsmd_handle_client_message(const tal_t *ctx, struct hsmd_client *client,
19061929
return handle_new_channel(client, msg);
19071930
case WIRE_HSMD_SETUP_CHANNEL:
19081931
return handle_setup_channel(client, msg);
1932+
case WIRE_HSMD_NEXT_FUNDING_PUBKEY:
1933+
return handle_next_funding_pubkey(client, msg);
19091934
case WIRE_HSMD_GET_OUTPUT_SCRIPTPUBKEY:
19101935
return handle_get_output_scriptpubkey(client, msg);
19111936
case WIRE_HSMD_CHECK_FUTURE_SECRET:
@@ -1983,6 +2008,7 @@ u8 *hsmd_handle_client_message(const tal_t *ctx, struct hsmd_client *client,
19832008
case WIRE_HSMD_CLIENT_HSMFD_REPLY:
19842009
case WIRE_HSMD_NEW_CHANNEL_REPLY:
19852010
case WIRE_HSMD_SETUP_CHANNEL_REPLY:
2011+
case WIRE_HSMD_NEXT_FUNDING_PUBKEY_REPLY:
19862012
case WIRE_HSMD_NODE_ANNOUNCEMENT_SIG_REPLY:
19872013
case WIRE_HSMD_SIGN_WITHDRAWAL_REPLY:
19882014
case WIRE_HSMD_SIGN_INVOICE_REPLY:

0 commit comments

Comments
 (0)