Skip to content

Commit 29c8693

Browse files
committed
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>
1 parent daf1560 commit 29c8693

File tree

5 files changed

+22
-53
lines changed

5 files changed

+22
-53
lines changed

channeld/channeld.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -913,6 +913,20 @@ static u8 *master_wait_sync_reply(const tal_t *ctx,
913913
}
914914

915915
/* Collect the htlcs for call to hsmd. */
916+
static struct simple_htlc *new_simple_htlc(const tal_t *ctx,
917+
enum side side,
918+
struct amount_msat amount,
919+
const struct sha256 *payment_hash,
920+
u32 cltv_expiry)
921+
{
922+
struct simple_htlc *simple = tal(ctx, struct simple_htlc);
923+
simple->side = side;
924+
simple->amount = amount;
925+
simple->payment_hash = *payment_hash;
926+
simple->cltv_expiry = cltv_expiry;
927+
return simple;
928+
}
929+
916930
static struct simple_htlc **collect_htlcs(const tal_t *ctx, const struct htlc **htlc_map)
917931
{
918932
struct simple_htlc **htlcs;

common/hsm_version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
* v5 with preapprove_check: 0ed6dd4ea2c02b67c51b1420b3d07ab2227a4c06ce7e2942d946967687e9baf7
2828
* v6 no secret from get_per_commitment_point: 0cad1790beb3473d64355f4cb4f64daa80c28c8a241998b7ef0223385d7ffff9
2929
* v6 with sign_bolt12_2 (tweak using node id): 8fcb731279a10af3f95aeb8be1da6b2ced76a1984afa18c5f46a03515d70ea0e
30-
* v6 (internal rework only): fba120d3d926de00f0377c4cba91caa89a9eaacb666fd04a5a0e677b4d310d65
30+
* v6 (internal rework only): eb34a3d575c2d2a2ed4d70df0858670b066fb8cb75ec8d39d0c996ae195a473b
3131
*/
3232
#define HSM_MIN_VERSION 5
3333
#define HSM_MAX_VERSION 6

common/htlc_wire.c

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,6 @@ static struct failed_htlc *failed_htlc_dup(const tal_t *ctx,
2424
return newf;
2525
}
2626

27-
struct simple_htlc *new_simple_htlc(const tal_t *ctx,
28-
enum side side,
29-
struct amount_msat amount,
30-
const struct sha256 *payment_hash,
31-
u32 cltv_expiry)
32-
{
33-
struct simple_htlc *simple = tal(ctx, struct simple_htlc);
34-
simple->side = side;
35-
simple->amount = amount;
36-
simple->payment_hash = *payment_hash;
37-
simple->cltv_expiry = cltv_expiry;
38-
return simple;
39-
}
40-
4127
struct existing_htlc *new_existing_htlc(const tal_t *ctx,
4228
u64 id,
4329
enum htlc_state state,
@@ -113,14 +99,6 @@ void towire_existing_htlc(u8 **pptr, const struct existing_htlc *existing)
11399
towire_bool(pptr, false);
114100
}
115101

116-
void towire_simple_htlc(u8 **pptr, const struct simple_htlc *simple)
117-
{
118-
towire_side(pptr, simple->side);
119-
towire_amount_msat(pptr, simple->amount);
120-
towire_sha256(pptr, &simple->payment_hash);
121-
towire_u32(pptr, simple->cltv_expiry);
122-
}
123-
124102
void towire_fulfilled_htlc(u8 **pptr, const struct fulfilled_htlc *fulfilled)
125103
{
126104
towire_u64(pptr, fulfilled->id);
@@ -217,18 +195,6 @@ struct existing_htlc *fromwire_existing_htlc(const tal_t *ctx,
217195
return existing;
218196
}
219197

220-
struct simple_htlc *fromwire_simple_htlc(const tal_t *ctx,
221-
const u8 **cursor, size_t *max)
222-
{
223-
struct simple_htlc *simple = tal(ctx, struct simple_htlc);
224-
225-
simple->side = fromwire_side(cursor, max);
226-
simple->amount = fromwire_amount_msat(cursor, max);
227-
fromwire_sha256(cursor, max, &simple->payment_hash);
228-
simple->cltv_expiry = fromwire_u32(cursor, max);
229-
return simple;
230-
}
231-
232198
void fromwire_fulfilled_htlc(const u8 **cursor, size_t *max,
233199
struct fulfilled_htlc *fulfilled)
234200
{

common/htlc_wire.h

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,6 @@ struct changed_htlc {
6060
u64 id;
6161
};
6262

63-
/* For signing interfaces */
64-
struct simple_htlc {
65-
enum side side;
66-
struct amount_msat amount;
67-
struct sha256 payment_hash;
68-
u32 cltv_expiry;
69-
};
70-
7163
struct existing_htlc *new_existing_htlc(const tal_t *ctx,
7264
u64 id,
7365
enum htlc_state state,
@@ -79,15 +71,8 @@ struct existing_htlc *new_existing_htlc(const tal_t *ctx,
7971
const struct preimage *preimage TAKES,
8072
const struct failed_htlc *failed TAKES);
8173

82-
struct simple_htlc *new_simple_htlc(const tal_t *ctx,
83-
enum side side,
84-
struct amount_msat amount,
85-
const struct sha256 *payment_hash,
86-
u32 cltv_expiry);
87-
8874
void towire_added_htlc(u8 **pptr, const struct added_htlc *added);
8975
void towire_existing_htlc(u8 **pptr, const struct existing_htlc *existing);
90-
void towire_simple_htlc(u8 **pptr, const struct simple_htlc *simple);
9176
void towire_fulfilled_htlc(u8 **pptr, const struct fulfilled_htlc *fulfilled);
9277
void towire_failed_htlc(u8 **pptr, const struct failed_htlc *failed);
9378
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,
9883
struct added_htlc *added);
9984
struct existing_htlc *fromwire_existing_htlc(const tal_t *ctx,
10085
const u8 **cursor, size_t *max);
101-
struct simple_htlc *fromwire_simple_htlc(const tal_t *ctx,
102-
const u8 **cursor, size_t *max);
10386
void fromwire_fulfilled_htlc(const u8 **cursor, size_t *max,
10487
struct fulfilled_htlc *fulfilled);
10588
struct failed_htlc *fromwire_failed_htlc(const tal_t *ctx, const u8 **cursor,

hsmd/hsmd_wire.csv

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,13 @@ msgdata,hsmd_sign_commitment_tx,commit_num,u64,
229229
msgtype,hsmd_sign_commitment_tx_reply,105
230230
msgdata,hsmd_sign_commitment_tx_reply,sig,bitcoin_signature,
231231

232+
#include <common/htlc_wire.h> // For enum side and towire_side
233+
subtype,simple_htlc
234+
subtypedata,simple_htlc,side,enum side,
235+
subtypedata,simple_htlc,amount,amount_msat,
236+
subtypedata,simple_htlc,payment_hash,sha256,
237+
subtypedata,simple_htlc,cltv_expiry,u32,
238+
232239
# Validate the counterparty's commitment signatures.
233240
msgtype,hsmd_validate_commitment_tx,35
234241
msgdata,hsmd_validate_commitment_tx,tx,bitcoin_tx,
@@ -290,7 +297,6 @@ msgdata,hsmd_sign_local_htlc_tx,wscript,u8,wscript_len
290297
msgdata,hsmd_sign_local_htlc_tx,option_anchor_outputs,bool,
291298

292299
# Openingd/channeld asks HSM to sign the other sides' commitment tx.
293-
#include <common/htlc_wire.h>
294300
msgtype,hsmd_sign_remote_commitment_tx,19
295301
msgdata,hsmd_sign_remote_commitment_tx,tx,bitcoin_tx,
296302
msgdata,hsmd_sign_remote_commitment_tx,remote_funding_key,pubkey,

0 commit comments

Comments
 (0)