Skip to content

Commit 554241e

Browse files
fixup! channeld: wip: be able to handle the update htlc by handling the endorsed field
1 parent 8a3cc9c commit 554241e

File tree

1 file changed

+40
-4
lines changed

1 file changed

+40
-4
lines changed

channeld/channeld.c

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -971,9 +971,29 @@ static void handle_peer_add_htlc(struct peer *peer, const u8 *msg)
971971
peer_failed_warn(peer->pps, &peer->channel_id,
972972
"Bad peer_add_htlc %s", tal_hex(msg, msg));
973973
}
974+
/* FIXME(vincenzopalazzo): We should check if the endorse value is zero or missing:
975+
*
976+
* BOLT 2 (0539ad868a263040087d2790684f69fb28d3fa97):
977+
* - if `endorsed` is not provided OR `endorsed` is zero:
978+
* - MAY choose to limit the liquidity and slots available to forward the
979+
* corresponding outgoing HTLC in `onion_routing_packet`, if any.*/
980+
981+
// FIXME(vincenzopalazzo): we should implement the hook to communicate to the
982+
// HTLC tlvs to plugins and give a possibility to change it (Wait but this is always safe? mh).
974983
add_err = channel_add_htlc(peer->channel, REMOTE, id, amount,
975984
cltv_expiry, &payment_hash,
976985
onion_routing_packet, tlvs->blinding_point, &htlc, NULL,
986+
/* BOLT 2 (0539ad868a263040087d2790684f69fb28d3fa97):
987+
* - otherwise:
988+
* - if `endorsed` is present and non-zero for the corresponding incoming HTLC
989+
* AND the incoming peer is considered to have sufficient local reputation
990+
* (see [Local Reputation](recommendations/local-resource-conservation.md#local-reputation)):
991+
* - SHOULD set `endorsed` to `1`
992+
* - otherwise:
993+
* - SHOULD set `endorsed` to `0`.
994+
*
995+
* FIXME(vincenzopalazzo): We should implement and consult the local reputation
996+
* but currently we just forward it because we should implement the local reputation before.*/
977997
tlvs->endorsed,
978998
/* We don't immediately fail incoming htlcs,
979999
* instead we wait and fail them after
@@ -5231,9 +5251,11 @@ static const u8 *get_cupdate(const struct peer *peer)
52315251
return peer->channel_update;
52325252
}
52335253

5254+
/* Offer an HTLC to the remote side. */
52345255
static void handle_offer_htlc(struct peer *peer, const u8 *inmsg)
52355256
{
52365257
u8 *msg;
5258+
bool endorsed;
52375259
u32 cltv_expiry;
52385260
struct amount_msat amount;
52395261
struct sha256 payment_hash;
@@ -5253,22 +5275,36 @@ static void handle_offer_htlc(struct peer *peer, const u8 *inmsg)
52535275
&cltv_expiry, &payment_hash,
52545276
onion_routing_packet, &blinding))
52555277
master_badmsg(WIRE_CHANNELD_OFFER_HTLC, inmsg);
5256-
52575278
if (blinding) {
52585279
tlvs = tlv_update_add_htlc_tlvs_new(tmpctx);
52595280
tlvs->blinding_point = tal_dup(tlvs, struct pubkey, blinding);
52605281
} else
52615282
tlvs = NULL;
52625283

5284+
/* BOLT 2 (0539ad868a263040087d2790684f69fb28d3fa97):
5285+
* A sending node:
5286+
* - if it is the original source of the HTLC:
5287+
* - if it does not expect immediate fulfillment upon receipt by the
5288+
* final destination:
5289+
* - SHOULD set `endorsed` to `0`.
5290+
* - otherwise:
5291+
* - SHOULD set `endorsed` to `1`.
5292+
*
5293+
* FIXME(vincenzopalazzo): In this case we should consult the metrics, but
5294+
* we are not there yet. Also this make me unsure if this is the correct
5295+
* place where calculate the endorsed or the endorsed should came from the
5296+
* channeld_offer_htlc, maybe in lightnind/pay.c would be better. */
5297+
endorsed = false;
52635298
e = channel_add_htlc(peer->channel, LOCAL, peer->htlc_id,
52645299
amount, cltv_expiry, &payment_hash,
52655300
onion_routing_packet, take(blinding), NULL,
5266-
&htlc_fee, false, true);
5267-
status_debug("Adding HTLC %"PRIu64" amount=%s cltv=%u gave %s",
5301+
&htlc_fee, endorsed, true);
5302+
status_debug("Adding HTLC %"PRIu64" amount=%s cltv=%u gave %s endorsed=%d",
52685303
peer->htlc_id,
52695304
type_to_string(tmpctx, struct amount_msat, &amount),
52705305
cltv_expiry,
5271-
channel_add_err_name(e));
5306+
channel_add_err_name(e),
5307+
endorsed);
52725308

52735309
switch (e) {
52745310
case CHANNEL_ERR_ADD_OK:

0 commit comments

Comments
 (0)