@@ -971,9 +971,29 @@ static void handle_peer_add_htlc(struct peer *peer, const u8 *msg)
971
971
peer_failed_warn (peer -> pps , & peer -> channel_id ,
972
972
"Bad peer_add_htlc %s" , tal_hex (msg , msg ));
973
973
}
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).
974
983
add_err = channel_add_htlc (peer -> channel , REMOTE , id , amount ,
975
984
cltv_expiry , & payment_hash ,
976
985
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.*/
977
997
tlvs -> endorsed ,
978
998
/* We don't immediately fail incoming htlcs,
979
999
* instead we wait and fail them after
@@ -5231,9 +5251,11 @@ static const u8 *get_cupdate(const struct peer *peer)
5231
5251
return peer -> channel_update ;
5232
5252
}
5233
5253
5254
+ /* Offer an HTLC to the remote side. */
5234
5255
static void handle_offer_htlc (struct peer * peer , const u8 * inmsg )
5235
5256
{
5236
5257
u8 * msg ;
5258
+ bool endorsed ;
5237
5259
u32 cltv_expiry ;
5238
5260
struct amount_msat amount ;
5239
5261
struct sha256 payment_hash ;
@@ -5253,22 +5275,36 @@ static void handle_offer_htlc(struct peer *peer, const u8 *inmsg)
5253
5275
& cltv_expiry , & payment_hash ,
5254
5276
onion_routing_packet , & blinding ))
5255
5277
master_badmsg (WIRE_CHANNELD_OFFER_HTLC , inmsg );
5256
-
5257
5278
if (blinding ) {
5258
5279
tlvs = tlv_update_add_htlc_tlvs_new (tmpctx );
5259
5280
tlvs -> blinding_point = tal_dup (tlvs , struct pubkey , blinding );
5260
5281
} else
5261
5282
tlvs = NULL ;
5262
5283
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;
5263
5298
e = channel_add_htlc (peer -> channel , LOCAL , peer -> htlc_id ,
5264
5299
amount , cltv_expiry , & payment_hash ,
5265
5300
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 " ,
5268
5303
peer -> htlc_id ,
5269
5304
type_to_string (tmpctx , struct amount_msat , & amount ),
5270
5305
cltv_expiry ,
5271
- channel_add_err_name (e ));
5306
+ channel_add_err_name (e ),
5307
+ endorsed );
5272
5308
5273
5309
switch (e ) {
5274
5310
case CHANNEL_ERR_ADD_OK :
0 commit comments