mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-18 22:54:25 +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)];
|
||||
enum channel_add_err add_err;
|
||||
struct htlc *htlc;
|
||||
#if EXPERIMENTAL_FEATURES
|
||||
struct tlv_update_add_tlvs *tlvs;
|
||||
#endif
|
||||
struct pubkey *blinding = NULL;
|
||||
|
||||
if (!fromwire_update_add_htlc
|
||||
#if EXPERIMENTAL_FEATURES
|
||||
(msg, msg, &channel_id, &id, &amount,
|
||||
&payment_hash, &cltv_expiry,
|
||||
onion_routing_packet, &tlvs)
|
||||
#else
|
||||
(msg, &channel_id, &id, &amount,
|
||||
&payment_hash, &cltv_expiry,
|
||||
onion_routing_packet)
|
||||
#endif
|
||||
)
|
||||
if (!fromwire_update_add_htlc(msg, msg, &channel_id, &id, &amount,
|
||||
&payment_hash, &cltv_expiry,
|
||||
onion_routing_packet, &tlvs)
|
||||
/* This is an *even* field: don't send if we didn't understand */
|
||||
|| (tlvs->blinding && !feature_offered(peer->our_features->bits[INIT_FEATURE],
|
||||
OPT_ROUTE_BLINDING))) {
|
||||
peer_failed_warn(peer->pps, &peer->channel_id,
|
||||
"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,
|
||||
cltv_expiry, &payment_hash,
|
||||
onion_routing_packet, blinding, &htlc, NULL,
|
||||
onion_routing_packet, tlvs->blinding, &htlc, NULL,
|
||||
/* We don't immediately fail incoming htlcs,
|
||||
* instead we wait and fail them after
|
||||
* they've been committed */
|
||||
@@ -2431,7 +2420,6 @@ static void resend_commitment(struct peer *peer, struct changed_htlc *last)
|
||||
last[i].id);
|
||||
|
||||
if (h->state == SENT_ADD_COMMIT) {
|
||||
#if EXPERIMENTAL_FEATURES
|
||||
struct tlv_update_add_tlvs *tlvs;
|
||||
if (h->blinding) {
|
||||
tlvs = tlv_update_add_tlvs_new(tmpctx);
|
||||
@@ -2439,17 +2427,12 @@ static void resend_commitment(struct peer *peer, struct changed_htlc *last)
|
||||
h->blinding);
|
||||
} else
|
||||
tlvs = NULL;
|
||||
#endif
|
||||
msg = towire_update_add_htlc(NULL, &peer->channel_id,
|
||||
h->id, h->amount,
|
||||
&h->rhash,
|
||||
abs_locktime_to_blocks(
|
||||
&h->expiry),
|
||||
h->routing
|
||||
#if EXPERIMENTAL_FEATURES
|
||||
, tlvs
|
||||
#endif
|
||||
);
|
||||
h->routing, tlvs);
|
||||
peer_write(peer->pps, take(msg));
|
||||
}
|
||||
}
|
||||
@@ -3315,6 +3298,7 @@ static void handle_offer_htlc(struct peer *peer, const u8 *inmsg)
|
||||
const char *failstr;
|
||||
struct amount_sat htlc_fee;
|
||||
struct pubkey *blinding;
|
||||
struct tlv_update_add_tlvs *tlvs;
|
||||
|
||||
if (!peer->channel_ready[LOCAL] || !peer->channel_ready[REMOTE])
|
||||
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))
|
||||
master_badmsg(WIRE_CHANNELD_OFFER_HTLC, inmsg);
|
||||
|
||||
#if EXPERIMENTAL_FEATURES
|
||||
struct tlv_update_add_tlvs *tlvs;
|
||||
if (blinding) {
|
||||
tlvs = tlv_update_add_tlvs_new(tmpctx);
|
||||
tlvs->blinding = tal_dup(tlvs, struct pubkey, blinding);
|
||||
} else
|
||||
tlvs = NULL;
|
||||
#endif
|
||||
|
||||
e = channel_add_htlc(peer->channel, LOCAL, peer->htlc_id,
|
||||
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,
|
||||
peer->htlc_id, amount,
|
||||
&payment_hash, cltv_expiry,
|
||||
onion_routing_packet
|
||||
#if EXPERIMENTAL_FEATURES
|
||||
, tlvs
|
||||
#endif
|
||||
);
|
||||
onion_routing_packet, tlvs);
|
||||
peer_write(peer->pps, take(msg));
|
||||
start_commit_timer(peer);
|
||||
/* 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_check(hin, __func__);
|
||||
|
||||
#if EXPERIMENTAL_FEATURES
|
||||
/* BOLT-route-blinding #4:
|
||||
* - If `blinding_point` is set in the incoming `update_add_htlc`:
|
||||
* - 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,
|
||||
WIRE_INVALID_ONION_BLINDING);
|
||||
} else
|
||||
#endif
|
||||
failed_htlc = mk_failed_htlc(tmpctx, hin, hin->failonion);
|
||||
|
||||
bool we_filled = false;
|
||||
@@ -1149,7 +1147,6 @@ static bool ecdh_maybe_blinding(const struct pubkey *ephemeral_key,
|
||||
{
|
||||
struct pubkey point = *ephemeral_key;
|
||||
|
||||
#if EXPERIMENTAL_FEATURES
|
||||
if (blinding) {
|
||||
struct secret hmac;
|
||||
struct secret blinding_ss;
|
||||
@@ -1167,7 +1164,6 @@ static bool ecdh_maybe_blinding(const struct pubkey *ephemeral_key,
|
||||
return false;
|
||||
}
|
||||
}
|
||||
#endif /* EXPERIMENTAL_FEATURES */
|
||||
ecdh(&point, ss);
|
||||
return true;
|
||||
}
|
||||
@@ -1234,6 +1230,10 @@ static bool peer_accepted_htlc(const tal_t *ctx,
|
||||
struct onionpacket *op;
|
||||
struct lightningd *ld = channel->peer->ld;
|
||||
struct htlc_accepted_hook_payload *hook_payload;
|
||||
const bool opt_blinding
|
||||
= feature_offered(ld->our_features->bits[INIT_FEATURE],
|
||||
OPT_ROUTE_BLINDING);
|
||||
|
||||
|
||||
*failmsg = NULL;
|
||||
*badonion = 0;
|
||||
@@ -1335,9 +1335,9 @@ static bool peer_accepted_htlc(const tal_t *ctx,
|
||||
hook_payload->channel = channel;
|
||||
hook_payload->next_onion = serialize_onionpacket(hook_payload, rs->next);
|
||||
|
||||
#if EXPERIMENTAL_FEATURES
|
||||
/* 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;
|
||||
blinding_hash_e_and_ss(hook_payload->payload->blinding,
|
||||
&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,
|
||||
hook_payload->next_blinding);
|
||||
} else
|
||||
#endif
|
||||
hook_payload->next_blinding = NULL;
|
||||
|
||||
/* 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;
|
||||
|
||||
fail:
|
||||
#if EXPERIMENTAL_FEATURES
|
||||
/* In a blinded path, *all* failures are "invalid_onion_blinding" */
|
||||
if (hin->blinding) {
|
||||
*failmsg = tal_free(*failmsg);
|
||||
*badonion = WIRE_INVALID_ONION_BLINDING;
|
||||
}
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -214,6 +214,9 @@ msgdata,update_add_htlc,amount_msat,u64,
|
||||
msgdata,update_add_htlc,payment_hash,sha256,
|
||||
msgdata,update_add_htlc,cltv_expiry,u32,
|
||||
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
|
||||
msgdata,update_fulfill_htlc,channel_id,channel_id,
|
||||
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->payment_hash,
|
||||
s->expiry,
|
||||
s->onion_routing_packet
|
||||
#if EXPERIMENTAL_FEATURES
|
||||
,NULL
|
||||
#endif
|
||||
);
|
||||
s->onion_routing_packet, NULL);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
if (fromwire_update_add_htlc
|
||||
#if EXPERIMENTAL_FEATURES
|
||||
(s, p,
|
||||
if (fromwire_update_add_htlc(s, p,
|
||||
&s->channel_id,
|
||||
&s->id,
|
||||
&s->amount_msat,
|
||||
&s->payment_hash,
|
||||
&s->expiry,
|
||||
s->onion_routing_packet,
|
||||
&s->tlvs
|
||||
#else
|
||||
(p,
|
||||
&s->channel_id,
|
||||
&s->id,
|
||||
&s->amount_msat,
|
||||
&s->payment_hash,
|
||||
&s->expiry,
|
||||
s->onion_routing_packet
|
||||
#endif
|
||||
))
|
||||
&s->tlvs))
|
||||
return s;
|
||||
return tal_free(s);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user