Skip to content

Commit

Permalink
wip: support endorsed flag on hook
Browse files Browse the repository at this point in the history
Signed-off-by: Vincenzo Palazzo <[email protected]>
  • Loading branch information
vincenzopalazzo committed Oct 13, 2023
1 parent 2d339b5 commit a7eb48a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
7 changes: 5 additions & 2 deletions lightningd/pay.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <lightningd/notification.h>
#include <lightningd/pay.h>
#include <lightningd/peer_control.h>
#include <stdbool.h>
#include <wallet/invoices.h>

/* Routing failure object */
Expand Down Expand Up @@ -768,7 +769,8 @@ static const u8 *send_onion(const tal_t *ctx, struct lightningd *ld,
u64 partid,
u64 groupid,
struct channel *channel,
struct htlc_out **hout)
struct htlc_out **hout,
bool endorsed)
{
const u8 *onion;
unsigned int base_expiry;
Expand All @@ -778,7 +780,8 @@ static const u8 *send_onion(const tal_t *ctx, struct lightningd *ld,
return send_htlc_out(ctx, channel, first_hop->amount,
base_expiry + first_hop->delay,
final_amount, payment_hash,
blinding, partid, groupid, onion, NULL, hout);
blinding, partid, groupid, onion, NULL, hout,
endorsed);
}

static struct command_result *check_invoice_request_usage(struct command *cmd,
Expand Down
12 changes: 8 additions & 4 deletions lightningd/peer_htlcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,8 @@ const u8 *send_htlc_out(const tal_t *ctx,
u64 groupid,
const u8 *onion_routing_packet,
struct htlc_in *in,
struct htlc_out **houtp)
struct htlc_out **houtp,
bool endorsed)
{
u8 *msg;

Expand Down Expand Up @@ -646,6 +647,7 @@ const u8 *send_htlc_out(const tal_t *ctx,
*houtp);
}

// FIXME: add the `endorsed` variable here
msg = towire_channeld_offer_htlc(out, amount, cltv, payment_hash,
onion_routing_packet, blinding);
subd_req(out->peer->ld, out->owner, take(msg), -1, 0, rcvd_htlc_reply,
Expand Down Expand Up @@ -700,7 +702,8 @@ static void forward_htlc(struct htlc_in *hin,
const struct short_channel_id *forward_scid,
const struct channel_id *forward_to,
const u8 next_onion[TOTAL_PACKET_SIZE(ROUTING_INFO_SIZE)],
const struct pubkey *next_blinding)
const struct pubkey *next_blinding,
const bool endorsed)
{
const u8 *failmsg;
struct lightningd *ld = hin->key.channel->peer->ld;
Expand Down Expand Up @@ -811,7 +814,7 @@ static void forward_htlc(struct htlc_in *hin,
outgoing_cltv_value, AMOUNT_MSAT(0),
&hin->payment_hash,
next_blinding, 0 /* partid */, 0 /* groupid */,
next_onion, hin, &hout);
next_onion, hin, &hout, endorsed);
if (!failmsg)
return;

Expand Down Expand Up @@ -1144,7 +1147,7 @@ htlc_accepted_hook_final(struct htlc_accepted_hook_payload *request STEALS)
request->payload->forward_channel,
request->fwd_channel_id,
serialize_onionpacket(tmpctx, rs->next),
request->next_blinding);
request->next_blinding, false /*endorsed*/);
} else
handle_localpay(hin,
request->payload->amt_to_forward,
Expand Down Expand Up @@ -1184,6 +1187,7 @@ static bool ecdh_maybe_blinding(const struct pubkey *ephemeral_key,
return true;
}

// FIXME: this is the way to implement the hook
REGISTER_PLUGIN_HOOK(htlc_accepted,
htlc_accepted_hook_deserialize,
htlc_accepted_hook_final,
Expand Down
3 changes: 2 additions & 1 deletion lightningd/peer_htlcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ const u8 *send_htlc_out(const tal_t *ctx,
u64 groupid,
const u8 *onion_routing_packet,
struct htlc_in *in,
struct htlc_out **houtp);
struct htlc_out **houtp,
bool endorsed);

void onchain_failed_our_htlc(const struct channel *channel,
const struct htlc_stub *htlc,
Expand Down

0 comments on commit a7eb48a

Please sign in to comment.