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

Function handle_get_per_commitment_point

hsmd/libhsmd.c:1360–1393  ·  view source on GitHub ↗

~ This get the Nth a per-commitment point, and for N > 2, returns the * grandparent per-commitment secret. This pattern is because after * negotiating commitment N-1, we send them the next per-commitment point, * and reveal the previous per-commitment secret as a promise not to spend * the previous commitment transaction. */

Source from the content-addressed store, hash-verified

1358 * and reveal the previous per-commitment secret as a promise not to spend
1359 * the previous commitment transaction. */
1360static u8 *handle_get_per_commitment_point(struct hsmd_client *c, const u8 *msg_in)
1361{
1362 struct secret channel_seed;
1363 struct sha256 shaseed;
1364 struct pubkey per_commitment_point;
1365 u64 n;
1366 struct secret *old_secret;
1367
1368 if (!fromwire_hsmd_get_per_commitment_point(msg_in, &n))
1369 return hsmd_status_malformed_request(c, msg_in);
1370
1371 get_channel_seed(&c->id, c->dbid, &channel_seed);
1372 if (!derive_shaseed(&channel_seed, &shaseed))
1373 return hsmd_status_bad_request(c, msg_in, "bad derive_shaseed");
1374
1375 if (!per_commit_point(&shaseed, &per_commitment_point, n))
1376 return hsmd_status_bad_request_fmt(
1377 c, msg_in, "bad per_commit_point %" PRIu64, n);
1378
1379 if (hsmd_mutual_version < 6 && n >= 2) {
1380 old_secret = tal(tmpctx, struct secret);
1381 if (!per_commit_secret(&shaseed, old_secret, n - 2)) {
1382 return hsmd_status_bad_request_fmt(
1383 c, msg_in, "Cannot derive secret %" PRIu64, n - 2);
1384 }
1385 } else
1386 old_secret = NULL;
1387
1388 /*~ hsm_client_wire.csv marks the secret field here optional, so it only
1389 * gets included if the parameter is non-NULL. We violate 80 columns
1390 * pretty badly here, but it's a recommendation not a religion. */
1391 return towire_hsmd_get_per_commitment_point_reply(
1392 NULL, &per_commitment_point, old_secret);
1393}
1394
1395/*~ lightningd asks us to sign a withdrawal; same as above but in theory
1396 * we can do more to check the previous case is valid. */

Callers 1

Calls 7

derive_shaseedFunction · 0.85
per_commit_pointFunction · 0.85
per_commit_secretFunction · 0.85
get_channel_seedFunction · 0.70
hsmd_status_bad_requestFunction · 0.70

Tested by

no test coverage detected