lnbits icon indicating copy to clipboard operation
lnbits copied to clipboard

Cliché wallet issues

Open fiatjaf opened this issue 3 years ago • 1 comments

I see 2 potential issues with the cliché wallet:

  1. It is using the "human-readable" command format, which makes the implementation bloated and more error-prone. Probably not a big deal, but the invoice descriptions will break. Instead there is the JSON-RPC interface, in which you instead of create-invoice --msatoshi 12 --description bla you write {"method": "create-invoice", "params": {"msatoshi": 12, "description": "bla"}}.
  2. It is opening a websocket, writing a command and reading the response immediately after. That is not safe if other commands are being called simultaneously. Cliché will write all responses and also event notifications to all websockets that are open at anytime. So to filter for the response you want you must check the id in the response object.

Proposed fix:

  • Open a single websocket.
  • Write commands to it, Assign a random id to each command called ({"method": "...", "params": {...}, "id": "892173"}). Keep track of the id and wait.
  • Listen to everything that comes from it. If it has an id that is known, wake up the method that was waiting for it so it can proceed. If it is an invoice paid notification, wake up the paid invoices listener.

I actually also do not know how to do this. I was trying just now, but I realized it would take me about 6 months to learn how to implement the flow above using asyncio, so I decided to just open this issue.

fiatjaf avatar Aug 02 '22 01:08 fiatjaf

FWIW, I've implemented something like this in Dart for Core Lightning. It should not be that hard to do translate to Python asyncio, but can't do it myself at the moment. Most interesting function is the _sendRequest function. Basically what I do is return a future for each request that will be completed once _eventStream finds an existing request ID.

fusion44 avatar Aug 09 '22 19:08 fusion44