Skip to content

Commit 900508e

Browse files
committed
introduce simple_htlc for communicating HTLCs to hsmd
1 parent 9b8bb9d commit 900508e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+191
-161
lines changed

channeld/channeld.c

Lines changed: 19 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,27 +1066,20 @@ static struct bitcoin_signature *calc_commitsigs(const tal_t *ctx,
10661066
// We use the existing_htlc to_wire routines, it's unfortunate that
10671067
// we have to send a dummy onion_routing_packet ...
10681068
//
1069-
struct existing_htlc **htlcs = tal_arr(tmpctx, struct existing_htlc *, 0);
1070-
u8 dummy_onion_routing_packet[TOTAL_PACKET_SIZE(ROUTING_INFO_SIZE)];
1071-
memset(dummy_onion_routing_packet, 0, sizeof(dummy_onion_routing_packet));
1069+
struct simple_htlc **htlcs = tal_arr(tmpctx, struct simple_htlc *, 0);
10721070
size_t num_entries = tal_count(htlc_map);
10731071
for (size_t ndx = 0; ndx < num_entries; ++ndx) {
10741072
struct htlc const *hh = htlc_map[ndx];
10751073
if (hh) {
10761074
status_debug("HTLC[%lu]=%" PRIu64 ", %s",
10771075
ndx, hh->id, htlc_state_name(hh->state));
1078-
struct existing_htlc *existing =
1079-
new_existing_htlc(NULL,
1080-
hh->id,
1081-
hh->state,
1082-
hh->amount,
1083-
&hh->rhash,
1084-
hh->expiry.locktime,
1085-
dummy_onion_routing_packet,
1086-
NULL,
1087-
NULL,
1088-
NULL);
1089-
tal_arr_expand(&htlcs, tal_steal(htlcs, existing));
1076+
struct simple_htlc *simple =
1077+
new_simple_htlc(NULL,
1078+
htlc_state_owner(hh->state),
1079+
hh->amount,
1080+
&hh->rhash,
1081+
hh->expiry.locktime);
1082+
tal_arr_expand(&htlcs, tal_steal(htlcs, simple));
10901083
}
10911084
}
10921085

@@ -1095,7 +1088,7 @@ static struct bitcoin_signature *calc_commitsigs(const tal_t *ctx,
10951088
&peer->remote_per_commit,
10961089
peer->channel->option_static_remotekey,
10971090
commit_index,
1098-
(const struct existing_htlc **) htlcs,
1091+
(const struct simple_htlc **) htlcs,
10991092
channel_feerate(peer->channel, REMOTE));
11001093
msg = hsm_req(tmpctx, take(msg));
11011094
if (!fromwire_hsmd_sign_tx_reply(msg, commit_sig))
@@ -1766,38 +1759,31 @@ static void handle_peer_commit_sig(struct peer *peer, const u8 *msg)
17661759

17671760
// Collect the htlcs for call to hsmd validate.
17681761
//
1769-
// We use the existing_htlc to_wire routines, it's unfortunate that
1762+
// We use the simple_htlc to_wire routines, it's unfortunate that
17701763
// we have to send a dummy onion_routing_packet ...
17711764
//
1772-
struct existing_htlc **htlcs = tal_arr(NULL, struct existing_htlc *, 0);
1773-
u8 dummy_onion_routing_packet[TOTAL_PACKET_SIZE(ROUTING_INFO_SIZE)];
1774-
memset(dummy_onion_routing_packet, 0, sizeof(dummy_onion_routing_packet));
1765+
struct simple_htlc **htlcs = tal_arr(NULL, struct simple_htlc *, 0);
17751766
size_t num_entries = tal_count(htlc_map);
17761767
for (size_t ndx = 0; ndx < num_entries; ++ndx) {
17771768
struct htlc const *hh = htlc_map[ndx];
17781769
if (hh) {
17791770
status_debug("HTLC[%lu]=%" PRIu64 ", %s",
17801771
ndx, hh->id, htlc_state_name(hh->state));
1781-
struct existing_htlc *existing =
1782-
new_existing_htlc(NULL,
1783-
hh->id,
1784-
hh->state,
1785-
hh->amount,
1786-
&hh->rhash,
1787-
hh->expiry.locktime,
1788-
dummy_onion_routing_packet,
1789-
NULL,
1790-
NULL,
1791-
NULL);
1792-
tal_arr_expand(&htlcs, tal_steal(htlcs, existing));
1772+
struct simple_htlc *simple =
1773+
new_simple_htlc(NULL,
1774+
htlc_state_owner(hh->state),
1775+
hh->amount,
1776+
&hh->rhash,
1777+
hh->expiry.locktime);
1778+
tal_arr_expand(&htlcs, tal_steal(htlcs, simple));
17931779
}
17941780
}
17951781

17961782
// Validate the counterparty's signatures, returns old_secret.
17971783
const u8 * msg2 =
17981784
towire_hsmd_validate_commitment_tx(NULL,
17991785
txs[0],
1800-
(const struct existing_htlc **) htlcs,
1786+
(const struct simple_htlc **) htlcs,
18011787
peer->next_index[LOCAL],
18021788
channel_feerate(peer->channel, LOCAL),
18031789
&commit_sig,

channeld/channeld_wiregen.c

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

channeld/channeld_wiregen.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

closingd/closingd_wiregen.c

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

closingd/closingd_wiregen.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

common/htlc_wire.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,20 @@ struct failed_htlc *failed_htlc_dup(const tal_t *ctx,
2828
return newf;
2929
}
3030

31+
struct simple_htlc *new_simple_htlc(const tal_t *ctx,
32+
enum side side,
33+
struct amount_msat amount,
34+
const struct sha256 *payment_hash,
35+
u32 cltv_expiry)
36+
{
37+
struct simple_htlc *simple = tal(NULL, struct simple_htlc);
38+
simple->side = side;
39+
simple->amount = amount;
40+
simple->payment_hash = *payment_hash;
41+
simple->cltv_expiry = cltv_expiry;
42+
return simple;
43+
}
44+
3145
struct existing_htlc *new_existing_htlc(const tal_t *ctx,
3246
u64 id,
3347
enum htlc_state state,
@@ -109,6 +123,14 @@ void towire_existing_htlc(u8 **pptr, const struct existing_htlc *existing)
109123
towire_bool(pptr, false);
110124
}
111125

126+
void towire_simple_htlc(u8 **pptr, const struct simple_htlc *simple)
127+
{
128+
towire_side(pptr, simple->side);
129+
towire_amount_msat(pptr, simple->amount);
130+
towire_sha256(pptr, &simple->payment_hash);
131+
towire_u32(pptr, simple->cltv_expiry);
132+
}
133+
112134
void towire_fulfilled_htlc(u8 **pptr, const struct fulfilled_htlc *fulfilled)
113135
{
114136
towire_u64(pptr, fulfilled->id);
@@ -205,6 +227,18 @@ struct existing_htlc *fromwire_existing_htlc(const tal_t *ctx,
205227
return existing;
206228
}
207229

230+
struct simple_htlc *fromwire_simple_htlc(const tal_t *ctx,
231+
const u8 **cursor, size_t *max)
232+
{
233+
struct simple_htlc *simple = tal(ctx, struct simple_htlc);
234+
235+
simple->side = fromwire_side(cursor, max);
236+
simple->amount = fromwire_amount_msat(cursor, max);
237+
fromwire_sha256(cursor, max, &simple->payment_hash);
238+
simple->cltv_expiry = fromwire_u32(cursor, max);
239+
return simple;
240+
}
241+
208242
void fromwire_fulfilled_htlc(const u8 **cursor, size_t *max,
209243
struct fulfilled_htlc *fulfilled)
210244
{

common/htlc_wire.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ struct changed_htlc {
6565
u64 id;
6666
};
6767

68+
/* For signing */
69+
struct simple_htlc {
70+
enum side side;
71+
struct amount_msat amount;
72+
struct sha256 payment_hash;
73+
u32 cltv_expiry;
74+
};
75+
6876
struct existing_htlc *new_existing_htlc(const tal_t *ctx,
6977
u64 id,
7078
enum htlc_state state,
@@ -76,10 +84,17 @@ struct existing_htlc *new_existing_htlc(const tal_t *ctx,
7684
const struct preimage *preimage TAKES,
7785
const struct failed_htlc *failed TAKES);
7886

87+
struct simple_htlc *new_simple_htlc(const tal_t *ctx,
88+
enum side side,
89+
struct amount_msat amount,
90+
const struct sha256 *payment_hash,
91+
u32 cltv_expiry);
92+
7993
struct failed_htlc *failed_htlc_dup(const tal_t *ctx, const struct failed_htlc *f TAKES);
8094

8195
void towire_added_htlc(u8 **pptr, const struct added_htlc *added);
8296
void towire_existing_htlc(u8 **pptr, const struct existing_htlc *existing);
97+
void towire_simple_htlc(u8 **pptr, const struct simple_htlc *simple);
8398
void towire_fulfilled_htlc(u8 **pptr, const struct fulfilled_htlc *fulfilled);
8499
void towire_failed_htlc(u8 **pptr, const struct failed_htlc *failed);
85100
void towire_changed_htlc(u8 **pptr, const struct changed_htlc *changed);
@@ -91,6 +106,8 @@ void fromwire_added_htlc(const u8 **cursor, size_t *max,
91106
struct added_htlc *added);
92107
struct existing_htlc *fromwire_existing_htlc(const tal_t *ctx,
93108
const u8 **cursor, size_t *max);
109+
struct simple_htlc *fromwire_simple_htlc(const tal_t *ctx,
110+
const u8 **cursor, size_t *max);
94111
void fromwire_fulfilled_htlc(const u8 **cursor, size_t *max,
95112
struct fulfilled_htlc *fulfilled);
96113
struct failed_htlc *fromwire_failed_htlc(const tal_t *ctx, const u8 **cursor,

common/peer_status_wiregen.c

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

common/peer_status_wiregen.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

common/status_wiregen.c

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)