Skip to content

Commit a7aac65

Browse files
committed
channeld: Add extra_tlvs to incomming wire msg
This appends the extra_tlvs to the internal channeld_offer_htlc wire msg. We also recombine the extra_tlvs with the blinded path key for forwarding htlcs. Signed-off-by: Peter Neuroth <[email protected]>
1 parent 3ed8588 commit a7aac65

File tree

6 files changed

+49
-28
lines changed

6 files changed

+49
-28
lines changed

channeld/channeld.c

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5991,27 +5991,57 @@ static void handle_offer_htlc(struct peer *peer, const u8 *inmsg)
59915991
const char *failstr;
59925992
struct amount_sat htlc_fee;
59935993
struct pubkey *path_key;
5994-
struct tlv_update_add_htlc_tlvs *tlvs;
5994+
struct tlv_field *extra_tlvs;
5995+
struct tlv_update_add_htlc_tlvs *tlvs = NULL;
5996+
u8 *extra_tlvs_raw;
59955997

59965998
if (!peer->channel_ready[LOCAL] || !peer->channel_ready[REMOTE])
59975999
status_failed(STATUS_FAIL_MASTER_IO,
59986000
"funding not locked for offer_htlc");
59996001

60006002
if (!fromwire_channeld_offer_htlc(tmpctx, inmsg, &amount,
60016003
&cltv_expiry, &payment_hash,
6002-
onion_routing_packet, &path_key))
6004+
onion_routing_packet, &path_key, &extra_tlvs_raw))
60036005
master_badmsg(WIRE_CHANNELD_OFFER_HTLC, inmsg);
60046006

6005-
if (path_key) {
6007+
6008+
if (extra_tlvs_raw || path_key) {
60066009
tlvs = tlv_update_add_htlc_tlvs_new(tmpctx);
6010+
}
6011+
if (extra_tlvs_raw) {
6012+
const u8 *cursor = extra_tlvs_raw;
6013+
size_t max = tal_bytelen(extra_tlvs_raw);
6014+
u64 failedtype;
6015+
const u64 *allowed = cast_const(u64 *, FROMWIRE_TLV_ANY_TYPE);
6016+
if (!fromwire_tlv(&cursor, &max, NULL, 0,
6017+
tlvs, &tlvs->fields,
6018+
allowed, NULL, &failedtype)) {
6019+
status_unusual("Malformed TLV type %"PRIu64": %s",
6020+
failedtype, tal_hex(tmpctx, extra_tlvs_raw));
6021+
}
6022+
6023+
extra_tlvs = tal_arr(tmpctx, struct tlv_field, 0);
6024+
for (size_t i = 0; i < tal_count(tlvs->fields); i++) {
6025+
/* We need to clone the fields to set the correct
6026+
* tal parent for the value and to be able to "take" in
6027+
* channel_add_htlc. */
6028+
struct tlv_field field;
6029+
field.length = tlvs->fields[i].length;
6030+
field.numtype = tlvs->fields[i].numtype;
6031+
field.value = tal_dup_arr(extra_tlvs, u8,
6032+
tlvs->fields[i].value,
6033+
field.length, 0);
6034+
tal_arr_expand(&extra_tlvs,field);
6035+
}
6036+
}
6037+
if (path_key) {
60076038
tlvs->blinded_path = tal_dup(tlvs, struct pubkey, path_key);
6008-
} else
6009-
tlvs = NULL;
6039+
}
60106040

