Skip to content

Commit 631a1d9

Browse files
nepetrustyrussell
authored andcommitted
channeld: Add extra_tlvs to wire htlcs
This appends the extra_tlvs to the internal wire htlcs "added" and "existing" for the extra tlvs to be handed to lightningd. Signed-off-by: Peter Neuroth <[email protected]>
1 parent f4cc633 commit 631a1d9

File tree

4 files changed

+69
-3
lines changed

4 files changed

+69
-3
lines changed

channeld/channeld.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1590,6 +1590,7 @@ static void marshall_htlc_info(const tal_t *ctx,
15901590
htlc->routing,
15911591
sizeof(a.onion_routing_packet));
15921592
a.path_key = htlc->path_key;
1593+
a.extra_tlvs = htlc->extra_tlvs;
15931594
a.fail_immediate = htlc->fail_immediate;
15941595
tal_arr_expand(added, a);
15951596
} else if (htlc->state == RCVD_REMOVE_COMMIT) {

channeld/full_channel.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1632,7 +1632,8 @@ bool channel_force_htlcs(struct channel *channel,
16321632
&htlcs[i]->payment_hash,
16331633
htlcs[i]->onion_routing_packet,
16341634
htlcs[i]->path_key,
1635-
&htlc, false, NULL, NULL, false);
1635+
&htlc, false, NULL,
1636+
htlcs[i]->extra_tlvs, false);
16361637
if (e != CHANNEL_ERR_ADD_OK) {
16371638
status_broken("%s HTLC %"PRIu64" failed error %u",
16381639
htlc_state_owner(htlcs[i]->state) == LOCAL

common/htlc_wire.c

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <ccan/crypto/shachain/shachain.h>
55
#include <common/htlc_wire.h>
66
#include <common/onionreply.h>
7+
#include <wire/tlvstream.h>
78

89
static struct failed_htlc *failed_htlc_dup(const tal_t *ctx,
910
const struct failed_htlc *f TAKES)
@@ -33,7 +34,8 @@ struct existing_htlc *new_existing_htlc(const tal_t *ctx,
3334
const u8 onion_routing_packet[TOTAL_PACKET_SIZE(ROUTING_INFO_SIZE)],
3435
const struct pubkey *path_key TAKES,
3536
const struct preimage *preimage TAKES,
36-
const struct failed_htlc *failed TAKES)
37+
const struct failed_htlc *failed TAKES,
38+
const struct tlv_field *extra_tlvs TAKES)
3739
{
3840
struct existing_htlc *existing = tal(ctx, struct existing_htlc);
3941

@@ -51,6 +53,17 @@ struct existing_htlc *new_existing_htlc(const tal_t *ctx,
5153
existing->failed = failed_htlc_dup(existing, failed);
5254
else
5355
existing->failed = NULL;
56+
if (extra_tlvs) {
57+
existing->extra_tlvs = tal_dup_talarr(existing, struct tlv_field, extra_tlvs);
58+
for (size_t i = 0; i < tal_count(extra_tlvs); i++) {
59+
/* We need to attach the value to the correct parent */
60+
existing->extra_tlvs[i].value
61+
= tal_dup_talarr(existing, u8,
62+
existing->extra_tlvs[i].value);
63+
}
64+
} else {
65+
existing->extra_tlvs = NULL;
66+
}
5467

5568
return existing;
5669
}
@@ -70,6 +83,16 @@ void towire_added_htlc(u8 **pptr, const struct added_htlc *added)
7083
towire_pubkey(pptr, added->path_key);
7184
} else
7285
towire_bool(pptr, false);
86+
if (added->extra_tlvs) {
87+
u8 *tmp_pptr = tal_arr(tmpctx, u8, 0);
88+
towire_tlvstream_raw(&tmp_pptr, added->extra_tlvs);
89+
90+
towire_bool(pptr, true);
91+
towire_u16(pptr, tal_bytelen(tmp_pptr));
92+
towire_u8_array(pptr, tmp_pptr,
93+
tal_bytelen(tmp_pptr));
94+
} else
95+
towire_bool(pptr, false);
7396
towire_bool(pptr, added->fail_immediate);
7497
}
7598

