Skip to content

Commit 385383d

Browse files
committed
hsmd: prune unreachable pre HSM_VERSION 5 code
Changelog-None: shouldn't affect others HSM_MIN_VERSION is 5 which implies use of WIRE_HSMD_REVOKE_COMMITMENT_TX; prune branches that can't happen.
1 parent ab4ea82 commit 385383d

File tree

1 file changed

+19
-34
lines changed

1 file changed

+19
-34
lines changed

channeld/channeld.c

Lines changed: 19 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,23 +1465,17 @@ static u8 *make_revocation_msg(const struct peer *peer, u64 revoke_index,
14651465

14661466
/* Now that the master has persisted the new commitment advance the HSMD
14671467
* and fetch the revocation secret for the old one. */
1468-
if (!hsm_is_capable(peer->hsm_capabilities, WIRE_HSMD_REVOKE_COMMITMENT_TX)) {
1469-
/* Prior to HSM_VERSION 5 we call get_per_commitment_point to
1470-
* get the old_secret and next point.
1471-
*/
1472-
get_per_commitment_point(revoke_index+2, point, &old_commit_secret);
1473-
} else {
1474-
/* After HSM_VERSION 5 we explicitly revoke the commitment in case
1475-
* the original revoke didn't complete. The hsmd_revoke_commitment_tx
1476-
* call is idempotent ...
1477-
*/
1478-
msg = towire_hsmd_revoke_commitment_tx(tmpctx, revoke_index);
1479-
msg = hsm_req(tmpctx, take(msg));
1480-
if (!fromwire_hsmd_revoke_commitment_tx_reply(msg, &old_commit_secret, point))
1481-
status_failed(STATUS_FAIL_HSM_IO,
1482-
"Reading revoke_commitment_tx reply: %s",
1483-
tal_hex(tmpctx, msg));
1484-
}
1468+
1469+
/* After HSM_VERSION 5 we explicitly revoke the commitment in case
1470+
* the original revoke didn't complete. The hsmd_revoke_commitment_tx
1471+
* call is idempotent ...
1472+
*/
1473+
msg = towire_hsmd_revoke_commitment_tx(tmpctx, revoke_index);
1474+
msg = hsm_req(tmpctx, take(msg));
1475+
if (!fromwire_hsmd_revoke_commitment_tx_reply(msg, &old_commit_secret, point))
1476+
status_failed(STATUS_FAIL_HSM_IO,
1477+
"Reading revoke_commitment_tx reply: %s",
1478+
tal_hex(tmpctx, msg));
14851479

14861480
return towire_revoke_and_ack(peer, &peer->channel_id, &old_commit_secret,
14871481
point);
@@ -1608,19 +1602,12 @@ static void send_revocation(struct peer *peer,
16081602

16091603
/* Now that the master has persisted the new commitment advance the HSMD
16101604
* and fetch the revocation secret for the old one. */
1611-
if (!hsm_is_capable(peer->hsm_capabilities, WIRE_HSMD_REVOKE_COMMITMENT_TX)) {
1612-
/* Prior to HSM_VERSION 5 we use the old_secret
1613-
* received earlier from validate_commitment_tx. */
1614-
old_secret2 = *old_secret;
1615-
next_point2 = *next_point;
1616-
} else {
1617-
msg = towire_hsmd_revoke_commitment_tx(tmpctx, peer->next_index[LOCAL] - 2);
1618-
msg = hsm_req(tmpctx, take(msg));
1619-
if (!fromwire_hsmd_revoke_commitment_tx_reply(msg, &old_secret2, &next_point2))
1620-
status_failed(STATUS_FAIL_HSM_IO,
1621-
"Reading revoke_commitment_tx reply: %s",
1622-
tal_hex(tmpctx, msg));
1623-
}
1605+
msg = towire_hsmd_revoke_commitment_tx(tmpctx, peer->next_index[LOCAL] - 2);
1606+
msg = hsm_req(tmpctx, take(msg));
1607+
if (!fromwire_hsmd_revoke_commitment_tx_reply(msg, &old_secret2, &next_point2))
1608+
status_failed(STATUS_FAIL_HSM_IO,
1609+
"Reading revoke_commitment_tx reply: %s",
1610+
tal_hex(tmpctx, msg));
16241611

16251612
/* Revoke previous commit, get new point. */
16261613
msg = make_revocation_msg_from_secret(peer, peer->next_index[LOCAL]-2,
@@ -2123,10 +2110,8 @@ static struct commitsig_info *handle_peer_commit_sig(struct peer *peer,
21232110
tal_steal(commitsigs, result);
21242111
}
21252112

2126-
// If the HSM doesn't support WIRE_HSMD_REVOKE_COMMITMENT_TX we'd better
2127-
// have the old_secret at this point.
2128-
if (!hsm_is_capable(peer->hsm_capabilities, WIRE_HSMD_REVOKE_COMMITMENT_TX))
2129-
assert(old_secret);
2113+
/* We no longer receive old_secret from hsmd_validate_commitment_tx */
2114+
assert(!old_secret);
21302115

21312116
send_revocation(peer, &commit_sig, htlc_sigs, changed_htlcs, txs[0],
21322117
old_secret, &next_point, commitsigs);

0 commit comments

Comments
 (0)