From 29c8693b26a9d8be18e64f54f9ae5c130f076155 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 6 May 2025 05:19:46 +0930 Subject: [PATCH] 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 --- channeld/channeld.c | 14 ++++++++++++++ common/hsm_version.h | 2 +- common/htlc_wire.c | 34 ---------------------------------- common/htlc_wire.h | 17 ----------------- hsmd/hsmd_wire.csv | 8 +++++++- 5 files changed, 22 insertions(+), 53 deletions(-) diff --git a/channeld/channeld.c b/channeld/channeld.c index 5db9df601..dd983d80d 100644 --- a/channeld/channeld.c +++ b/channeld/channeld.c @@ -913,6 +913,20 @@ static u8 *master_wait_sync_reply(const tal_t *ctx, } /* 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) { struct simple_htlc **htlcs; diff --git a/common/hsm_version.h b/common/hsm_version.h index 8ee80cf84..f5ea02f94 100644 --- a/common/hsm_version.h +++ b/common/hsm_version.h @@ -27,7 +27,7 @@ * v5 with preapprove_check: 0ed6dd4ea2c02b67c51b1420b3d07ab2227a4c06ce7e2942d946967687e9baf7 * v6 no secret from get_per_commitment_point: 0cad1790beb3473d64355f4cb4f64daa80c28c8a241998b7ef0223385d7ffff9 * 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_MAX_VERSION 6 diff --git a/common/htlc_wire.c b/common/htlc_wire.c index 22735388c..aa3ef92f1 100644 --- a/common/htlc_wire.c +++ b/common/htlc_wire.c @@ -24,20 +24,6 @@ static struct failed_htlc *failed_htlc_dup(const tal_t *ctx, 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, u64 id, enum htlc_state state, @@ -113,14 +99,6 @@ void towire_existing_htlc(u8 **pptr, const struct existing_htlc *existing) 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) { towire_u64(pptr, fulfilled->id); @@ -217,18 +195,6 @@ struct existing_htlc *fromwire_existing_htlc(const tal_t *ctx, 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, struct fulfilled_htlc *fulfilled) { diff --git a/common/htlc_wire.h b/common/htlc_wire.h index c2026a8c4..4d758a649 100644 --- a/common/htlc_wire.h +++ b/common/htlc_wire.h @@ -60,14 +60,6 @@ struct changed_htlc { 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, u64 id, 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 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_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_failed_htlc(u8 **pptr, const struct failed_htlc *failed); 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 existing_htlc *fromwire_existing_htlc(const tal_t *ctx, 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, struct fulfilled_htlc *fulfilled); struct failed_htlc *fromwire_failed_htlc(const tal_t *ctx, const u8 **cursor, diff --git a/hsmd/hsmd_wire.csv b/hsmd/hsmd_wire.csv index a0b1823f6..38ca06f08 100644 --- a/hsmd/hsmd_wire.csv +++ b/hsmd/hsmd_wire.csv @@ -229,6 +229,13 @@ msgdata,hsmd_sign_commitment_tx,commit_num,u64, msgtype,hsmd_sign_commitment_tx_reply,105 msgdata,hsmd_sign_commitment_tx_reply,sig,bitcoin_signature, +#include // 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. msgtype,hsmd_validate_commitment_tx,35 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, # Openingd/channeld asks HSM to sign the other sides' commitment tx. -#include msgtype,hsmd_sign_remote_commitment_tx,19 msgdata,hsmd_sign_remote_commitment_tx,tx,bitcoin_tx, msgdata,hsmd_sign_remote_commitment_tx,remote_funding_key,pubkey,