Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jsonrpc: Add description_hash parameter to invoice #4892

Closed

Conversation

laanwj
Copy link
Contributor

@laanwj laanwj commented Oct 28, 2021

Add an optional description_hash parameter to the invoice command. This can be specified instead of the description, to create an invoice that only commits to a 256 bit hash (generally SHA256) of the description.

This is used in the lnurlp protocol. See lightningd/plugins#307 for example usage.

Closes #4705

@laanwj laanwj requested a review from cdecker as a code owner October 28, 2021 17:02
@laanwj laanwj force-pushed the 2021-10-description-hash branch 2 times, most recently from f1c8361 to 8582691 Compare October 28, 2021 18:41
Copy link
Collaborator

@vincenzopalazzo vincenzopalazzo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I have only a small comment for the python doc string

contrib/pyln-client/pyln/client/lightning.py Outdated Show resolved Hide resolved
lightningd/invoice.c Outdated Show resolved Hide resolved
@laanwj
Copy link
Contributor Author

laanwj commented Oct 31, 2021

I have pushed a new version with (thanks @vincenzopalazzo).

  • slightly extended documentation string for invoice (mention that description needs to be empty)
  • add blurb to manual page
  • updated invoice python docstring from lightning-cli help output
  • added CHANGELOG.md entry

Edit: Somehow it's still saying that the PR is missing a changelog entry 🤷‍♀️ (should be fixed now)

Add an optional description_hash parameter to the invoice command. This can be specified instead of the description, to create an invoice that only commits to a 256 bit hash (generally SHA256) of the description.

This is used in the lnurlp protocol. See lightningd/plugins#307 for example usage.

Closes ElementsProject#4705.

Changelog-Added: JSON-RPC: `invoice` now accepts `description_hash` parameter.
Copy link
Collaborator

@vincenzopalazzo vincenzopalazzo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 4788cba

@rustyrussell
Copy link
Contributor

Sorry for delay on this!

I prefer a boolean flag to say "hash description instead": that way lightningd can save the description in the db and show it in listinvoices. Otherwise you've made an unknown commitment (pun intended!) which it has to honor.

We've generally steered away from hashed descriptions, because there was not a transport which used them. Time to bring them back!

@laanwj
Copy link
Contributor Author

laanwj commented Nov 17, 2021

I prefer a boolean flag to say "hash description instead": that way lightningd can save the description in the db and show it in listinvoices

I didnt do this because the descriptions can be extremely long, and in the case of lnurlp they're kind of boring (e.g. it's just the same metadata, which can include images, every time, sometimes with other metadata concatenated). You could store it in the db for every payment but it also seems wasteful in a way.

@rustyrussell
Copy link
Contributor

You control this though, right? You're issuing the invoice, you'd better control what it says. Otherwise use keysend, it's simpler.

nixbitcoin added a commit to fort-nix/nixbitcoin.org that referenced this pull request Nov 22, 2021
e0509fb add test/dev.sh (Erik Arvstedt)
bbcd704 add test (Erik Arvstedt)
2a336cd shell: add command `nginx-conf` (Erik Arvstedt)
aa44d9c website: move obwatcher -> orderbook (Erik Arvstedt)
99313eb website: add rate limiting (Erik Arvstedt)
2e74219 website: extract 'donate' module (Erik Arvstedt)
4a424c5 website: disallow access to btcpayserver root (Erik Arvstedt)
aeeaf63 nix-bitcoin-release 0.0.58 (Erik Arvstedt)
79bdca9 add btcpayserver test config (Erik Arvstedt)
e1c0b20 shell: add dev helper commands (Erik Arvstedt)
66f955c scenarios: disable joinmarket-ob-watcher (Erik Arvstedt)
656a359 scenarios: extract scenario `disableFeatures` (Erik Arvstedt)
369d608 move scenarios.nix to test/ (Erik Arvstedt)
218232c homepage: add `community` section (Erik Arvstedt)
7b4ea9a website: enable nginx reload (Erik Arvstedt)
69b7012 matrix: use nginx proxy_pass syntax (Erik Arvstedt)

