diff --git a/common/test/run-bolt12_merkle-json.c b/common/test/run-bolt12_merkle-json.c index 204f9ecf7..d1eaf16d9 100644 --- a/common/test/run-bolt12_merkle-json.c +++ b/common/test/run-bolt12_merkle-json.c @@ -57,9 +57,6 @@ void towire_secp256k1_ecdsa_signature(u8 **pptr UNNEEDED, /* 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_tu16 */ -void towire_tu16(u8 **pptr UNNEEDED, u16 v UNNEEDED) -{ fprintf(stderr, "towire_tu16 called!\n"); abort(); } /* Generated stub for towire_tu32 */ void towire_tu32(u8 **pptr UNNEEDED, u32 v UNNEEDED) { fprintf(stderr, "towire_tu32 called!\n"); abort(); } diff --git a/lightningd/invoice.c b/lightningd/invoice.c index 7b3ec16c9..6ae17b9e5 100644 --- a/lightningd/invoice.c +++ b/lightningd/invoice.c @@ -1634,15 +1634,13 @@ static struct command_result *fail_exists(struct command *cmd, /* This is only if we're a public node; otherwise, the offers plugin * will have populated a real blinded path */ -static struct tlv_invoice *add_stub_blindedpath(const tal_t *ctx, - struct lightningd *ld, - struct tlv_invoice *inv STEALS) +static void add_stub_blindedpath(const tal_t *ctx, + struct lightningd *ld, + struct tlv_invoice *inv) { struct blinded_path *path; struct privkey blinding; struct tlv_encrypted_data_tlv *tlv; - u8 *wire; - size_t dlen; path = tal(NULL, struct blinded_path); if (!pubkey_from_node_id(&path->first_node_id, &ld->id)) @@ -1686,14 +1684,9 @@ static struct tlv_invoice *add_stub_blindedpath(const tal_t *ctx, inv->invoice_blindedpay[0]->htlc_maximum_msat = AMOUNT_MSAT(21000000 * MSAT_PER_BTC); inv->invoice_blindedpay[0]->features = NULL; - /* But we need to update ->fields, so re-linearize */ - wire = tal_arr(tmpctx, u8, 0); - towire_tlv_invoice(&wire, inv); - tal_free(inv); - - dlen = tal_bytelen(wire); - return fromwire_tlv_invoice(ctx, - cast_const2(const u8 **, &wire), &dlen); + /* Recalc ->fields */ + tal_free(inv->fields); + inv->fields = tlv_make_fields(inv, tlv_invoice); } static struct command_result *json_createinvoice(struct command *cmd, @@ -1782,7 +1775,7 @@ static struct command_result *json_createinvoice(struct command *cmd, * can recognize payments (bolt12 doesn't use * payment_secret) */ if (!inv->invoice_paths) - inv = add_stub_blindedpath(cmd, cmd->ld, inv); + add_stub_blindedpath(cmd, cmd->ld, inv); if (inv->signature) return command_fail(cmd, JSONRPC2_INVALID_PARAMS, diff --git a/plugins/fetchinvoice.c b/plugins/fetchinvoice.c index f109a7e06..3a4892ae5 100644 --- a/plugins/fetchinvoice.c +++ b/plugins/fetchinvoice.c @@ -907,14 +907,11 @@ static struct command_result *invreq_done(struct command *cmd, static struct command_result * force_payer_secret(struct command *cmd, struct sent *sent, - struct tlv_invoice_request *invreq, + struct tlv_invoice_request *invreq STEALS, const struct secret *payer_secret) { struct sha256 merkle, sha; secp256k1_keypair kp; - u8 *msg; - const u8 *p; - size_t len; if (secp256k1_keypair_create(secp256k1_ctx, &kp, payer_secret->data) != 1) return command_fail(cmd, LIGHTNINGD, "Bad payer_secret"); @@ -928,16 +925,11 @@ force_payer_secret(struct command *cmd, "secp256k1_keypair_pub failed on %s?", type_to_string(tmpctx, struct secret, payer_secret)); - /* Linearize populates ->fields */ - msg = tal_arr(tmpctx, u8, 0); - towire_tlv_invoice_request(&msg, invreq); - p = msg; - len = tal_bytelen(msg); - sent->invreq = fromwire_tlv_invoice_request(cmd, &p, &len); - if (!sent->invreq) - plugin_err(cmd->plugin, - "Could not remarshall invreq %s", tal_hex(tmpctx, msg)); + /* Re-calculate ->fields */ + tal_free(invreq->fields); + invreq->fields = tlv_make_fields(invreq, tlv_invoice_request); + sent->invreq = tal_steal(sent, invreq); merkle_tlv(sent->invreq->fields, &merkle); sighash_from_merkle("invoice_request", "signature", &merkle, &sha); diff --git a/wire/Makefile b/wire/Makefile index e4c0d09ed..bce447bfc 100644 --- a/wire/Makefile +++ b/wire/Makefile @@ -137,7 +137,7 @@ wire/peer_exp_printgen.h_args := --include='wire/channel_type_printgen.h' wire/onion_exp_wiregen.h_args := $(wire/onion_wiregen.h_args) wire/onion_exp_wiregen.c_args := $(wire/onion_wiregen.c_args) -wire/bolt12_wiregen.c_args := -s --expose-tlv-type=tlv_blinded_path --expose-tlv-type=tlv_invoice_request +wire/bolt12_wiregen.c_args := -s --expose-tlv-type=tlv_blinded_path --expose-tlv-type=tlv_invoice_request --expose-tlv-type=tlv_invoice wire/bolt12_wiregen.h_args := --include='bitcoin/short_channel_id.h' --include='bitcoin/signature.h' --include='bitcoin/privkey.h' --include='common/bigsize.h' --include='common/amount.h' --include='common/node_id.h' --include='bitcoin/block.h' --include='wire/onion_wire.h' $(wire/bolt12_wiregen.c_args) wire/bolt12_printgen.c_args := --expose-tlv-type=tlv_blinded_path --expose-tlv-type=tlv_invoice_request --include='wire/onion$(EXP)_wiregen.h' --include='wire/onion$(EXP)_printgen.h' @@ -155,7 +155,7 @@ wire/channel_type_wiregen.h_args := -s wire/channel_type_wiregen.c_args := $(wire/channel_type_wiregen.h_args) # All generated wire/ files depend on this Makefile -$(filter %printgen.h %printgen.c %wiregen.h %wiregen.c, $(WIRE_SRC) $(WIRE_PRINT_SRC) $(WIRE_NONEXP_SRC) $(WIRE_HEADERS) $(WIRE_NONEXP_HEADERS)): wire/Makefile +$(filter %printgen.h %printgen.c %wiregen.h %wiregen.c, $(WIRE_SRC) $(WIRE_BOLT12_SRC) $(WIRE_PRINT_SRC) $(WIRE_NONEXP_SRC) $(WIRE_HEADERS) $(WIRE_NONEXP_HEADERS)): wire/Makefile maintainer-clean: wire-maintainer-clean