mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 07:04:22 +01:00
hsmd: Add sign splice command
Changelog-None
This commit is contained in:
committed by
Rusty Russell
parent
e626f91267
commit
eda570c095
@@ -15,6 +15,7 @@
|
||||
* v4 with sign_any_penalty_to_us: ead7963185194a515d1f14d2c44401392575299d68ce9a13d8a12baff3cf4f35
|
||||
* v4 with sign_anchorspend: 8a30722e38b56e82af566b9629ff18da01fcebd1e80ec67f04d8b3a2fa66d81c
|
||||
* v4 with sign_htlc_tx_mingle: b9247e75d41ee1b3fc2f7db0bac8f4e92d544ab2f017d430ae3a000589c384e5
|
||||
* v4 with splicing: 06f21012936f825913af289fa81af1512c9ada1cb97c611698975a8fd287edbb
|
||||
*/
|
||||
#define HSM_MIN_VERSION 3
|
||||
#define HSM_MAX_VERSION 4
|
||||
|
||||
@@ -661,6 +661,7 @@ static struct io_plan *handle_client(struct io_conn *conn, struct client *c)
|
||||
case WIRE_HSMD_SIGN_REMOTE_COMMITMENT_TX:
|
||||
case WIRE_HSMD_SIGN_REMOTE_HTLC_TX:
|
||||
case WIRE_HSMD_SIGN_MUTUAL_CLOSE_TX:
|
||||
case WIRE_HSMD_SIGN_SPLICE_TX:
|
||||
case WIRE_HSMD_GET_PER_COMMITMENT_POINT:
|
||||
case WIRE_HSMD_SIGN_WITHDRAWAL:
|
||||
case WIRE_HSMD_GET_CHANNEL_BASEPOINTS:
|
||||
|
||||
@@ -248,6 +248,12 @@ msgtype,hsmd_sign_mutual_close_tx,21
|
||||
msgdata,hsmd_sign_mutual_close_tx,tx,bitcoin_tx,
|
||||
msgdata,hsmd_sign_mutual_close_tx,remote_funding_key,pubkey,
|
||||
|
||||
# channeld asks HSM to sign splice tx.
|
||||
msgtype,hsmd_sign_splice_tx,29
|
||||
msgdata,hsmd_sign_splice_tx,tx,bitcoin_tx,
|
||||
msgdata,hsmd_sign_splice_tx,remote_funding_key,pubkey,
|
||||
msgdata,hsmd_sign_splice_tx,input_index,u32,
|
||||
|
||||
# Reply for all the above requests.
|
||||
msgtype,hsmd_sign_tx_reply,112
|
||||
msgdata,hsmd_sign_tx_reply,sig,bitcoin_signature,
|
||||
|
||||
|
@@ -106,6 +106,9 @@ bool hsmd_check_client_capabilities(struct hsmd_client *client,
|
||||
case WIRE_HSMD_SIGN_MUTUAL_CLOSE_TX:
|
||||
return (client->capabilities & HSM_CAP_SIGN_CLOSING_TX) != 0;
|
||||
|
||||
case WIRE_HSMD_SIGN_SPLICE_TX:
|
||||
return (client->capabilities & HSM_CAP_SIGN_CLOSING_TX) != 0;
|
||||
|
||||
case WIRE_HSMD_SIGN_OPTION_WILL_FUND_OFFER:
|
||||
return (client->capabilities & HSM_CAP_SIGN_WILL_FUND_OFFER) != 0;
|
||||
|
||||
@@ -1162,6 +1165,40 @@ static u8 *handle_sign_mutual_close_tx(struct hsmd_client *c, const u8 *msg_in)
|
||||
return towire_hsmd_sign_tx_reply(NULL, &sig);
|
||||
}
|
||||
|
||||
/* This is used by channeld to sign the final splice tx. */
|
||||
static u8 *handle_sign_splice_tx(struct hsmd_client *c, const u8 *msg_in)
|
||||
{
|
||||
struct secret channel_seed;
|
||||
struct bitcoin_tx *tx;
|
||||
struct pubkey remote_funding_pubkey, local_funding_pubkey;
|
||||
struct bitcoin_signature sig;
|
||||
struct secrets secrets;
|
||||
unsigned int input_index;
|
||||
const u8 *funding_wscript;
|
||||
|
||||
if (!fromwire_hsmd_sign_splice_tx(tmpctx, msg_in,
|
||||
&tx,
|
||||
&remote_funding_pubkey,
|
||||
&input_index))
|
||||
return hsmd_status_malformed_request(c, msg_in);
|
||||
|
||||
tx->chainparams = c->chainparams;
|
||||
get_channel_seed(&c->id, c->dbid, &channel_seed);
|
||||
derive_basepoints(&channel_seed,
|
||||
&local_funding_pubkey, NULL, &secrets, NULL);
|
||||
|
||||
funding_wscript = bitcoin_redeem_2of2(tmpctx,
|
||||
&local_funding_pubkey,
|
||||
&remote_funding_pubkey);
|
||||
|
||||
sign_tx_input(tx, input_index, NULL, funding_wscript,
|
||||
&secrets.funding_privkey,
|
||||
&local_funding_pubkey,
|
||||
SIGHASH_ALL, &sig);
|
||||
|
||||
return towire_hsmd_sign_tx_reply(NULL, &sig);
|
||||
}
|
||||
|
||||
/*~ Originally, onchaind would ask for hsmd to sign txs directly, and then
|
||||
* tell lightningd to broadcast it. With "bring-your-own-fees" HTLCs, this
|
||||
* changed, since we need to find a UTXO to attach to the transaction,
|
||||
@@ -1901,6 +1938,8 @@ u8 *hsmd_handle_client_message(const tal_t *ctx, struct hsmd_client *client,
|
||||
return handle_sign_withdrawal_tx(client, msg);
|
||||
case WIRE_HSMD_SIGN_MUTUAL_CLOSE_TX:
|
||||
return handle_sign_mutual_close_tx(client, msg);
|
||||
case WIRE_HSMD_SIGN_SPLICE_TX:
|
||||
return handle_sign_splice_tx(client, msg);
|
||||
case WIRE_HSMD_SIGN_LOCAL_HTLC_TX:
|
||||
return handle_sign_local_htlc_tx(client, msg);
|
||||
case WIRE_HSMD_SIGN_REMOTE_HTLC_TX:
|
||||
|
||||
Reference in New Issue
Block a user