mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 23:24:27 +01:00
channeld, lightningd: allow blinded payments with !EXPERIMENTAL_FEATURES.
Gate it (where necessary) by the route-blinding feature bit. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -690,31 +690,20 @@ static void handle_peer_add_htlc(struct peer *peer, const u8 *msg)
|
|||||||
u8 onion_routing_packet[TOTAL_PACKET_SIZE(ROUTING_INFO_SIZE)];
|
u8 onion_routing_packet[TOTAL_PACKET_SIZE(ROUTING_INFO_SIZE)];
|
||||||
enum channel_add_err add_err;
|
enum channel_add_err add_err;
|
||||||
struct htlc *htlc;
|
struct htlc *htlc;
|
||||||
#if EXPERIMENTAL_FEATURES
|
|
||||||
struct tlv_update_add_tlvs *tlvs;
|
struct tlv_update_add_tlvs *tlvs;
|
||||||
#endif
|
|
||||||
struct pubkey *blinding = NULL;
|
|
||||||
|
|
||||||
if (!fromwire_update_add_htlc
|
if (!fromwire_update_add_htlc(msg, msg, &channel_id, &id, &amount,
|
||||||
#if EXPERIMENTAL_FEATURES
|
&payment_hash, &cltv_expiry,
|
||||||
(msg, msg, &channel_id, &id, &amount,
|
onion_routing_packet, &tlvs)
|
||||||
&payment_hash, &cltv_expiry,
|
/* This is an *even* field: don't send if we didn't understand */
|
||||||
onion_routing_packet, &tlvs)
|
|| (tlvs->blinding && !feature_offered(peer->our_features->bits[INIT_FEATURE],
|
||||||
#else
|
OPT_ROUTE_BLINDING))) {
|
||||||
(msg, &channel_id, &id, &amount,
|
|
||||||
&payment_hash, &cltv_expiry,
|
|
||||||
onion_routing_packet)
|
|
||||||
#endif
|
|
||||||
)
|
|
||||||
peer_failed_warn(peer->pps, &peer->channel_id,
|
peer_failed_warn(peer->pps, &peer->channel_id,
|
||||||
"Bad peer_add_htlc %s", tal_hex(msg, msg));
|
"Bad peer_add_htlc %s", tal_hex(msg, msg));
|
||||||
|
}
|
||||||
#if EXPERIMENTAL_FEATURES
|
|
||||||
blinding = tlvs->blinding;
|
|
||||||
#endif
|
|
||||||
add_err = channel_add_htlc(peer->channel, REMOTE, id, amount,
|
add_err = channel_add_htlc(peer->channel, REMOTE, id, amount,
|
||||||
cltv_expiry, &payment_hash,
|
cltv_expiry, &payment_hash,
|
||||||
onion_routing_packet, blinding, &htlc, NULL,
|
onion_routing_packet, tlvs->blinding, &htlc, NULL,
|
||||||
/* We don't immediately fail incoming htlcs,
|
/* We don't immediately fail incoming htlcs,
|
||||||
* instead we wait and fail them after
|
* instead we wait and fail them after
|
||||||
* they've been committed */
|
* they've been committed */
|
||||||
@@ -2431,7 +2420,6 @@ static void resend_commitment(struct peer *peer, struct changed_htlc *last)
|
|||||||
last[i].id);
|
last[i].id);
|
||||||
|
|
||||||
if (h->state == SENT_ADD_COMMIT) {
|
if (h->state == SENT_ADD_COMMIT) {
|
||||||
#if EXPERIMENTAL_FEATURES
|
|
||||||
struct tlv_update_add_tlvs *tlvs;
|
struct tlv_update_add_tlvs *tlvs;
|
||||||
if (h->blinding) {
|
if (h->blinding) {
|
||||||
tlvs = tlv_update_add_tlvs_new(tmpctx);
|
tlvs = tlv_update_add_tlvs_new(tmpctx);
|
||||||
@@ -2439,17 +2427,12 @@ static void resend_commitment(struct peer *peer, struct changed_htlc *last)
|
|||||||
h->blinding);
|
h->blinding);
|
||||||
} else
|
} else
|
||||||
tlvs = NULL;
|
tlvs = NULL;
|
||||||
#endif
|
|
||||||
msg = towire_update_add_htlc(NULL, &peer->channel_id,
|
msg = towire_update_add_htlc(NULL, &peer->channel_id,
|
||||||
h->id, h->amount,
|
h->id, h->amount,
|
||||||
&h->rhash,
|
&h->rhash,
|
||||||
abs_locktime_to_blocks(
|
abs_locktime_to_blocks(
|
||||||
&h->expiry),
|
&h->expiry),
|
||||||
h->routing
|
h->routing, tlvs);
|
||||||
#if EXPERIMENTAL_FEATURES
|
|
||||||
, tlvs
|
|
||||||
#endif
|
|
||||||
);
|
|
||||||
peer_write(peer->pps, take(msg));
|
peer_write(peer->pps, take(msg));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3315,6 +3298,7 @@ static void handle_offer_htlc(struct peer *peer, const u8 *inmsg)
|
|||||||
const char *failstr;
|
const char *failstr;
|
||||||
struct amount_sat htlc_fee;
|
struct amount_sat htlc_fee;
|
||||||
struct pubkey *blinding;
|
struct pubkey *blinding;
|
||||||
|
struct tlv_update_add_tlvs *tlvs;
|
||||||
|
|
||||||
if (!peer->channel_ready[LOCAL] || !peer->channel_ready[REMOTE])
|
if (!peer->channel_ready[LOCAL] || !peer->channel_ready[REMOTE])
|
||||||
status_failed(STATUS_FAIL_MASTER_IO,
|
status_failed(STATUS_FAIL_MASTER_IO,
|
||||||
@@ -3325,14 +3309,11 @@ static void handle_offer_htlc(struct peer *peer, const u8 *inmsg)
|
|||||||
onion_routing_packet, &blinding))
|
onion_routing_packet, &blinding))
|
||||||
master_badmsg(WIRE_CHANNELD_OFFER_HTLC, inmsg);
|
master_badmsg(WIRE_CHANNELD_OFFER_HTLC, inmsg);
|
||||||
|
|
||||||
#if EXPERIMENTAL_FEATURES
|
|
||||||
struct tlv_update_add_tlvs *tlvs;
|
|
||||||
if (blinding) {
|
if (blinding) {
|
||||||
tlvs = tlv_update_add_tlvs_new(tmpctx);
|
tlvs = tlv_update_add_tlvs_new(tmpctx);
|
||||||
tlvs->blinding = tal_dup(tlvs, struct pubkey, blinding);
|
tlvs->blinding = tal_dup(tlvs, struct pubkey, blinding);
|
||||||
} else
|
} else
|
||||||
tlvs = NULL;
|
tlvs = NULL;
|
||||||
#endif
|
|
||||||
|
|
||||||
e = channel_add_htlc(peer->channel, LOCAL, peer->htlc_id,
|
e = channel_add_htlc(peer->channel, LOCAL, peer->htlc_id,
|
||||||
amount, cltv_expiry, &payment_hash,
|
amount, cltv_expiry, &payment_hash,
|
||||||
@@ -3350,11 +3331,7 @@ static void handle_offer_htlc(struct peer *peer, const u8 *inmsg)
|
|||||||
msg = towire_update_add_htlc(NULL, &peer->channel_id,
|
msg = towire_update_add_htlc(NULL, &peer->channel_id,
|
||||||
peer->htlc_id, amount,
|
peer->htlc_id, amount,
|
||||||
&payment_hash, cltv_expiry,
|
&payment_hash, cltv_expiry,
|
||||||
onion_routing_packet
|
onion_routing_packet, tlvs);
|
||||||
#if EXPERIMENTAL_FEATURES
|
|
||||||
, tlvs
|
|
||||||
#endif
|
|
||||||
);
|
|
||||||
peer_write(peer->pps, take(msg));
|
peer_write(peer->pps, take(msg));
|
||||||
start_commit_timer(peer);
|
start_commit_timer(peer);
|
||||||
/* Tell the master. */
|
/* Tell the master. */
|
||||||
|
|||||||
@@ -149,7 +149,6 @@ static void fail_in_htlc(struct htlc_in *hin,
|
|||||||
htlc_in_update_state(hin->key.channel, hin, SENT_REMOVE_HTLC);
|
htlc_in_update_state(hin->key.channel, hin, SENT_REMOVE_HTLC);
|
||||||
htlc_in_check(hin, __func__);
|
htlc_in_check(hin, __func__);
|
||||||
|
|
||||||
#if EXPERIMENTAL_FEATURES
|
|
||||||
/* BOLT-route-blinding #4:
|
/* BOLT-route-blinding #4:
|
||||||
* - If `blinding_point` is set in the incoming `update_add_htlc`:
|
* - If `blinding_point` is set in the incoming `update_add_htlc`:
|
||||||
* - MUST return `invalid_onion_blinding` on any error, including
|
* - MUST return `invalid_onion_blinding` on any error, including
|
||||||
@@ -159,7 +158,6 @@ static void fail_in_htlc(struct htlc_in *hin,
|
|||||||
failed_htlc = mk_failed_htlc_badonion(tmpctx, hin,
|
failed_htlc = mk_failed_htlc_badonion(tmpctx, hin,
|
||||||
WIRE_INVALID_ONION_BLINDING);
|
WIRE_INVALID_ONION_BLINDING);
|
||||||
} else
|
} else
|
||||||
#endif
|
|
||||||
failed_htlc = mk_failed_htlc(tmpctx, hin, hin->failonion);
|
failed_htlc = mk_failed_htlc(tmpctx, hin, hin->failonion);
|
||||||
|
|
||||||
bool we_filled = false;
|
bool we_filled = false;
|
||||||
@@ -1149,7 +1147,6 @@ static bool ecdh_maybe_blinding(const struct pubkey *ephemeral_key,
|
|||||||
{
|
{
|
||||||
struct pubkey point = *ephemeral_key;
|
struct pubkey point = *ephemeral_key;
|
||||||
|
|
||||||
#if EXPERIMENTAL_FEATURES
|
|
||||||
if (blinding) {
|
if (blinding) {
|
||||||
struct secret hmac;
|
struct secret hmac;
|
||||||
struct secret blinding_ss;
|
struct secret blinding_ss;
|
||||||
@@ -1167,7 +1164,6 @@ static bool ecdh_maybe_blinding(const struct pubkey *ephemeral_key,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif /* EXPERIMENTAL_FEATURES */
|
|
||||||
ecdh(&point, ss);
|
ecdh(&point, ss);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -1234,6 +1230,10 @@ static bool peer_accepted_htlc(const tal_t *ctx,
|
|||||||
struct onionpacket *op;
|
struct onionpacket *op;
|
||||||
struct lightningd *ld = channel->peer->ld;
|
struct lightningd *ld = channel->peer->ld;
|
||||||
struct htlc_accepted_hook_payload *hook_payload;
|
struct htlc_accepted_hook_payload *hook_payload;
|
||||||
|
const bool opt_blinding
|
||||||
|
= feature_offered(ld->our_features->bits[INIT_FEATURE],
|
||||||
|
OPT_ROUTE_BLINDING);
|
||||||
|
|
||||||
|
|
||||||
*failmsg = NULL;
|
*failmsg = NULL;
|
||||||
*badonion = 0;
|
*badonion = 0;
|
||||||
@@ -1335,9 +1335,9 @@ static bool peer_accepted_htlc(const tal_t *ctx,
|
|||||||
hook_payload->channel = channel;
|
hook_payload->channel = channel;
|
||||||
hook_payload->next_onion = serialize_onionpacket(hook_payload, rs->next);
|
hook_payload->next_onion = serialize_onionpacket(hook_payload, rs->next);
|
||||||
|
|
||||||
#if EXPERIMENTAL_FEATURES
|
|
||||||
/* We could have blinding from hin or from inside onion. */
|
/* We could have blinding from hin or from inside onion. */
|
||||||
if (hook_payload->payload && hook_payload->payload->blinding) {
|
if (opt_blinding
|
||||||
|
&& hook_payload->payload && hook_payload->payload->blinding) {
|
||||||
struct sha256 sha;
|
struct sha256 sha;
|
||||||
blinding_hash_e_and_ss(hook_payload->payload->blinding,
|
blinding_hash_e_and_ss(hook_payload->payload->blinding,
|
||||||
&hook_payload->payload->blinding_ss,
|
&hook_payload->payload->blinding_ss,
|
||||||
@@ -1346,7 +1346,6 @@ static bool peer_accepted_htlc(const tal_t *ctx,
|
|||||||
blinding_next_pubkey(hook_payload->payload->blinding, &sha,
|
blinding_next_pubkey(hook_payload->payload->blinding, &sha,
|
||||||
hook_payload->next_blinding);
|
hook_payload->next_blinding);
|
||||||
} else
|
} else
|
||||||
#endif
|
|
||||||
hook_payload->next_blinding = NULL;
|
hook_payload->next_blinding = NULL;
|
||||||
|
|
||||||
/* The scid is merely used to indicate the next peer, it is not
|
/* The scid is merely used to indicate the next peer, it is not
|
||||||
@@ -1365,13 +1364,11 @@ static bool peer_accepted_htlc(const tal_t *ctx,
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
#if EXPERIMENTAL_FEATURES
|
|
||||||
/* In a blinded path, *all* failures are "invalid_onion_blinding" */
|
/* In a blinded path, *all* failures are "invalid_onion_blinding" */
|
||||||
if (hin->blinding) {
|
if (hin->blinding) {
|
||||||
*failmsg = tal_free(*failmsg);
|
*failmsg = tal_free(*failmsg);
|
||||||
*badonion = WIRE_INVALID_ONION_BLINDING;
|
*badonion = WIRE_INVALID_ONION_BLINDING;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -214,6 +214,9 @@ msgdata,update_add_htlc,amount_msat,u64,
|
|||||||
msgdata,update_add_htlc,payment_hash,sha256,
|
msgdata,update_add_htlc,payment_hash,sha256,
|
||||||
msgdata,update_add_htlc,cltv_expiry,u32,
|
msgdata,update_add_htlc,cltv_expiry,u32,
|
||||||
msgdata,update_add_htlc,onion_routing_packet,byte,1366
|
msgdata,update_add_htlc,onion_routing_packet,byte,1366
|
||||||
|
msgdata,update_add_htlc,tlvs,update_add_tlvs,
|
||||||
|
tlvtype,update_add_tlvs,blinding,2
|
||||||
|
tlvdata,update_add_tlvs,blinding,blinding,point,
|
||||||
msgtype,update_fulfill_htlc,130
|
msgtype,update_fulfill_htlc,130
|
||||||
msgdata,update_fulfill_htlc,channel_id,channel_id,
|
msgdata,update_fulfill_htlc,channel_id,channel_id,
|
||||||
msgdata,update_fulfill_htlc,id,u64,
|
msgdata,update_fulfill_htlc,id,u64,
|
||||||
|
|||||||
|
@@ -680,37 +680,21 @@ static void *towire_struct_update_add_htlc(const tal_t *ctx,
|
|||||||
s->amount_msat,
|
s->amount_msat,
|
||||||
&s->payment_hash,
|
&s->payment_hash,
|
||||||
s->expiry,
|
s->expiry,
|
||||||
s->onion_routing_packet
|
s->onion_routing_packet, NULL);
|
||||||
#if EXPERIMENTAL_FEATURES
|
|
||||||
,NULL
|
|
||||||
#endif
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct msg_update_add_htlc *fromwire_struct_update_add_htlc(const tal_t *ctx, const void *p)
|
static struct msg_update_add_htlc *fromwire_struct_update_add_htlc(const tal_t *ctx, const void *p)
|
||||||
{
|
{
|
||||||
struct msg_update_add_htlc *s = tal(ctx, struct msg_update_add_htlc);
|
struct msg_update_add_htlc *s = tal(ctx, struct msg_update_add_htlc);
|
||||||
|
|
||||||
if (fromwire_update_add_htlc
|
if (fromwire_update_add_htlc(s, p,
|
||||||
#if EXPERIMENTAL_FEATURES
|
|
||||||
(s, p,
|
|
||||||
&s->channel_id,
|
&s->channel_id,
|
||||||
&s->id,
|
&s->id,
|
||||||
&s->amount_msat,
|
&s->amount_msat,
|
||||||
&s->payment_hash,
|
&s->payment_hash,
|
||||||
&s->expiry,
|
&s->expiry,
|
||||||
s->onion_routing_packet,
|
s->onion_routing_packet,
|
||||||
&s->tlvs
|
&s->tlvs))
|
||||||
#else
|
|
||||||
(p,
|
|
||||||
&s->channel_id,
|
|
||||||
&s->id,
|
|
||||||
&s->amount_msat,
|
|
||||||
&s->payment_hash,
|
|
||||||
&s->expiry,
|
|
||||||
s->onion_routing_packet
|
|
||||||
#endif
|
|
||||||
))
|
|
||||||
return s;
|
return s;
|
||||||
return tal_free(s);
|
return tal_free(s);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user