Pull request description:

  This branch is a copy of #22 with LNURL donation support removed.
  LNURL is [not yet supported](ElementsProject/lightning#4892) by `clighting`.

Top commit has no ACKs.

Tree-SHA512: dfd3f93843cae8225de4dfca193421dae32bd26be2c262a0598c4a2de8ff33fadf7b31cdd625d451d17a313b51e8ed95e1387ebad91a62f9c05651a53d891c2b
@laanwj
Copy link
Contributor Author

laanwj commented Nov 22, 2021

You control this though, right? You're issuing the invoice, you'd better control what it says. Otherwise use keysend, it's simpler.

Yes and no. The creator of the invoice controls it. But in the case of lnurlp (the primary use of this), they have to commit to data in a specific format (the metadata string as specified in LUD-06). Wallets do check the description_hash field and don't allow paying the invoice if it's something else (Something I discovered in ACINQ/phoenix#213).

I don't think there's an option to use keysend here (but I might be wong).

@laanwj
Copy link
Contributor Author

laanwj commented Nov 23, 2021

Anyhow, I'm happy to rewrite this to use the full description and a boolean argument instead.
I think I need help on the "store the description in the database without making it part of the invoice" (with no limit to length) part though. Not sure how to do that.

@erikarvstedt
Copy link

LUD-06 allows embedding base64-encoded images in the description which would needlessly bloat the invoice DB.
I'd prefer to let clients decide where and whether to store the description.

@rustyrussell
Copy link
Contributor

Sure, you can always remove old invoices (in fact, autocleaninvoice does this!) though. It doesn't remove paid ones though, that would need enhancement.

We actually already have a 'description' field in the db, and it's wired through (we initially supported creating invoices with description hashes, but nobody used them so we removed the ability).

Just hand the description (instead of b11->description, which will be NULL) to wallet_invoice_create() and it will all Just Work.

@rustyrussell
Copy link
Contributor

LUD-06 allows embedding base64-encoded images in the description which would needlessly bloat the invoice DB. I'd prefer to let clients decide where and whether to store the description.

The invoice is the contract you're committing to. You really want to save it all by strong default; sure, there are scenarios where you can reproduce it, but storage is cheap.

@laanwj
Copy link
Contributor Author

laanwj commented Dec 19, 2021

Just hand the description (instead of b11->description, which will be NULL) to wallet_invoice_create() and it will all Just Work.

Thanks, I'll look into that.

@rustyrussell rustyrussell added this to the v0.11 milestone Mar 9, 2022
@fiatjaf
Copy link
Contributor

fiatjaf commented Mar 20, 2022

Some reasons why c-lightning storing the full description is a bad idea:

  1. Unlike normal invoices, these invoices will never be generated manually, they will be generated automatically by some other program that will hopefully be storing the full description.
  2. For most lnurlpay cases the description can be regenerated anytime by just inputting the same parameters to a function.
  3. For most lnurlpay cases the description will repeat itself many many times as the paycode is reused -- for example:
    • A donation lnurlpay code will say "donate to Bob" and contain a picture of Bob, base64-encoded, and that will have to be stored again and again every time someone donates to Bob?
    • Someone buying a coffee on a coffeeshop by scanning the lnurlpay QR, the description will contain the name of the coffee item and a picture of the coffee.
  4. Most importantly: it's the buyer's responsibility to keep track of what he has paid for. Once the buyer is able to show the full description and the hash of that matches the description hash on the signed invoice, everything is proved and it doesn't matter that the seller has stored the full description or not.

@rustyrussell
Copy link
Contributor

Some reasons why c-lightning storing the full description is a bad idea:

1. Unlike normal invoices, these invoices will never be generated manually, they will be generated automatically by some other program that will hopefully be storing the full description.

That's a big assumption! You'd be surprised what people start doing to make QR codes smaller.

2. For most lnurlpay cases the description can be regenerated anytime by just inputting the same parameters to a function.

3. For most lnurlpay cases the description will repeat itself many many times as the paycode is reused -- for example:
   
   * A donation lnurlpay code will say "donate to Bob" and contain a picture of Bob, base64-encoded, and that will have to be stored again and again every time someone donates to Bob?
   * Someone buying a coffee on a coffeeshop by scanning the lnurlpay QR, the description will contain the name of the coffee item and a picture of the coffee.

Sure. Put 1MB in there, and still nobody cares, as long as you expire unused invoices?

4. Most importantly: it's the buyer's responsibility to keep track of what he has paid for. Once the buyer is able to show the full description and the hash of that matches the description hash on the signed invoice, everything is proved and it doesn't matter that the seller has stored the full description or not.

Sure, in a perfect world! But in practice they do "hey, I paid this " and you go, "um, you did, I have no idea what that is".

The default should never be to discard this information. I'd rather add an option to autoclean to remove it (maybe have delinvoice add a 'desconly' option?).

rustyrussell added a commit to rustyrussell/lightning that referenced this pull request Mar 23, 2022
LNURL wants this so they can include images etc in descriptions.

Replaces: ElementsProject#4892
Changelog-Added: JSON-RPC: `invoice` has a new parameter `deschashonly` to put hash of description in bolt11.
Signed-off-by: Rusty Russell <[email protected]>
@rustyrussell
Copy link
Contributor

See #5121 for comparison.

@fiatjaf
Copy link
Contributor

fiatjaf commented Mar 23, 2022

I'm fine with that one considering the new ways to delete invoices. The benefit is that it might be simpler for some users to delegate the description-hashing process to c-lightning.

rustyrussell added a commit to rustyrussell/lightning that referenced this pull request Mar 23, 2022
LNURL wants this so they can include images etc in descriptions.

Replaces: ElementsProject#4892
Changelog-Added: JSON-RPC: `invoice` has a new parameter `deschashonly` to put hash of description in bolt11.
Signed-off-by: Rusty Russell <[email protected]>
rustyrussell added a commit that referenced this pull request Mar 28, 2022
LNURL wants this so they can include images etc in descriptions.

Replaces: #4892
Changelog-Added: JSON-RPC: `invoice` has a new parameter `deschashonly` to put hash of description in bolt11.
Signed-off-by: Rusty Russell <[email protected]>
@rustyrussell
Copy link
Contributor

rustyrussell commented Mar 30, 2022

Merged #5121 instead

@callebtc
Copy link

I need this feature as well, not the way it is implemented today (with deschash_only).

There are countless apps out there that can only pass the hash and don't have access to the description itself (because they don't really need to and/or want to avoid unnecessary bloat).

Afaik, CLN is the only implementation that doesn't accept the hash directly and requires special treatment in LNbits. Having the option to just pass the hash would make many things easier and more efficient.

@kiwiidb
Copy link
Contributor

kiwiidb commented Sep 7, 2022

+1 we would like to support CLN as a backend in https://github.com/getAlby/lndhub.go
But this requires a minimum of API overlap with LND and not being able to do this is a complete blocker :(

@jb55
Copy link
Collaborator

jb55 commented Sep 7, 2022 via email

@kiwiidb
Copy link
Contributor

kiwiidb commented Sep 7, 2022

It's not that we don't have the description. It's just that writing a service with multiple node back-ends is more difficult due to this difference in API. I guess we could also make a breaking change and do it this way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: Allow invoice creation with description_hash instead of description.
8 participants