Skip to content

Commit

Permalink
tools/generate_wire.py: tlvs should start with tlv_
Browse files Browse the repository at this point in the history
No more "towire_offer", but "towire_tlv_offer".

This means we double-up on the unfortunately-named `tlv_payload` inside
the onion, but we should rename that in the spec when we remove
old payloads.

Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell committed Mar 25, 2022
1 parent f447e39 commit fa0c29f
Show file tree
Hide file tree
Showing 22 changed files with 114 additions and 114 deletions.
4 changes: 2 additions & 2 deletions common/blindedpath.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ static u8 *enctlv_from_encmsg(const tal_t *ctx,
struct pubkey *node_alias)
{
u8 *encmsg_raw = tal_arr(NULL, u8, 0);
towire_encrypted_data_tlv(&encmsg_raw, encmsg);
towire_tlv_encrypted_data_tlv(&encmsg_raw, encmsg);
return enctlv_from_encmsg_raw(ctx, blinding, node, take(encmsg_raw),
next_blinding, node_alias);
}
Expand Down Expand Up @@ -198,7 +198,7 @@ static struct tlv_encrypted_data_tlv *decrypt_encmsg(const tal_t *ctx,
* - MUST drop the message.
*/
encmsg = tlv_encrypted_data_tlv_new(ctx);
if (!fromwire_encrypted_data_tlv(&cursor, &maxlen, encmsg)
if (!fromwire_tlv_encrypted_data_tlv(&cursor, &maxlen, encmsg)
|| !tlv_fields_valid(encmsg->fields, NULL, NULL))
return tal_free(encmsg);

Expand Down
12 changes: 6 additions & 6 deletions common/bolt12.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ char *offer_encode(const tal_t *ctx, const struct tlv_offer *offer_tlv)
u8 *wire;

wire = tal_arr(tmpctx, u8, 0);
towire_offer(&wire, offer_tlv);
towire_tlv_offer(&wire, offer_tlv);

return to_bech32_charset(ctx, "lno", wire);
}
Expand All @@ -174,7 +174,7 @@ struct tlv_offer *offer_decode(const tal_t *ctx,
if (!data)
return tal_free(offer);

if (!fromwire_offer(&data, &dlen, offer)) {
if (!fromwire_tlv_offer(&data, &dlen, offer)) {
*fail = tal_fmt(ctx, "invalid offer data");
return tal_free(offer);
}
Expand Down Expand Up @@ -208,7 +208,7 @@ char *invrequest_encode(const tal_t *ctx, const struct tlv_invoice_request *invr
u8 *wire;

wire = tal_arr(tmpctx, u8, 0);
towire_invoice_request(&wire, invrequest_tlv);
towire_tlv_invoice_request(&wire, invrequest_tlv);

return to_bech32_charset(ctx, "lnr", wire);
}
Expand All @@ -227,7 +227,7 @@ struct tlv_invoice_request *invrequest_decode(const tal_t *ctx,
if (!data)
return tal_free(invrequest);

if (!fromwire_invoice_request(&data, &dlen, invrequest)) {
if (!fromwire_tlv_invoice_request(&data, &dlen, invrequest)) {
*fail = tal_fmt(ctx, "invalid invoice_request data");
return tal_free(invrequest);
}
Expand All @@ -247,7 +247,7 @@ char *invoice_encode(const tal_t *ctx, const struct tlv_invoice *invoice_tlv)
u8 *wire;

wire = tal_arr(tmpctx, u8, 0);
towire_invoice(&wire, invoice_tlv);
towire_tlv_invoice(&wire, invoice_tlv);

return to_bech32_charset(ctx, "lni", wire);
}
Expand All @@ -266,7 +266,7 @@ struct tlv_invoice *invoice_decode_nosig(const tal_t *ctx,
if (!data)
return tal_free(invoice);

if (!fromwire_invoice(&data, &dlen, invoice)) {
if (!fromwire_tlv_invoice(&data, &dlen, invoice)) {
*fail = tal_fmt(ctx, "invalid invoice data");
return tal_free(invoice);
}
Expand Down
6 changes: 3 additions & 3 deletions common/onion.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ static u8 *make_tlv_hop(const tal_t *ctx,
/* We can't have over 64k anyway */
u8 *tlvs = tal_arr(ctx, u8, 3);

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

switch (bigsize_put(tlvs, tal_bytelen(tlvs) - 3)) {
case 1:
Expand Down Expand Up @@ -195,7 +195,7 @@ static struct tlv_tlv_payload *decrypt_tlv(const tal_t *ctx,
tlv = tlv_tlv_payload_new(ctx);
cursor = dec;
max = tal_bytelen(dec);
if (!fromwire_tlv_payload(&cursor, &max, tlv))
if (!fromwire_tlv_tlv_payload(&cursor, &max, tlv))
return tal_free(tlv);

return tlv;
Expand All @@ -220,7 +220,7 @@ struct onion_payload *onion_decode(const tal_t *ctx,
goto general_fail;

tlv = tlv_tlv_payload_new(p);
if (!fromwire_tlv_payload(&cursor, &max, tlv)) {
if (!fromwire_tlv_tlv_payload(&cursor, &max, tlv)) {
/* FIXME: Fill in correct thing here! */
goto general_fail;
}
Expand Down
4 changes: 2 additions & 2 deletions common/test/run-blindedpath_onion.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ static u8 *next_onion(const tal_t *ctx, u8 *omsg,
max = tal_bytelen(rs->raw_payload);
maxlen = fromwire_bigsize(&cursor, &max);
om = tlv_onionmsg_payload_new(tmpctx);
assert(fromwire_onionmsg_payload(&cursor, &maxlen, om));
assert(fromwire_tlv_onionmsg_payload(&cursor, &maxlen, om));

if (rs->nextcase == ONION_END)
return NULL;
Expand Down Expand Up @@ -204,7 +204,7 @@ int main(int argc, char *argv[])
= tlv_onionmsg_payload_new(tmpctx);
payload->encrypted_data_tlv = enctlv[i];
onionmsg_payload[i] = tal_arr(tmpctx, u8, 0);
towire_onionmsg_payload(&onionmsg_payload[i], payload);
towire_tlv_onionmsg_payload(&onionmsg_payload[i], payload);
sphinx_add_modern_hop(sphinx_path, &alias[i],
onionmsg_payload[i]);
}
Expand Down
42 changes: 21 additions & 21 deletions common/test/run-bolt12_decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,6 @@ bool fromwire_bool(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
/* Generated stub for fromwire_fail */
void *fromwire_fail(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
{ fprintf(stderr, "fromwire_fail called!\n"); abort(); }
/* Generated stub for fromwire_invoice */
bool fromwire_invoice(const u8 **cursor UNNEEDED, size_t *max UNNEEDED,
struct tlv_invoice * record UNNEEDED)
{ fprintf(stderr, "fromwire_invoice called!\n"); abort(); }
/* Generated stub for fromwire_invoice_request */
bool fromwire_invoice_request(const u8 **cursor UNNEEDED, size_t *max UNNEEDED,
struct tlv_invoice_request * record UNNEEDED)
{ fprintf(stderr, "fromwire_invoice_request called!\n"); abort(); }
/* Generated stub for fromwire_offer */
bool fromwire_offer(const u8 **cursor UNNEEDED, size_t *max UNNEEDED,
struct tlv_offer * record UNNEEDED)
{ fprintf(stderr, "fromwire_offer called!\n"); abort(); }
/* Generated stub for fromwire_secp256k1_ecdsa_signature */
void fromwire_secp256k1_ecdsa_signature(const u8 **cursor UNNEEDED, size_t *max UNNEEDED,
secp256k1_ecdsa_signature *signature UNNEEDED)
Expand All @@ -79,6 +67,18 @@ void fromwire_sha256(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct sh
u8 *fromwire_tal_arrn(const tal_t *ctx UNNEEDED,
const u8 **cursor UNNEEDED, size_t *max UNNEEDED, size_t num UNNEEDED)
{ fprintf(stderr, "fromwire_tal_arrn called!\n"); abort(); }
/* Generated stub for fromwire_tlv_invoice */
bool fromwire_tlv_invoice(const u8 **cursor UNNEEDED, size_t *max UNNEEDED,
struct tlv_invoice * record UNNEEDED)
{ fprintf(stderr, "fromwire_tlv_invoice called!\n"); abort(); }
/* Generated stub for fromwire_tlv_invoice_request */
bool fromwire_tlv_invoice_request(const u8 **cursor UNNEEDED, size_t *max UNNEEDED,
struct tlv_invoice_request * record UNNEEDED)
{ fprintf(stderr, "fromwire_tlv_invoice_request called!\n"); abort(); }
/* Generated stub for fromwire_tlv_offer */
bool fromwire_tlv_offer(const u8 **cursor UNNEEDED, size_t *max UNNEEDED,
struct tlv_offer * record UNNEEDED)
{ fprintf(stderr, "fromwire_tlv_offer called!\n"); abort(); }
/* Generated stub for fromwire_u32 */
u32 fromwire_u32(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
{ fprintf(stderr, "fromwire_u32 called!\n"); abort(); }
Expand Down Expand Up @@ -125,22 +125,22 @@ void towire(u8 **pptr UNNEEDED, const void *data UNNEEDED, size_t len UNNEEDED)
/* Generated stub for towire_bool */
void towire_bool(u8 **pptr UNNEEDED, bool v UNNEEDED)
{ fprintf(stderr, "towire_bool called!\n"); abort(); }
/* Generated stub for towire_invoice */
void towire_invoice(u8 **pptr UNNEEDED, const struct tlv_invoice *record UNNEEDED)
{ fprintf(stderr, "towire_invoice called!\n"); abort(); }
/* Generated stub for towire_invoice_request */
void towire_invoice_request(u8 **pptr UNNEEDED, const struct tlv_invoice_request *record UNNEEDED)
{ fprintf(stderr, "towire_invoice_request called!\n"); abort(); }
/* Generated stub for towire_offer */
void towire_offer(u8 **pptr UNNEEDED, const struct tlv_offer *record UNNEEDED)
{ fprintf(stderr, "towire_offer called!\n"); abort(); }
/* Generated stub for towire_secp256k1_ecdsa_signature */
void towire_secp256k1_ecdsa_signature(u8 **pptr UNNEEDED,
const secp256k1_ecdsa_signature *signature UNNEEDED)
{ fprintf(stderr, "towire_secp256k1_ecdsa_signature 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(); }
/* Generated stub for towire_tlv_invoice */
void towire_tlv_invoice(u8 **pptr UNNEEDED, const struct tlv_invoice *record UNNEEDED)
{ fprintf(stderr, "towire_tlv_invoice called!\n"); abort(); }
/* Generated stub for towire_tlv_invoice_request */
void towire_tlv_invoice_request(u8 **pptr UNNEEDED, const struct tlv_invoice_request *record UNNEEDED)
{ fprintf(stderr, "towire_tlv_invoice_request called!\n"); abort(); }
/* Generated stub for towire_tlv_offer */
void towire_tlv_offer(u8 **pptr UNNEEDED, const struct tlv_offer *record UNNEEDED)
{ fprintf(stderr, "towire_tlv_offer called!\n"); abort(); }
/* Generated stub for towire_u32 */
void towire_u32(u8 **pptr UNNEEDED, u32 v UNNEEDED)
{ fprintf(stderr, "towire_u32 called!\n"); abort(); }
Expand Down
4 changes: 2 additions & 2 deletions common/test/run-bolt12_merkle-json.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,14 @@ int main(int argc, char *argv[])
if (streq(tlvtype, "n1")) {
struct tlv_n1 *n1 = tlv_n1_new(tmpctx);
size_t len = tal_bytelen(tlv);
assert(fromwire_n1(&tlv, &len, n1));
assert(fromwire_tlv_n1(&tlv, &len, n1));
assert(len == 0);
merkle_tlv(n1->fields, &merkle);
assert(sha256_eq(&merkle, &expected_merkle));
} else if (streq(tlvtype, "offer")) {
struct tlv_offer *offer = tlv_offer_new(tmpctx);
size_t len = tal_bytelen(tlv);
assert(fromwire_offer(&tlv, &len, offer));
assert(fromwire_tlv_offer(&tlv, &len, offer));
assert(len == 0);
merkle_tlv(offer->fields, &merkle);
assert(sha256_eq(&merkle, &expected_merkle));
Expand Down
4 changes: 2 additions & 2 deletions common/test/run-bolt12_merkle.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ static void merkle_n1(const struct tlv_n1 *n1, struct sha256 *test_m)

/* Linearize to populate ->fields */
v = tal_arr(tmpctx, u8, 0);
towire_n1(&v, n1);
towire_tlv_n1(&v, n1);

len = tal_bytelen(v);
tmp = tlv_n1_new(tmpctx);
if (!fromwire_n1(cast_const2(const u8 **, &v), &len, tmp))
if (!fromwire_tlv_n1(cast_const2(const u8 **, &v), &len, tmp))
abort();
assert(len == 0);

Expand Down
42 changes: 21 additions & 21 deletions common/test/run-bolt12_period.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,6 @@ bool fromwire_bool(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
/* Generated stub for fromwire_fail */
void *fromwire_fail(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
{ fprintf(stderr, "fromwire_fail called!\n"); abort(); }
/* Generated stub for fromwire_invoice */
bool fromwire_invoice(const u8 **cursor UNNEEDED, size_t *max UNNEEDED,
struct tlv_invoice * record UNNEEDED)
{ fprintf(stderr, "fromwire_invoice called!\n"); abort(); }
/* Generated stub for fromwire_invoice_request */
bool fromwire_invoice_request(const u8 **cursor UNNEEDED, size_t *max UNNEEDED,
struct tlv_invoice_request * record UNNEEDED)
{ fprintf(stderr, "fromwire_invoice_request called!\n"); abort(); }
/* Generated stub for fromwire_offer */
bool fromwire_offer(const u8 **cursor UNNEEDED, size_t *max UNNEEDED,
struct tlv_offer * record UNNEEDED)
{ fprintf(stderr, "fromwire_offer called!\n"); abort(); }
/* Generated stub for fromwire_secp256k1_ecdsa_signature */
void fromwire_secp256k1_ecdsa_signature(const u8 **cursor UNNEEDED, size_t *max UNNEEDED,
secp256k1_ecdsa_signature *signature UNNEEDED)
Expand All @@ -82,6 +70,18 @@ void fromwire_sha256(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct sh
u8 *fromwire_tal_arrn(const tal_t *ctx UNNEEDED,
const u8 **cursor UNNEEDED, size_t *max UNNEEDED, size_t num UNNEEDED)
{ fprintf(stderr, "fromwire_tal_arrn called!\n"); abort(); }
/* Generated stub for fromwire_tlv_invoice */
bool fromwire_tlv_invoice(const u8 **cursor UNNEEDED, size_t *max UNNEEDED,
struct tlv_invoice * record UNNEEDED)
{ fprintf(stderr, "fromwire_tlv_invoice called!\n"); abort(); }
/* Generated stub for fromwire_tlv_invoice_request */
bool fromwire_tlv_invoice_request(const u8 **cursor UNNEEDED, size_t *max UNNEEDED,
struct tlv_invoice_request * record UNNEEDED)
{ fprintf(stderr, "fromwire_tlv_invoice_request called!\n"); abort(); }
/* Generated stub for fromwire_tlv_offer */
bool fromwire_tlv_offer(const u8 **cursor UNNEEDED, size_t *max UNNEEDED,
struct tlv_offer * record UNNEEDED)
{ fprintf(stderr, "fromwire_tlv_offer called!\n"); abort(); }
/* Generated stub for fromwire_u32 */
u32 fromwire_u32(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
{ fprintf(stderr, "fromwire_u32 called!\n"); abort(); }
Expand Down Expand Up @@ -132,22 +132,22 @@ void towire(u8 **pptr UNNEEDED, const void *data UNNEEDED, size_t len UNNEEDED)
/* Generated stub for towire_bool */
void towire_bool(u8 **pptr UNNEEDED, bool v UNNEEDED)
{ fprintf(stderr, "towire_bool called!\n"); abort(); }
/* Generated stub for towire_invoice */
void towire_invoice(u8 **pptr UNNEEDED, const struct tlv_invoice *record UNNEEDED)
{ fprintf(stderr, "towire_invoice called!\n"); abort(); }
/* Generated stub for towire_invoice_request */
void towire_invoice_request(u8 **pptr UNNEEDED, const struct tlv_invoice_request *record UNNEEDED)
{ fprintf(stderr, "towire_invoice_request called!\n"); abort(); }
/* Generated stub for towire_offer */
void towire_offer(u8 **pptr UNNEEDED, const struct tlv_offer *record UNNEEDED)
{ fprintf(stderr, "towire_offer called!\n"); abort(); }
/* Generated stub for towire_secp256k1_ecdsa_signature */
void towire_secp256k1_ecdsa_signature(u8 **pptr UNNEEDED,
const secp256k1_ecdsa_signature *signature UNNEEDED)
{ fprintf(stderr, "towire_secp256k1_ecdsa_signature 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(); }
/* Generated stub for towire_tlv_invoice */
void towire_tlv_invoice(u8 **pptr UNNEEDED, const struct tlv_invoice *record UNNEEDED)
{ fprintf(stderr, "towire_tlv_invoice called!\n"); abort(); }
/* Generated stub for towire_tlv_invoice_request */
void towire_tlv_invoice_request(u8 **pptr UNNEEDED, const struct tlv_invoice_request *record UNNEEDED)
{ fprintf(stderr, "towire_tlv_invoice_request called!\n"); abort(); }
/* Generated stub for towire_tlv_offer */
void towire_tlv_offer(u8 **pptr UNNEEDED, const struct tlv_offer *record UNNEEDED)
{ fprintf(stderr, "towire_tlv_offer called!\n"); abort(); }
/* Generated stub for towire_u32 */
void towire_u32(u8 **pptr UNNEEDED, u32 v UNNEEDED)
{ fprintf(stderr, "towire_u32 called!\n"); abort(); }
Expand Down
2 changes: 1 addition & 1 deletion common/test/run-route_blinding_override_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ static u8 *json_to_enctlvs(const tal_t *ctx,
}
}
ret = tal_arr(ctx, u8, 0);
towire_encrypted_data_tlv(&ret, enctlv);
towire_tlv_encrypted_data_tlv(&ret, enctlv);
towire_u8_array(&ret, appended, tal_bytelen(appended));
return ret;
}
Expand Down
2 changes: 1 addition & 1 deletion common/test/run-route_blinding_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ static u8 *json_to_enctlvs(const tal_t *ctx,
}
}
ret = tal_arr(ctx, u8, 0);
towire_encrypted_data_tlv(&ret, enctlv);
towire_tlv_encrypted_data_tlv(&ret, enctlv);
towire_u8_array(&ret, appended, tal_bytelen(appended));
return ret;
}
Expand Down
2 changes: 1 addition & 1 deletion connectd/onion_message.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void handle_onion_message(struct daemon *daemon,
}

om = tlv_onionmsg_payload_new(msg);
if (!fromwire_onionmsg_payload(&cursor, &maxlen, om)) {
if (!fromwire_tlv_onionmsg_payload(&cursor, &maxlen, om)) {
status_peer_debug(&peer->id, "onion msg: invalid onionmsg_payload %s",
tal_hex(tmpctx, rs->raw_payload));
return;
Expand Down
2 changes: 1 addition & 1 deletion lightningd/offer.c
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ static struct command_result *json_createinvoicerequest(struct command *cmd,
* [Signature Calculation](#signature-calculation) using the `payer_key`.
*/
/* This populates the ->fields from our entries */
invreq->fields = tlv_make_fields(invreq, invoice_request);
invreq->fields = tlv_make_fields(invreq, tlv_invoice_request);
merkle_tlv(invreq->fields, &merkle);
invreq->signature = tal(invreq, struct bip340sig);
if (deprecated_apis)
Expand Down
2 changes: 1 addition & 1 deletion lightningd/onion_message.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ void handle_onionmsg_to_us(struct lightningd *ld, const u8 *msg)
submsglen = tal_bytelen(submsg);
subptr = submsg;
payload->om = tlv_onionmsg_payload_new(payload);
if (!fromwire_onionmsg_payload(&subptr, &submsglen, payload->om)) {
if (!fromwire_tlv_onionmsg_payload(&subptr, &submsglen, payload->om)) {
log_broken(ld->log, "bad got_onionmsg_tous om: %s",
tal_hex(tmpctx, msg));
return;
Expand Down
Loading

0 comments on commit fa0c29f

Please sign in to comment.