hsmd: roll the definition of simple_htlc into the csv.

This is such a simple struct that we can actually define it in csv.
This prevents us from accidentally breaking the ABI in future.

I tested this hadn't accidentally changed the wire format by disabling
version checks and using an old hsmd with the altered daemons and
running the test suite.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2025-05-06 05:19:46 +09:30
parent daf1560eb4
commit 29c8693b26
5 changed files with 22 additions and 53 deletions

View File

@@ -913,6 +913,20 @@ static u8 *master_wait_sync_reply(const tal_t *ctx,
} }
/* Collect the htlcs for call to hsmd. */ /* Collect the htlcs for call to hsmd. */
static struct simple_htlc *new_simple_htlc(const tal_t *ctx,
enum side side,
struct amount_msat amount,
const struct sha256 *payment_hash,
u32 cltv_expiry)
{
struct simple_htlc *simple = tal(ctx, struct simple_htlc);
simple->side = side;
simple->amount = amount;
simple->payment_hash = *payment_hash;
simple->cltv_expiry = cltv_expiry;
return simple;
}
static struct simple_htlc **collect_htlcs(const tal_t *ctx, const struct htlc **htlc_map) static struct simple_htlc **collect_htlcs(const tal_t *ctx, const struct htlc **htlc_map)
{ {
struct simple_htlc **htlcs; struct simple_htlc **htlcs;

View File

@@ -27,7 +27,7 @@
* v5 with preapprove_check: 0ed6dd4ea2c02b67c51b1420b3d07ab2227a4c06ce7e2942d946967687e9baf7 * v5 with preapprove_check: 0ed6dd4ea2c02b67c51b1420b3d07ab2227a4c06ce7e2942d946967687e9baf7
* v6 no secret from get_per_commitment_point: 0cad1790beb3473d64355f4cb4f64daa80c28c8a241998b7ef0223385d7ffff9 * v6 no secret from get_per_commitment_point: 0cad1790beb3473d64355f4cb4f64daa80c28c8a241998b7ef0223385d7ffff9
* v6 with sign_bolt12_2 (tweak using node id): 8fcb731279a10af3f95aeb8be1da6b2ced76a1984afa18c5f46a03515d70ea0e * v6 with sign_bolt12_2 (tweak using node id): 8fcb731279a10af3f95aeb8be1da6b2ced76a1984afa18c5f46a03515d70ea0e
* v6 (internal rework only): fba120d3d926de00f0377c4cba91caa89a9eaacb666fd04a5a0e677b4d310d65 * v6 (internal rework only): eb34a3d575c2d2a2ed4d70df0858670b066fb8cb75ec8d39d0c996ae195a473b
*/ */
#define HSM_MIN_VERSION 5 #define HSM_MIN_VERSION 5
#define HSM_MAX_VERSION 6 #define HSM_MAX_VERSION 6

View File

@@ -24,20 +24,6 @@ static struct failed_htlc *failed_htlc_dup(const tal_t *ctx,
return newf; return newf;
} }
struct simple_htlc *new_simple_htlc(const tal_t *ctx,
enum side side,
struct amount_msat amount,
const struct sha256 *payment_hash,
u32 cltv_expiry)
{
struct simple_htlc *simple = tal(ctx, struct simple_htlc);
simple->side = side;
simple->amount = amount;
simple->payment_hash = *payment_hash;
simple->cltv_expiry = cltv_expiry;
return simple;
}
struct existing_htlc *new_existing_htlc(const tal_t *ctx, struct existing_htlc *new_existing_htlc(const tal_t *ctx,
u64 id, u64 id,
enum htlc_state state, enum htlc_state state,
@@ -113,14 +99,6 @@ void towire_existing_htlc(u8 **pptr, const struct existing_htlc *existing)
towire_bool(pptr, false); towire_bool(pptr, false);
} }
void towire_simple_htlc(u8 **pptr, const struct simple_htlc *simple)
{
towire_side(pptr, simple->side);
towire_amount_msat(pptr, simple->amount);
towire_sha256(pptr, &simple->payment_hash);
towire_u32(pptr, simple->cltv_expiry);
}
void towire_fulfilled_htlc(u8 **pptr, const struct fulfilled_htlc *fulfilled) void towire_fulfilled_htlc(u8 **pptr, const struct fulfilled_htlc *fulfilled)
{ {
towire_u64(pptr, fulfilled->id); towire_u64(pptr, fulfilled->id);
@@ -217,18 +195,6 @@ struct existing_htlc *fromwire_existing_htlc(const tal_t *ctx,
return existing; return existing;
} }
struct simple_htlc *fromwire_simple_htlc(const tal_t *ctx,
const u8 **cursor, size_t *max)
{
struct simple_htlc *simple = tal(ctx, struct simple_htlc);
simple->side = fromwire_side(cursor, max);
simple->amount = fromwire_amount_msat(cursor, max);
fromwire_sha256(cursor, max, &simple->payment_hash);
simple->cltv_expiry = fromwire_u32(cursor, max);
return simple;
}
void fromwire_fulfilled_htlc(const u8 **cursor, size_t *max, void fromwire_fulfilled_htlc(const u8 **cursor, size_t *max,
struct fulfilled_htlc *fulfilled) struct fulfilled_htlc *fulfilled)
{ {

View File

@@ -60,14 +60,6 @@ struct changed_htlc {
u64 id; u64 id;
}; };
/* For signing interfaces */
struct simple_htlc {
enum side side;
struct amount_msat amount;
struct sha256 payment_hash;
u32 cltv_expiry;
};
struct existing_htlc *new_existing_htlc(const tal_t *ctx, struct existing_htlc *new_existing_htlc(const tal_t *ctx,
u64 id, u64 id,
enum htlc_state state, enum htlc_state state,
@@ -79,15 +71,8 @@ struct existing_htlc *new_existing_htlc(const tal_t *ctx,
const struct preimage *preimage TAKES, const struct preimage *preimage TAKES,
const struct failed_htlc *failed TAKES); const struct failed_htlc *failed TAKES);
struct simple_htlc *new_simple_htlc(const tal_t *ctx,
enum side side,
struct amount_msat amount,
const struct sha256 *payment_hash,
u32 cltv_expiry);
void towire_added_htlc(u8 **pptr, const struct added_htlc *added); void towire_added_htlc(u8 **pptr, const struct added_htlc *added);
void towire_existing_htlc(u8 **pptr, const struct existing_htlc *existing); void towire_existing_htlc(u8 **pptr, const struct existing_htlc *existing);
void towire_simple_htlc(u8 **pptr, const struct simple_htlc *simple);
void towire_fulfilled_htlc(u8 **pptr, const struct fulfilled_htlc *fulfilled); void towire_fulfilled_htlc(u8 **pptr, const struct fulfilled_htlc *fulfilled);
void towire_failed_htlc(u8 **pptr, const struct failed_htlc *failed); void towire_failed_htlc(u8 **pptr, const struct failed_htlc *failed);
void towire_changed_htlc(u8 **pptr, const struct changed_htlc *changed); void towire_changed_htlc(u8 **pptr, const struct changed_htlc *changed);
@@ -98,8 +83,6 @@ void fromwire_added_htlc(const u8 **cursor, size_t *max,
struct added_htlc *added); struct added_htlc *added);
struct existing_htlc *fromwire_existing_htlc(const tal_t *ctx, struct existing_htlc *fromwire_existing_htlc(const tal_t *ctx,
const u8 **cursor, size_t *max); const u8 **cursor, size_t *max);
struct simple_htlc *fromwire_simple_htlc(const tal_t *ctx,
const u8 **cursor, size_t *max);
void fromwire_fulfilled_htlc(const u8 **cursor, size_t *max, void fromwire_fulfilled_htlc(const u8 **cursor, size_t *max,
struct fulfilled_htlc *fulfilled); struct fulfilled_htlc *fulfilled);
struct failed_htlc *fromwire_failed_htlc(const tal_t *ctx, const u8 **cursor, struct failed_htlc *fromwire_failed_htlc(const tal_t *ctx, const u8 **cursor,

View File

@@ -229,6 +229,13 @@ msgdata,hsmd_sign_commitment_tx,commit_num,u64,
msgtype,hsmd_sign_commitment_tx_reply,105 msgtype,hsmd_sign_commitment_tx_reply,105
msgdata,hsmd_sign_commitment_tx_reply,sig,bitcoin_signature, msgdata,hsmd_sign_commitment_tx_reply,sig,bitcoin_signature,
#include <common/htlc_wire.h> // For enum side and towire_side
subtype,simple_htlc
subtypedata,simple_htlc,side,enum side,
subtypedata,simple_htlc,amount,amount_msat,
subtypedata,simple_htlc,payment_hash,sha256,
subtypedata,simple_htlc,cltv_expiry,u32,
# Validate the counterparty's commitment signatures. # Validate the counterparty's commitment signatures.
msgtype,hsmd_validate_commitment_tx,35 msgtype,hsmd_validate_commitment_tx,35
msgdata,hsmd_validate_commitment_tx,tx,bitcoin_tx, msgdata,hsmd_validate_commitment_tx,tx,bitcoin_tx,
@@ -290,7 +297,6 @@ msgdata,hsmd_sign_local_htlc_tx,wscript,u8,wscript_len
msgdata,hsmd_sign_local_htlc_tx,option_anchor_outputs,bool, msgdata,hsmd_sign_local_htlc_tx,option_anchor_outputs,bool,
# Openingd/channeld asks HSM to sign the other sides' commitment tx. # Openingd/channeld asks HSM to sign the other sides' commitment tx.
#include <common/htlc_wire.h>
msgtype,hsmd_sign_remote_commitment_tx,19 msgtype,hsmd_sign_remote_commitment_tx,19
msgdata,hsmd_sign_remote_commitment_tx,tx,bitcoin_tx, msgdata,hsmd_sign_remote_commitment_tx,tx,bitcoin_tx,
msgdata,hsmd_sign_remote_commitment_tx,remote_funding_key,pubkey, msgdata,hsmd_sign_remote_commitment_tx,remote_funding_key,pubkey,
Can't render this file because it contains an unexpected character in line 169 and column 43.