Skip to content

Commit fa8c1b3

Browse files
committed
Add attribution data to onionreply and update_fail_htlc
Adding the optional TLVs to update_fail_htlc and struct onionreply so that we can parse and store it. Key Changes: - Add tlvtype 'attribution_data' to 'update_fail_htlc' msgtype. - Add 'htlc_hold_time' & 'truncated_hmac' to struct onionreply.
1 parent 8e41ee4 commit fa8c1b3

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

common/onionreply.c

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ void towire_onionreply(u8 **cursor, const struct onionreply *r)
88
{
99
towire_u16(cursor, tal_count(r->contents));
1010
towire_u8_array(cursor, r->contents, tal_count(r->contents));
11+
if (r->htlc_hold_time && r->truncated_hmac)
12+
towire_u8_array(cursor, r->htlc_hold_time, 80);
13+
towire_u8_array(cursor, r->truncated_hmac, 840);
1114
}
1215

1316
struct onionreply *fromwire_onionreply(const tal_t *ctx,
@@ -16,6 +19,14 @@ struct onionreply *fromwire_onionreply(const tal_t *ctx,
1619
struct onionreply *r = tal(ctx, struct onionreply);
1720
r->contents = fromwire_tal_arrn(r, cursor, max,
1821
fromwire_u16(cursor, max));
22+
if (*max >= 80 + 840) {
23+
r->htlc_hold_time = fromwire_tal_arrn(r, cursor, max, 80);
24+
r->truncated_hmac = fromwire_tal_arrn(r, cursor, max, 840);
25+
} else {
26+
r->htlc_hold_time = NULL;
27+
r->truncated_hmac = NULL;
28+
}
29+
1930
if (!*cursor)
2031
return tal_free(r);
2132
return r;
@@ -31,12 +42,26 @@ struct onionreply *dup_onionreply(const tal_t *ctx,
3142

3243
n = tal(ctx, struct onionreply);
3344
n->contents = tal_dup_talarr(n, u8, r->contents);
45+
if (r->htlc_hold_time && r->truncated_hmac) {
46+
n->htlc_hold_time = tal_dup_arr(r, u8, r->htlc_hold_time, 80, 0);
47+
n->truncated_hmac = tal_dup_arr(r, u8, r->truncated_hmac, 840, 0);
48+
} else {
49+
n->htlc_hold_time = NULL;
50+
n->truncated_hmac = NULL;
51+
}
3452
return n;
3553
}
3654

37-
struct onionreply *new_onionreply(const tal_t *ctx, const u8 *contents TAKES)
55+
struct onionreply *new_onionreply(const tal_t *ctx, const u8 *contents TAKES, const u8 htlc_hold_time[80] TAKES, const u8 truncated_hmac[840] TAKES)
3856
{
3957
struct onionreply *r = tal(ctx, struct onionreply);
4058
r->contents = tal_dup_talarr(r, u8, contents);
59+
if (htlc_hold_time && truncated_hmac) {
60+
r->htlc_hold_time = tal_dup_arr(r, u8, htlc_hold_time, 80, 0);
61+
r->truncated_hmac = tal_dup_arr(r, u8, truncated_hmac, 840, 0);
62+
} else {
63+
r->htlc_hold_time = NULL;
64+
r->truncated_hmac = NULL;
65+
}
4166
return r;
4267
}

common/onionreply.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
/* A separate type for an onion reply, to differentiate from a wire msg. */
88
struct onionreply {
99
u8 *contents;
10+
u8 *htlc_hold_time;
11+
u8 *truncated_hmac;
1012
};
1113

1214
/**
@@ -20,5 +22,5 @@ struct onionreply *fromwire_onionreply(const tal_t *ctx,
2022
struct onionreply *dup_onionreply(const tal_t *ctx,
2123
const struct onionreply *r TAKES);
2224

23-
struct onionreply *new_onionreply(const tal_t *ctx, const u8 *contents TAKES);
25+
struct onionreply *new_onionreply(const tal_t *ctx, const u8 *contents TAKES, const u8 htlc_hold_time[80] TAKES, const u8 truncated_hmac[840] TAKES);
2426
#endif /* LIGHTNING_COMMON_ONIONREPLY_H */

wire/peer_wire.csv

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,9 @@ msgdata,update_fail_htlc,channel_id,channel_id,
287287
msgdata,update_fail_htlc,id,u64,
288288
msgdata,update_fail_htlc,len,u16,
289289
msgdata,update_fail_htlc,reason,byte,len
290+
tlvtype,update_fail_htlc_tlvs,attribution_data,1
291+
tlvdata,update_fail_htlc_tlvs,attribution_data,htlc_hold_times,u8,80
292+
tlvdata,update_fail_htlc_tlvs,attribution_data,truncated_hmacs,u8,840
290293
msgtype,update_fail_malformed_htlc,135
291294
msgdata,update_fail_malformed_htlc,channel_id,channel_id,
292295
msgdata,update_fail_malformed_htlc,id,u64,

0 commit comments

Comments
 (0)