Skip to content

Commit f4cc633

Browse files
nepetrustyrussell
authored andcommitted
channeld: add extra_tlvs from update_add_htlc msg
We currently only consider known tlv types in the internal representation of a htlc. This commit adds the remaining unknown tlv fields to the htlc as well. This is in prepareation to forward these to the htlc_accepted_hook. Signed-off-by: Peter Neuroth <[email protected]>
1 parent e3e4116 commit f4cc633

File tree

6 files changed

+45
-13
lines changed

6 files changed

+45
-13
lines changed

channeld/channeld.c

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -621,9 +621,14 @@ static void handle_peer_add_htlc(struct peer *peer, const u8 *msg)
621621
peer_failed_warn(peer->pps, &peer->channel_id,
622622
"Bad peer_add_htlc %s", tal_hex(msg, msg));
623623
}
624+
624625
add_err = channel_add_htlc(peer->channel, REMOTE, id, amount,
625626
cltv_expiry, &payment_hash,
626-
onion_routing_packet, tlvs->blinded_path, &htlc, NULL,
627+
onion_routing_packet,
628+
take(tlvs->blinded_path), &htlc, NULL,
629+
/* NOTE: It might be better to remove the
630+
* blinded_path from the extra_tlvs */
631+
tlvs->fields,
627632
/* We don't immediately fail incoming htlcs,
628633
* instead we wait and fail them after
629634
* they've been committed */
@@ -5201,13 +5206,24 @@ static void resend_commitment(struct peer *peer, struct changed_htlc *last)
52015206
last[i].id);
52025207

