Skip to content

Commit 8152a0a

Browse files
committed
Serialize and deserialize attr data
Sending attr data while sending update_fail_htlc and processing the attr data when received a update_fail_htlc msg. Key Changes: - Serializing updated attr data inside send_fail_or_fulfill. - Deserializing and processing the TLVs while parsing recvd update_fail_htlc msg.
1 parent 7bf121f commit 8152a0a

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

channeld/channeld.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2577,10 +2577,11 @@ static void handle_peer_fail_htlc(struct peer *peer, const u8 *msg)
25772577
u8 *reason;
25782578
struct htlc *htlc;
25792579
struct failed_htlc *f;
2580+
struct tlv_update_fail_htlc_tlvs *tlvs_attr_data;
25802581

25812582
/* reason is not an onionreply because spec doesn't know about that */
25822583
if (!fromwire_update_fail_htlc(msg, msg,
2583-
&channel_id, &id, &reason)) {
2584+
&channel_id, &id, &reason, &tlvs_attr_data)) {
25842585
peer_failed_warn(peer->pps, &peer->channel_id,
25852586
"Bad update_fail_htlc %s", tal_hex(msg, msg));
25862587
}
@@ -2591,7 +2592,12 @@ static void handle_peer_fail_htlc(struct peer *peer, const u8 *msg)
25912592
htlc->failed = f = tal(htlc, struct failed_htlc);
25922593
f->id = id;
25932594
f->sha256_of_onion = NULL;
2594-
f->onion = new_onionreply(f, take(reason));
2595+
struct attribution_data *attr = tal(f, struct attribution_data);
2596+
attr->htlc_hold_time = tal_dup_arr(f, u8, tlvs_attr_data->attribution_data->htlc_hold_times, 80, 0);
2597+
attr->truncated_hmac = tal_dup_arr(f, u8, tlvs_attr_data->attribution_data->truncated_hmacs, 840, 0);
2598+
f->onion = new_onionreply(f, take(reason),
2599+
attr);
2600+
25952601
start_commit_timer(peer);
25962602
return;
25972603
}
@@ -4964,8 +4970,12 @@ static void send_fail_or_fulfill(struct peer *peer, const struct htlc *h)
49644970
f->sha256_of_onion,
49654971
f->badonion);
49664972
} else {
4973+
struct tlv_update_fail_htlc_tlvs *attr_data_tlv = tlv_update_fail_htlc_tlvs_new(peer);
4974+
attr_data_tlv->attribution_data = tal(peer, struct tlv_update_fail_htlc_tlvs_attribution_data);
4975+
memcpy(attr_data_tlv->attribution_data->htlc_hold_times, f->onion->attr_data->htlc_hold_time, 80);
4976+
memcpy(attr_data_tlv->attribution_data->truncated_hmacs, f->onion->attr_data->truncated_hmac, 840);
49674977
msg = towire_update_fail_htlc(peer, &peer->channel_id, h->id,
4968-
f->onion->contents);
4978+
f->onion->contents, attr_data_tlv);
49694979
}
49704980
} else if (h->r) {
49714981
msg = towire_update_fulfill_htlc(NULL, &peer->channel_id, h->id,

lightningd/peer_htlcs.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <ccan/cast/cast.h>
33
#include <ccan/mem/mem.h>
44
#include <ccan/tal/str/str.h>
5+
#include <ccan/time/time.h>
56
#include <channeld/channeld_wiregen.h>
67
#include <common/blinding.h>
78
#include <common/configdir.h>
@@ -10,6 +11,7 @@
1011
#include <common/json_param.h>
1112
#include <common/onion_decode.h>
1213
#include <common/onionreply.h>
14+
#include <common/sphinx.h>
1315
#include <common/timeout.h>
1416
#include <connectd/connectd_wiregen.h>
1517
#include <db/exec.h>
@@ -313,16 +315,22 @@ static void fail_out_htlc(struct htlc_out *hout, const char *localfail)
313315
hout->failmsg,
314316
localfail);
315317
} else if (hout->in) {
318+
const struct onionreply *final_failonion;
319+
struct onionreply *failonion;
316320
const u32 hold_times = time_between(time_now(), hout->send_timestamp).ts.tv_nsec/1000000;
317321
/* If we have an onion, simply copy it. */
318322
if (hout->failonion)
319-
failonion = hout->failonion;
323+
failonion = dup_onionreply(hout, hout->failonion);
320324
/* Otherwise, we need to onionize this local error. */
321325
else
322326
failonion = create_onionreply(hout,
323327
hout->in->shared_secret,
324328
hout->failmsg);
325-
fail_in_htlc(hout->in, failonion);
329+
330+
update_attributable_data(failonion, hold_times, hout->in->shared_secret);
331+
332+
final_failonion = failonion;
333+
fail_in_htlc(hout->in, final_failonion);
326334
} else {
327335
log_broken(hout->key.channel->log, "Neither origin nor in?");
328336
}

plugins/renepay/json.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ static bool get_data_details_onionreply(struct payment_result *result,
9090
goto fail;
9191
onionreply = new_onionreply(
9292
this_ctx,
93-
take(json_tok_bin_from_hex(this_ctx, buffer, onionreplytok)));
93+
take(json_tok_bin_from_hex(this_ctx, buffer, onionreplytok)), NULL);
9494
assert(onionreply);
9595
/* FIXME: It seems that lightningd will unwrap top portion of the
9696
* onionreply for us before serializing it, while unwrap_onionreply will

0 commit comments

Comments
 (0)