@@ -97,6 +120,16 @@ void towire_existing_htlc(u8 **pptr, const struct existing_htlc *existing)
97120
towire_pubkey(pptr, existing->path_key);
98121
} else
99122
towire_bool(pptr, false);
123+
if (existing->extra_tlvs) {
124+
u8 *tmp_pptr = tal_arr(tmpctx, u8, 0);
125+
towire_tlvstream_raw(&tmp_pptr, existing->extra_tlvs);
126+
127+
towire_bool(pptr, true);
128+
towire_u16(pptr, tal_bytelen(tmp_pptr));
129+
towire_u8_array(pptr, tmp_pptr,
130+
tal_bytelen(tmp_pptr));
131+
} else
132+
towire_bool(pptr, false);
100133
}
101134

102135
void towire_fulfilled_htlc(u8 **pptr, const struct fulfilled_htlc *fulfilled)
@@ -163,6 +196,20 @@ void fromwire_added_htlc(const u8 **cursor, size_t *max,
163196
fromwire_pubkey(cursor, max, added->path_key);
164197
} else
165198
added->path_key = NULL;
199+
if (fromwire_bool(cursor, max)) {
200+
size_t tlv_len = fromwire_u16(cursor, max);
201+
/* NOTE: We might consider to be more strict and only allow for
202+
* known tlv types from the tlvs_tlv_update_add_htlc_tlvs
203+
* record. */
204+
const u64 *allowed = cast_const(u64 *, FROMWIRE_TLV_ANY_TYPE);
205+
added->extra_tlvs = tal_arr(added, struct tlv_field, 0);
206+
if (!fromwire_tlv(cursor, &tlv_len, NULL, 0, added,
207+
&added->extra_tlvs, allowed, NULL, NULL)) {
208+
tal_free(added->extra_tlvs);
209+
added->extra_tlvs = NULL;
210+
}
211+
} else
212+
added->extra_tlvs = NULL;
166213
added->fail_immediate = fromwire_bool(cursor, max);
167214
}
168215

@@ -192,6 +239,20 @@ struct existing_htlc *fromwire_existing_htlc(const tal_t *ctx,
192239
fromwire_pubkey(cursor, max, existing->path_key);
193240
} else
194241
existing->path_key = NULL;
242+
if (fromwire_bool(cursor, max)) {
243+
size_t tlv_len = fromwire_u16(cursor, max);
244+
/* NOTE: We might consider to be more strict and only allow for
245+
* known tlv types from the tlvs_tlv_update_add_htlc_tlvs
246+
* record. */
247+
const u64 *allowed = cast_const(u64 *, FROMWIRE_TLV_ANY_TYPE);
248+
existing->extra_tlvs = tal_arr(existing, struct tlv_field, 0);
249+
if (!fromwire_tlv(cursor, &tlv_len, NULL, 0, existing,
250+
&existing->extra_tlvs, allowed, NULL, NULL)) {
251+
tal_free(existing->extra_tlvs);
252+
existing->extra_tlvs = NULL;
253+
}
254+
} else
255+
existing->extra_tlvs = NULL;
195256
return existing;
196257
}
197258

common/htlc_wire.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ struct added_htlc {
1717
u8 onion_routing_packet[TOTAL_PACKET_SIZE(ROUTING_INFO_SIZE)];
1818
bool fail_immediate;
1919
struct pubkey *path_key;
20+
struct tlv_field *extra_tlvs;
2021
};
2122

2223
/* This is how lightningd tells us about HTLCs which already exist at startup */
@@ -33,6 +34,7 @@ struct existing_htlc {
3334
struct preimage *payment_preimage;
3435
/* If failed, this is set */
3536
const struct failed_htlc *failed;
37+
struct tlv_field *extra_tlvs;
3638
};
3739

3840
struct fulfilled_htlc {
@@ -69,7 +71,8 @@ struct existing_htlc *new_existing_htlc(const tal_t *ctx,
6971
const u8 onion_routing_packet[TOTAL_PACKET_SIZE(ROUTING_INFO_SIZE)],
7072
const struct pubkey *path_key TAKES,
7173
const struct preimage *preimage TAKES,
72-
const struct failed_htlc *failed TAKES);
74+
const struct failed_htlc *failed TAKES,
75+
const struct tlv_field *extra_tlvs TAKES);
7376

7477
void towire_added_htlc(u8 **pptr, const struct added_htlc *added);
7578
void towire_existing_htlc(u8 **pptr, const struct existing_htlc *existing);

0 commit comments

Comments
 (0)