Skip to content

Commit 2154289

Browse files
committed
hsmd: rename simple_htlc to hsm_htlc, don't gratuitously dynamically allocate.
The renaming makes it clear that it's HSM specific. And it has no pointers, so we can have an array instead of an array of pointers. 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 29c8693 commit 2154289

File tree

7 files changed

+27
-46
lines changed

7 files changed

+27
-46
lines changed

channeld/channeld.c

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -912,37 +912,22 @@ static u8 *master_wait_sync_reply(const tal_t *ctx,
912912
return reply;
913913
}
914914

915-
/* 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)
915+
static struct hsm_htlc *collect_htlcs(const tal_t *ctx,
916+
const struct htlc **htlc_map)
921917
{
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-
930-
static struct simple_htlc **collect_htlcs(const tal_t *ctx, const struct htlc **htlc_map)
931-
{
932-
struct simple_htlc **htlcs;
918+
struct hsm_htlc *htlcs;
933919

934-
htlcs = tal_arr(ctx, struct simple_htlc *, 0);
920+
htlcs = tal_arr(ctx, struct hsm_htlc, 0);
935921
size_t num_entries = tal_count(htlc_map);
936922
for (size_t ndx = 0; ndx < num_entries; ++ndx) {
937923
struct htlc const *hh = htlc_map[ndx];
938924
if (hh) {
939-
struct simple_htlc *simple =
940-
new_simple_htlc(htlcs,
941-
htlc_state_owner(hh->state),
942-
hh->amount,
943-
&hh->rhash,
944-
hh->expiry.locktime);
945-
tal_arr_expand(&htlcs, simple);
925+
struct hsm_htlc htlc;
926+
htlc.side = htlc_state_owner(hh->state);
927+
htlc.amount = hh->amount;
928+
htlc.payment_hash = hh->rhash;
929+
htlc.cltv_expiry = hh->expiry.locktime;
930+
tal_arr_expand(&htlcs, htlc);
946931
}
947932
}
948933
return htlcs;
@@ -960,7 +945,7 @@ static struct bitcoin_signature *calc_commitsigs(const tal_t *ctx,
960945
struct bitcoin_signature *commit_sig,
961946
struct pubkey remote_funding_pubkey)
962947
{
963-
struct simple_htlc **htlcs;
948+
struct hsm_htlc *htlcs;
964949
size_t i;
965950
struct pubkey local_htlckey;
966951
const u8 *msg;
@@ -973,7 +958,7 @@ static struct bitcoin_signature *calc_commitsigs(const tal_t *ctx,
973958
channel_has(peer->channel,
974959
OPT_STATIC_REMOTEKEY),
975960
commit_index,
976-
(const struct simple_htlc **) htlcs,
961+
htlcs,
977962
channel_feerate(peer->channel, REMOTE));
978963

979964
msg = hsm_req(tmpctx, take(msg));
@@ -1897,7 +1882,7 @@ static struct commitsig_info *handle_peer_commit_sig(struct peer *peer,
18971882
const struct htlc **htlc_map;
18981883
const u8 *funding_wscript;
18991884
size_t i;
1900-
struct simple_htlc **htlcs;
1885+
const struct hsm_htlc *htlcs;
19011886
const u8 * msg2;
19021887
u8 *splice_msg;
19031888
int type;
@@ -2105,7 +2090,7 @@ static struct commitsig_info *handle_peer_commit_sig(struct peer *peer,
21052090
htlcs = collect_htlcs(NULL, htlc_map);
21062091
msg2 = towire_hsmd_validate_commitment_tx(NULL,
21072092
txs[0],
2108-
(const struct simple_htlc **) htlcs,
2093+
htlcs,
21092094
local_index,
21102095
channel_feerate(peer->channel, LOCAL),
21112096
&commit_sig,

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): eb34a3d575c2d2a2ed4d70df0858670b066fb8cb75ec8d39d0c996ae195a473b
30+
* v6 (internal rework only): 22dc3adfb0d63dbd6a92ff1daacbb6218c5efa3080f8910933a18683ce75bf5f
3131
*/
3232
#define HSM_MIN_VERSION 5
3333
#define HSM_MAX_VERSION 6

hsmd/hsmd_wire.csv

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -230,17 +230,17 @@ msgtype,hsmd_sign_commitment_tx_reply,105
230230
msgdata,hsmd_sign_commitment_tx_reply,sig,bitcoin_signature,
231231

232232
#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,
233+
subtype,hsm_htlc
234+
subtypedata,hsm_htlc,side,enum side,
235+
subtypedata,hsm_htlc,amount,amount_msat,
236+
subtypedata,hsm_htlc,payment_hash,sha256,
237+
subtypedata,hsm_htlc,cltv_expiry,u32,
238238

