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

Function handle_get_per_commitment_point

hsmd/libhsmd.c:1362–1395  ·  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

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