Skip to content

Commit

Permalink
Protocol: make var_onion, payment_secret and basic_mpp non-EXPERIMENTAL.
Browse files Browse the repository at this point in the history
Thanks to @t-bast, who made this possible by interop testing with Eclair!

Changelog-Added: Protocol: can now send and receive TLV-style onion messages.
Changelog-Added: Protocol: can now send and receive BOLT11 payment_secrets.
Changelog-Added: Protocol: can now receive basic multi-part payments.
Changelog-Added: RPC: low-level commands sendpay and waitsendpay can now be used to manually send multi-part payments.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
  • Loading branch information
rustyrussell committed Dec 12, 2019
1 parent e6edb76 commit f33c75f
Show file tree
Hide file tree
Showing 20 changed files with 96 additions and 185 deletions.
2 changes: 0 additions & 2 deletions channeld/channeld.c
Original file line number Diff line number Diff line change
Expand Up @@ -960,11 +960,9 @@ static u8 *make_failmsg(const tal_t *ctx,
/* FIXME: wire this into tlv parser somehow. */
msg = towire_invalid_onion_payload(ctx, 0, 0);
goto done;
#if EXPERIMENTAL_FEATURES
case WIRE_MPP_TIMEOUT:
msg = towire_mpp_timeout(ctx);
goto done;
#endif /* EXPERIMENTAL_FEATURES */
}
status_failed(STATUS_FAIL_INTERNAL_ERROR,
"Asked to create failmsg %u (%s)",
Expand Down
2 changes: 0 additions & 2 deletions common/features.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ static const u32 our_features[] = {
OPTIONAL_FEATURE(OPT_DATA_LOSS_PROTECT),
OPTIONAL_FEATURE(OPT_UPFRONT_SHUTDOWN_SCRIPT),
OPTIONAL_FEATURE(OPT_GOSSIP_QUERIES),
#if EXPERIMENTAL_FEATURES
OPTIONAL_FEATURE(OPT_VAR_ONION),
OPTIONAL_FEATURE(OPT_PAYMENT_SECRET),
OPTIONAL_FEATURE(OPT_BASIC_MPP),
#endif
OPTIONAL_FEATURE(OPT_GOSSIP_QUERIES_EX),
OPTIONAL_FEATURE(OPT_STATIC_REMOTEKEY),
};
Expand Down
15 changes: 0 additions & 15 deletions common/onion.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,7 @@ u8 *onion_final_hop(const tal_t *ctx,
struct tlv_tlv_payload *tlv = tlv_tlv_payload_new(tmpctx);
struct tlv_tlv_payload_amt_to_forward tlv_amt;
struct tlv_tlv_payload_outgoing_cltv_value tlv_cltv;
#if EXPERIMENTAL_FEATURES
struct tlv_tlv_payload_payment_data tlv_pdata;
#endif

/* BOLT #4:
*
Expand All @@ -118,17 +116,11 @@ u8 *onion_final_hop(const tal_t *ctx,
tlv->amt_to_forward = &tlv_amt;
tlv->outgoing_cltv_value = &tlv_cltv;

#if EXPERIMENTAL_FEATURES
if (payment_secret) {
tlv_pdata.payment_secret = *payment_secret;
tlv_pdata.total_msat = total_msat.millisatoshis; /* Raw: TLV convert */
tlv->payment_data = &tlv_pdata;
}
#else
/* Wihtout EXPERIMENTAL_FEATURES, we can't send payment_secret */
if (payment_secret)
return NULL;
#endif
return make_tlv_hop(ctx, tlv);
} else {
static struct short_channel_id all_zero_scid;
Expand Down Expand Up @@ -170,10 +162,6 @@ static bool pull_payload_length(const u8 **cursor,
return true;
}

#if !EXPERIMENTAL_FEATURES
/* Only handle legacy format */
return false;
#else
/* BOLT #4:
* - `tlv_payload` format, identified by any length over `1`. In this
* case the `hop_payload_length` is equal to the numeric value of
Expand All @@ -191,7 +179,6 @@ static bool pull_payload_length(const u8 **cursor,
}

return false;
#endif /* EXPERIMENTAL_FEATURES */
}