60116041
e = channel_add_htlc(peer->channel, LOCAL, peer->htlc_id,
60126042
amount, cltv_expiry, &payment_hash,
60136043
onion_routing_packet, take(path_key), NULL,
6014-
&htlc_fee, NULL, true);
6044+
&htlc_fee, take(extra_tlvs), true);
60156045
status_debug("Adding HTLC %"PRIu64" amount=%s cltv=%u gave %s",
60166046
peer->htlc_id,
60176047
fmt_amount_msat(tmpctx, amount),

channeld/channeld_wire.csv

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ msgdata,channeld_offer_htlc,cltv_expiry,u32,
9494
msgdata,channeld_offer_htlc,payment_hash,sha256,
9595
msgdata,channeld_offer_htlc,onion_routing_packet,u8,1366
9696
msgdata,channeld_offer_htlc,path_key,?pubkey,
97+
msgdata,channeld_offer_htlc,extra_tlvs_len,u16,
98+
msgdata,channeld_offer_htlc,extra_tlvs,u8,extra_tlvs_len
9799

98100
# Reply; synchronous since IDs have to increment.
99101
msgtype,channeld_offer_htlc_reply,1104

lightningd/peer_htlcs.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ const u8 *send_htlc_out(const tal_t *ctx,
701701
struct htlc_in *in,
702702
struct htlc_out **houtp)
703703
{
704-
u8 *msg;
704+
u8 *msg, *raw_tlvs = NULL;
705705

706706
*houtp = NULL;
707707

@@ -743,7 +743,8 @@ const u8 *send_htlc_out(const tal_t *ctx,
743743
}
744744

745745
msg = towire_channeld_offer_htlc(out, amount, cltv, payment_hash,
746-
onion_routing_packet, path_key);
746+
onion_routing_packet, path_key,
747+
raw_tlvs);
747748
subd_req(out->peer->ld, out->owner, take(msg), -1, 0, rcvd_htlc_reply,
748749
*houtp);
749750

@@ -2646,7 +2647,7 @@ const struct existing_htlc **peer_htlcs(const tal_t *ctx,
26462647
hin->onion_routing_packet,
26472648
hin->path_key,
26482649
hin->preimage,
2649-
f);
2650+
f, NULL);
26502651
tal_arr_expand(&htlcs, existing);
26512652
}
26522653

@@ -2678,7 +2679,7 @@ const struct existing_htlc **peer_htlcs(const tal_t *ctx,
26782679
hout->onion_routing_packet,
26792680
hout->path_key,
26802681
hout->preimage,
2681-
f);
2682+
f, NULL);
26822683
tal_arr_expand(&htlcs, existing);
26832684
}
26842685

tests/plugins/channeld_fakenet.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,7 @@ static void delayed_forward(struct delayed_forward *dfwd)
871871

872872
static void handle_offer_htlc(struct info *info, const u8 *inmsg)
873873
{
874-
u8 *msg;
874+
u8 *msg, *extratlvs;
875875
u32 cltv_expiry;
876876
struct amount_msat amount;
877877
u8 onion_routing_packet[TOTAL_PACKET_SIZE(ROUTING_INFO_SIZE)];
@@ -887,7 +887,7 @@ static void handle_offer_htlc(struct info *info, const u8 *inmsg)
887887
htlc->htlc_id = htlc_id;
888888
if (!fromwire_channeld_offer_htlc(tmpctx, inmsg, &amount,
889889
&cltv_expiry, &htlc->payment_hash,
890-
onion_routing_packet, &blinding))
890+
onion_routing_packet, &blinding, &extratlvs))
891891
master_badmsg(WIRE_CHANNELD_OFFER_HTLC, inmsg);
892892

