From 44c469d52b1ce620d6f48762d5667fd4460e254c Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 21 Jul 2021 15:07:44 +0930 Subject: [PATCH] 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 99bbd0af3..e3ea0210c 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 396151ba2..35e13f040 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 07e177bc4..c781a54b0 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 7dd27da86..34e0b303c 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 7ccdabf77..0b7fd17eb 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 ec0d7c660..636c0bbc3 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 e9a26b611..67cdc4c3c 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 f25881696..7985dc5a0 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;