size_t onion_payload_length(const u8 *raw_payload, size_t len,
Expand Down Expand Up @@ -289,7 +276,6 @@ struct onion_payload *onion_decode(const tal_t *ctx,

p->payment_secret = NULL;

#if EXPERIMENTAL_FEATURES
if (tlv->payment_data) {
p->payment_secret = tal_dup(p, struct secret,
&tlv->payment_data->payment_secret);
Expand All @@ -298,7 +284,6 @@ struct onion_payload *onion_decode(const tal_t *ctx,
p->total_msat->millisatoshis /* Raw: tu64 on wire */
= tlv->payment_data->total_msat;
}
#endif
tal_free(tlv);
return p;
}
Expand Down
5 changes: 0 additions & 5 deletions common/sphinx.c
Original file line number Diff line number Diff line change
Expand Up @@ -498,11 +498,6 @@ struct route_step *process_onionpacket(

payload_size = onion_payload_length(paddedheader, ROUTING_INFO_SIZE,
&valid, NULL);
#if !EXPERIMENTAL_FEATURES
/* We don't even attempt to handle non-legacy or malformed payloads */
if (!valid)
return tal_free(step);
#endif

/* Can't decode? Treat it as terminal. */
if (!valid) {
Expand Down
10 changes: 7 additions & 3 deletions contrib/pyln-client/pyln/client/lightning.py
Original file line number Diff line number Diff line change
Expand Up @@ -886,12 +886,15 @@ def sendpay(self, route, payment_hash, *args, **kwargs):
if 'description' in kwargs:
return self._deprecated_sendpay(route, payment_hash, *args, **kwargs)

def _sendpay(route, payment_hash, label=None, msatoshi=None):
def _sendpay(route, payment_hash, label=None, msatoshi=None, bolt11=None, payment_secret=None, partid=None):
payload = {
"route": route,
"payment_hash": payment_hash,
"label": label,
"msatoshi": msatoshi,
"bolt11": bolt11,
"payment_secret": payment_secret,
"partid": partid,
}
return self.call("sendpay", payload)

Expand Down Expand Up @@ -935,13 +938,14 @@ def waitinvoice(self, label):
}
return self.call("waitinvoice", payload)

def waitsendpay(self, payment_hash, timeout=None):
def waitsendpay(self, payment_hash, timeout=None, partid=None):
"""
Wait for payment for preimage of {payment_hash} to complete
"""
payload = {
"payment_hash": payment_hash,
"timeout": timeout
"timeout": timeout,
"partid": partid,
}
return self.call("waitsendpay", payload)

Expand Down
26 changes: 14 additions & 12 deletions doc/lightning-sendpay.7

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 9 additions & 8 deletions doc/lightning-sendpay.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ SYNOPSIS
--------

**sendpay** *route* *payment\_hash* \[*label*\] \[*msatoshi*\]
\[*bolt11*\]
\[*bolt11*\] \[*partid*\]

DESCRIPTION
-----------
Expand All @@ -29,20 +29,21 @@ The *label* and *bolt11* parameters, if provided, will be returned in

The *msatoshi* amount, if provided, is the amount that will be recorded
as the target payment value. If not specified, it will be the final
amount to the destination. If specified, then the final amount at the
destination must be from the specified *msatoshi* to twice the specified
*msatoshi*, inclusive. This is intended to obscure payments by
overpaying slightly at the destination; the actual target payment is
what should be specified as the *msatoshi* argument. *msatoshi* is in
millisatoshi precision; it can be a whole number, or a whole number
amount to the destination. By default it is in millisatoshi precision; it can be a whole number, or a whole number
ending in *msat* or *sat*, or a number with three decimal places ending
in *sat*, or a number with 1 to 11 decimal places ending in *btc*.

The *partid* value, if provided and non-zero, allows for multiple parallel
partial payments with the same *payment_hash*. The *msatoshi* amount
(which must be provided) for each **sendpay** with matching
*payment_hash* must be equal, and **sendpay** will fail if there are
already *msatoshi* worth of payments pending.

Once a payment has succeeded, calls to **sendpay** with the same
*payment\_hash* but a different *msatoshi* or destination will fail;
this prevents accidental multiple payments. Calls to **sendpay** with
the same *payment\_hash*, *msatoshi*, and destination as a previous
successful payment (even if a different route) will return immediately
successful payment (even if a different route or *partid*) will return immediately
with success.

RETURN VALUE
Expand Down
13 changes: 8 additions & 5 deletions doc/lightning-waitsendpay.7

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion doc/lightning-waitsendpay.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ lightning-waitsendpay -- Command for sending a payment via a route
SYNOPSIS
--------

**waitsendpay** *payment\_hash* \[*timeout*\]
**waitsendpay** *payment\_hash* \[*timeout*\] \[*partid*\]

DESCRIPTION
-----------
Expand All @@ -13,6 +13,8 @@ The **waitsendpay** RPC command polls or waits for the status of an
outgoing payment that was initiated by a previous **sendpay**
invocation.

The *partid* argument must match that of the **sendpay** command.

Optionally the client may provide a *timeout*, an integer in seconds,
for this RPC command to return. If the *timeout* is provided and the
given amount of time passes without the payment definitely succeeding or
Expand Down
Loading

0 comments on commit f33c75f

Please sign in to comment.