Skip to content

Commit 3ed8588

Browse files
committed
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 6a9fbc8 commit 3ed8588

File tree

4 files changed

+70
-3
lines changed

4 files changed

+70
-3
lines changed

channeld/channeld.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1534,6 +1534,7 @@ static void marshall_htlc_info(const tal_t *ctx,
15341534
htlc->routing,
15351535
sizeof(a.onion_routing_packet));
15361536
a.path_key = htlc->path_key;
1537+
a.extra_tlvs = htlc->extra_tlvs;
15371538
a.fail_immediate = htlc->fail_immediate;
15381539
tal_arr_expand(added, a);
15391540
} 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
@@ -1634,7 +1634,8 @@ bool channel_force_htlcs(struct channel *channel,
16341634
&htlcs[i]->payment_hash,
16351635
htlcs[i]->onion_routing_packet,
16361636
htlcs[i]->path_key,
1637-
&htlc, false, NULL, NULL, false);
1637+
&htlc, false, NULL,
1638+
htlcs[i]->extra_tlvs, false);
16381639
if (e != CHANNEL_ERR_ADD_OK) {
16391640
status_broken("%s HTLC %"PRIu64" failed error %u",
16401641
htlc_state_owner(htlcs[i]->state) == LOCAL

common/htlc_wire.c

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#include "config.h"
2+
#include "wire/tlvstream.h"
23
#include <ccan/array_size/array_size.h>
34
#include <ccan/cast/cast.h>
45
#include <ccan/crypto/shachain/shachain.h>
56
#include <common/htlc_wire.h>
67
#include <common/onionreply.h>
8+
#include <stdio.h>
79

810
static struct failed_htlc *failed_htlc_dup(const tal_t *ctx,
911
const struct failed_htlc *f TAKES)
@@ -33,7 +35,8 @@ struct existing_htlc *new_existing_htlc(const tal_t *ctx,
3335
const u8 onion_routing_packet[TOTAL_PACKET_SIZE(ROUTING_INFO_SIZE)],
3436
const struct pubkey *path_key TAKES,
3537
const struct preimage *preimage TAKES,
36-
const struct failed_htlc *failed TAKES)
38+
const struct failed_htlc *failed TAKES,
39+
const struct tlv_field *extra_tlvs TAKES)
3740
{
3841
struct existing_htlc *existing = tal(ctx, struct existing_htlc);
3942

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

5569
return existing;
5670
}
@@ -70,6 +84,16 @@ void towire_added_htlc(u8 **pptr, const struct added_htlc *added)
7084
towire_pubkey(pptr, added->path_key);
7185
} else
7286
towire_bool(pptr, false);
87+
if (added->extra_tlvs) {
88+
u8 *tmp_pptr = tal_arr(tmpctx, u8, 0);
89+
towire_tlvstream_raw(&tmp_pptr, added->extra_tlvs);
90+
91+
towire_bool(pptr, true);
92+
towire_u16(pptr, tal_bytelen(tmp_pptr));
93+
towire_u8_array(pptr, tmp_pptr,
94+
tal_bytelen(tmp_pptr));
95+
} else
96+
towire_bool(pptr, false);
7397
towire_bool(pptr, added->fail_immediate);
7498
}
7599

@@ -97,6 +121,16 @@ void towire_existing_htlc(u8 **pptr, const struct existing_htlc *existing)
97121
towire_pubkey(pptr, existing->path_key);
98122
} else
99123
towire_bool(pptr, false);
124+
if (existing->extra_tlvs) {
125+
u8 *tmp_pptr = tal_arr(tmpctx, u8, 0);
126+
towire_tlvstream_raw(&tmp_pptr, existing->extra_tlvs);
127+
128+
towire_bool(pptr, true);
129+
towire_u16(pptr, tal_bytelen(tmp_pptr));
130+
towire_u8_array(pptr, tmp_pptr,
131+
tal_bytelen(tmp_pptr));
132+
} else
133+
towire_bool(pptr, false);
100134
}
101135

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

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

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)