From 522e14e419d2a57690bc9cdf5062ca18c4464c07 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 21 Jul 2021 11:01:39 +0930 Subject: [PATCH 1/9] bolt12: import latest spec (timestamp -> created_at). @shesek points out that we called this field created_at in bolt11 decode, which makes more sense anyway. Changelog-EXPERIMENTAL: bolt12 decode `timestamp` field deprecated in favor of new name `created_at`. Signed-off-by: Rusty Russell --- common/bolt12.h | 4 ++-- devtools/bolt12-cli.c | 22 +++++++++++----------- doc/lightning-decode.7 | 8 ++++---- doc/lightning-decode.7.md | 8 ++++---- doc/schemas/decode.schema.json | 14 +++++++++----- plugins/fetchinvoice.c | 14 +++++++------- plugins/offers.c | 17 ++++++++++------- plugins/offers_invreq_hook.c | 22 +++++++++++----------- plugins/pay.c | 14 +++++++------- wire/bolt12_exp_wire.csv | 6 +++--- wire/bolt12_wire.csv | 6 +++--- wire/bolt12_wiregen.c | 18 +++++++++--------- wire/bolt12_wiregen.h | 4 ++-- 13 files changed, 82 insertions(+), 75 deletions(-) diff --git a/common/bolt12.h b/common/bolt12.h index a136e17304e1..71d17ce894cb 100644 --- a/common/bolt12.h +++ b/common/bolt12.h @@ -12,10 +12,10 @@ struct feature_set; /* BOLT-offers #12: * - if `relative_expiry` is present: * - MUST reject the invoice if the current time since 1970-01-01 UTC - * is greater than `timestamp` plus `seconds_from_timestamp`. + * is greater than `created_at` plus `seconds_from_creation`. * - otherwise: * - MUST reject the invoice if the current time since 1970-01-01 UTC - * is greater than `timestamp` plus 7200. + * is greater than `created_at` plus 7200. */ #define BOLT12_DEFAULT_REL_EXPIRY 7200 diff --git a/devtools/bolt12-cli.c b/devtools/bolt12-cli.c index 243c09191d82..4f454eff542f 100644 --- a/devtools/bolt12-cli.c +++ b/devtools/bolt12-cli.c @@ -379,9 +379,9 @@ static void print_payer_note(const char *payer_note) (int)tal_bytelen(payer_note), payer_note); } -static void print_timestamp(u64 timestamp) +static void print_created_at(u64 timestamp) { - printf("timestamp: %"PRIu64" (%s)\n", + printf("created_at: %"PRIu64" (%s)\n", timestamp, fmt_time(tmpctx, timestamp)); } @@ -396,27 +396,27 @@ static void print_cltv(u32 cltv) printf("min_final_cltv_expiry: %u\n", cltv); } -static void print_relative_expiry(u64 *timestamp, u32 *relative) +static void print_relative_expiry(u64 *created_at, u32 *relative) { /* Ignore if already malformed */ - if (!timestamp) + if (!created_at) return; /* BOLT-offers #12: * - if `relative_expiry` is present: * - MUST reject the invoice if the current time since 1970-01-01 UTC - * is greater than `timestamp` plus `seconds_from_timestamp`. + * is greater than `created_at` plus `seconds_from_creation`. * - otherwise: * - MUST reject the invoice if the current time since 1970-01-01 UTC - * is greater than `timestamp` plus 7200. + * is greater than `created_at` plus 7200. */ if (!relative) printf("relative_expiry: %u (%s) (default)\n", BOLT12_DEFAULT_REL_EXPIRY, - fmt_time(tmpctx, *timestamp + BOLT12_DEFAULT_REL_EXPIRY)); + fmt_time(tmpctx, *created_at + BOLT12_DEFAULT_REL_EXPIRY)); else printf("relative_expiry: %u (%s)\n", *relative, - fmt_time(tmpctx, *timestamp + *relative)); + fmt_time(tmpctx, *created_at + *relative)); } static void print_fallbacks(const struct tlv_invoice_fallbacks *fallbacks) @@ -622,11 +622,11 @@ int main(int argc, char *argv[]) } if (must_have(invoice, payer_key)) print_payer_key(invoice->payer_key, invoice->payer_info); - if (must_have(invoice, timestamp)) - print_timestamp(*invoice->timestamp); + if (must_have(invoice, created_at)) + print_created_at(*invoice->created_at); if (invoice->payer_note) print_payer_note(invoice->payer_note); - print_relative_expiry(invoice->timestamp, + print_relative_expiry(invoice->created_at, invoice->relative_expiry); if (must_have(invoice, payment_hash)) print_payment_hash(invoice->payment_hash); diff --git a/doc/lightning-decode.7 b/doc/lightning-decode.7 index f4cc5e0310cf..174c04b985ad 100644 --- a/doc/lightning-decode.7 +++ b/doc/lightning-decode.7 @@ -153,11 +153,11 @@ If \fBtype\fR is "bolt12 invoice", and \fBvalid\fR is \fItrue\fR: .IP \[bu] \fBdescription\fR (string): the description of the purpose of the offer .IP \[bu] -\fBtimestamp\fR (u64): the UNIX timestamp of the invoice +\fBcreated_at\fR (u64): the UNIX timestamp of invoice creation .IP \[bu] \fBpayment_hash\fR (hex): the hash of the \fIpayment_preimage\fR (always 64 characters) .IP \[bu] -\fBrelative_expiry\fR (u32): the number of seconds after \fItimestamp\fR when this expires +\fBrelative_expiry\fR (u32): the number of seconds after \fIcreated_at\fR when this expires .IP \[bu] \fBmin_final_cltv_expiry\fR (u32): the number of blocks required by destination .IP \[bu] @@ -256,7 +256,7 @@ the following warnings are possible: .IP \[bu] \fBwarning_invoice_missing_recurrence_basetime\fR: Has \fBrecurrence_counter\fR without \fBrecurrence_basetime\fR .IP \[bu] -\fBwarning_invoice_missing_timestamp\fR: Missing \fBtimestamp\fR +\fBwarning_invoice_missing_created_at\fR: Missing \fBcreated_at\fR .IP \[bu] \fBwarning_invoice_missing_payment_hash\fR: Missing \fBpayment_hash\fR .IP \[bu] @@ -414,4 +414,4 @@ Rusty Russell \fI is mainly responsible\. Main web site: \fIhttps://github.com/ElementsProject/lightning\fR -\" SHA256STAMP:cd54af7c631f06b3db72848cdf90951ceb14d89b8bca981dba69244cd2ddbae5 +\" SHA256STAMP:dda6e1cff3e58c38b637c5a11673b5a9f4837cbdf89ed3be52a8bfc874af87d4 diff --git a/doc/lightning-decode.7.md b/doc/lightning-decode.7.md index e0b62d39be4d..81e6f24a63b2 100644 --- a/doc/lightning-decode.7.md +++ b/doc/lightning-decode.7.md @@ -70,9 +70,9 @@ If **type** is "bolt12 invoice", and **valid** is *true*: - **signature** (bip340sig): BIP-340 signature of the *node_id* on this offer - **amount_msat** (msat): the amount in bitcoin - **description** (string): the description of the purpose of the offer - - **timestamp** (u64): the UNIX timestamp of the invoice + - **created_at** (u64): the UNIX timestamp of invoice creation - **payment_hash** (hex): the hash of the *payment_preimage* (always 64 characters) - - **relative_expiry** (u32): the number of seconds after *timestamp* when this expires + - **relative_expiry** (u32): the number of seconds after *created_at* when this expires - **min_final_cltv_expiry** (u32): the number of blocks required by destination - **offer_id** (hex, optional): the id of this offer (merkle hash of non-signature fields) (always 64 characters) - **chains** (array of hexs, optional): which blockchains this offer is for (missing implies bitcoin mainnet only): @@ -108,7 +108,7 @@ If **type** is "bolt12 invoice", and **valid** is *false*: - **warning_invoice_missing_blinded_payinfo**: Has **paths** without payinfo - **warning_invoice_invalid_blinded_payinfo**: Does not have exactly one payinfo for each of **paths** - **warning_invoice_missing_recurrence_basetime**: Has **recurrence_counter** without **recurrence_basetime** - - **warning_invoice_missing_timestamp**: Missing **timestamp** + - **warning_invoice_missing_created_at**: Missing **created_at** - **warning_invoice_missing_payment_hash**: Missing **payment_hash** - **warning_invoice_refund_signature_missing_payer_key**: Missing **payer_key** for refund_signature - **warning_invoice_refund_signature_invalid**: **refund_signature** incorrect @@ -183,4 +183,4 @@ RESOURCES Main web site: -[comment]: # ( SHA256STAMP:8ca0b9178b8ea6575cd80291001263dc27f721664648086a7c1a02efcb545ee7) +[comment]: # ( SHA256STAMP:fbbfc116c23489d4f346b4d5eb06dd922592c543ec68e5a76b6822b2658bd46d) diff --git a/doc/schemas/decode.schema.json b/doc/schemas/decode.schema.json index ad168d24e06a..33890f511075 100644 --- a/doc/schemas/decode.schema.json +++ b/doc/schemas/decode.schema.json @@ -263,7 +263,7 @@ } }, "then": { - "required": [ "node_id", "signature", "amount_msat", "description", "timestamp", "payment_hash", "relative_expiry", "min_final_cltv_expiry" ], + "required": [ "node_id", "signature", "amount_msat", "description", "created_at", "payment_hash", "relative_expiry", "min_final_cltv_expiry" ], "additionalProperties": false, "properties": { "type": { }, @@ -378,8 +378,11 @@ "description": "the payer-provided blob to derive payer_key" }, "timestamp": { + "deprecated": true + }, + "created_at": { "type": "u64", - "description": "the UNIX timestamp of the invoice" + "description": "the UNIX timestamp of invoice creation" }, "payment_hash": { "type": "hex", @@ -389,7 +392,7 @@ }, "relative_expiry": { "type": "u32", - "description": "the number of seconds after *timestamp* when this expires" + "description": "the number of seconds after *created_at* when this expires" }, "min_final_cltv_expiry": { "type": "u32", @@ -462,6 +465,7 @@ "payer_key": { }, "payer_info": { }, "timestamp": { }, + "created_at": { }, "payment_hash": { }, "relative_expiry": { }, "min_final_cltv_expiry": { }, @@ -487,9 +491,9 @@ "type": "string", "description": "Has **recurrence_counter** without **recurrence_basetime**" }, - "warning_invoice_missing_timestamp": { + "warning_invoice_missing_created_at": { "type": "string", - "description": "Missing **timestamp**" + "description": "Missing **created_at**" }, "warning_invoice_missing_payment_hash": { "type": "string", diff --git a/plugins/fetchinvoice.c b/plugins/fetchinvoice.c index 12a0800814f7..8882a8f0ae81 100644 --- a/plugins/fetchinvoice.c +++ b/plugins/fetchinvoice.c @@ -1413,17 +1413,17 @@ static struct command_result *json_sendinvoice(struct command *cmd, } /* BOLT-offers #12: - * - MUST set `timestamp` to the number of seconds since Midnight 1 - * January 1970, UTC. + * - MUST set `created_at` to the number of seconds since Midnight 1 + * January 1970, UTC when the offer was created. */ - sent->inv->timestamp = tal(sent->inv, u64); - *sent->inv->timestamp = time_now().ts.tv_sec; + sent->inv->created_at = tal(sent->inv, u64); + *sent->inv->created_at = time_now().ts.tv_sec; /* BOLT-offers #12: * - if the expiry for accepting payment is not 7200 seconds after - * `timestamp`: - * - MUST set `relative_expiry` `seconds_from_timestamp` to the number - * of seconds after `timestamp` that payment of this invoice should + * `created_at`: + * - MUST set `relative_expiry` `seconds_from_creation` to the number + * of seconds after `created_at` that payment of this invoice should * not be attempted. */ if (sent->wait_timeout != 7200) { diff --git a/plugins/offers.c b/plugins/offers.c index dad431d97433..305ec1655690 100644 --- a/plugins/offers.c +++ b/plugins/offers.c @@ -543,13 +543,16 @@ static void json_add_b12_invoice(struct json_stream *js, tal_bytelen(invoice->payer_note)); /* BOLT-offers #12: - * - MUST reject the invoice if `timestamp` is not present. + * - MUST reject the invoice if `created_at` is not present. */ - if (invoice->timestamp) - json_add_u64(js, "timestamp", *invoice->timestamp); - else { - json_add_string(js, "warning_invoice_missing_timestamp", - "invoices without a timestamp are invalid"); + if (invoice->created_at) { + /* FIXME: Remove soon! */ + if (deprecated_apis) + json_add_u64(js, "timestamp", *invoice->created_at); + json_add_u64(js, "created_at", *invoice->created_at); + } else { + json_add_string(js, "warning_invoice_missing_created_at", + "invoices without created_at are invalid"); valid = false; } @@ -567,7 +570,7 @@ static void json_add_b12_invoice(struct json_stream *js, /* BOLT-offers #12: * * - if the expiry for accepting payment is not 7200 seconds after - * `timestamp`: + * `created_at`: * - MUST set `relative_expiry` */ if (invoice->relative_expiry) diff --git a/plugins/offers_invreq_hook.c b/plugins/offers_invreq_hook.c index 843738cad511..2facf35ee538 100644 --- a/plugins/offers_invreq_hook.c +++ b/plugins/offers_invreq_hook.c @@ -114,8 +114,8 @@ test_field(struct command *cmd, * - if the invoice corresponds to an offer with `recurrence`: * ... * - if it sets `relative_expiry`: - * - MUST NOT set `relative_expiry` `seconds_from_timestamp` more than the - * number of seconds after `timestamp` that payment for this period will + * - MUST NOT set `relative_expiry` `seconds_from_creation` more than the + * number of seconds after `created_at` that payment for this period will * be accepted. */ static void set_recurring_inv_expiry(struct tlv_invoice *inv, u64 last_pay) @@ -123,10 +123,10 @@ static void set_recurring_inv_expiry(struct tlv_invoice *inv, u64 last_pay) inv->relative_expiry = tal(inv, u32); /* Don't give them a 0 second invoice, even if it's true. */ - if (last_pay <= *inv->timestamp) + if (last_pay <= *inv->created_at) *inv->relative_expiry = 1; else - *inv->relative_expiry = last_pay - *inv->timestamp; + *inv->relative_expiry = last_pay - *inv->created_at; /* FIXME: Shorten expiry if we're doing currency conversion! */ } @@ -292,14 +292,14 @@ static struct command_result *check_period(struct command *cmd, ir->offer->recurrence_base, basetime, period_idx, &paywindow_start, &paywindow_end); - if (*ir->inv->timestamp < paywindow_start) { + if (*ir->inv->created_at < paywindow_start) { return fail_invreq(cmd, ir, "period_index %"PRIu64 " too early (start %"PRIu64")", period_idx, paywindow_start); } - if (*ir->inv->timestamp > paywindow_end) { + if (*ir->inv->created_at > paywindow_end) { return fail_invreq(cmd, ir, "period_index %"PRIu64 " too late (ended %"PRIu64")", @@ -327,9 +327,9 @@ static struct command_result *check_period(struct command *cmd, u64 end = offer_period_start(basetime, period_idx + 1, ir->offer->recurrence); - if (*ir->inv->timestamp > start) { + if (*ir->inv->created_at > start) { *ir->inv->amount - *= (double)((*ir->inv->timestamp - start) + *= (double)((*ir->inv->created_at - start) / (end - start)); /* Round up to make it non-zero if necessary. */ if (*ir->inv->amount == 0) @@ -401,7 +401,7 @@ static struct command_result *check_previous_invoice(struct command *cmd, /* No previous? Just pass through */ if (*ir->invreq->recurrence_counter == 0) - return check_period(cmd, ir, *ir->inv->timestamp); + return check_period(cmd, ir, *ir->inv->created_at); req = jsonrpc_request_start(cmd->plugin, cmd, "listinvoices", @@ -806,8 +806,8 @@ static struct command_result *listoffers_done(struct command *cmd, ir->inv->cltv = tal_dup(ir->inv, u32, &cltv_final); - ir->inv->timestamp = tal(ir->inv, u64); - *ir->inv->timestamp = time_now().ts.tv_sec; + ir->inv->created_at = tal(ir->inv, u64); + *ir->inv->created_at = time_now().ts.tv_sec; /* We may require currency lookup; if so, do it now. */ if (ir->offer->amount && ir->offer->currency) diff --git a/plugins/pay.c b/plugins/pay.c index 95d09ba84bf3..5925354ae774 100644 --- a/plugins/pay.c +++ b/plugins/pay.c @@ -2072,9 +2072,9 @@ static struct command_result *json_paymod(struct command *cmd, if (!b12->payment_hash) return command_fail(cmd, JSONRPC2_INVALID_PARAMS, "invoice missing payment_hash"); - if (!b12->timestamp) + if (!b12->created_at) return command_fail(cmd, JSONRPC2_INVALID_PARAMS, - "invoice missing timestamp"); + "invoice missing created_at"); if (b12->amount) { invmsat = tal(cmd, struct amount_msat); *invmsat = amount_msat(*b12->amount); @@ -2110,17 +2110,17 @@ static struct command_result *json_paymod(struct command *cmd, /* BOLT-offers #12: * - if `relative_expiry` is present: * - MUST reject the invoice if the current time since - * 1970-01-01 UTC is greater than `timestamp` plus - * `seconds_from_timestamp`. + * 1970-01-01 UTC is greater than `created_at` plus + * `seconds_from_creation`. * - otherwise: * - MUST reject the invoice if the current time since - * 1970-01-01 UTC is greater than `timestamp` plus + * 1970-01-01 UTC is greater than `created_at` plus * 7200. */ if (b12->relative_expiry) - invexpiry = *b12->timestamp + *b12->relative_expiry; + invexpiry = *b12->created_at + *b12->relative_expiry; else - invexpiry = *b12->timestamp + BOLT12_DEFAULT_REL_EXPIRY; + invexpiry = *b12->created_at + BOLT12_DEFAULT_REL_EXPIRY; p->local_offer_id = tal_steal(p, local_offer_id); } diff --git a/wire/bolt12_exp_wire.csv b/wire/bolt12_exp_wire.csv index 727dcfbfa38a..4eb79522033b 100644 --- a/wire/bolt12_exp_wire.csv +++ b/wire/bolt12_exp_wire.csv @@ -102,12 +102,12 @@ tlvtype,invoice,payer_note,39 tlvdata,invoice,payer_note,note,utf8,... tlvtype,invoice,payer_info,50 tlvdata,invoice,payer_info,blob,byte,... -tlvtype,invoice,timestamp,40 -tlvdata,invoice,timestamp,timestamp,tu64, +tlvtype,invoice,created_at,40 +tlvdata,invoice,created_at,timestamp,tu64, tlvtype,invoice,payment_hash,42 tlvdata,invoice,payment_hash,payment_hash,sha256, tlvtype,invoice,relative_expiry,44 -tlvdata,invoice,relative_expiry,seconds_from_timestamp,tu32, +tlvdata,invoice,relative_expiry,seconds_from_creation,tu32, tlvtype,invoice,cltv,46 tlvdata,invoice,cltv,min_final_cltv_expiry,tu32, tlvtype,invoice,fallbacks,48 diff --git a/wire/bolt12_wire.csv b/wire/bolt12_wire.csv index 727dcfbfa38a..4eb79522033b 100644 --- a/wire/bolt12_wire.csv +++ b/wire/bolt12_wire.csv @@ -102,12 +102,12 @@ tlvtype,invoice,payer_note,39 tlvdata,invoice,payer_note,note,utf8,... tlvtype,invoice,payer_info,50 tlvdata,invoice,payer_info,blob,byte,... -tlvtype,invoice,timestamp,40 -tlvdata,invoice,timestamp,timestamp,tu64, +tlvtype,invoice,created_at,40 +tlvdata,invoice,created_at,timestamp,tu64, tlvtype,invoice,payment_hash,42 tlvdata,invoice,payment_hash,payment_hash,sha256, tlvtype,invoice,relative_expiry,44 -tlvdata,invoice,relative_expiry,seconds_from_timestamp,tu32, +tlvdata,invoice,relative_expiry,seconds_from_creation,tu32, tlvtype,invoice,cltv,46 tlvdata,invoice,cltv,min_final_cltv_expiry,tu32, tlvtype,invoice,fallbacks,48 diff --git a/wire/bolt12_wiregen.c b/wire/bolt12_wiregen.c index a5d1792a25a6..62b68352052b 100644 --- a/wire/bolt12_wiregen.c +++ b/wire/bolt12_wiregen.c @@ -1342,28 +1342,28 @@ static void fromwire_tlv_invoice_payer_info(const u8 **cursor, size_t *plen, voi r->payer_info = *plen ? tal_arr(r, u8, *plen) : NULL; fromwire_u8_array(cursor, plen, r->payer_info, *plen); } -/* INVOICE MSG: timestamp */ -static u8 *towire_tlv_invoice_timestamp(const tal_t *ctx, const void *vrecord) +/* INVOICE MSG: created_at */ +static u8 *towire_tlv_invoice_created_at(const tal_t *ctx, const void *vrecord) { const struct tlv_invoice *r = vrecord; u8 *ptr; - if (!r->timestamp) + if (!r->created_at) return NULL; ptr = tal_arr(ctx, u8, 0); - towire_tu64(&ptr, *r->timestamp); + towire_tu64(&ptr, *r->created_at); return ptr; } -static void fromwire_tlv_invoice_timestamp(const u8 **cursor, size_t *plen, void *vrecord) +static void fromwire_tlv_invoice_created_at(const u8 **cursor, size_t *plen, void *vrecord) { struct tlv_invoice *r = vrecord; - r->timestamp = tal(r, u64); + r->created_at = tal(r, u64); -*r->timestamp = fromwire_tu64(cursor, plen); +*r->created_at = fromwire_tu64(cursor, plen); } /* INVOICE MSG: payment_hash */ static u8 *towire_tlv_invoice_payment_hash(const tal_t *ctx, const void *vrecord) @@ -1553,7 +1553,7 @@ static const struct tlv_record_type tlvs_invoice[] = { { 36, towire_tlv_invoice_recurrence_counter, fromwire_tlv_invoice_recurrence_counter }, { 38, towire_tlv_invoice_payer_key, fromwire_tlv_invoice_payer_key }, { 39, towire_tlv_invoice_payer_note, fromwire_tlv_invoice_payer_note }, - { 40, towire_tlv_invoice_timestamp, fromwire_tlv_invoice_timestamp }, + { 40, towire_tlv_invoice_created_at, fromwire_tlv_invoice_created_at }, { 42, towire_tlv_invoice_payment_hash, fromwire_tlv_invoice_payment_hash }, { 44, towire_tlv_invoice_relative_expiry, fromwire_tlv_invoice_relative_expiry }, { 46, towire_tlv_invoice_cltv, fromwire_tlv_invoice_cltv }, @@ -1684,4 +1684,4 @@ bool invoice_error_is_valid(const struct tlv_invoice_error *record, size_t *err_ return tlv_fields_valid(record->fields, NULL, err_index); } -// SHA256STAMP:27ffc38bc2be76e159508470734655f35e59d82927beb8c1f62917e592d76d10 +// SHA256STAMP:2946a3a3734bd6af218cb73b4d42ec16fe68c1041b48e084cc160810870bcdd5 diff --git a/wire/bolt12_wiregen.h b/wire/bolt12_wiregen.h index 0f331da8ad6e..527125b7b7ca 100644 --- a/wire/bolt12_wiregen.h +++ b/wire/bolt12_wiregen.h @@ -120,7 +120,7 @@ struct tlv_invoice { struct pubkey32 *payer_key; utf8 *payer_note; u8 *payer_info; - u64 *timestamp; + u64 *created_at; struct sha256 *payment_hash; u32 *relative_expiry; u32 *cltv; @@ -323,4 +323,4 @@ struct fallback_address *fromwire_fallback_address(const tal_t *ctx, const u8 ** #endif /* LIGHTNING_WIRE_BOLT12_WIREGEN_H */ -// SHA256STAMP:27ffc38bc2be76e159508470734655f35e59d82927beb8c1f62917e592d76d10 +// SHA256STAMP:2946a3a3734bd6af218cb73b4d42ec16fe68c1041b48e084cc160810870bcdd5 From eb265671f4428fc7df55322567c6079553b731af Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 21 Jul 2021 15:07:08 +0930 Subject: [PATCH 2/9] offers: make sure quantity limits are sane. You could have quantity_min of 0, which makes no sense; spec has been updated, so quote and enforce that. Reported-by: @shesek Signed-off-by: Rusty Russell --- plugins/offers_offer.c | 22 ++++++++++++++++++++++ tests/test_pay.py | 20 ++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/plugins/offers_offer.c b/plugins/offers_offer.c index 080968bcfa18..9d270ec5aab3 100644 --- a/plugins/offers_offer.c +++ b/plugins/offers_offer.c @@ -319,6 +319,28 @@ struct command_result *json_offer(struct command *cmd, NULL)) return command_param_failed(); + /* BOLT-offers #12: + * - MUST NOT set `quantity_min` or `quantity_max` less than 1. + */ + if (offer->quantity_min && *offer->quantity_min < 1) + return command_fail_badparam(cmd, "quantity_min", + buffer, params, + "must be >= 1"); + if (offer->quantity_max && *offer->quantity_max < 1) + return command_fail_badparam(cmd, "quantity_max", + buffer, params, + "must be >= 1"); + /* BOLT-offers #12: + * - if both: + * - MUST set `quantity_min` less than or equal to `quantity_max`. + */ + if (offer->quantity_min && offer->quantity_max) { + if (*offer->quantity_min > *offer->quantity_max) + return command_fail_badparam(cmd, "quantity_min", + buffer, params, + "must be <= quantity_max"); + } + /* BOLT-offers #12: * * - if the chain for the invoice is not solely bitcoin: diff --git a/tests/test_pay.py b/tests/test_pay.py index 49c1f7e35576..8e870723bd41 100644 --- a/tests/test_pay.py +++ b/tests/test_pay.py @@ -4006,6 +4006,26 @@ def test_offer(node_factory, bitcoind): offer['bolt12']]).decode('UTF-8') assert 'quantity_max: 2' in output + # BOLT-offers #12: + # * - MUST NOT set `quantity_min` or `quantity_max` less than 1. + with pytest.raises(RpcError, match='quantity_min: must be >= 1'): + ret = l1.rpc.call('offer', {'amount': '100000sat', + 'description': 'quantity_min test', + 'quantity_min': 0}) + + with pytest.raises(RpcError, match='quantity_max: must be >= 1'): + ret = l1.rpc.call('offer', {'amount': '100000sat', + 'description': 'quantity_max test', + 'quantity_max': 0}) + # BOLT-offers #12: + # - if both: + # - MUST set `quantity_min` greater or equal to `quantity_max`. + with pytest.raises(RpcError, match='quantity_min: must be <= quantity_max'): + ret = l1.rpc.call('offer', {'amount': '100000sat', + 'description': 'quantity_max test', + 'quantity_min': 10, + 'quantity_max': 9}) + # Test absolute_expiry exp = int(time.time() + 2) ret = l1.rpc.call('offer', {'amount': '100000sat', From af3585b76ae43a86bf53e2bab542083eb6c2238b Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 21 Jul 2021 15:07:39 +0930 Subject: [PATCH 3/9] fetchinvoice: don't consider "msat" a change if fetchinvoice specified it. We don't automatically *reject* an invoice which asks for a different msat than we specified (caller may!), but we don't bother noting it unless it is different. Reported-by: @shesek Signed-off-by: Rusty Russell --- plugins/fetchinvoice.c | 7 +++++-- tests/test_pay.py | 9 +++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/plugins/fetchinvoice.c b/plugins/fetchinvoice.c index 8882a8f0ae81..6d1b010675d9 100644 --- a/plugins/fetchinvoice.c +++ b/plugins/fetchinvoice.c @@ -253,8 +253,11 @@ static struct command_result *handle_invreq_response(struct command *cmd, if ((badfield = field_diff(sent->invreq, inv, payer_info))) goto badinv; - /* Get the amount we expected. */ - if (sent->offer->amount && !sent->offer->currency) { + /* Get the amount we expected: firstly, if that's what we sent, + * secondly, if specified in the invoice. */ + if (sent->invreq->amount) { + expected_amount = tal_dup(tmpctx, u64, sent->invreq->amount); + } else if (sent->offer->amount && !sent->offer->currency) { expected_amount = tal(tmpctx, u64); *expected_amount = *sent->offer->amount; diff --git a/tests/test_pay.py b/tests/test_pay.py index 8e870723bd41..433e35e1be6b 100644 --- a/tests/test_pay.py +++ b/tests/test_pay.py @@ -4158,6 +4158,15 @@ def test_fetchinvoice(node_factory, bitcoind): with pytest.raises(RpcError, match="Remote node sent failure message.*Amount must be at least 2msat"): l1.rpc.call('fetchinvoice', {'offer': offer1['bolt12'], 'msatoshi': 1}) + # If no amount is specified in offer, one must be in invoice. + offer_noamount = l3.rpc.call('offer', {'amount': 'any', + 'description': 'any amount test'}) + with pytest.raises(RpcError, match="msatoshi parameter required"): + l1.rpc.call('fetchinvoice', {'offer': offer_noamount['bolt12']}) + inv1 = l1.rpc.call('fetchinvoice', {'offer': offer_noamount['bolt12'], 'msatoshi': 100}) + # But amount won't appear in changes + assert 'msat' not in inv1['changes'] + # Single-use invoice can be fetched multiple times, only paid once. offer2 = l3.rpc.call('offer', {'amount': '1msat', 'description': 'single-use test', From 51eef46731912769eac320b33599e73c1dc6ff51 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 21 Jul 2021 15:07:44 +0930 Subject: [PATCH 4/9] disableoffer: fix disabling of already-used offers. Turns out we didn't actually test this at all, and next commit does :( offer_status_in_db: 4 is invalid lightningd: FATAL SIGNAL 6 (version v0.10.0-459-g48fbd45-modded) 0x5608cd360855 send_backtrace common/daemon.c:39 0x5608cd3608ff crashdump common/daemon.c:52 0x7f9af1dae20f ??? ???:0 0x7f9af1dae18b ??? ???:0 0x7f9af1d8d858 ??? ???:0 0x5608cd30a47e fatal lightningd/log.c:819 0x5608cd3430c5 offer_status_in_db wallet/wallet.h:1424 0x5608cd34f1f3 wallet_offer_disable wallet/wallet.c:4494 0x5608cd33ae2e json_disableoffer lightningd/offer.c:256 0x5608cd3038fc command_exec lightningd/jsonrpc.c:643 Signed-off-by: Rusty Russell --- doc/lightning-disableoffer.7 | 4 ++-- doc/lightning-disableoffer.7.md | 4 ++-- doc/schemas/disableoffer.schema.json | 2 +- wallet/db_postgres_sqlgen.c | 2 +- wallet/db_sqlite3_sqlgen.c | 2 +- wallet/statements_gettextgen.po | 2 +- wallet/wallet.c | 2 +- wallet/wallet.h | 4 ++++ 8 files changed, 13 insertions(+), 9 deletions(-) diff --git a/doc/lightning-disableoffer.7 b/doc/lightning-disableoffer.7 index 99bbd0af3973..e3ea0210c04f 100644 --- a/doc/lightning-disableoffer.7 +++ b/doc/lightning-disableoffer.7 @@ -42,7 +42,7 @@ On success, an object is returned, containing: .IP \[bu] \fBoffer_id\fR (hex): the merkle hash of the offer (always 64 characters) .IP \[bu] -\fBactive\fR (boolean): Whether the offer can produce invoices/payments (always "false") +\fBactive\fR (boolean): Whether the offer can produce invoices/payments (always \fIfalse\fR) .IP \[bu] \fBsingle_use\fR (boolean): Whether the offer is disabled after first successful use .IP \[bu] @@ -80,4 +80,4 @@ Rusty Russell \fI is mainly responsible\. Main web site: \fIhttps://github.com/ElementsProject/lightning\fR -\" SHA256STAMP:2383f44a3bcc1023d6619f5ead4c27d7b2bd9a52bd64d00142fd26658a49dd32 +\" SHA256STAMP:e905cb7b8acef73c3ca6bbd41d861234b006aa28185c46b6ba1419c4a0065c3a diff --git a/doc/lightning-disableoffer.7.md b/doc/lightning-disableoffer.7.md index 396151ba27ba..35e13f040534 100644 --- a/doc/lightning-disableoffer.7.md +++ b/doc/lightning-disableoffer.7.md @@ -37,7 +37,7 @@ Note: the returned object is the same format as **listoffers**. [comment]: # (GENERATE-FROM-SCHEMA-START) On success, an object is returned, containing: - **offer_id** (hex): the merkle hash of the offer (always 64 characters) -- **active** (boolean): Whether the offer can produce invoices/payments (always "false") +- **active** (boolean): Whether the offer can produce invoices/payments (always *false*) - **single_use** (boolean): Whether the offer is disabled after first successful use - **bolt12** (string): The bolt12 string representing this offer - **bolt12_unsigned** (string): The bolt12 string representing this offer, without signature @@ -73,4 +73,4 @@ RESOURCES --------- Main web site: -[comment]: # ( SHA256STAMP:5b96eca3e35f6c556b93db1743c617b59e69058c9421ece9cc99a9c8814c176b) +[comment]: # ( SHA256STAMP:8f0595c22a7684d99da3000cc19b2465991fa1d2ee435a395b7a1527330aa490) diff --git a/doc/schemas/disableoffer.schema.json b/doc/schemas/disableoffer.schema.json index 07e177bc4c5b..c781a54b0b60 100644 --- a/doc/schemas/disableoffer.schema.json +++ b/doc/schemas/disableoffer.schema.json @@ -12,7 +12,7 @@ }, "active": { "type": "boolean", - "enum": [ "false" ], + "enum": [ false ], "description": "Whether the offer can produce invoices/payments" }, "single_use": { diff --git a/wallet/db_postgres_sqlgen.c b/wallet/db_postgres_sqlgen.c index 7dd27da86f53..34e0b303c30c 100644 --- a/wallet/db_postgres_sqlgen.c +++ b/wallet/db_postgres_sqlgen.c @@ -2026,4 +2026,4 @@ struct db_query db_postgres_queries[] = { #endif /* LIGHTNINGD_WALLET_GEN_DB_POSTGRES */ -// SHA256STAMP:020ef91a3637bbe29c82477083389a5ecaf359ae049940017ec5c76609c08fdc +// SHA256STAMP:6353b67b3e4f539da2d1f0c2564c4a8243f07d59cd0b73bc83d5552600bd67f7 diff --git a/wallet/db_sqlite3_sqlgen.c b/wallet/db_sqlite3_sqlgen.c index 7ccdabf77598..0b7fd17eb1c8 100644 --- a/wallet/db_sqlite3_sqlgen.c +++ b/wallet/db_sqlite3_sqlgen.c @@ -2026,4 +2026,4 @@ struct db_query db_sqlite3_queries[] = { #endif /* LIGHTNINGD_WALLET_GEN_DB_SQLITE3 */ -// SHA256STAMP:020ef91a3637bbe29c82477083389a5ecaf359ae049940017ec5c76609c08fdc +// SHA256STAMP:6353b67b3e4f539da2d1f0c2564c4a8243f07d59cd0b73bc83d5552600bd67f7 diff --git a/wallet/statements_gettextgen.po b/wallet/statements_gettextgen.po index ec0d7c660e17..636c0bbc37ca 100644 --- a/wallet/statements_gettextgen.po +++ b/wallet/statements_gettextgen.po @@ -1337,4 +1337,4 @@ msgstr "" #: wallet/test/run-wallet.c:1696 msgid "INSERT INTO channels (id) VALUES (1);" msgstr "" -# SHA256STAMP:c273019025094b8ac8311eb7a8489207006506ca46a1963c5924e1947e4c60d5 +# SHA256STAMP:e203d19d9f4192ad6b3aa1a6f257d4f7b267df56c5de9810b573f0affa0122fd diff --git a/wallet/wallet.c b/wallet/wallet.c index e9a26b611cee..67cdc4c3c1cf 100644 --- a/wallet/wallet.c +++ b/wallet/wallet.c @@ -4666,7 +4666,7 @@ enum offer_status wallet_offer_disable(struct wallet *w, assert(offer_status_active(s)); - newstatus = offer_status_in_db(s &= ~OFFER_STATUS_ACTIVE_F); + newstatus = offer_status_in_db(s & ~OFFER_STATUS_ACTIVE_F); offer_status_update(w->db, offer_id, s, newstatus); return newstatus; diff --git a/wallet/wallet.h b/wallet/wallet.h index f25881696806..7985dc5a03cb 100644 --- a/wallet/wallet.h +++ b/wallet/wallet.h @@ -1398,6 +1398,7 @@ enum offer_status { OFFER_SINGLE_USE_UNUSED = OFFER_STATUS_ACTIVE_F|OFFER_STATUS_SINGLE_F, OFFER_SINGLE_USE_USED = OFFER_STATUS_SINGLE_F|OFFER_STATUS_USED_F, OFFER_SINGLE_DISABLED = OFFER_STATUS_SINGLE_F, + OFFER_MULTIPLE_USED_DISABLED = OFFER_STATUS_USED_F, OFFER_MULTIPLE_DISABLED = 0, }; @@ -1419,6 +1420,9 @@ static inline enum offer_status offer_status_in_db(enum offer_status s) case OFFER_SINGLE_DISABLED: BUILD_ASSERT(OFFER_SINGLE_DISABLED == 2); return s; + case OFFER_MULTIPLE_USED_DISABLED: + BUILD_ASSERT(OFFER_MULTIPLE_USED_DISABLED == 4); + return s; case OFFER_MULTIPLE_DISABLED: BUILD_ASSERT(OFFER_MULTIPLE_DISABLED == 0); return s; From 9b33a9d0947bb1122b3123e58689e79c6c85f7e2 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 21 Jul 2021 15:07:49 +0930 Subject: [PATCH 5/9] offer / offerout: return existing if its still active. As requested by @shesek: it's weird to fail if they ask for the exact same thing (which is quite possible, since offers don't expire by default). And add a new "created" field so they can tell if they have an old one. Signed-off-by: Rusty Russell --- doc/lightning-offer.7 | 19 +++++++++++++------ doc/lightning-offer.7.md | 17 +++++++++++------ doc/lightning-offerout.7 | 4 +++- doc/lightning-offerout.7.md | 3 ++- doc/schemas/offer.schema.json | 7 +++++-- doc/schemas/offerout.schema.json | 6 +++++- lightningd/offer.c | 25 +++++++++++++++++++------ plugins/offers_offer.c | 30 +++++++++++++++++++++++++++--- tests/test_pay.py | 10 ++++++++++ 9 files changed, 95 insertions(+), 26 deletions(-) diff --git a/doc/lightning-offer.7 b/doc/lightning-offer.7 index ee94a4194b17..54d4cf80054f 100644 --- a/doc/lightning-offer.7 +++ b/doc/lightning-offer.7 @@ -10,9 +10,10 @@ lightning-offer - Command for accepting payments .SH DESCRIPTION -The \fBoffer\fR RPC command creates an offer, which is a precursor to -creating one or more invoices\. It automatically enables the processing of -an incoming invoice_request, and issuing of invoices\. +The \fBoffer\fR RPC command creates an offer (or returns an existing +one), which is a precursor to creating one or more invoices\. It +automatically enables the processing of an incoming invoice_request, +and issuing of invoices\. Note that it creates two variants of the offer: a signed and an @@ -119,7 +120,9 @@ On success, an object is returned, containing: .IP \[bu] \fBbolt12_unsigned\fR (string): the bolt12 encoding of the offer, without a signature .IP \[bu] -\fBused\fR (boolean): True if an associated invoice has been paid (always \fIfalse\fR) +\fBused\fR (boolean): True if an associated invoice has been paid +.IP \[bu] +\fBcreated\fR (boolean): false if the offer already existed .IP \[bu] \fBlabel\fR (string, optional): the (optional) user-specified label @@ -131,13 +134,17 @@ lightning process fails before responding, the caller should use not\. +If the offer already existed, and is still active, that is returned; +if it's not active then this call fails\. + + The following error codes may occur: .RS .IP \[bu] -1: Catchall nonspecific error\. .IP \[bu] -1000: Offer with this offer_id already exists\. +1000: Offer with this offer_id already exists (but is not active)\. .RE .SH AUTHOR @@ -152,4 +159,4 @@ Rusty Russell \fI is mainly responsible\. Main web site: \fIhttps://github.com/ElementsProject/lightning\fR -\" SHA256STAMP:f7faf86c7cb052200c3b4d6e3d6209afa54600cc7a33e1082583a2766d02a275 +\" SHA256STAMP:bd1bae6f6b56d4efa95e17b7aff042b897acacdd783cef7df0dd729f6c9b5d8f diff --git a/doc/lightning-offer.7.md b/doc/lightning-offer.7.md index d739ad02a6a6..d7c0acf6a884 100644 --- a/doc/lightning-offer.7.md +++ b/doc/lightning-offer.7.md @@ -11,9 +11,10 @@ SYNOPSIS DESCRIPTION ----------- -The **offer** RPC command creates an offer, which is a precursor to -creating one or more invoices. It automatically enables the processing of -an incoming invoice_request, and issuing of invoices. +The **offer** RPC command creates an offer (or returns an existing +one), which is a precursor to creating one or more invoices. It +automatically enables the processing of an incoming invoice_request, +and issuing of invoices. Note that it creates two variants of the offer: a signed and an unsigned one (which is smaller). Wallets should accept both: the @@ -100,7 +101,8 @@ On success, an object is returned, containing: - **single_use** (boolean): whether this expires as soon as it's paid (reflects the *single_use* parameter) - **bolt12** (string): the bolt12 encoding of the offer - **bolt12_unsigned** (string): the bolt12 encoding of the offer, without a signature -- **used** (boolean): True if an associated invoice has been paid (always *false*) +- **used** (boolean): True if an associated invoice has been paid +- **created** (boolean): false if the offer already existed - **label** (string, optional): the (optional) user-specified label [comment]: # (GENERATE-FROM-SCHEMA-END) @@ -109,9 +111,12 @@ lightning process fails before responding, the caller should use lightning-listoffers(7) to query whether this offer was created or not. +If the offer already existed, and is still active, that is returned; +if it's not active then this call fails. + The following error codes may occur: - -1: Catchall nonspecific error. -- 1000: Offer with this offer_id already exists. +- 1000: Offer with this offer_id already exists (but is not active). AUTHOR ------ @@ -128,4 +133,4 @@ RESOURCES Main web site: -[comment]: # ( SHA256STAMP:0f9cfd3cc68aaba20af0eee763c93b475016619d960e3f5bbc0b762a809f0fef) +[comment]: # ( SHA256STAMP:53f1460e28d45129b2c00b7116c87eb47a5b717f7912f499e864f4aa28b320fa) diff --git a/doc/lightning-offerout.7 b/doc/lightning-offerout.7 index a0317f5dacae..d5f5edcc8306 100644 --- a/doc/lightning-offerout.7 +++ b/doc/lightning-offerout.7 @@ -73,6 +73,8 @@ On success, an object is returned, containing: .IP \[bu] \fBused\fR (boolean): True if an incoming invoice has been paid (always \fIfalse\fR) .IP \[bu] +\fBcreated\fR (boolean): false if the offer already existed +.IP \[bu] \fBlabel\fR (string, optional): the (optional) user-specified label .RE @@ -113,4 +115,4 @@ Rusty Russell \fI is mainly responsible\. Main web site: \fIhttps://github.com/ElementsProject/lightning\fR -\" SHA256STAMP:3de11c6de7905322d9ef748981fc1d4f9ca91f4be46d76af6e9124572853047d +\" SHA256STAMP:4998ef3e06f37823c969a524fc3deb96b58eb2babee560df27e3f006fc535186 diff --git a/doc/lightning-offerout.7.md b/doc/lightning-offerout.7.md index 5fa92266ef64..4eec757e4fae 100644 --- a/doc/lightning-offerout.7.md +++ b/doc/lightning-offerout.7.md @@ -61,6 +61,7 @@ On success, an object is returned, containing: - **bolt12** (string): the bolt12 encoding of the offer - **bolt12_unsigned** (string): the bolt12 encoding of the offer, without a signature - **used** (boolean): True if an incoming invoice has been paid (always *false*) +- **created** (boolean): false if the offer already existed - **label** (string, optional): the (optional) user-specified label [comment]: # (GENERATE-FROM-SCHEMA-END) @@ -97,4 +98,4 @@ RESOURCES Main web site: -[comment]: # ( SHA256STAMP:2b7e7b543a88a10dbfbca2508e034af79f43ed0845abdb9df1fdf7e28ee33c26) +[comment]: # ( SHA256STAMP:14fada9336956a08b6d55c4ce01fcb62726cbdef9a065f1966335f61c4e91ce5) diff --git a/doc/schemas/offer.schema.json b/doc/schemas/offer.schema.json index 83f7c4e5b01c..45e0e7872f22 100644 --- a/doc/schemas/offer.schema.json +++ b/doc/schemas/offer.schema.json @@ -2,7 +2,7 @@ "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "additionalProperties": false, - "required": [ "offer_id", "active", "single_use", "bolt12", "bolt12_unsigned", "used" ], + "required": [ "offer_id", "active", "single_use", "bolt12", "bolt12_unsigned", "used", "created" ], "properties": { "offer_id": { "type": "hex", @@ -29,9 +29,12 @@ }, "used": { "type": "boolean", - "enum": [ false ], "description": "True if an associated invoice has been paid" }, + "created": { + "type": "boolean", + "description": "false if the offer already existed" + }, "label": { "type": "string", "description": "the (optional) user-specified label" diff --git a/doc/schemas/offerout.schema.json b/doc/schemas/offerout.schema.json index 03d98aeeb9a5..531d9dad8f8b 100644 --- a/doc/schemas/offerout.schema.json +++ b/doc/schemas/offerout.schema.json @@ -2,7 +2,7 @@ "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "additionalProperties": false, - "required": [ "offer_id", "active", "single_use", "bolt12", "bolt12_unsigned", "used" ], + "required": [ "offer_id", "active", "single_use", "bolt12", "bolt12_unsigned", "used", "created" ], "properties": { "offer_id": { "type": "hex", @@ -33,6 +33,10 @@ "enum": [ false ], "description": "True if an incoming invoice has been paid" }, + "created": { + "type": "boolean", + "description": "false if the offer already existed" + }, "label": { "type": "string", "description": "the (optional) user-specified label" diff --git a/lightningd/offer.c b/lightningd/offer.c index ef5dd9053f53..0330e4bf8dc0 100644 --- a/lightningd/offer.c +++ b/lightningd/offer.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -91,6 +92,7 @@ static struct command_result *json_createoffer(struct command *cmd, bool *single_use; enum offer_status status; struct pubkey32 key; + bool created; if (!param(cmd, buffer, params, p_req("bolt12", param_b12_offer, &offer), @@ -110,17 +112,28 @@ static struct command_result *json_createoffer(struct command *cmd, hsm_sign_b12(cmd->ld, "offer", "signature", &merkle, NULL, &key, offer->signature); b12str = offer_encode(cmd, offer); - if (!wallet_offer_create(cmd->ld->wallet, &merkle, b12str, label, - status)) { - return command_fail(cmd, - OFFER_ALREADY_EXISTS, - "Duplicate offer"); - } + + /* If it already exists, we use that one instead (and then + * the offer plugin will complain if it's inactive or expired) */ + if (!wallet_offer_create(cmd->ld->wallet, &merkle, + b12str, label, status)) { + if (!wallet_offer_find(cmd, cmd->ld->wallet, &merkle, + cast_const2(const struct json_escape **, + &label), + &status)) { + return command_fail(cmd, LIGHTNINGD, + "Could not create, nor find offer"); + } + created = false; + } else + created = true; + offer->signature = tal_free(offer->signature); b12str_nosig = offer_encode(cmd, offer); response = json_stream_success(cmd); json_populate_offer(response, &merkle, b12str, b12str_nosig, label, status); + json_add_bool(response, "created", created); return command_success(cmd, response); } diff --git a/plugins/offers_offer.c b/plugins/offers_offer.c index 9d270ec5aab3..8fa29ae71bad 100644 --- a/plugins/offers_offer.c +++ b/plugins/offers_offer.c @@ -255,6 +255,31 @@ struct offer_info { bool *single_use; }; +static struct command_result *check_result(struct command *cmd, + const char *buf, + const jsmntok_t *result, + void *arg UNNEEDED) +{ + bool active; + + /* If it's inactive, we can't return it, */ + if (!json_to_bool(buf, json_get_member(buf, result, "active"), + &active)) { + return command_fail(cmd, + LIGHTNINGD, + "Bad creaoffer status reply %.*s", + json_tok_full_len(result), + json_tok_full(buf, result)); + } + if (!active) + return command_fail(cmd, + OFFER_ALREADY_EXISTS, + "Offer already exists, but isn't active"); + + /* Otherwise, push through the result. */ + return forward_result(cmd, buf, result, arg); +} + static struct command_result *create_offer(struct command *cmd, struct offer_info *offinfo) { @@ -262,7 +287,7 @@ static struct command_result *create_offer(struct command *cmd, /* We simply pass this through. */ req = jsonrpc_request_start(cmd->plugin, cmd, "createoffer", - forward_result, forward_error, + check_result, forward_error, offinfo); json_add_string(req->js, "bolt12", offer_encode(tmpctx, offinfo->offer)); @@ -436,9 +461,8 @@ struct command_result *json_offerout(struct command *cmd, offer->node_id = tal_dup(offer, struct pubkey32, &id); - /* We simply pass this through. */ req = jsonrpc_request_start(cmd->plugin, cmd, "createoffer", - forward_result, forward_error, + check_result, forward_error, offer); json_add_string(req->js, "bolt12", offer_encode(tmpctx, offer)); if (label) diff --git a/tests/test_pay.py b/tests/test_pay.py index 433e35e1be6b..678810885672 100644 --- a/tests/test_pay.py +++ b/tests/test_pay.py @@ -4122,6 +4122,7 @@ def test_fetchinvoice(node_factory, bitcoind): # Simple offer first. offer1 = l3.rpc.call('offer', {'amount': '2msat', 'description': 'simple test'}) + assert offer1['created'] is True inv1 = l1.rpc.call('fetchinvoice', {'offer': offer1['bolt12']}) inv2 = l1.rpc.call('fetchinvoice', {'offer': offer1['bolt12_unsigned'], @@ -4274,6 +4275,15 @@ def test_fetchinvoice(node_factory, bitcoind): # But we can still pay the (already-converted) invoice. l1.rpc.pay(inv['invoice']) + # Identical creation gives it again, just with created false. + offer1 = l3.rpc.call('offer', {'amount': '2msat', + 'description': 'simple test'}) + assert offer1['created'] is False + l3.rpc.call('disableoffer', {'offer_id': offer1['offer_id']}) + with pytest.raises(RpcError, match="1000.*Offer already exists, but isn't active"): + l3.rpc.call('offer', {'amount': '2msat', + 'description': 'simple test'}) + # Test timeout. l3.stop() with pytest.raises(RpcError, match='Timeout waiting for response'): From 2c0645542a0c3c18d703e8589de069c13f0890be Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 21 Jul 2021 15:08:14 +0930 Subject: [PATCH 6/9] offerout: don't insist that invoice vendor match our vendor. This was a bug in the spec, actually. Reported-by: @shesek Signed-off-by: Rusty Russell Fixes: #4666 --- plugins/offers_inv_hook.c | 4 ---- tests/test_pay.py | 21 +++++++++++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/plugins/offers_inv_hook.c b/plugins/offers_inv_hook.c index 1752f78e1bd6..caba93f6984e 100644 --- a/plugins/offers_inv_hook.c +++ b/plugins/offers_inv_hook.c @@ -229,15 +229,11 @@ static struct command_result *listoffers_done(struct command *cmd, * or unset exactly as they are in the `offer`: * - `refund_for` * - `description` - * - `vendor` */ err = inv_must_equal_offer(cmd, inv, refund_for); if (err) return err; err = inv_must_equal_offer(cmd, inv, description); - if (err) - return err; - err = inv_must_equal_offer(cmd, inv, vendor); if (err) return err; diff --git a/tests/test_pay.py b/tests/test_pay.py index 678810885672..8108b67c455e 100644 --- a/tests/test_pay.py +++ b/tests/test_pay.py @@ -4452,6 +4452,27 @@ def test_sendinvoice(node_factory, bitcoind): 'label': 'test sendinvoice refund'}) wait_for(lambda: only_one(l2.rpc.call('listoffers', [refund['offer_id']])['offers'])['used'] is True) + # Offer with vendor: we must not copy vendor into our invoice! + offer = l1.rpc.call('offerout', {'amount': '10000sat', + 'description': 'simple test', + 'vendor': "clightning test suite"}) + + out = l2.rpc.call('sendinvoice', {'offer': offer['bolt12'], + 'label': 'test sendinvoice 3'}) + assert out['label'] == 'test sendinvoice 3' + assert out['description'] == 'simple test' + assert 'vendor' not in out + assert 'bolt12' in out + assert 'payment_hash' in out + assert out['status'] == 'paid' + assert 'payment_preimage' in out + assert 'expires_at' in out + assert out['msatoshi'] == 10000000 + assert out['amount_msat'] == Millisatoshi(10000000) + assert 'pay_index' in out + assert out['msatoshi_received'] == 10000000 + assert out['amount_received_msat'] == Millisatoshi(10000000) + def test_self_pay(node_factory): """Repro test for issue 4345: pay ourselves via the pay plugin. From 7cb705438760874d430ce7c65cf31160eeb75e3c Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 21 Jul 2021 15:08:20 +0930 Subject: [PATCH 7/9] pytest: test for offer failing decode when empty description. In particular, Shesek tried an empty offer description, and the resulting signature didn't match since it was omitted entirely from the bolt12 string! Reported-by: @shesek Signed-off-by: Rusty Russell --- tests/test_pay.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/test_pay.py b/tests/test_pay.py index 8108b67c455e..64e92f3adb9e 100644 --- a/tests/test_pay.py +++ b/tests/test_pay.py @@ -3923,10 +3923,15 @@ def test_offer_needs_option(node_factory): l1.rpc.call('fetchinvoice', {'offer': 'aaaa'}) +@pytest.mark.xfail(strict=True) def test_offer(node_factory, bitcoind): plugin = os.path.join(os.path.dirname(__file__), 'plugins/currencyUSDAUD5000.py') l1 = node_factory.get_node(options={'plugin': plugin, 'experimental-offers': None}) + # Try empty description + ret = l1.rpc.call('offer', [9, '']) + l1.rpc.decode(ret['bolt12']) + bolt12tool = os.path.join(os.path.dirname(__file__), "..", "devtools", "bolt12-cli") # Try different amount strings for amount in ['1msat', '0.1btc', 'any', '1USD', '1.10AUD']: From ba9251ba796e2108d49a1c4d7a1a7615b32cf77d Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 21 Jul 2021 15:08:25 +0930 Subject: [PATCH 8/9] lightningd: don't assume zero-length tlv fields will be NULL. 1. We assumed an empty upfront_shutdown_script TLV would become NULL: RPC call failed: method: fundchannel, payload: {'id': '022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d59', 'amount': 1000000, 'announce': True}, error: {'code': -1, 'message': 'They sent error channel e7c2d5d14462fe269631418fbfc3db327843382e6a2a5a9c2991d2d6ba31d9f5: Unacceptable upfront_shutdown_script ', 'data': {'id': '022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d59', 'method': 'fundchannel_start'}}" 2. We were assuming an empty enctlv would become NULL, too. We should not have done this (there's a semantic difference between "empty" and not-present for TLVs), so prepare for the change. Signed-off-by: Rusty Russell --- lightningd/onion_message.c | 2 +- openingd/openingd.c | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lightningd/onion_message.c b/lightningd/onion_message.c index 63269c441e75..1851b950955a 100644 --- a/lightningd/onion_message.c +++ b/lightningd/onion_message.c @@ -28,7 +28,7 @@ static void onion_message_serialize(struct onion_message_hook_payload *payload, json_object_start(stream, NULL); json_add_pubkey(stream, "id", &payload->reply_path[i]->node_id); - if (payload->reply_path[i]->enctlv) + if (tal_bytelen(payload->reply_path[i]->enctlv) != 0) json_add_hex_talarr(stream, "enctlv", payload->reply_path[i]->enctlv); if (i == 0) diff --git a/openingd/openingd.c b/openingd/openingd.c index 113210d8cdd6..d12850fd2772 100644 --- a/openingd/openingd.c +++ b/openingd/openingd.c @@ -329,6 +329,16 @@ static void set_remote_upfront_shutdown(struct state *state, state->their_features, OPT_SHUTDOWN_ANYSEGWIT); + /* BOLT #2: + * + * - MUST include `upfront_shutdown_script` with either a valid + * `shutdown_scriptpubkey` as required by `shutdown` `scriptpubkey`, + * or a zero-length `shutdown_scriptpubkey` (ie. `0x0000`). + */ + /* We turn empty into NULL. */ + if (tal_bytelen(shutdown_scriptpubkey) == 0) + shutdown_scriptpubkey = tal_free(shutdown_scriptpubkey); + state->upfront_shutdown_script[REMOTE] = tal_steal(state, shutdown_scriptpubkey); From 2f0299448628b3077d635a968c5a1fb4d7c54767 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 21 Jul 2021 15:08:29 +0930 Subject: [PATCH 9/9] lightningd: don't turn zero-length tlv fields into NULL. Fixes: #4667 Signed-off-by: Rusty Russell --- channeld/channeld_wiregen.c | 2 +- channeld/channeld_wiregen.h | 2 +- closingd/closingd_wiregen.c | 2 +- closingd/closingd_wiregen.h | 2 +- common/peer_status_wiregen.c | 2 +- common/peer_status_wiregen.h | 2 +- common/status_wiregen.c | 2 +- common/status_wiregen.h | 2 +- connectd/connectd_gossipd_wiregen.c | 2 +- connectd/connectd_gossipd_wiregen.h | 2 +- connectd/connectd_wiregen.c | 2 +- connectd/connectd_wiregen.h | 2 +- doc/lightning-offer.7 | 2 +- gossipd/gossip_store_wiregen.c | 2 +- gossipd/gossip_store_wiregen.h | 2 +- gossipd/gossipd_peerd_wiregen.c | 2 +- gossipd/gossipd_peerd_wiregen.h | 2 +- gossipd/gossipd_wiregen.c | 2 +- gossipd/gossipd_wiregen.h | 2 +- hsmd/hsmd_wiregen.c | 2 +- hsmd/hsmd_wiregen.h | 2 +- onchaind/onchaind_wiregen.c | 2 +- onchaind/onchaind_wiregen.h | 2 +- openingd/dualopend_wiregen.c | 2 +- openingd/dualopend_wiregen.h | 2 +- openingd/openingd_wiregen.c | 2 +- openingd/openingd_wiregen.h | 2 +- tests/test_pay.py | 1 - tools/gen/impl_template | 2 +- wire/bolt12_wiregen.c | 34 ++++++++++++++--------------- wire/bolt12_wiregen.h | 2 +- wire/common_wiregen.c | 2 +- wire/common_wiregen.h | 2 +- wire/onion_printgen.c | 2 +- wire/onion_printgen.h | 2 +- wire/onion_wiregen.c | 12 +++++----- wire/onion_wiregen.h | 2 +- wire/peer_printgen.c | 2 +- wire/peer_printgen.h | 2 +- wire/peer_wiregen.c | 16 +++++++------- wire/peer_wiregen.h | 2 +- 41 files changed, 68 insertions(+), 69 deletions(-) diff --git a/channeld/channeld_wiregen.c b/channeld/channeld_wiregen.c index edfec2ce4b4a..d0f252459fa6 100644 --- a/channeld/channeld_wiregen.c +++ b/channeld/channeld_wiregen.c @@ -1181,4 +1181,4 @@ bool fromwire_channeld_blockheight(const void *p, u32 *blockheight) *blockheight = fromwire_u32(&cursor, &plen); return cursor != NULL; } -// SHA256STAMP:977cf1dac7bbca4163cfbbf53f8f448430775368496205ee6f181eb4d8c8c8af +// SHA256STAMP:6f130803e485882bd3fee03f792036434d0a7062e1ba4ec6bc97756460d6b21a diff --git a/channeld/channeld_wiregen.h b/channeld/channeld_wiregen.h index e52eafa2019b..3ee7f2addf9b 100644 --- a/channeld/channeld_wiregen.h +++ b/channeld/channeld_wiregen.h @@ -240,4 +240,4 @@ bool fromwire_channeld_blockheight(const void *p, u32 *blockheight); #endif /* LIGHTNING_CHANNELD_CHANNELD_WIREGEN_H */ -// SHA256STAMP:977cf1dac7bbca4163cfbbf53f8f448430775368496205ee6f181eb4d8c8c8af +// SHA256STAMP:6f130803e485882bd3fee03f792036434d0a7062e1ba4ec6bc97756460d6b21a diff --git a/closingd/closingd_wiregen.c b/closingd/closingd_wiregen.c index e8c766b39a27..e53826507e43 100644 --- a/closingd/closingd_wiregen.c +++ b/closingd/closingd_wiregen.c @@ -195,4 +195,4 @@ bool fromwire_closingd_complete(const void *p) return false; return cursor != NULL; } -// SHA256STAMP:681e83ed1e1950220b1e9dbf168e5583e23120981b9a084eab5bc6ce1bc9a1aa +// SHA256STAMP:961ca5ceef03f911684ba0e7863d69993e692b9b418108e6038a567cb7cc7b3e diff --git a/closingd/closingd_wiregen.h b/closingd/closingd_wiregen.h index 7d46f18b63f3..cc1ad7c9dfaa 100644 --- a/closingd/closingd_wiregen.h +++ b/closingd/closingd_wiregen.h @@ -56,4 +56,4 @@ bool fromwire_closingd_complete(const void *p); #endif /* LIGHTNING_CLOSINGD_CLOSINGD_WIREGEN_H */ -// SHA256STAMP:681e83ed1e1950220b1e9dbf168e5583e23120981b9a084eab5bc6ce1bc9a1aa +// SHA256STAMP:961ca5ceef03f911684ba0e7863d69993e692b9b418108e6038a567cb7cc7b3e diff --git a/common/peer_status_wiregen.c b/common/peer_status_wiregen.c index fa756278e897..15d6779589e3 100644 --- a/common/peer_status_wiregen.c +++ b/common/peer_status_wiregen.c @@ -80,4 +80,4 @@ bool fromwire_status_peer_error(const tal_t *ctx, const void *p, struct channel_ fromwire_u8_array(&cursor, &plen, *error_for_them, len); return cursor != NULL; } -// SHA256STAMP:db80a04b587e0918ef55f7e82519f7ff86620c5ec4fd845452214059c1cdbd41 +// SHA256STAMP:4606ed7d72f93f4fe260080b8b6810ef1b0efa60e96d22b987a6bd16213e365f diff --git a/common/peer_status_wiregen.h b/common/peer_status_wiregen.h index 94978e02cec7..06a07885640a 100644 --- a/common/peer_status_wiregen.h +++ b/common/peer_status_wiregen.h @@ -34,4 +34,4 @@ bool fromwire_status_peer_error(const tal_t *ctx, const void *p, struct channel_ #endif /* LIGHTNING_COMMON_PEER_STATUS_WIREGEN_H */ -// SHA256STAMP:db80a04b587e0918ef55f7e82519f7ff86620c5ec4fd845452214059c1cdbd41 +// SHA256STAMP:4606ed7d72f93f4fe260080b8b6810ef1b0efa60e96d22b987a6bd16213e365f diff --git a/common/status_wiregen.c b/common/status_wiregen.c index 90da24ae2783..46b1aec4c840 100644 --- a/common/status_wiregen.c +++ b/common/status_wiregen.c @@ -214,4 +214,4 @@ bool fromwire_status_version(const tal_t *ctx, const void *p, wirestring **versi *version = fromwire_wirestring(ctx, &cursor, &plen); return cursor != NULL; } -// SHA256STAMP:6f868de7019bd204be0d90618a044c20ec1170430e3196674040ddb7f7278e80 +// SHA256STAMP:2649c615ee63c7855d66cd8d9731deb4819dd4e442d59f59d2616ea7be0fed71 diff --git a/common/status_wiregen.h b/common/status_wiregen.h index 202ac0143bbd..d5b59d53aac5 100644 --- a/common/status_wiregen.h +++ b/common/status_wiregen.h @@ -58,4 +58,4 @@ bool fromwire_status_version(const tal_t *ctx, const void *p, wirestring **versi #endif /* LIGHTNING_COMMON_STATUS_WIREGEN_H */ -// SHA256STAMP:6f868de7019bd204be0d90618a044c20ec1170430e3196674040ddb7f7278e80 +// SHA256STAMP:2649c615ee63c7855d66cd8d9731deb4819dd4e442d59f59d2616ea7be0fed71 diff --git a/connectd/connectd_gossipd_wiregen.c b/connectd/connectd_gossipd_wiregen.c index 1830b4707dc3..1394358718fe 100644 --- a/connectd/connectd_gossipd_wiregen.c +++ b/connectd/connectd_gossipd_wiregen.c @@ -161,4 +161,4 @@ bool fromwire_gossipd_get_addrs_reply(const tal_t *ctx, const void *p, struct wi fromwire_wireaddr(&cursor, &plen, *addrs + i); return cursor != NULL; } -// SHA256STAMP:a115dcd604f1bcbe48bf57b25bfc2b59ec7eff3c4790812fa1c460aee2b50811 +// SHA256STAMP:f046184497c8415e2e1337f2b82412bc0094c9c7935e5a3312560331ca6c9f32 diff --git a/connectd/connectd_gossipd_wiregen.h b/connectd/connectd_gossipd_wiregen.h index 2dfc3b12b4f2..36934ba14f08 100644 --- a/connectd/connectd_gossipd_wiregen.h +++ b/connectd/connectd_gossipd_wiregen.h @@ -54,4 +54,4 @@ bool fromwire_gossipd_get_addrs_reply(const tal_t *ctx, const void *p, struct wi #endif /* LIGHTNING_CONNECTD_CONNECTD_GOSSIPD_WIREGEN_H */ -// SHA256STAMP:a115dcd604f1bcbe48bf57b25bfc2b59ec7eff3c4790812fa1c460aee2b50811 +// SHA256STAMP:f046184497c8415e2e1337f2b82412bc0094c9c7935e5a3312560331ca6c9f32 diff --git a/connectd/connectd_wiregen.c b/connectd/connectd_wiregen.c index 63e764fa3644..2426dacaa9c2 100644 --- a/connectd/connectd_wiregen.c +++ b/connectd/connectd_wiregen.c @@ -443,4 +443,4 @@ bool fromwire_connectd_dev_memleak_reply(const void *p, bool *leak) *leak = fromwire_bool(&cursor, &plen); return cursor != NULL; } -// SHA256STAMP:27a03f6c7a77a83be6fc4d063fd37d4bc47e7280310f19d72859ff3f409e05ca +// SHA256STAMP:685593d3211a88f48474420db7f114a48d0619ee00eb7ec337fe8d78deecf426 diff --git a/connectd/connectd_wiregen.h b/connectd/connectd_wiregen.h index e4f5c6504207..eb1c87b561e6 100644 --- a/connectd/connectd_wiregen.h +++ b/connectd/connectd_wiregen.h @@ -110,4 +110,4 @@ bool fromwire_connectd_dev_memleak_reply(const void *p, bool *leak); #endif /* LIGHTNING_CONNECTD_CONNECTD_WIREGEN_H */ -// SHA256STAMP:27a03f6c7a77a83be6fc4d063fd37d4bc47e7280310f19d72859ff3f409e05ca +// SHA256STAMP:685593d3211a88f48474420db7f114a48d0619ee00eb7ec337fe8d78deecf426 diff --git a/doc/lightning-offer.7 b/doc/lightning-offer.7 index 54d4cf80054f..3c189b5bdb9c 100644 --- a/doc/lightning-offer.7 +++ b/doc/lightning-offer.7 @@ -159,4 +159,4 @@ Rusty Russell \fI is mainly responsible\. Main web site: \fIhttps://github.com/ElementsProject/lightning\fR -\" SHA256STAMP:bd1bae6f6b56d4efa95e17b7aff042b897acacdd783cef7df0dd729f6c9b5d8f +\" SHA256STAMP:e6b321a49c0613e9812343cdc252850930569e63e19291afbcbf6a4a135d2552 diff --git a/gossipd/gossip_store_wiregen.c b/gossipd/gossip_store_wiregen.c index 7dee245adcb5..adcda3ddf1bb 100644 --- a/gossipd/gossip_store_wiregen.c +++ b/gossipd/gossip_store_wiregen.c @@ -210,4 +210,4 @@ bool fromwire_gossipd_local_add_channel_obs(const tal_t *ctx, const void *p, str fromwire_u8_array(&cursor, &plen, *features, flen); return cursor != NULL; } -// SHA256STAMP:a709d2e8f179fb393064e210e72f1118fd60f67134d5f94fe33dc58a62f38ff7 +// SHA256STAMP:9bf21787d4ea17d2ae119c2120fd14d025824ab239b12855720addae5a919b2b diff --git a/gossipd/gossip_store_wiregen.h b/gossipd/gossip_store_wiregen.h index 8788114fb449..203966c2c832 100644 --- a/gossipd/gossip_store_wiregen.h +++ b/gossipd/gossip_store_wiregen.h @@ -63,4 +63,4 @@ bool fromwire_gossipd_local_add_channel_obs(const tal_t *ctx, const void *p, str #endif /* LIGHTNING_GOSSIPD_GOSSIP_STORE_WIREGEN_H */ -// SHA256STAMP:a709d2e8f179fb393064e210e72f1118fd60f67134d5f94fe33dc58a62f38ff7 +// SHA256STAMP:9bf21787d4ea17d2ae119c2120fd14d025824ab239b12855720addae5a919b2b diff --git a/gossipd/gossipd_peerd_wiregen.c b/gossipd/gossipd_peerd_wiregen.c index f44c95924881..86518988fb43 100644 --- a/gossipd/gossipd_peerd_wiregen.c +++ b/gossipd/gossipd_peerd_wiregen.c @@ -161,4 +161,4 @@ bool fromwire_gossipd_local_channel_announcement(const tal_t *ctx, const void *p fromwire_u8_array(&cursor, &plen, *cannount, len); return cursor != NULL; } -// SHA256STAMP:3b60c444839f3c615c80609a295f43fd95f1bd6e9b4a66e56c95cf0e4e7607b1 +// SHA256STAMP:d90ca8e3167dc1e0d140bedca5963b94de835eaae18aba97c99e79f500c068d1 diff --git a/gossipd/gossipd_peerd_wiregen.h b/gossipd/gossipd_peerd_wiregen.h index 5dd30cd8a81c..6a0cbc33d6bf 100644 --- a/gossipd/gossipd_peerd_wiregen.h +++ b/gossipd/gossipd_peerd_wiregen.h @@ -57,4 +57,4 @@ bool fromwire_gossipd_local_channel_announcement(const tal_t *ctx, const void *p #endif /* LIGHTNING_GOSSIPD_GOSSIPD_PEERD_WIREGEN_H */ -// SHA256STAMP:3b60c444839f3c615c80609a295f43fd95f1bd6e9b4a66e56c95cf0e4e7607b1 +// SHA256STAMP:d90ca8e3167dc1e0d140bedca5963b94de835eaae18aba97c99e79f500c068d1 diff --git a/gossipd/gossipd_wiregen.c b/gossipd/gossipd_wiregen.c index 0c0b3171bcc2..85fc20f5b837 100644 --- a/gossipd/gossipd_wiregen.c +++ b/gossipd/gossipd_wiregen.c @@ -777,4 +777,4 @@ bool fromwire_gossipd_new_lease_rates(const void *p, struct lease_rates *rates) fromwire_lease_rates(&cursor, &plen, rates); return cursor != NULL; } -// SHA256STAMP:a0408d2e1f668c085378bc2729e08d8712a95edc48d12df8c6cbf063aeddbf32 +// SHA256STAMP:6252e4a2529ea03470fbb950ebe3d616c6a8ffedf199ff3091608f2d9f18efcf diff --git a/gossipd/gossipd_wiregen.h b/gossipd/gossipd_wiregen.h index 7a21446be492..0d3b1385dcdb 100644 --- a/gossipd/gossipd_wiregen.h +++ b/gossipd/gossipd_wiregen.h @@ -188,4 +188,4 @@ bool fromwire_gossipd_new_lease_rates(const void *p, struct lease_rates *rates); #endif /* LIGHTNING_GOSSIPD_GOSSIPD_WIREGEN_H */ -// SHA256STAMP:a0408d2e1f668c085378bc2729e08d8712a95edc48d12df8c6cbf063aeddbf32 +// SHA256STAMP:6252e4a2529ea03470fbb950ebe3d616c6a8ffedf199ff3091608f2d9f18efcf diff --git a/hsmd/hsmd_wiregen.c b/hsmd/hsmd_wiregen.c index 1ffce0751a96..42047696fb37 100644 --- a/hsmd/hsmd_wiregen.c +++ b/hsmd/hsmd_wiregen.c @@ -1331,4 +1331,4 @@ bool fromwire_hsmd_sign_option_will_fund_offer_reply(const void *p, secp256k1_ec fromwire_secp256k1_ecdsa_signature(&cursor, &plen, rsig); return cursor != NULL; } -// SHA256STAMP:5cc29ba49eb086d023342733bcaeb16b5b8e3c5b7b9d5826e70dd4f46b0d1dd2 +// SHA256STAMP:ca4451abdbde0ac4c8a542e9ba48d2075fb7fcd12a30be739371966dcd8b3d9e diff --git a/hsmd/hsmd_wiregen.h b/hsmd/hsmd_wiregen.h index 830d52f62c3a..6bbeee96e538 100644 --- a/hsmd/hsmd_wiregen.h +++ b/hsmd/hsmd_wiregen.h @@ -295,4 +295,4 @@ bool fromwire_hsmd_sign_option_will_fund_offer_reply(const void *p, secp256k1_ec #endif /* LIGHTNING_HSMD_HSMD_WIREGEN_H */ -// SHA256STAMP:5cc29ba49eb086d023342733bcaeb16b5b8e3c5b7b9d5826e70dd4f46b0d1dd2 +// SHA256STAMP:ca4451abdbde0ac4c8a542e9ba48d2075fb7fcd12a30be739371966dcd8b3d9e diff --git a/onchaind/onchaind_wiregen.c b/onchaind/onchaind_wiregen.c index 91ca990a9178..1b1b1d81e82e 100644 --- a/onchaind/onchaind_wiregen.c +++ b/onchaind/onchaind_wiregen.c @@ -639,4 +639,4 @@ bool fromwire_onchaind_notify_coin_mvt(const void *p, struct chain_coin_mvt *mvt fromwire_chain_coin_mvt(&cursor, &plen, mvt); return cursor != NULL; } -// SHA256STAMP:5aa638efffb78c0f1cac4889fb37e3666792ad716f7db66c925b4640628ffbde +// SHA256STAMP:f226dc95c62a951ec3fa958313783f65daff69034a06ef4188b81ca80fe7b53a diff --git a/onchaind/onchaind_wiregen.h b/onchaind/onchaind_wiregen.h index e8a4d758935b..8b7afbb44ab3 100644 --- a/onchaind/onchaind_wiregen.h +++ b/onchaind/onchaind_wiregen.h @@ -161,4 +161,4 @@ bool fromwire_onchaind_notify_coin_mvt(const void *p, struct chain_coin_mvt *mvt #endif /* LIGHTNING_ONCHAIND_ONCHAIND_WIREGEN_H */ -// SHA256STAMP:5aa638efffb78c0f1cac4889fb37e3666792ad716f7db66c925b4640628ffbde +// SHA256STAMP:f226dc95c62a951ec3fa958313783f65daff69034a06ef4188b81ca80fe7b53a diff --git a/openingd/dualopend_wiregen.c b/openingd/dualopend_wiregen.c index 605e51e2c454..c37c75869434 100644 --- a/openingd/dualopend_wiregen.c +++ b/openingd/dualopend_wiregen.c @@ -1096,4 +1096,4 @@ bool fromwire_dualopend_validate_lease_reply(const tal_t *ctx, const void *p, wi } return cursor != NULL; } -// SHA256STAMP:893f2d8e99ee42b814c293ee5fc24c6234b4198c87eaa9ec55e83c8085b5045f +// SHA256STAMP:323fc0085091d47b8f1f66ee5455fd229fdb4a29fc43711ac81cc5fe9eb9b696 diff --git a/openingd/dualopend_wiregen.h b/openingd/dualopend_wiregen.h index c4f693f21b98..0c40a3565ab6 100644 --- a/openingd/dualopend_wiregen.h +++ b/openingd/dualopend_wiregen.h @@ -237,4 +237,4 @@ bool fromwire_dualopend_validate_lease_reply(const tal_t *ctx, const void *p, wi #endif /* LIGHTNING_OPENINGD_DUALOPEND_WIREGEN_H */ -// SHA256STAMP:893f2d8e99ee42b814c293ee5fc24c6234b4198c87eaa9ec55e83c8085b5045f +// SHA256STAMP:323fc0085091d47b8f1f66ee5455fd229fdb4a29fc43711ac81cc5fe9eb9b696 diff --git a/openingd/openingd_wiregen.c b/openingd/openingd_wiregen.c index be6688027f3e..07aa2d2fae5f 100644 --- a/openingd/openingd_wiregen.c +++ b/openingd/openingd_wiregen.c @@ -604,4 +604,4 @@ bool fromwire_openingd_dev_memleak_reply(const void *p, bool *leak) *leak = fromwire_bool(&cursor, &plen); return cursor != NULL; } -// SHA256STAMP:779aa98c325bc5c87c31b24767f45f22edd135b8e2be4fe3ca1282d91950f0c4 +// SHA256STAMP:e01a9f3e8b3c9962c9b35502d3b74977e289e61ebebf28627276e97d06bc4b35 diff --git a/openingd/openingd_wiregen.h b/openingd/openingd_wiregen.h index d319eb102079..91d752e57d2d 100644 --- a/openingd/openingd_wiregen.h +++ b/openingd/openingd_wiregen.h @@ -128,4 +128,4 @@ bool fromwire_openingd_dev_memleak_reply(const void *p, bool *leak); #endif /* LIGHTNING_OPENINGD_OPENINGD_WIREGEN_H */ -// SHA256STAMP:779aa98c325bc5c87c31b24767f45f22edd135b8e2be4fe3ca1282d91950f0c4 +// SHA256STAMP:e01a9f3e8b3c9962c9b35502d3b74977e289e61ebebf28627276e97d06bc4b35 diff --git a/tests/test_pay.py b/tests/test_pay.py index 64e92f3adb9e..545961be8378 100644 --- a/tests/test_pay.py +++ b/tests/test_pay.py @@ -3923,7 +3923,6 @@ def test_offer_needs_option(node_factory): l1.rpc.call('fetchinvoice', {'offer': 'aaaa'}) -@pytest.mark.xfail(strict=True) def test_offer(node_factory, bitcoind): plugin = os.path.join(os.path.dirname(__file__), 'plugins/currencyUSDAUD5000.py') l1 = node_factory.get_node(options={'plugin': plugin, 'experimental-offers': None}) diff --git a/tools/gen/impl_template b/tools/gen/impl_template index ad4b62e5c4ce..61f643598f1d 100644 --- a/tools/gen/impl_template +++ b/tools/gen/impl_template @@ -79,7 +79,7 @@ towire_${type_obj.name}(${ptr}, ${'' if type_obj.is_assignable() or type_obj.is_ % if f.type_obj.has_array_helper(): ## We assume array helpers only deal with things literally transcribed!! % if f.is_varlen(): -${fieldname} = ${f.size('*plen')} ? tal_arr(${ctx}, ${typename}, ${f.size('*plen')}) : NULL; +${fieldname} = tal_arr(${ctx}, ${typename}, ${f.size('*plen')}); % endif fromwire_${type_}_array(cursor, plen, ${fieldname}, ${f.size('*plen')}); % else: diff --git a/wire/bolt12_wiregen.c b/wire/bolt12_wiregen.c index 62b68352052b..171cd8c7e6ad 100644 --- a/wire/bolt12_wiregen.c +++ b/wire/bolt12_wiregen.c @@ -66,7 +66,7 @@ fromwire_blinded_payinfo(const tal_t *ctx, const u8 **cursor, size_t *plen) blinded_payinfo->fee_proportional_millionths = fromwire_u32(cursor, plen); blinded_payinfo->cltv_expiry_delta = fromwire_u16(cursor, plen); flen = fromwire_u16(cursor, plen); - blinded_payinfo->features = flen ? tal_arr(blinded_payinfo, u8, flen) : NULL; + blinded_payinfo->features = tal_arr(blinded_payinfo, u8, flen); fromwire_u8_array(cursor, plen, blinded_payinfo->features, flen); return blinded_payinfo; @@ -89,7 +89,7 @@ fromwire_fallback_address(const tal_t *ctx, const u8 **cursor, size_t *plen) fallback_address->version = fromwire_u8(cursor, plen); len = fromwire_u16(cursor, plen); - fallback_address->address = len ? tal_arr(fallback_address, u8, len) : NULL; + fallback_address->address = tal_arr(fallback_address, u8, len); fromwire_u8_array(cursor, plen, fallback_address->address, len); return fallback_address; @@ -152,7 +152,7 @@ static void fromwire_tlv_offer_currency(const u8 **cursor, size_t *plen, void *v { struct tlv_offer *r = vrecord; - r->currency = *plen ? tal_arr(r, utf8, *plen) : NULL; + r->currency = tal_arr(r, utf8, *plen); fromwire_utf8_array(cursor, plen, r->currency, *plen); } /* OFFER MSG: amount */ @@ -197,7 +197,7 @@ static void fromwire_tlv_offer_description(const u8 **cursor, size_t *plen, void { struct tlv_offer *r = vrecord; - r->description = *plen ? tal_arr(r, utf8, *plen) : NULL; + r->description = tal_arr(r, utf8, *plen); fromwire_utf8_array(cursor, plen, r->description, *plen); } /* OFFER MSG: features */ @@ -219,7 +219,7 @@ static void fromwire_tlv_offer_features(const u8 **cursor, size_t *plen, void *v { struct tlv_offer *r = vrecord; - r->features = *plen ? tal_arr(r, u8, *plen) : NULL; + r->features = tal_arr(r, u8, *plen); fromwire_u8_array(cursor, plen, r->features, *plen); } /* OFFER MSG: absolute_expiry */ @@ -291,7 +291,7 @@ static void fromwire_tlv_offer_vendor(const u8 **cursor, size_t *plen, void *vre { struct tlv_offer *r = vrecord; - r->vendor = *plen ? tal_arr(r, utf8, *plen) : NULL; + r->vendor = tal_arr(r, utf8, *plen); fromwire_utf8_array(cursor, plen, r->vendor, *plen); } /* OFFER MSG: quantity_min */ @@ -670,7 +670,7 @@ static void fromwire_tlv_invoice_request_features(const u8 **cursor, size_t *ple { struct tlv_invoice_request *r = vrecord; - r->features = *plen ? tal_arr(r, u8, *plen) : NULL; + r->features = tal_arr(r, u8, *plen); fromwire_u8_array(cursor, plen, r->features, *plen); } /* INVOICE_REQUEST MSG: quantity */ @@ -784,7 +784,7 @@ static void fromwire_tlv_invoice_request_payer_note(const u8 **cursor, size_t *p { struct tlv_invoice_request *r = vrecord; - r->payer_note = *plen ? tal_arr(r, utf8, *plen) : NULL; + r->payer_note = tal_arr(r, utf8, *plen); fromwire_utf8_array(cursor, plen, r->payer_note, *plen); } /* INVOICE_REQUEST MSG: payer_info */ @@ -806,7 +806,7 @@ static void fromwire_tlv_invoice_request_payer_info(const u8 **cursor, size_t *p { struct tlv_invoice_request *r = vrecord; - r->payer_info = *plen ? tal_arr(r, u8, *plen) : NULL; + r->payer_info = tal_arr(r, u8, *plen); fromwire_u8_array(cursor, plen, r->payer_info, *plen); } /* INVOICE_REQUEST MSG: replace_invoice */ @@ -990,7 +990,7 @@ static void fromwire_tlv_invoice_description(const u8 **cursor, size_t *plen, vo { struct tlv_invoice *r = vrecord; - r->description = *plen ? tal_arr(r, utf8, *plen) : NULL; + r->description = tal_arr(r, utf8, *plen); fromwire_utf8_array(cursor, plen, r->description, *plen); } /* INVOICE MSG: features */ @@ -1012,7 +1012,7 @@ static void fromwire_tlv_invoice_features(const u8 **cursor, size_t *plen, void { struct tlv_invoice *r = vrecord; - r->features = *plen ? tal_arr(r, u8, *plen) : NULL; + r->features = tal_arr(r, u8, *plen); fromwire_u8_array(cursor, plen, r->features, *plen); } /* INVOICE MSG: paths */ @@ -1115,7 +1115,7 @@ static void fromwire_tlv_invoice_vendor(const u8 **cursor, size_t *plen, void *v { struct tlv_invoice *r = vrecord; - r->vendor = *plen ? tal_arr(r, utf8, *plen) : NULL; + r->vendor = tal_arr(r, utf8, *plen); fromwire_utf8_array(cursor, plen, r->vendor, *plen); } /* INVOICE MSG: node_id */ @@ -1317,7 +1317,7 @@ static void fromwire_tlv_invoice_payer_note(const u8 **cursor, size_t *plen, voi { struct tlv_invoice *r = vrecord; - r->payer_note = *plen ? tal_arr(r, utf8, *plen) : NULL; + r->payer_note = tal_arr(r, utf8, *plen); fromwire_utf8_array(cursor, plen, r->payer_note, *plen); } /* INVOICE MSG: payer_info */ @@ -1339,7 +1339,7 @@ static void fromwire_tlv_invoice_payer_info(const u8 **cursor, size_t *plen, voi { struct tlv_invoice *r = vrecord; - r->payer_info = *plen ? tal_arr(r, u8, *plen) : NULL; + r->payer_info = tal_arr(r, u8, *plen); fromwire_u8_array(cursor, plen, r->payer_info, *plen); } /* INVOICE MSG: created_at */ @@ -1636,7 +1636,7 @@ static void fromwire_tlv_invoice_error_suggested_value(const u8 **cursor, size_t { struct tlv_invoice_error *r = vrecord; - r->suggested_value = *plen ? tal_arr(r, u8, *plen) : NULL; + r->suggested_value = tal_arr(r, u8, *plen); fromwire_u8_array(cursor, plen, r->suggested_value, *plen); } /* INVOICE_ERROR MSG: error */ @@ -1658,7 +1658,7 @@ static void fromwire_tlv_invoice_error_error(const u8 **cursor, size_t *plen, vo { struct tlv_invoice_error *r = vrecord; - r->error = *plen ? tal_arr(r, utf8, *plen) : NULL; + r->error = tal_arr(r, utf8, *plen); fromwire_utf8_array(cursor, plen, r->error, *plen); } @@ -1684,4 +1684,4 @@ bool invoice_error_is_valid(const struct tlv_invoice_error *record, size_t *err_ return tlv_fields_valid(record->fields, NULL, err_index); } -// SHA256STAMP:2946a3a3734bd6af218cb73b4d42ec16fe68c1041b48e084cc160810870bcdd5 +// SHA256STAMP:f29bdf0cc1fd0cce9362c88e3b8681781e11c203cc3026fe13e6c52a845154ba diff --git a/wire/bolt12_wiregen.h b/wire/bolt12_wiregen.h index 527125b7b7ca..a07edec15367 100644 --- a/wire/bolt12_wiregen.h +++ b/wire/bolt12_wiregen.h @@ -323,4 +323,4 @@ struct fallback_address *fromwire_fallback_address(const tal_t *ctx, const u8 ** #endif /* LIGHTNING_WIRE_BOLT12_WIREGEN_H */ -// SHA256STAMP:2946a3a3734bd6af218cb73b4d42ec16fe68c1041b48e084cc160810870bcdd5 +// SHA256STAMP:f29bdf0cc1fd0cce9362c88e3b8681781e11c203cc3026fe13e6c52a845154ba diff --git a/wire/common_wiregen.c b/wire/common_wiregen.c index d61d6405eadd..4c4d39178f28 100644 --- a/wire/common_wiregen.c +++ b/wire/common_wiregen.c @@ -100,4 +100,4 @@ bool fromwire_custommsg_out(const tal_t *ctx, const void *p, u8 **msg) fromwire_u8_array(&cursor, &plen, *msg, msg_len); return cursor != NULL; } -// SHA256STAMP:959a0af7e5dc054bc1bd313dee486b3c2040853b8f3772d889e51048e14ac2b5 +// SHA256STAMP:5e31b6f1281965e31e28ce8a6d1a7e54635170b877bbd11b6ec09cba60f317aa diff --git a/wire/common_wiregen.h b/wire/common_wiregen.h index ad19ec882098..d6a013dc2d92 100644 --- a/wire/common_wiregen.h +++ b/wire/common_wiregen.h @@ -41,4 +41,4 @@ bool fromwire_custommsg_out(const tal_t *ctx, const void *p, u8 **msg); #endif /* LIGHTNING_WIRE_COMMON_WIREGEN_H */ -// SHA256STAMP:959a0af7e5dc054bc1bd313dee486b3c2040853b8f3772d889e51048e14ac2b5 +// SHA256STAMP:5e31b6f1281965e31e28ce8a6d1a7e54635170b877bbd11b6ec09cba60f317aa diff --git a/wire/onion_printgen.c b/wire/onion_printgen.c index d4d237fb4112..b0a7b81c85e8 100644 --- a/wire/onion_printgen.c +++ b/wire/onion_printgen.c @@ -859,4 +859,4 @@ void printonion_wire_tlv_message(const char *tlv_name, const u8 *msg) { printwire_tlvs(tlv_name, &msg, &plen, print_tlvs_encmsg_tlvs, ARRAY_SIZE(print_tlvs_encmsg_tlvs)); } } -// SHA256STAMP:fcaea2b057478205299b8935161c994fece0e410e6942503943747625ddcfc8a +// SHA256STAMP:79946dd94a6cd6e0af297d3676c688228c7098e6b874469cd49b63fee97ac8cf diff --git a/wire/onion_printgen.h b/wire/onion_printgen.h index fa2e5b1e44a2..7acaf3be8446 100644 --- a/wire/onion_printgen.h +++ b/wire/onion_printgen.h @@ -58,4 +58,4 @@ void printwire_mpp_timeout(const char *fieldname, const u8 *cursor); void printwire_onionmsg_path(const char *fieldname, const u8 **cursor, size_t *plen); #endif /* LIGHTNING_WIRE_ONION_PRINTGEN_H */ -// SHA256STAMP:fcaea2b057478205299b8935161c994fece0e410e6942503943747625ddcfc8a +// SHA256STAMP:79946dd94a6cd6e0af297d3676c688228c7098e6b874469cd49b63fee97ac8cf diff --git a/wire/onion_wiregen.c b/wire/onion_wiregen.c index c6b47b0522e0..9272b70966a5 100644 --- a/wire/onion_wiregen.c +++ b/wire/onion_wiregen.c @@ -98,7 +98,7 @@ fromwire_onionmsg_path(const tal_t *ctx, const u8 **cursor, size_t *plen) fromwire_pubkey(cursor, plen, &onionmsg_path->node_id); enclen = fromwire_u16(cursor, plen); - onionmsg_path->enctlv = enclen ? tal_arr(onionmsg_path, u8, enclen) : NULL; + onionmsg_path->enctlv = tal_arr(onionmsg_path, u8, enclen); fromwire_u8_array(cursor, plen, onionmsg_path->enctlv, enclen); return onionmsg_path; @@ -340,7 +340,7 @@ static void fromwire_tlv_onionmsg_payload_enctlv(const u8 **cursor, size_t *plen { struct tlv_onionmsg_payload *r = vrecord; - r->enctlv = *plen ? tal_arr(r, u8, *plen) : NULL; + r->enctlv = tal_arr(r, u8, *plen); fromwire_u8_array(cursor, plen, r->enctlv, *plen); } /* ONIONMSG_PAYLOAD MSG: blinding */ @@ -385,7 +385,7 @@ static void fromwire_tlv_onionmsg_payload_invoice_request(const u8 **cursor, siz { struct tlv_onionmsg_payload *r = vrecord; - r->invoice_request = *plen ? tal_arr(r, u8, *plen) : NULL; + r->invoice_request = tal_arr(r, u8, *plen); fromwire_u8_array(cursor, plen, r->invoice_request, *plen); } /* ONIONMSG_PAYLOAD MSG: invoice */ @@ -407,7 +407,7 @@ static void fromwire_tlv_onionmsg_payload_invoice(const u8 **cursor, size_t *ple { struct tlv_onionmsg_payload *r = vrecord; - r->invoice = *plen ? tal_arr(r, u8, *plen) : NULL; + r->invoice = tal_arr(r, u8, *plen); fromwire_u8_array(cursor, plen, r->invoice, *plen); } /* ONIONMSG_PAYLOAD MSG: invoice_error */ @@ -429,7 +429,7 @@ static void fromwire_tlv_onionmsg_payload_invoice_error(const u8 **cursor, size_ { struct tlv_onionmsg_payload *r = vrecord; - r->invoice_error = *plen ? tal_arr(r, u8, *plen) : NULL; + r->invoice_error = tal_arr(r, u8, *plen); fromwire_u8_array(cursor, plen, r->invoice_error, *plen); } @@ -1026,4 +1026,4 @@ bool fromwire_mpp_timeout(const void *p) return false; return cursor != NULL; } -// SHA256STAMP:fcaea2b057478205299b8935161c994fece0e410e6942503943747625ddcfc8a +// SHA256STAMP:79946dd94a6cd6e0af297d3676c688228c7098e6b874469cd49b63fee97ac8cf diff --git a/wire/onion_wiregen.h b/wire/onion_wiregen.h index 479c89b61041..d5c9a0ac876a 100644 --- a/wire/onion_wiregen.h +++ b/wire/onion_wiregen.h @@ -317,4 +317,4 @@ bool fromwire_mpp_timeout(const void *p); #endif /* LIGHTNING_WIRE_ONION_WIREGEN_H */ -// SHA256STAMP:fcaea2b057478205299b8935161c994fece0e410e6942503943747625ddcfc8a +// SHA256STAMP:79946dd94a6cd6e0af297d3676c688228c7098e6b874469cd49b63fee97ac8cf diff --git a/wire/peer_printgen.c b/wire/peer_printgen.c index 6b40e3a0ea32..f36f70eccb72 100644 --- a/wire/peer_printgen.c +++ b/wire/peer_printgen.c @@ -3079,4 +3079,4 @@ void printpeer_wire_tlv_message(const char *tlv_name, const u8 *msg) { printwire_tlvs(tlv_name, &msg, &plen, print_tlvs_onion_message_tlvs, ARRAY_SIZE(print_tlvs_onion_message_tlvs)); } } -// SHA256STAMP:7c9612ec7cc62b3a44ae65d19b855b521e96796940b4c3d50977d768ace8712e +// SHA256STAMP:7acdb2f85dec7c26fb60ae3302f387fbccae349e182d05c6e4bb043ce2546797 diff --git a/wire/peer_printgen.h b/wire/peer_printgen.h index 997adc7fc320..99c8995603dd 100644 --- a/wire/peer_printgen.h +++ b/wire/peer_printgen.h @@ -99,4 +99,4 @@ void printwire_channel_update_checksums(const char *fieldname, const u8 **cursor void printwire_channel_update_timestamps(const char *fieldname, const u8 **cursor, size_t *plen); void printwire_witness_stack(const char *fieldname, const u8 **cursor, size_t *plen); #endif /* LIGHTNING_WIRE_PEER_PRINTGEN_H */ -// SHA256STAMP:7c9612ec7cc62b3a44ae65d19b855b521e96796940b4c3d50977d768ace8712e +// SHA256STAMP:7acdb2f85dec7c26fb60ae3302f387fbccae349e182d05c6e4bb043ce2546797 diff --git a/wire/peer_wiregen.c b/wire/peer_wiregen.c index 5c706df2fc9e..3365a3e8d4bb 100644 --- a/wire/peer_wiregen.c +++ b/wire/peer_wiregen.c @@ -134,7 +134,7 @@ fromwire_witness_element(const tal_t *ctx, const u8 **cursor, size_t *plen) u16 len; len = fromwire_u16(cursor, plen); - witness_element->witness = len ? tal_arr(witness_element, u8, len) : NULL; + witness_element->witness = tal_arr(witness_element, u8, len); fromwire_u8_array(cursor, plen, witness_element->witness, len); return witness_element; @@ -514,7 +514,7 @@ static void fromwire_tlv_open_channel_tlvs_upfront_shutdown_script(const u8 **cu { struct tlv_open_channel_tlvs *r = vrecord; - r->upfront_shutdown_script = *plen ? tal_arr(r, u8, *plen) : NULL; + r->upfront_shutdown_script = tal_arr(r, u8, *plen); fromwire_u8_array(cursor, plen, r->upfront_shutdown_script, *plen); } @@ -568,7 +568,7 @@ static void fromwire_tlv_accept_channel_tlvs_upfront_shutdown_script(const u8 ** { struct tlv_accept_channel_tlvs *r = vrecord; - r->upfront_shutdown_script = *plen ? tal_arr(r, u8, *plen) : NULL; + r->upfront_shutdown_script = tal_arr(r, u8, *plen); fromwire_u8_array(cursor, plen, r->upfront_shutdown_script, *plen); } @@ -628,7 +628,7 @@ static void fromwire_tlv_opening_tlvs_option_upfront_shutdown_script(const u8 ** r->option_upfront_shutdown_script = tal(r, struct tlv_opening_tlvs_option_upfront_shutdown_script); shutdown_len = fromwire_u16(cursor, plen); - r->option_upfront_shutdown_script->shutdown_scriptpubkey = shutdown_len ? tal_arr(r->option_upfront_shutdown_script, u8, shutdown_len) : NULL; + r->option_upfront_shutdown_script->shutdown_scriptpubkey = tal_arr(r->option_upfront_shutdown_script, u8, shutdown_len); fromwire_u8_array(cursor, plen, r->option_upfront_shutdown_script->shutdown_scriptpubkey, shutdown_len); } /* OPENING_TLVS MSG: request_funds */ @@ -714,7 +714,7 @@ static void fromwire_tlv_accept_tlvs_option_upfront_shutdown_script(const u8 **c r->option_upfront_shutdown_script = tal(r, struct tlv_accept_tlvs_option_upfront_shutdown_script); shutdown_len = fromwire_u16(cursor, plen); - r->option_upfront_shutdown_script->shutdown_scriptpubkey = shutdown_len ? tal_arr(r->option_upfront_shutdown_script, u8, shutdown_len) : NULL; + r->option_upfront_shutdown_script->shutdown_scriptpubkey = tal_arr(r->option_upfront_shutdown_script, u8, shutdown_len); fromwire_u8_array(cursor, plen, r->option_upfront_shutdown_script->shutdown_scriptpubkey, shutdown_len); } /* ACCEPT_TLVS MSG: will_fund */ @@ -910,7 +910,7 @@ static void fromwire_tlv_query_short_channel_ids_tlvs_query_flags(const u8 **cur r->query_flags = tal(r, struct tlv_query_short_channel_ids_tlvs_query_flags); r->query_flags->encoding_type = fromwire_u8(cursor, plen); - r->query_flags->encoded_query_flags = *plen ? tal_arr(r->query_flags, u8, *plen) : NULL; + r->query_flags->encoded_query_flags = tal_arr(r->query_flags, u8, *plen); fromwire_u8_array(cursor, plen, r->query_flags->encoded_query_flags, *plen); } @@ -1023,7 +1023,7 @@ static void fromwire_tlv_reply_channel_range_tlvs_timestamps_tlv(const u8 **curs r->timestamps_tlv = tal(r, struct tlv_reply_channel_range_tlvs_timestamps_tlv); r->timestamps_tlv->encoding_type = fromwire_u8(cursor, plen); - r->timestamps_tlv->encoded_timestamps = *plen ? tal_arr(r->timestamps_tlv, u8, *plen) : NULL; + r->timestamps_tlv->encoded_timestamps = tal_arr(r->timestamps_tlv, u8, *plen); fromwire_u8_array(cursor, plen, r->timestamps_tlv->encoded_timestamps, *plen); } /* REPLY_CHANNEL_RANGE_TLVS MSG: checksums_tlv */ @@ -2484,4 +2484,4 @@ bool fromwire_channel_update_option_channel_htlc_max(const void *p, secp256k1_ec *htlc_maximum_msat = fromwire_amount_msat(&cursor, &plen); return cursor != NULL; } -// SHA256STAMP:7c9612ec7cc62b3a44ae65d19b855b521e96796940b4c3d50977d768ace8712e +// SHA256STAMP:7acdb2f85dec7c26fb60ae3302f387fbccae349e182d05c6e4bb043ce2546797 diff --git a/wire/peer_wiregen.h b/wire/peer_wiregen.h index dc1b44de2af3..b6a2e1f60c06 100644 --- a/wire/peer_wiregen.h +++ b/wire/peer_wiregen.h @@ -930,4 +930,4 @@ bool fromwire_channel_update_option_channel_htlc_max(const void *p, secp256k1_ec #endif /* LIGHTNING_WIRE_PEER_WIREGEN_H */ -// SHA256STAMP:7c9612ec7cc62b3a44ae65d19b855b521e96796940b4c3d50977d768ace8712e +// SHA256STAMP:7acdb2f85dec7c26fb60ae3302f387fbccae349e182d05c6e4bb043ce2546797