52035208
if (h->state == SENT_ADD_COMMIT) {
5204-
struct tlv_update_add_htlc_tlvs *tlvs;
5205-
if (h->path_key) {
5209+
struct tlv_update_add_htlc_tlvs *tlvs = NULL;
5210+
if (h->extra_tlvs || h->path_key) {
52065211
tlvs = tlv_update_add_htlc_tlvs_new(tmpctx);
5207-
tlvs->blinded_path = tal_dup(tlvs, struct pubkey,
5212+
}
5213+
if (h->extra_tlvs) {
5214+
tlvs->fields = tal_dup_talarr(tmpctx,
5215+
struct tlv_field,
5216+
h->extra_tlvs);
5217+
}
5218+
if (h->path_key) {
5219+
/* It is fine to just set the binded_path
5220+
* independent of what is in tlv->fields as the
5221+
* towire logic will serialize unknown fields
5222+
* and known types seperately. */
5223+
tlvs->blinded_path = tal_dup(tlvs,
5224+
struct pubkey,
52085225
h->path_key);
5209-
} else
5210-
tlvs = NULL;
5226+
}
52115227
msg = towire_update_add_htlc(NULL, &peer->channel_id,
52125228
h->id, h->amount,
52135229
&h->rhash,
@@ -6165,7 +6181,7 @@ static void handle_offer_htlc(struct peer *peer, const u8 *inmsg)
61656181
e = channel_add_htlc(peer->channel, LOCAL, peer->htlc_id,
61666182
amount, cltv_expiry, &payment_hash,
61676183
onion_routing_packet, take(path_key), NULL,
6168-
&htlc_fee, true);
6184+
&htlc_fee, NULL, true);
61696185
status_debug("Adding HTLC %"PRIu64" amount=%s cltv=%u gave %s",
61706186
peer->htlc_id,
61716187
fmt_amount_msat(tmpctx, amount),

channeld/channeld_htlc.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <common/htlc.h>
66
#include <common/pseudorand.h>
77
#include <wire/onion_wire.h>
8+
#include <wire/tlvstream.h>
89

910
struct htlc {
1011
/* What's the status. */
@@ -29,6 +30,9 @@ struct htlc {
2930
/* Blinding (optional). */
3031
struct pubkey *path_key;
3132

33+
/* Any extra tlvs attached to this hltc (optional). */
34+
struct tlv_field *extra_tlvs;
35+
3236
/* Should we immediately fail this htlc? */
3337
bool fail_immediate;
3438
};

channeld/full_channel.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,7 @@ static enum channel_add_err add_htlc(struct channel *channel,
588588
struct htlc **htlcp,
589589
bool enforce_aggregate_limits,
590590
struct amount_sat *htlc_fee,
591+
struct tlv_field *extra_tlvs,
591592
bool err_immediate_failures)
592593
{
593594
struct htlc *htlc, *old;
@@ -613,6 +614,15 @@ static enum channel_add_err add_htlc(struct channel *channel,
613614
htlc->failed = NULL;
614615
htlc->r = NULL;
615616
htlc->routing = tal_dup_arr(htlc, u8, routing, TOTAL_PACKET_SIZE(ROUTING_INFO_SIZE), 0);
617+
if (extra_tlvs && tal_count(extra_tlvs) > 0) {
618+
htlc->extra_tlvs = tal_dup_talarr(htlc, struct tlv_field, extra_tlvs);
619+
for (size_t i = 0; i < tal_count(extra_tlvs); i++) {
620+
/* We need to attach the value to the correct parent */
621+
htlc->extra_tlvs[i].value = tal_dup_talarr(htlc, u8, htlc->extra_tlvs[i].value);
622+
}
623+
} else {
624+
htlc->extra_tlvs = NULL;
625+
}
616626

617627
/* FIXME: Change expiry to simple u32 */
618628

@@ -905,6 +915,7 @@ enum channel_add_err channel_add_htlc(struct channel *channel,
905915
const struct pubkey *path_key TAKES,
906916
struct htlc **htlcp,
907917
struct amount_sat *htlc_fee,
918+
struct tlv_field *extra_tlvs,
908919
bool err_immediate_failures)
909920
{
910921
enum htlc_state state;
@@ -923,7 +934,7 @@ enum channel_add_err channel_add_htlc(struct channel *channel,
923934

924935
return add_htlc(channel, state, id, amount, cltv_expiry,
925936
payment_hash, routing, path_key,
926-
htlcp, true, htlc_fee, err_immediate_failures);
937+
htlcp, true, htlc_fee, extra_tlvs, err_immediate_failures);
927938
}
928939

929940
struct htlc *channel_get_htlc(struct channel *channel, enum side sender, u64 id)
@@ -1621,7 +1632,7 @@ bool channel_force_htlcs(struct channel *channel,
16211632
&htlcs[i]->payment_hash,
16221633
htlcs[i]->onion_routing_packet,
16231634
htlcs[i]->path_key,
1624-
&htlc, false, NULL, false);
1635+
&htlc, false, NULL, NULL, false);
16251636
if (e != CHANNEL_ERR_ADD_OK) {
16261637
status_broken("%s HTLC %"PRIu64" failed error %u",
16271638
htlc_state_owner(htlcs[i]->state) == LOCAL

channeld/full_channel.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ struct channel *new_full_channel(const tal_t *ctx,
6868
* @remote_splice_amnt: how much is being spliced in (or out, if -ve) of remote side.
6969
* @other_anchor_outnum: which output (-1 if none) is the !!side anchor
7070
* @funding_pubkeys: The funding pubkeys (specify NULL to use channel's value).
71-
*
7271
* Returns the unsigned commitment transaction for the committed state
7372
* for @side, followed by the htlc transactions in output order and
7473
* fills in @htlc_map, or NULL on key derivation failure.
@@ -115,6 +114,7 @@ u32 actual_feerate(const struct channel *channel,
115114
* @routing: routing information (copied)
116115
* @blinding: optional blinding information for this HTLC.
117116
* @htlcp: optional pointer for resulting htlc: filled in if and only if CHANNEL_ERR_NONE.
117+
* @extra_tlvs: optinal tlvs attached to this HTLC.
118118
* @err_immediate_failures: in some cases (dusty htlcs) we want to immediately
119119
* fail the htlc; for peer incoming don't want to
120120
* error, but rather mark it as failed and fail after
@@ -134,6 +134,7 @@ enum channel_add_err channel_add_htlc(struct channel *channel,
134134
const struct pubkey *blinding TAKES,
135135
struct htlc **htlcp,
136136
struct amount_sat *htlc_fee,
137+
struct tlv_field *extra_tlvs,
137138
bool err_immediate_failures);
138139

139140
/**

channeld/test/run-full_channel.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ static const struct htlc **include_htlcs(struct channel *channel, enum side side
177177
memset(&preimage, i, sizeof(preimage));
178178
sha256(&hash, &preimage, sizeof(preimage));
179179
e = channel_add_htlc(channel, sender, i, msatoshi, 500+i, &hash,
180-
dummy_routing, NULL, NULL, NULL, true);
180+
dummy_routing, NULL, NULL, NULL, NULL, true);
181181
assert(e == CHANNEL_ERR_ADD_OK);
182182
htlcs[i] = channel_get_htlc(channel, sender, i);
183183
}
@@ -269,7 +269,7 @@ static void send_and_fulfill_htlc(struct channel *channel,
269269
sha256(&rhash, &r, sizeof(r));
270270

271271
assert(channel_add_htlc(channel, sender, 1337, msatoshi, 900, &rhash,
272-
dummy_routing, NULL, NULL, NULL, true)
272+
dummy_routing, NULL, NULL, NULL, NULL, true)
273273
== CHANNEL_ERR_ADD_OK);
274274
htlc = channel_get_htlc(channel, sender, 1337);
275275
assert(htlc);

tests/plugins/channeld_fakenet.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,7 @@ static void handle_offer_htlc(struct info *info, const u8 *inmsg)
893893
e = channel_add_htlc(info->channel, LOCAL, htlc->htlc_id,
894894
amount, cltv_expiry, &htlc->payment_hash,
895895
onion_routing_packet, take(blinding), NULL,
896-
&htlc_fee, true);
896+
&htlc_fee, NULL, true);
897897
status_debug("Adding HTLC %"PRIu64" amount=%s cltv=%u gave %s",
898898
htlc->htlc_id, fmt_amount_msat(tmpctx, amount),
899899
cltv_expiry,

0 commit comments

Comments
 (0)