Skip to content

Commit

Permalink
fixup! lightningd: allow htlc_accepted hook to replace onion payload.
Browse files Browse the repository at this point in the history
  • Loading branch information
cdecker committed Apr 15, 2020
1 parent 4b4814f commit fce4412
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion lightningd/peer_htlcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,20 @@ htlc_accepted_hook_try_resolve(struct htlc_accepted_hook_payload *request,
}
}

static u8 *prepend_length(const tal_t *ctx, const u8 *payload TAKES)
{
u8 buf[BIGSIZE_MAX_LEN], *ret;
size_t len;

len = bigsize_put(buf, tal_bytelen(payload));
ret = tal_arr(ctx, u8, len + tal_bytelen(payload));
memcpy(ret, buf, len);
memcpy(ret + len, payload, tal_bytelen(payload));
if (taken(payload))
tal_free(payload);
return ret;
}

/**
* Callback when a plugin answers to the htlc_accepted hook
*/
Expand Down Expand Up @@ -888,7 +902,8 @@ static bool htlc_accepted_hook_deserialize(struct htlc_accepted_hook_payload *re
buffer + payloadtok->start);
tal_free(request->payload);
tal_free(rs->raw_payload);
rs->raw_payload = tal_steal(rs, payload);

rs->raw_payload = prepend_length(rs, take(payload));
request->payload = onion_decode(request, rs,
hin->blinding, &hin->blinding_ss,
&request->failtlvtype,
Expand Down

0 comments on commit fce4412

Please sign in to comment.