Skip to content

Commit b67ae70

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 b689dac commit b67ae70

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

channeld/channeld.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2367,10 +2367,11 @@ static void handle_peer_fail_htlc(struct peer *peer, const u8 *msg)
23672367
u8 *reason;
23682368
struct htlc *htlc;
23692369
struct failed_htlc *f;
2370+
struct tlv_update_fail_htlc_tlvs *tlvs_attr_data;
23702371

23712372
/* reason is not an onionreply because spec doesn't know about that */
23722373
if (!fromwire_update_fail_htlc(msg, msg,
2373-
&channel_id, &id, &reason)) {
2374+
&channel_id, &id, &reason, &tlvs_attr_data)) {
23742375
peer_failed_warn(peer->pps, &peer->channel_id,
23752376
"Bad update_fail_htlc %s", tal_hex(msg, msg));
23762377
}
@@ -2381,7 +2382,10 @@ static void handle_peer_fail_htlc(struct peer *peer, const u8 *msg)
23812382
htlc->failed = f = tal(htlc, struct failed_htlc);
23822383
f->id = id;
23832384
f->sha256_of_onion = NULL;
2384-
f->onion = new_onionreply(f, take(reason));
2385+
f->onion = new_onionreply(f, take(reason),
2386+
tlvs_attr_data->attribution_data->htlc_hold_times,
2387+
tlvs_attr_data->attribution_data->truncated_hmacs);
2388+
23852389
start_commit_timer(peer);
23862390
return;
23872391
}
@@ -4621,8 +4625,12 @@ static void send_fail_or_fulfill(struct peer *peer, const struct htlc *h)
46214625
f->sha256_of_onion,
46224626
f->badonion);
46234627
} else {
4628+
struct tlv_update_fail_htlc_tlvs *attr_data_tlv = tlv_update_fail_htlc_tlvs_new(peer);
4629+
attr_data_tlv->attribution_data = tal(peer, struct tlv_update_fail_htlc_tlvs_attribution_data);
4630+
memcpy(attr_data_tlv->attribution_data->htlc_hold_times, f->onion->htlc_hold_time, 80);
4631+
memcpy(attr_data_tlv->attribution_data->truncated_hmacs, f->onion->truncated_hmac, 840);
46244632
msg = towire_update_fail_htlc(peer, &peer->channel_id, h->id,
4625-
f->onion->contents);
4633+
f->onion->contents, attr_data_tlv);
46264634
}
46274635
} else if (h->r) {
46284636
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, 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)