mirror of
https://github.com/aljazceru/lightning.git
synced 2026-01-19 13:54:24 +01:00
spec: update to experimental BOLTs with secret/total_amount.
Also pulls in a new onion error (mpp_timeout). We change our route_step_decode_end() to always return the total_msat and optional secret. We check total_amount (to prohibit mpp), but we do nothing with secret for now other than hand it to the htlc_accepted hook. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -192,16 +192,25 @@ void sphinx_add_nonfinal_hop(struct sphinx_path *path,
|
||||
}
|
||||
}
|
||||
|
||||
void sphinx_add_final_hop(struct sphinx_path *path,
|
||||
bool sphinx_add_final_hop(struct sphinx_path *path,
|
||||
const struct pubkey *pubkey,
|
||||
bool use_tlv,
|
||||
struct amount_msat forward,
|
||||
u32 outgoing_cltv)
|
||||
u32 outgoing_cltv,
|
||||
struct amount_msat total_msat,
|
||||
const struct secret *payment_secret)
|
||||
{
|
||||
/* These go together! */
|
||||
if (!payment_secret)
|
||||
assert(amount_msat_eq(total_msat, forward));
|
||||
|
||||
if (use_tlv) {
|
||||
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:
|
||||
*
|
||||
@@ -216,12 +225,27 @@ void sphinx_add_final_hop(struct sphinx_path *path,
|
||||
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 false;
|
||||
#endif
|
||||
sphinx_add_tlv_hop(path, pubkey, tlv);
|
||||
} else {
|
||||
static struct short_channel_id all_zero_scid;
|
||||
/* No payment secrets in legacy format. */
|
||||
if (payment_secret)
|
||||
return false;
|
||||
sphinx_add_v0_hop(path, pubkey, &all_zero_scid,
|
||||
forward, outgoing_cltv);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Small helper to append data to a buffer and update the position
|
||||
@@ -693,6 +717,12 @@ static void route_step_decode(struct route_step *rs)
|
||||
case SPHINX_V0_PAYLOAD:
|
||||
rs->amt_to_forward = &rs->payload.v0.amt_forward;
|
||||
rs->outgoing_cltv = &rs->payload.v0.outgoing_cltv;
|
||||
rs->payment_secret = NULL;
|
||||
/* BOLT-e36f7b6517e1173dcbd49da3b516cfe1f48ae556 #4:
|
||||
* - if it is the final node:
|
||||
* - MUST treat `total_msat` as if it were equal to
|
||||
* `amt_to_forward` if it is not present. */
|
||||
rs->total_msat = rs->amt_to_forward;
|
||||
if (rs->nextcase == ONION_FORWARD) {
|
||||
rs->forward_channel = &rs->payload.v0.channel_id;
|
||||
} else {
|
||||
@@ -722,6 +752,23 @@ static void route_step_decode(struct route_step *rs)
|
||||
->short_channel_id;
|
||||
else
|
||||
rs->forward_channel = NULL;
|
||||
|
||||
rs->payment_secret = NULL;
|
||||
/* BOLT-e36f7b6517e1173dcbd49da3b516cfe1f48ae556 #4:
|
||||
* - if it is the final node:
|
||||
* - MUST treat `total_msat` as if it were equal to
|
||||
* `amt_to_forward` if it is not present. */
|
||||
rs->total_msat = rs->amt_to_forward;
|
||||
|
||||
#if EXPERIMENTAL_FEATURES
|
||||
if (rs->payload.tlv->payment_data) {
|
||||
rs->payment_secret
|
||||
= &rs->payload.tlv->payment_data->payment_secret;
|
||||
rs->total_msat = tal(rs, struct amount_msat);
|
||||
rs->total_msat->millisatoshis /* Raw: tu64 on wire */
|
||||
= rs->payload.tlv->payment_data->total_msat;
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
case SPHINX_INVALID_PAYLOAD:
|
||||
case SPHINX_RAW_PAYLOAD:
|
||||
|
||||
@@ -89,6 +89,8 @@ struct route_step {
|
||||
struct amount_msat *amt_to_forward;
|
||||
u32 *outgoing_cltv;
|
||||
struct short_channel_id *forward_channel;
|
||||
struct secret *payment_secret;
|
||||
struct amount_msat *total_msat;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -243,10 +245,12 @@ void sphinx_add_nonfinal_hop(struct sphinx_path *path,
|
||||
/**
|
||||
* Add a final hop to the path.
|
||||
*/
|
||||
void sphinx_add_final_hop(struct sphinx_path *path,
|
||||
bool sphinx_add_final_hop(struct sphinx_path *path,
|
||||
const struct pubkey *pubkey,
|
||||
bool use_tlv,
|
||||
struct amount_msat forward,
|
||||
u32 outgoing_cltv);
|
||||
u32 outgoing_cltv,
|
||||
struct amount_msat total_msat,
|
||||
const struct secret *payment_secret);
|
||||
|
||||
#endif /* LIGHTNING_COMMON_SPHINX_H */
|
||||
|
||||
@@ -18,6 +18,9 @@ bool amount_asset_is_main(struct amount_asset *asset UNNEEDED)
|
||||
/* Generated stub for amount_asset_to_sat */
|
||||
struct amount_sat amount_asset_to_sat(struct amount_asset *asset UNNEEDED)
|
||||
{ fprintf(stderr, "amount_asset_to_sat called!\n"); abort(); }
|
||||
/* Generated stub for amount_msat_eq */
|
||||
bool amount_msat_eq(struct amount_msat a UNNEEDED, struct amount_msat b UNNEEDED)
|
||||
{ fprintf(stderr, "amount_msat_eq called!\n"); abort(); }
|
||||
/* Generated stub for amount_msat_from_u64 */
|
||||
void amount_msat_from_u64(struct amount_msat *msat UNNEEDED, u64 millisatoshis UNNEEDED)
|
||||
{ fprintf(stderr, "amount_msat_from_u64 called!\n"); abort(); }
|
||||
@@ -52,6 +55,9 @@ bigsize_t fromwire_bigsize(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
|
||||
/* Generated stub for fromwire_fail */
|
||||
const void *fromwire_fail(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
|
||||
{ fprintf(stderr, "fromwire_fail called!\n"); abort(); }
|
||||
/* Generated stub for fromwire_secret */
|
||||
void fromwire_secret(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct secret *secret UNNEEDED)
|
||||
{ fprintf(stderr, "fromwire_secret called!\n"); abort(); }
|
||||
/* Generated stub for fromwire_sha256 */
|
||||
void fromwire_sha256(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct sha256 *sha256 UNNEEDED)
|
||||
{ fprintf(stderr, "fromwire_sha256 called!\n"); abort(); }
|
||||
@@ -89,6 +95,9 @@ void towire_bigsize(u8 **pptr UNNEEDED, const bigsize_t val UNNEEDED)
|
||||
/* Generated stub for towire_pad */
|
||||
void towire_pad(u8 **pptr UNNEEDED, size_t num UNNEEDED)
|
||||
{ fprintf(stderr, "towire_pad called!\n"); abort(); }
|
||||
/* Generated stub for towire_secret */
|
||||
void towire_secret(u8 **pptr UNNEEDED, const struct secret *secret UNNEEDED)
|
||||
{ fprintf(stderr, "towire_secret called!\n"); abort(); }
|
||||
/* Generated stub for towire_sha256 */
|
||||
void towire_sha256(u8 **pptr UNNEEDED, const struct sha256 *sha256 UNNEEDED)
|
||||
{ fprintf(stderr, "towire_sha256 called!\n"); abort(); }
|
||||
|
||||
Reference in New Issue
Block a user