Skip to content

Commit 7904073

Browse files
committed
splice: Add hsmd_check_outpoint and hsmd_lock_outpoint ([ElementsProject#6722])
Changelog-Added: Added hsmd_check_outpoint and hsmd_lock_outpoint per ([ElementsProject#6722])
1 parent 37ad963 commit 7904073

File tree

4 files changed

+67
-0
lines changed

4 files changed

+67
-0
lines changed

hsmd/hsmd.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,8 @@ 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_NEXT_FUNDING_PUBKEY:
658+
case WIRE_HSMD_CHECK_OUTPOINT:
659+
case WIRE_HSMD_LOCK_OUTPOINT:
658660
case WIRE_HSMD_SIGN_COMMITMENT_TX:
659661
case WIRE_HSMD_VALIDATE_COMMITMENT_TX:
660662
case WIRE_HSMD_VALIDATE_REVOCATION:
@@ -701,6 +703,8 @@ static struct io_plan *handle_client(struct io_conn *conn, struct client *c)
701703
case WIRE_HSMD_NEW_CHANNEL_REPLY:
702704
case WIRE_HSMD_SETUP_CHANNEL_REPLY:
703705
case WIRE_HSMD_NEXT_FUNDING_PUBKEY_REPLY:
706+
case WIRE_HSMD_CHECK_OUTPOINT_REPLY:
707+
case WIRE_HSMD_LOCK_OUTPOINT_REPLY:
704708
case WIRE_HSMD_NODE_ANNOUNCEMENT_SIG_REPLY:
705709
case WIRE_HSMD_SIGN_WITHDRAWAL_REPLY:
706710
case WIRE_HSMD_SIGN_INVOICE_REPLY:

hsmd/hsmd_wire.csv

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,22 @@ msgdata,hsmd_next_funding_pubkey,funding_txout,u32,
100100
msgtype,hsmd_next_funding_pubkey_reply,134
101101
msgdata,hsmd_next_funding_pubkey_reply,next_funding_pubkey,pubkey,
102102

103+
# check if the signer agrees that a funding candidate outpoint is buried
104+
msgtype,hsmd_check_outpoint,32
105+
msgdata,hsmd_check_outpoint,funding_txid,bitcoin_txid,
106+
msgdata,hsmd_check_outpoint,funding_txout,u16,
107+
108+
msgtype,hsmd_check_outpoint_reply,132
109+
msgdata,hsmd_check_outpoint_reply,is_buried,bool,
110+
111+
# change the funding/splice state to locked
112+
msgtype,hsmd_lock_outpoint,37
113+
msgdata,hsmd_lock_outpoint,funding_txid,bitcoin_txid,
114+
msgdata,hsmd_lock_outpoint,funding_txout,u16,
115+
116+
# No value returned.
117+
msgtype,hsmd_lock_outpoint_reply,137
118+
103119
# Return signature for a funding tx.
104120
#include <common/utxo.h>
105121

hsmd/libhsmd.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ bool hsmd_check_client_capabilities(struct hsmd_client *client,
112112
case WIRE_HSMD_SIGN_OPTION_WILL_FUND_OFFER:
113113
return (client->capabilities & HSM_PERM_SIGN_WILL_FUND_OFFER) != 0;
114114

115+
case WIRE_HSMD_CHECK_OUTPOINT:
116+
case WIRE_HSMD_LOCK_OUTPOINT:
117+
return (client->capabilities & HSM_PERM_LOCK_OUTPOINT) != 0;
118+
115119
case WIRE_HSMD_INIT:
116120
case WIRE_HSMD_NEW_CHANNEL:
117121
case WIRE_HSMD_CLIENT_HSMFD:
@@ -145,6 +149,8 @@ bool hsmd_check_client_capabilities(struct hsmd_client *client,
145149
case WIRE_HSMD_CLIENT_HSMFD_REPLY:
146150
case WIRE_HSMD_NEW_CHANNEL_REPLY:
147151
case WIRE_HSMD_SETUP_CHANNEL_REPLY:
152+
case WIRE_HSMD_CHECK_OUTPOINT_REPLY:
153+
case WIRE_HSMD_LOCK_OUTPOINT_REPLY:
148154
case WIRE_HSMD_NODE_ANNOUNCEMENT_SIG_REPLY:
149155
case WIRE_HSMD_SIGN_WITHDRAWAL_REPLY:
150156
case WIRE_HSMD_SIGN_INVOICE_REPLY:
@@ -402,6 +408,38 @@ static u8 *handle_next_funding_pubkey(struct hsmd_client *c, const u8 *msg_in)
402408
return towire_hsmd_setup_channel_reply(NULL);
403409
}
404410

411+
/* ~This stub implementation is overriden by fully validating signers
412+
* to ensure they are caught up when outpoints are freshly buried */
413+
static u8 *handle_check_outpoint(struct hsmd_client *c, const u8 *msg_in)
414+
{
415+
struct bitcoin_txid funding_txid;
416+
u16 funding_txout;
417+
bool is_buried;
418+
419+
if (!fromwire_hsmd_check_outpoint(msg_in, &funding_txid, &funding_txout))
420+
return hsmd_status_malformed_request(c, msg_in);
421+
422+
/* This stub always approves */
423+
is_buried = true;
424+
425+
return towire_hsmd_check_outpoint_reply(NULL, is_buried);
426+
}
427+
428+
/* ~This stub implementation is overriden by fully validating signers to
429+
* change their funding/splice state to locked */
430+
static u8 *handle_lock_outpoint(struct hsmd_client *c, const u8 *msg_in)
431+
{
432+
struct bitcoin_txid funding_txid;
433+
u16 funding_txout;
434+
435+
if (!fromwire_hsmd_lock_outpoint(msg_in, &funding_txid, &funding_txout))
436+
return hsmd_status_malformed_request(c, msg_in);
437+
438+
/* Stub implementation */
439+
440+
return towire_hsmd_lock_outpoint_reply(NULL);
441+
}
442+
405443
/*~ For almost every wallet tx we use the BIP32 seed, but not for onchain
406444
* unilateral closes from a peer: they (may) have an output to us using a
407445
* public key based on the channel basepoints. It's a bit spammy to spend
@@ -1931,6 +1969,10 @@ u8 *hsmd_handle_client_message(const tal_t *ctx, struct hsmd_client *client,
19311969
return handle_setup_channel(client, msg);
19321970
case WIRE_HSMD_NEXT_FUNDING_PUBKEY:
19331971
return handle_next_funding_pubkey(client, msg);
1972+
case WIRE_HSMD_CHECK_OUTPOINT:
1973+
return handle_check_outpoint(client, msg);
1974+
case WIRE_HSMD_LOCK_OUTPOINT:
1975+
return handle_lock_outpoint(client, msg);
19341976
case WIRE_HSMD_GET_OUTPUT_SCRIPTPUBKEY:
19351977
return handle_get_output_scriptpubkey(client, msg);
19361978
case WIRE_HSMD_CHECK_FUTURE_SECRET:
@@ -2009,6 +2051,8 @@ u8 *hsmd_handle_client_message(const tal_t *ctx, struct hsmd_client *client,
20092051
case WIRE_HSMD_NEW_CHANNEL_REPLY:
20102052
case WIRE_HSMD_SETUP_CHANNEL_REPLY:
20112053
case WIRE_HSMD_NEXT_FUNDING_PUBKEY_REPLY:
2054+
case WIRE_HSMD_CHECK_OUTPOINT_REPLY:
2055+
case WIRE_HSMD_LOCK_OUTPOINT_REPLY:
20122056
case WIRE_HSMD_NODE_ANNOUNCEMENT_SIG_REPLY:
20132057
case WIRE_HSMD_SIGN_WITHDRAWAL_REPLY:
20142058
case WIRE_HSMD_SIGN_INVOICE_REPLY:
@@ -2051,6 +2095,8 @@ u8 *hsmd_init(struct secret hsm_secret,
20512095
WIRE_HSMD_SIGN_ANCHORSPEND,
20522096
WIRE_HSMD_SIGN_HTLC_TX_MINGLE,
20532097
WIRE_HSMD_SIGN_SPLICE_TX,
2098+
WIRE_HSMD_CHECK_OUTPOINT,
2099+
WIRE_HSMD_LOCK_OUTPOINT,
20542100
};
20552101

20562102
/*~ Don't swap this. */

hsmd/permissions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#define HSM_PERM_SIGN_CLOSING_TX 32
1111
#define HSM_PERM_SIGN_WILL_FUND_OFFER 64
1212
#define HSM_PERM_SIGN_SPLICE_TX 128
13+
#define HSM_PERM_LOCK_OUTPOINT 256
1314

1415
#define HSM_PERM_MASTER 1024
1516
#endif /* LIGHTNING_HSMD_PERMISSIONS_H */

0 commit comments

Comments
 (0)