893893
e = channel_add_htlc(info->channel, LOCAL, htlc->htlc_id,

wallet/test/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ WALLET_TEST_COMMON_OBJS := \
3030
common/utxo.o \
3131
common/wireaddr.o \
3232
common/version.o \
33+
common/bigsize.o \
3334
wallet/db_sqlite3_sqlgen.o \
3435
wire/towire.o \
35-
wire/fromwire.o
36+
wire/fromwire.o \
37+
wire/tlvstream.o
3638

3739
$(WALLET_TEST_PROGRAMS): $(BITCOIN_OBJS) $(WALLET_TEST_COMMON_OBJS)
3840
$(WALLET_TEST_OBJS): $(WALLET_HDRS) $(WALLET_SRC)

wallet/test/run-wallet.c

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@ static void test_error(struct lightningd *ld, bool fatal, const char *fmt, va_li
4646
void add_node_announcement_sig(u8 *nannounce UNNEEDED,
4747
const secp256k1_ecdsa_signature *sig UNNEEDED)
4848
{ fprintf(stderr, "add_node_announcement_sig called!\n"); abort(); }
49-
/* Generated stub for bigsize_put */
50-
size_t bigsize_put(u8 buf[BIGSIZE_MAX_LEN] UNNEEDED, bigsize_t v UNNEEDED)
51-
{ fprintf(stderr, "bigsize_put called!\n"); abort(); }
5249
/* Generated stub for bitcoind_getrawblockbyheight_ */
5350
void bitcoind_getrawblockbyheight_(const tal_t *ctx UNNEEDED,
5451
struct bitcoind *bitcoind UNNEEDED,
@@ -368,12 +365,6 @@ bool fromwire_onchaind_dev_memleak_reply(const void *p UNNEEDED, bool *leak UNNE
368365
/* Generated stub for fromwire_openingd_dev_memleak_reply */
369366
bool fromwire_openingd_dev_memleak_reply(const void *p UNNEEDED, bool *leak UNNEEDED)
370367
{ fprintf(stderr, "fromwire_openingd_dev_memleak_reply called!\n"); abort(); }
371-
/* Generated stub for fromwire_tlv */
372-
bool fromwire_tlv(const u8 **cursor UNNEEDED, size_t *max UNNEEDED,
373-
const struct tlv_record_type *types UNNEEDED, size_t num_types UNNEEDED,
374-
void *record UNNEEDED, struct tlv_field **fields UNNEEDED,
375-
const u64 *extra_types UNNEEDED, size_t *err_off UNNEEDED, u64 *err_type UNNEEDED)
376-
{ fprintf(stderr, "fromwire_tlv called!\n"); abort(); }
377368
/* Generated stub for get_network_blockheight */
378369
u32 get_network_blockheight(const struct chain_topology *topo UNNEEDED)
379370
{ fprintf(stderr, "get_network_blockheight called!\n"); abort(); }
@@ -1079,7 +1070,7 @@ u8 *towire_channeld_got_commitsig_reply(const tal_t *ctx UNNEEDED)
10791070
u8 *towire_channeld_got_revoke_reply(const tal_t *ctx UNNEEDED)
10801071
{ fprintf(stderr, "towire_channeld_got_revoke_reply called!\n"); abort(); }
10811072
/* Generated stub for towire_channeld_offer_htlc */
1082-
u8 *towire_channeld_offer_htlc(const tal_t *ctx UNNEEDED, struct amount_msat amount_msat UNNEEDED, u32 cltv_expiry UNNEEDED, const struct sha256 *payment_hash UNNEEDED, const u8 onion_routing_packet[1366] UNNEEDED, const struct pubkey *path_key UNNEEDED)
1073+
u8 *towire_channeld_offer_htlc(const tal_t *ctx UNNEEDED, struct amount_msat amount_msat UNNEEDED, u32 cltv_expiry UNNEEDED, const struct sha256 *payment_hash UNNEEDED, const u8 onion_routing_packet[1366] UNNEEDED, const struct pubkey *path_key UNNEEDED, const u8 *extra_tlvs UNNEEDED)
10831074
{ fprintf(stderr, "towire_channeld_offer_htlc called!\n"); abort(); }
10841075
/* Generated stub for towire_channeld_sending_commitsig_reply */
10851076
u8 *towire_channeld_sending_commitsig_reply(const tal_t *ctx UNNEEDED)
@@ -1185,11 +1176,6 @@ u8 *towire_temporary_channel_failure(const tal_t *ctx UNNEEDED, const u8 *channe
11851176
/* Generated stub for towire_temporary_node_failure */
11861177
u8 *towire_temporary_node_failure(const tal_t *ctx UNNEEDED)
11871178
{ fprintf(stderr, "towire_temporary_node_failure called!\n"); abort(); }
1188-
/* Generated stub for towire_tlv */
1189-
void towire_tlv(u8 **pptr UNNEEDED,
1190-
const struct tlv_record_type *types UNNEEDED, size_t num_types UNNEEDED,
1191-
const void *record UNNEEDED)
1192-
{ fprintf(stderr, "towire_tlv called!\n"); abort(); }
11931179
/* Generated stub for towire_unknown_next_peer */
11941180
u8 *towire_unknown_next_peer(const tal_t *ctx UNNEEDED)
11951181
{ fprintf(stderr, "towire_unknown_next_peer called!\n"); abort(); }

0 commit comments

Comments
 (0)