239239
# Validate the counterparty's commitment signatures.
240240
msgtype,hsmd_validate_commitment_tx,35
241241
msgdata,hsmd_validate_commitment_tx,tx,bitcoin_tx,
242242
msgdata,hsmd_validate_commitment_tx,num_htlcs,u16,
243-
msgdata,hsmd_validate_commitment_tx,htlcs,simple_htlc,num_htlcs
243+
msgdata,hsmd_validate_commitment_tx,htlcs,hsm_htlc,num_htlcs
244244
msgdata,hsmd_validate_commitment_tx,commit_num,u64,
245245
msgdata,hsmd_validate_commitment_tx,feerate,u32,
246246
msgdata,hsmd_validate_commitment_tx,sig,bitcoin_signature,
@@ -304,7 +304,7 @@ msgdata,hsmd_sign_remote_commitment_tx,remote_per_commit,pubkey,
304304
msgdata,hsmd_sign_remote_commitment_tx,option_static_remotekey,bool,
305305
msgdata,hsmd_sign_remote_commitment_tx,commit_num,u64,
306306
msgdata,hsmd_sign_remote_commitment_tx,num_htlcs,u16,
307-
msgdata,hsmd_sign_remote_commitment_tx,htlcs,simple_htlc,num_htlcs
307+
msgdata,hsmd_sign_remote_commitment_tx,htlcs,hsm_htlc,num_htlcs
308308
msgdata,hsmd_sign_remote_commitment_tx,feerate,u32,
309309

310310
# channeld asks HSM to sign remote HTLC tx.

hsmd/libhsmd.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1584,7 +1584,7 @@ static u8 *handle_sign_remote_commitment_tx(struct hsmd_client *c, const u8 *msg
15841584
struct pubkey remote_per_commit;
15851585
bool option_static_remotekey;
15861586
u64 commit_num;
1587-
struct simple_htlc **htlc;
1587+
struct hsm_htlc *htlc;
15881588
u32 feerate;
15891589

15901590
if (!fromwire_hsmd_sign_remote_commitment_tx(tmpctx, msg_in,
@@ -1820,7 +1820,7 @@ static u8 *handle_sign_commitment_tx(struct hsmd_client *c, const u8 *msg_in)
18201820
static u8 *handle_validate_commitment_tx(struct hsmd_client *c, const u8 *msg_in)
18211821
{
18221822
struct bitcoin_tx *tx;
1823-
struct simple_htlc **htlc;
1823+
struct hsm_htlc *htlc;
18241824
u64 commit_num;
18251825
u32 feerate;
18261826
struct bitcoin_signature sig;

openingd/dualopend.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,7 +1107,6 @@ static u8 *msg_for_remote_commit(const tal_t *ctx,
11071107
struct wally_tx_output *direct_outputs[NUM_SIDES];
11081108
struct bitcoin_tx *remote_commit;
11091109
struct bitcoin_signature local_sig;
1110-
struct simple_htlc **htlcs = tal_arr(tmpctx, struct simple_htlc *, 0);
11111110
u32 feerate = 0; // unused since there are no htlcs
11121111
u64 commit_num = 0;
11131112
u8 *msg;
@@ -1132,7 +1131,7 @@ static u8 *msg_for_remote_commit(const tal_t *ctx,
11321131
&state->first_per_commitment_point[REMOTE],
11331132
true,
11341133
commit_num,
1135-
(const struct simple_htlc **) htlcs,
1134+
NULL, /* no HTLCS */
11361135
feerate);
11371136
wire_sync_write(HSM_FD, take(msg));
11381137
msg = wire_sync_read(tmpctx, HSM_FD);

openingd/openingd.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,6 @@ static bool funder_finalize_channel_setup(struct state *state,
703703
* witness script. It also needs the amount of the funding output,
704704
* as segwit signatures commit to that as well, even though it doesn't
705705
* explicitly appear in the transaction itself. */
706-
struct simple_htlc **htlcs = tal_arr(tmpctx, struct simple_htlc *, 0);
707706
u32 feerate = 0; // unused since there are no htlcs
708707
u64 commit_num = 0;
709708
msg = towire_hsmd_sign_remote_commitment_tx(NULL,
@@ -713,7 +712,7 @@ static bool funder_finalize_channel_setup(struct state *state,
713712
channel_has(state->channel,
714713
OPT_STATIC_REMOTEKEY),
715714
commit_num,
716-
(const struct simple_htlc **) htlcs,
715+
NULL, /* No htlcs */
717716
feerate);
718717

719718
wire_sync_write(HSM_FD, take(msg));
@@ -1321,7 +1320,6 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg)
13211320
}
13221321

13231322
/* Make HSM sign it */
1324-
struct simple_htlc **htlcs = tal_arr(tmpctx, struct simple_htlc *, 0);
13251323
u32 feerate = 0; // unused since there are no htlcs
13261324
u64 commit_num = 0;
13271325
msg = towire_hsmd_sign_remote_commitment_tx(NULL,
@@ -1331,7 +1329,7 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg)
13311329
channel_has(state->channel,
13321330
OPT_STATIC_REMOTEKEY),
13331331
commit_num,
1334-
(const struct simple_htlc **) htlcs,
1332+
NULL, /* No htlcs */
13351333
feerate);
13361334

13371335
wire_sync_write(HSM_FD, take(msg));

tools/generate-wire.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,6 @@ class Type(FieldSet):
231231
'gossip_getchannels_entry',
232232
'failed_htlc',
233233
'existing_htlc',
234-
'simple_htlc',
235234
'inflight',
236235
'hsm_utxo',
237236
'bitcoin_tx',

0 commit comments

Comments
 (0)