Skip to content

Commit

Permalink
Makefile: update bolts to 60cfb5972ad4bec4c49ee0f9e729fb3352fcdc6a.
Browse files Browse the repository at this point in the history
"BOLT 4: Remove legacy format, make var_onion_optin compulsory."

This also renamed the redundant "tlv_payload" to "payload", so we
replace "tlv_tlv_payload" with "tlv_payload" everyhere!

Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell authored and ddustin committed May 12, 2023
1 parent b99a793 commit 47731be
Show file tree
Hide file tree
Showing 15 changed files with 118 additions and 146 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ CCANDIR := ccan

# Where we keep the BOLT RFCs
BOLTDIR := ../bolts/
DEFAULT_BOLTVERSION := f32c6ddb5f11b431c9bb4f501cdec604172a90de
DEFAULT_BOLTVERSION := 60cfb5972ad4bec4c49ee0f9e729fb3352fcdc6a
# Can be overridden on cmdline.
BOLTVERSION := $(DEFAULT_BOLTVERSION)

Expand Down
7 changes: 2 additions & 5 deletions common/gossip_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@
#include "config.h"
#include <common/utils.h>

/* BOLT #4:
*
* - a 1300-byte `hop_payloads` consisting of multiple, variable length,
* `hop_payload` payloads or up to 20 fixed sized legacy `hop_data` payloads.
*/
/* FIXME: This is a legacy concept, which should be eliminated now we have
* only onion tlv payloads. */
#define ROUTING_MAX_HOPS 20

