Skip to content

Commit f62c2ba

Browse files
lightningd: handling the endorsed field
Signed-off-by: Vincenzo Palazzo <[email protected]>
1 parent 3c1d9e4 commit f62c2ba

File tree

5 files changed

+28
-7
lines changed

5 files changed

+28
-7
lines changed

channeld/channeld.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,8 @@ static void handle_peer_add_htlc(struct peer *peer, const u8 *msg)
974974
add_err = channel_add_htlc(peer->channel, REMOTE, id, amount,
975975
cltv_expiry, &payment_hash,
976976
onion_routing_packet, tlvs->blinding_point, &htlc, NULL,
977+
/* We just forward it :) smart ah? */
978+
tlvs->endorsed,
977979
/* We don't immediately fail incoming htlcs,
978980
* instead we wait and fail them after
979981
* they've been committed */
@@ -5230,9 +5232,11 @@ static const u8 *get_cupdate(const struct peer *peer)
52305232
return peer->channel_update;
52315233
}
52325234

5235+
/* Offer an HTLC to the remote side. */
52335236
static void handle_offer_htlc(struct peer *peer, const u8 *inmsg)
52345237
{
52355238
u8 *msg;
5239+
bool endorsed;
52365240
u32 cltv_expiry;
52375241
struct amount_msat amount;
52385242
struct sha256 payment_hash;
@@ -5252,22 +5256,23 @@ static void handle_offer_htlc(struct peer *peer, const u8 *inmsg)
52525256
&cltv_expiry, &payment_hash,
52535257
onion_routing_packet, &blinding))
52545258
master_badmsg(WIRE_CHANNELD_OFFER_HTLC, inmsg);
5255-
52565259
if (blinding) {
52575260
tlvs = tlv_update_add_htlc_tlvs_new(tmpctx);
52585261
tlvs->blinding_point = tal_dup(tlvs, struct pubkey, blinding);
52595262
} else
52605263
tlvs = NULL;
52615264

5265+
endorsed = false;
52625266
e = channel_add_htlc(peer->channel, LOCAL, peer->htlc_id,
52635267
amount, cltv_expiry, &payment_hash,
52645268
onion_routing_packet, take(blinding), NULL,
5265-
&htlc_fee, true);
5266-
status_debug("Adding HTLC %"PRIu64" amount=%s cltv=%u gave %s",
5269+
&htlc_fee, endorsed, true);
5270+
status_debug("Adding HTLC %"PRIu64" amount=%s cltv=%u gave %s endorsed=%d",
52675271
peer->htlc_id,
52685272
type_to_string(tmpctx, struct amount_msat, &amount),
52695273
cltv_expiry,
5270-
channel_add_err_name(e));
5274+
channel_add_err_name(e),
5275+
endorsed);
52715276

52725277
switch (e) {
52735278
case CHANNEL_ERR_ADD_OK:

channeld/full_channel.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,7 @@ enum channel_add_err channel_add_htlc(struct channel *channel,
928928
const struct pubkey *blinding TAKES,
929929
struct htlc **htlcp,
930930
struct amount_sat *htlc_fee,
931+
const bool endorsed,
931932
bool err_immediate_failures)
932933
{
933934
enum htlc_state state;

channeld/full_channel.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ enum channel_add_err channel_add_htlc(struct channel *channel,
138138
const struct pubkey *blinding TAKES,
139139
struct htlc **htlcp,
140140
struct amount_sat *htlc_fee,
141+
const bool endorsed,
141142
bool err_immediate_failures);
142143

143144
/**

channeld/test/run-full_channel.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ static const struct htlc **include_htlcs(struct channel *channel, enum side side
168168
memset(&preimage, i, sizeof(preimage));
169169
sha256(&hash, &preimage, sizeof(preimage));
170170
e = channel_add_htlc(channel, sender, i, msatoshi, 500+i, &hash,
171-
dummy_routing, NULL, NULL, NULL, true);
171+
dummy_routing, NULL, NULL, NULL, false, true);
172172
assert(e == CHANNEL_ERR_ADD_OK);
173173
htlcs[i] = channel_get_htlc(channel, sender, i);
174174
}
@@ -260,7 +260,7 @@ static void send_and_fulfill_htlc(struct channel *channel,
260260
sha256(&rhash, &r, sizeof(r));
261261

262262
assert(channel_add_htlc(channel, sender, 1337, msatoshi, 900, &rhash,
263-
dummy_routing, NULL, NULL, NULL, true)
263+
dummy_routing, NULL, NULL, NULL, false, true)
264264
== CHANNEL_ERR_ADD_OK);
265265
htlc = channel_get_htlc(channel, sender, 1337);
266266
assert(htlc);

lightningd/pay.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1084,6 +1084,7 @@ send_payment_core(struct lightningd *ld,
10841084
const struct wallet_payment *old_payment;
10851085
struct channel *channel;
10861086
const u8 *failmsg;
1087+
bool endorsed;
10871088
struct htlc_out *hout;
10881089
struct routing_failure *fail;
10891090
struct command_result *ret;
@@ -1116,9 +1117,22 @@ send_payment_core(struct lightningd *ld,
11161117
return command_failed(cmd, data);
11171118
}
11181119

1120+
1121+
/* BOLT 2 (0539ad868a263040087d2790684f69fb28d3fa97):
1122+
* A sending node:
1123+
* - if it is the original source of the HTLC:
1124+
* - if it does not expect immediate fulfillment upon receipt by the
1125+
* final destination:
1126+
* - SHOULD set `endorsed` to `0`.
1127+
* - otherwise:
1128+
* - SHOULD set `endorsed` to `1`.
1129+
*
1130+
* We wait that someone else smarted than me will provide the way to
1131+
* calculate it for now it is just a placesolder. */
1132+
endorsed = false;
11191133
failmsg = send_onion(tmpctx, ld, packet, first_hop, msat,
11201134
rhash, NULL, partid,
1121-
group, channel, &hout);
1135+
group, channel, &hout, endorsed);
11221136

11231137
if (failmsg) {
11241138
fail = immediate_routing_failure(

0 commit comments

Comments
 (0)