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

Function handle_get_per_commitment_point

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

1003 * and reveal the previous per-commitment secret as a promise not to spend
1004 * the previous commitment transaction. */
1005static u8 *handle_get_per_commitment_point(struct hsmd_client *c, const u8 *msg_in)
1006{
1007 struct secret channel_seed;
1008 struct sha256 shaseed;
1009 struct pubkey per_commitment_point;
1010 u64 n;
1011 struct secret *old_secret;
1012
1013 if (!fromwire_hsmd_get_per_commitment_point(msg_in, &n))
1014 return hsmd_status_malformed_request(c, msg_in);
1015
1016 get_channel_seed(&c->id, c->dbid, &channel_seed);
1017 if (!derive_shaseed(&channel_seed, &shaseed))
1018 return hsmd_status_bad_request(c, msg_in, "bad derive_shaseed");
1019
1020 if (!per_commit_point(&shaseed, &per_commitment_point, n))
1021 return hsmd_status_bad_request_fmt(
1022 c, msg_in, "bad per_commit_point %" PRIu64, n);
1023
1024 if (n >= 2) {
1025 old_secret = tal(tmpctx, struct secret);
1026 if (!per_commit_secret(&shaseed, old_secret, n - 2)) {
1027 return hsmd_status_bad_request_fmt(
1028 c, msg_in, "Cannot derive secret %" PRIu64, n - 2);
1029 }
1030 } else
1031 old_secret = NULL;
1032
1033 /*~ hsm_client_wire.csv marks the secret field here optional, so it only
1034 * gets included if the parameter is non-NULL. We violate 80 columns
1035 * pretty badly here, but it's a recommendation not a religion. */
1036 return towire_hsmd_get_per_commitment_point_reply(
1037 NULL, &per_commitment_point, old_secret);
1038}
1039
1040/*~ lightningd asks us to sign a withdrawal; same as above but in theory
1041 * 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