common/onion: remove all trace of legacy parsing.

We still have an "enum forward_style" for the database, where old-style
forwards can still exist.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Removed: Protocol: we no longer forward HTLCs with legacy onions.
This commit is contained in:
Rusty Russell
2022-09-28 13:39:41 +09:30
committed by Christian Decker
parent 1de4e46276
commit c8ad9e18a9
6 changed files with 19 additions and 131 deletions

View File

@@ -130,41 +130,22 @@ static bool pull_payload_length(const u8 **cursor,
if (!cursor)
return false;
/* BOLT #4:
* - Legacy `hop_data` format, identified by a single `0x00` byte for
* length. In this case the `hop_payload_length` is defined to be 32
* bytes.
*/
if (has_realm && *len == 0) {
if (type)
*type = ONION_V0_PAYLOAD;
assert(*cursor - start == 1);
*len = 1 + 32;
return true;
}
/* 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
* `length`.
*/
if (!has_realm || *len > 1) {
/* It's still invalid if it claims to be too long! */
if (has_realm) {
if (*len > ROUTING_INFO_SIZE - HMAC_SIZE)
return false;
} else {
if (*len > *max)
return false;
}
if (*len <= 1)
return false;
if (type)
*type = ONION_TLV_PAYLOAD;
*len += (*cursor - start);
return true;
}
/* It's invalid if it claims to be too long! */
if (*len > *max)
return false;
return false;
if (type)
*type = ONION_TLV_PAYLOAD;
*len += (*cursor - start);
return true;
}
size_t onion_payload_length(const u8 *raw_payload, size_t len, bool has_realm,
@@ -235,26 +216,6 @@ struct onion_payload *onion_decode(const tal_t *ctx,
goto fail_no_tlv;
}
/* Very limited legacy handling: forward only. */
if (p->type == ONION_V0_PAYLOAD && rs->nextcase == ONION_FORWARD) {
p->forward_channel = tal(p, struct short_channel_id);
fromwire_short_channel_id(&cursor, &max, p->forward_channel);
p->total_msat = NULL;
p->amt_to_forward = fromwire_amount_msat(&cursor, &max);
p->outgoing_cltv = fromwire_u32(&cursor, &max);
p->payment_secret = NULL;
p->payment_metadata = NULL;
p->blinding = NULL;
/* We can't handle blinding with a legacy payload */
if (blinding)
return tal_free(p);
/* If they somehow got an invalid onion this far, fail. */
if (!cursor)
return tal_free(p);
p->tlv = NULL;
return p;
}
/* We do this manually so we can accept extra types, and get
* error off and type. */
tlv = tlv_tlv_payload_new(p);

View File

@@ -7,7 +7,6 @@
struct route_step;
enum onion_payload_type {
ONION_V0_PAYLOAD = 0,
ONION_TLV_PAYLOAD = 1,
};

View File

@@ -53,27 +53,6 @@ enum route_next_case {
*/
struct sphinx_path;
/* BOLT #4:
*
* ## Legacy `hop_data` payload format
*
* The `hop_data` format is identified by a single `0x00`-byte length,
* for backward compatibility. Its payload is defined as:
*
* 1. type: `hop_data` (for `realm` 0)
* 2. data:
* * [`short_channel_id`:`short_channel_id`]
* * [`u64`:`amt_to_forward`]
* * [`u32`:`outgoing_cltv_value`]
* * [`12*byte`:`padding`]
*/
struct hop_data_legacy {
u8 realm;
struct short_channel_id channel_id;
struct amount_msat amt_forward;
u32 outgoing_cltv;
};
/*
* All the necessary information to generate a valid onion for this hop on a
* sphinx path. The payload is preserialized in order since the onion