-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
hsmd: add explicit hsmd_revoke_commitment_tx #103
base: 2024-01-unilateral-close-info-anchors
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,8 @@ | |
#include <common/billboard.h> | ||
#include <common/ecdh_hsmd.h> | ||
#include <common/gossip_store.h> | ||
#include <common/hsm_capable.h> | ||
#include <common/hsm_version.h> | ||
#include <common/interactivetx.h> | ||
#include <common/key_derive.h> | ||
#include <common/memleak.h> | ||
|
@@ -77,6 +79,9 @@ struct peer { | |
/* Features we support. */ | ||
struct feature_set *our_features; | ||
|
||
/* What (additional) messages the HSM accepts */ | ||
u32 *hsm_capabilities; | ||
|
||
/* Tolerable amounts for feerate (only relevant for fundee). */ | ||
u32 feerate_min, feerate_max; | ||
|
||
|
@@ -1920,6 +1925,7 @@ static void send_revocation(struct peer *peer, | |
const struct failed_htlc **failed; | ||
struct added_htlc *added; | ||
const u8 *msg; | ||
const u8 *msg2; | ||
const u8 *msg_for_master; | ||
|
||
/* Marshall it now before channel_sending_revoke_and_ack changes htlcs */ | ||
|
@@ -1931,11 +1937,6 @@ static void send_revocation(struct peer *peer, | |
&failed, | ||
&added); | ||
|
||
/* Revoke previous commit, get new point. */ | ||
msg = make_revocation_msg_from_secret(peer, peer->next_index[LOCAL]-1, | ||
&peer->next_local_per_commit, | ||
old_secret, next_point); | ||
|
||
/* From now on we apply changes to the next commitment */ | ||
peer->next_index[LOCAL]++; | ||
|
||
|
@@ -1966,6 +1967,30 @@ static void send_revocation(struct peer *peer, | |
|
||
peer->splice_state->await_commitment_succcess = false; | ||
|
||
/* Now that the master has persisted the new commitment advance the HSMD | ||
* and fetch the revocation secret for the old one. */ | ||
struct secret old_secret2; | ||
struct pubkey next_point2; | ||
if (HSM_MAX_VERSION < 5 || | ||
!hsm_is_capable(peer->hsm_capabilities, WIRE_HSMD_REVOKE_COMMITMENT_TX)) { | ||
/* Prior to HSM_VERSION 5 we use the old_secret | ||
* received earlier from validate_commitment_tx. */ | ||
memcpy(&old_secret2, old_secret, sizeof(old_secret2)); | ||
memcpy(&next_point2, next_point, sizeof(next_point2)); | ||
} else { | ||
msg2 = towire_hsmd_revoke_commitment_tx(tmpctx, peer->next_index[LOCAL] - 2); | ||
msg2 = hsm_req(tmpctx, take(msg2)); | ||
if (!fromwire_hsmd_revoke_commitment_tx_reply(msg2, &old_secret2, &next_point2)) | ||
status_failed(STATUS_FAIL_HSM_IO, | ||
"Reading revoke_commitment_tx reply: %s", | ||
tal_hex(tmpctx, msg2)); | ||
} | ||
|
||
/* Revoke previous commit, get new point. */ | ||
msg = make_revocation_msg_from_secret(peer, peer->next_index[LOCAL]-2, | ||
&peer->next_local_per_commit, | ||
&old_secret2, &next_point2); | ||
|
||
/* Now we can finally send revoke_and_ack to peer */ | ||
peer_write(peer->pps, take(msg)); | ||
} | ||
|
@@ -2270,7 +2295,11 @@ static struct commitsig_info *handle_peer_commit_sig(struct peer *peer, | |
tal_steal(commitsigs, result); | ||
} | ||
|
||
assert(old_secret); | ||
// If the HSM doesn't support WIRE_HSMD_REVOKE_COMMITMENT_TX we'd better | ||
// have the old_secret at this point. | ||
if (HSM_MAX_VERSION < 5 || | ||
!hsm_is_capable(peer->hsm_capabilities, WIRE_HSMD_REVOKE_COMMITMENT_TX)) | ||
Comment on lines
+2300
to
+2301
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mh this is just a comment for a future improvement. Would be nice to have a method to avoid checking the version here, but with the current enum system for the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure if we can hack around the |
||
assert(old_secret); | ||
|
||
send_revocation(peer, &commit_sig, htlc_sigs, changed_htlcs, txs[0], | ||
old_secret, &next_point, commitsigs); | ||
|
@@ -6085,6 +6114,7 @@ static void init_channel(struct peer *peer) | |
if (!fromwire_channeld_init(peer, msg, | ||
&chainparams, | ||
&peer->our_features, | ||
&peer->hsm_capabilities, | ||
&peer->channel_id, | ||
&funding, | ||
&funding_sats, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include "config.h" | ||
#include <common/hsm_capable.h> | ||
|
||
/* Is this capability supported by the HSM? (So far, always a message | ||
* number) */ | ||
bool hsm_is_capable(u32 *capabilities, u32 msgtype) | ||
{ | ||
for (size_t i = 0; i < tal_count(capabilities); i++) { | ||
if (capabilities[i] == msgtype) | ||
return true; | ||
} | ||
return false; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#ifndef LIGHTNING_COMMON_HSM_CAPABLE_H | ||
#define LIGHTNING_COMMON_HSM_CAPABLE_H | ||
#include "config.h" | ||
#include <ccan/short_types/short_types.h> | ||
#include <ccan/tal/tal.h> | ||
#include <stdbool.h> | ||
|
||
/* Is this capability supported by the HSM? (So far, always a message | ||
* number) */ | ||
bool hsm_is_capable(u32 *capabilities, u32 msgtype); | ||
#endif /* LIGHTNING_COMMON_HSM_CAPABLE_H */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider removing these additional variables and just use
old_secret
andnext_point
everywhere belowThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is the originals are: