MCPcopy Create free account
hub / github.com/ElementsProject/lightning / handle_sign_commitment_tx

Function handle_sign_commitment_tx

hsmd/libhsmd.c:1317–1364  ·  view source on GitHub ↗

~ This is another lightningd-only interface; signing a commit transaction. * This is dangerous, since if we sign a revoked commitment tx we'll lose * funds, thus it's only available to lightningd. * * * Oh look, another FIXME! */ FIXME: Ensure HSM never does this twice for same dbid! */

Source from the content-addressed store, hash-verified

1315 * Oh look, another FIXME! */
1316/* FIXME: Ensure HSM never does this twice for same dbid! */
1317static u8 *handle_sign_commitment_tx(struct hsmd_client *c, const u8 *msg_in)
1318{
1319 struct pubkey remote_funding_pubkey, local_funding_pubkey;
1320 struct node_id peer_id;
1321 u64 dbid;
1322 struct secret channel_seed;
1323 struct bitcoin_tx *tx;
1324 struct bitcoin_signature sig;
1325 u64 commit_num;
1326 struct secrets secrets;
1327 const u8 *funding_wscript;
1328
1329 if (!fromwire_hsmd_sign_commitment_tx(tmpctx, msg_in,
1330 &peer_id, &dbid,
1331 &tx,
1332 &remote_funding_pubkey,
1333 &commit_num))
1334 return hsmd_status_malformed_request(c, msg_in);
1335
1336 tx->chainparams = c->chainparams;
1337
1338 /* Basic sanity checks. */
1339 if (tx->wtx->num_inputs != 1)
1340 return hsmd_status_bad_request(c, msg_in,
1341 "tx must have 1 input");
1342
1343 if (tx->wtx->num_outputs == 0)
1344 return hsmd_status_bad_request_fmt(c, msg_in,
1345 "tx must have > 0 outputs");
1346
1347 get_channel_seed(&peer_id, dbid, &channel_seed);
1348 derive_basepoints(&channel_seed,
1349 &local_funding_pubkey, NULL, &secrets, NULL);
1350
1351 /*~ Bitcoin signatures cover the (part of) the script they're
1352 * executing; the rules are a bit complex in general, but for
1353 * Segregated Witness it's simply the current script. */
1354 funding_wscript = bitcoin_redeem_2of2(tmpctx,
1355 &local_funding_pubkey,
1356 &remote_funding_pubkey);
1357 sign_tx_input(tx, 0, NULL, funding_wscript,
1358 &secrets.funding_privkey,
1359 &local_funding_pubkey,
1360 SIGHASH_ALL,
1361 &sig);
1362
1363 return towire_hsmd_sign_commitment_tx_reply(NULL, &sig);
1364}
1365
1366/* ~This stub implementation is overriden by fully validating signers
1367 * that need to independently verify the peer's signatures. */

Callers 1

Calls 7

derive_basepointsFunction · 0.85
bitcoin_redeem_2of2Function · 0.85
sign_tx_inputFunction · 0.85
hsmd_status_bad_requestFunction · 0.70
get_channel_seedFunction · 0.70

Tested by

no test coverage detected