/* BOLT #7:
Expand Down
62 changes: 31 additions & 31 deletions common/onion_decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
* - MUST return an error if the payload contains other tlv fields than
* `encrypted_recipient_data` and `current_blinding_point`.
*/
static bool check_nonfinal_tlv(const struct tlv_tlv_payload *tlv,
static bool check_nonfinal_tlv(const struct tlv_payload *tlv,
u64 *failtlvtype)
{
for (size_t i = 0; i < tal_count(tlv->fields); i++) {
switch (tlv->fields[i].numtype) {
case TLV_TLV_PAYLOAD_BLINDING_POINT:
case TLV_TLV_PAYLOAD_ENCRYPTED_RECIPIENT_DATA:
case TLV_PAYLOAD_BLINDING_POINT:
case TLV_PAYLOAD_ENCRYPTED_RECIPIENT_DATA:
continue;
}
*failtlvtype = tlv->fields[i].numtype;
Expand All @@ -39,16 +39,16 @@ static bool check_nonfinal_tlv(const struct tlv_tlv_payload *tlv,
* `encrypted_recipient_data`, `current_blinding_point`, `amt_to_forward`,
* `outgoing_cltv_value` and `total_amount_msat`.
*/
static bool check_final_tlv(const struct tlv_tlv_payload *tlv,
static bool check_final_tlv(const struct tlv_payload *tlv,
u64 *failtlvtype)
{
for (size_t i = 0; i < tal_count(tlv->fields); i++) {
switch (tlv->fields[i].numtype) {
case TLV_TLV_PAYLOAD_ENCRYPTED_RECIPIENT_DATA:
case TLV_TLV_PAYLOAD_BLINDING_POINT:
case TLV_TLV_PAYLOAD_AMT_TO_FORWARD:
case TLV_TLV_PAYLOAD_OUTGOING_CLTV_VALUE:
case TLV_TLV_PAYLOAD_TOTAL_AMOUNT_MSAT:
case TLV_PAYLOAD_ENCRYPTED_RECIPIENT_DATA:
case TLV_PAYLOAD_BLINDING_POINT:
case TLV_PAYLOAD_AMT_TO_FORWARD:
case TLV_PAYLOAD_OUTGOING_CLTV_VALUE:
case TLV_PAYLOAD_TOTAL_AMOUNT_MSAT:
continue;
}
*failtlvtype = tlv->fields[i].numtype;
Expand All @@ -65,7 +65,7 @@ static u64 ceil_div(u64 a, u64 b)
static bool handle_blinded_forward(struct onion_payload *p,
struct amount_msat amount_in,
u32 cltv_expiry,
const struct tlv_tlv_payload *tlv,
const struct tlv_payload *tlv,
const struct tlv_encrypted_data_tlv *enc,
u64 *failtlvtype)
{
Expand All @@ -81,7 +81,7 @@ static bool handle_blinded_forward(struct onion_payload *p,
* contain either `short_channel_id` or `next_node_id`.
*/
if (!enc->short_channel_id && !enc->next_node_id) {
*failtlvtype = TLV_TLV_PAYLOAD_ENCRYPTED_RECIPIENT_DATA;
*failtlvtype = TLV_PAYLOAD_ENCRYPTED_RECIPIENT_DATA;
return false;
}

Expand All @@ -104,7 +104,7 @@ static bool handle_blinded_forward(struct onion_payload *p,
* contain `payment_relay`.
*/
if (!enc->payment_relay) {
*failtlvtype = TLV_TLV_PAYLOAD_ENCRYPTED_RECIPIENT_DATA;
*failtlvtype = TLV_PAYLOAD_ENCRYPTED_RECIPIENT_DATA;
return false;
}

Expand All @@ -118,7 +118,7 @@ static bool handle_blinded_forward(struct onion_payload *p,
}

static bool handle_blinded_terminal(struct onion_payload *p,
const struct tlv_tlv_payload *tlv,
const struct tlv_payload *tlv,
const struct tlv_encrypted_data_tlv *enc,
u64 *failtlvtype)
{
Expand All @@ -132,17 +132,17 @@ static bool handle_blinded_terminal(struct onion_payload *p,
* for the payment.
*/
if (!tlv->amt_to_forward) {
*failtlvtype = TLV_TLV_PAYLOAD_AMT_TO_FORWARD;
*failtlvtype = TLV_PAYLOAD_AMT_TO_FORWARD;
return false;
}

if (!tlv->outgoing_cltv_value) {
*failtlvtype = TLV_TLV_PAYLOAD_OUTGOING_CLTV_VALUE;
*failtlvtype = TLV_PAYLOAD_OUTGOING_CLTV_VALUE;
return false;
}

if (!tlv->total_amount_msat) {
*failtlvtype = TLV_TLV_PAYLOAD_TOTAL_AMOUNT_MSAT;
*failtlvtype = TLV_PAYLOAD_TOTAL_AMOUNT_MSAT;
return false;
}

Expand Down Expand Up @@ -182,7 +182,7 @@ struct onion_payload *onion_decode(const tal_t *ctx,

p->final = (rs->nextcase == ONION_END);

/* BOLT-remove-legacy-onion #4:
/* BOLT #4:
* 1. type: `hop_payloads`
* 2. data:
* * [`bigsize`:`length`]
Expand All @@ -197,9 +197,9 @@ struct onion_payload *onion_decode(const tal_t *ctx,

/* We do this manually so we can accept extra types, and get
* error off and type. */
p->tlv = tlv_tlv_payload_new(p);
if (!fromwire_tlv(&cursor, &max, tlvs_tlv_tlv_payload,
TLVS_ARRAY_SIZE_tlv_tlv_payload,
p->tlv = tlv_payload_new(p);
if (!fromwire_tlv(&cursor, &max, tlvs_tlv_payload,
TLVS_ARRAY_SIZE_tlv_payload,
p->tlv, &p->tlv->fields, accepted_extra_tlvs,
failtlvpos, failtlvtype)) {
return tal_free(p);
Expand All @@ -216,7 +216,7 @@ struct onion_payload *onion_decode(const tal_t *ctx,

/* Only supported with --experimental-onion-messages! */
if (!blinding_support) {
*failtlvtype = TLV_TLV_PAYLOAD_ENCRYPTED_RECIPIENT_DATA;
*failtlvtype = TLV_PAYLOAD_ENCRYPTED_RECIPIENT_DATA;
goto field_bad;
}

Expand All @@ -231,13 +231,13 @@ struct onion_payload *onion_decode(const tal_t *ctx,
*/
if (blinding) {
if (p->tlv->blinding_point) {
*failtlvtype = TLV_TLV_PAYLOAD_BLINDING_POINT;
*failtlvtype = TLV_PAYLOAD_BLINDING_POINT;
goto field_bad;
}
p->blinding = tal_dup(p, struct pubkey, blinding);
} else {
if (!p->tlv->blinding_point) {
*failtlvtype = TLV_TLV_PAYLOAD_BLINDING_POINT;
*failtlvtype = TLV_PAYLOAD_BLINDING_POINT;
goto field_bad;
}
p->blinding = tal_dup(p, struct pubkey,
Expand All @@ -255,7 +255,7 @@ struct onion_payload *onion_decode(const tal_t *ctx,
enc = decrypt_encrypted_data(tmpctx, p->blinding, &p->blinding_ss,
p->tlv->encrypted_recipient_data);
if (!enc) {
*failtlvtype = TLV_TLV_PAYLOAD_ENCRYPTED_RECIPIENT_DATA;
*failtlvtype = TLV_PAYLOAD_ENCRYPTED_RECIPIENT_DATA;
goto field_bad;
}

Expand All @@ -266,7 +266,7 @@ struct onion_payload *onion_decode(const tal_t *ctx,
* `encrypted_recipient_data.payment_constraints.max_cltv_expiry`.
*/
if (cltv_expiry > enc->payment_constraints->max_cltv_expiry) {
*failtlvtype = TLV_TLV_PAYLOAD_ENCRYPTED_RECIPIENT_DATA;
*failtlvtype = TLV_PAYLOAD_ENCRYPTED_RECIPIENT_DATA;
goto field_bad;
}

Expand All @@ -278,7 +278,7 @@ struct onion_payload *onion_decode(const tal_t *ctx,
*/
if (amount_msat_less(amount_in,
amount_msat(enc->payment_constraints->htlc_minimum_msat))) {
*failtlvtype = TLV_TLV_PAYLOAD_ENCRYPTED_RECIPIENT_DATA;
*failtlvtype = TLV_PAYLOAD_ENCRYPTED_RECIPIENT_DATA;
goto field_bad;
}

Expand All @@ -303,7 +303,7 @@ struct onion_payload *onion_decode(const tal_t *ctx,
/* No features, this is easy */
if (!memeqzero(enc->allowed_features,
tal_bytelen(enc->allowed_features))) {
*failtlvtype = TLV_TLV_PAYLOAD_ENCRYPTED_RECIPIENT_DATA;
*failtlvtype = TLV_PAYLOAD_ENCRYPTED_RECIPIENT_DATA;
goto field_bad;
}

Expand Down Expand Up @@ -335,7 +335,7 @@ struct onion_payload *onion_decode(const tal_t *ctx,
* is present.
*/
if (blinding || p->tlv->blinding_point) {
*failtlvtype = TLV_TLV_PAYLOAD_ENCRYPTED_RECIPIENT_DATA;
*failtlvtype = TLV_PAYLOAD_ENCRYPTED_RECIPIENT_DATA;
goto field_bad;
}

Expand All @@ -346,11 +346,11 @@ struct onion_payload *onion_decode(const tal_t *ctx,
* `outgoing_cltv_value` are not present.
*/
if (!p->tlv->amt_to_forward) {
*failtlvtype = TLV_TLV_PAYLOAD_AMT_TO_FORWARD;
*failtlvtype = TLV_PAYLOAD_AMT_TO_FORWARD;
goto field_bad;
}
if (!p->tlv->outgoing_cltv_value) {
*failtlvtype = TLV_TLV_PAYLOAD_OUTGOING_CLTV_VALUE;
*failtlvtype = TLV_PAYLOAD_OUTGOING_CLTV_VALUE;
goto field_bad;
}

Expand All @@ -366,7 +366,7 @@ struct onion_payload *onion_decode(const tal_t *ctx,
*/
if (!p->final) {
if (!p->tlv->short_channel_id) {
*failtlvtype = TLV_TLV_PAYLOAD_SHORT_CHANNEL_ID;
*failtlvtype = TLV_PAYLOAD_SHORT_CHANNEL_ID;
goto field_bad;
}
p->forward_channel = tal_dup(p, struct short_channel_id,
Expand Down
22 changes: 9 additions & 13 deletions common/onion_encode.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,18 @@

/* BOLT #4:
*
* ### `tlv_payload` format
* ### `payload` format
*
* This is a more flexible format, which avoids the redundant
* `short_channel_id` field for the final node. It is formatted
* according to the Type-Length-Value format defined in [BOLT
* #1](01-messaging.md#type-length-value-format).
* This is formatted according to the Type-Length-Value format defined
* in [BOLT #1](01-messaging.md#type-length-value-format).
*/
static u8 *make_tlv_hop(const tal_t *ctx,
const struct tlv_tlv_payload *tlv)
const struct tlv_payload *tlv)
{
/* We can't have over 64k anyway */
u8 *tlvs = tal_arr(ctx, u8, 3);

towire_tlv_tlv_payload(&tlvs, tlv);
towire_tlv_payload(&tlvs, tlv);

switch (bigsize_put(tlvs, tal_bytelen(tlvs) - 3)) {
case 1:
Expand All @@ -43,12 +41,11 @@ u8 *onion_nonfinal_hop(const tal_t *ctx,
struct amount_msat forward,
u32 outgoing_cltv)
{
struct tlv_tlv_payload *tlv = tlv_tlv_payload_new(tmpctx);
struct tlv_payload *tlv = tlv_payload_new(tmpctx);

/* BOLT #4:
*
* The writer:
*...
* - For every node:
* - MUST include `amt_to_forward` and `outgoing_cltv_value`.
* - For every non-final node:
Expand All @@ -68,8 +65,8 @@ u8 *onion_final_hop(const tal_t *ctx,
const struct secret *payment_secret,
const u8 *payment_metadata)
{
struct tlv_tlv_payload *tlv = tlv_tlv_payload_new(tmpctx);
struct tlv_tlv_payload_payment_data tlv_pdata;
struct tlv_payload *tlv = tlv_payload_new(tmpctx);
struct tlv_payload_payment_data tlv_pdata;

/* These go together! */
if (!payment_secret)
Expand All @@ -78,7 +75,6 @@ u8 *onion_final_hop(const tal_t *ctx,
/* BOLT #4:
*
* The writer:
*...
* - For every node:
* - MUST include `amt_to_forward` and `outgoing_cltv_value`.
*...
Expand Down Expand Up @@ -108,7 +104,7 @@ u8 *onion_blinded_hop(const tal_t *ctx,
const u8 *enctlv,
const struct pubkey *blinding)
{
struct tlv_tlv_payload *tlv = tlv_tlv_payload_new(tmpctx);
struct tlv_payload *tlv = tlv_payload_new(tmpctx);

if (amt_to_forward) {
tlv->amt_to_forward
Expand Down
2 changes: 1 addition & 1 deletion common/onion_encode.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ struct onion_payload {
struct secret blinding_ss;

/* The raw TLVs contained in the payload. */
struct tlv_tlv_payload *tlv;
struct tlv_payload *tlv;
};

u8 *onion_nonfinal_hop(const tal_t *ctx,
Expand Down
2 changes: 1 addition & 1 deletion common/sphinx.c
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ struct route_step *process_onionpacket(
cursor - paddedheader, 0);
fromwire_hmac(&cursor, &max, &step->next->hmac);

/* BOLT-remove-legacy-onion #4:
/* BOLT #4:
* Since no `payload` TLV value can ever be shorter than 2 bytes, `length` values of 0 and 1 are
* reserved. (`0` indicated a legacy format no longer supported, and `1` is reserved for future
* use). */
Expand Down
2 changes: 1 addition & 1 deletion lightningd/invoice.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ static void invoice_payment_add_tlvs(struct json_stream *stream,
struct htlc_set *hset)
{
struct htlc_in *hin;
const struct tlv_tlv_payload *tlvs;
const struct tlv_payload *tlvs;
assert(tal_count(hset->htlcs) > 0);

/* Pick the first HTLC as representative for the entire set. */
Expand Down
8 changes: 0 additions & 8 deletions lightningd/pay.c
Original file line number Diff line number Diff line change
Expand Up @@ -1184,14 +1184,6 @@ send_payment(struct lightningd *ld,
ret = pubkey_from_node_id(&pubkey, &ids[i]);
assert(ret);

/* BOLT #4:
* - Unless `node_announcement`, `init` message or the
* [BOLT #11](11-payment-encoding.md#tagged-fields) offers feature
* `var_onion_optin`:
* - MUST use the legacy payload format instead.
*/
/* FIXME: This requirement is now obsolete, and we should remove it! */

onion = onion_final_hop(cmd,
route[i].amount,
base_expiry + route[i].delay,
Expand Down
Loading

0 comments on commit 47731be

Please sign in to comment.