ElementsProject / lightning

Core Lightning — Lightning Network implementation focusing on spec compliance and performance
Other
2.81k stars 887 forks source link

Exposing inter-node messaging through API #2638

Open jooray opened 5 years ago

jooray commented 5 years ago

It would be very useful to expose messaging and communication interface through an API. There are many decentralised finance applications built on top of the Lightning Network that would greatly benefit if nodes could exchange other messages than direct payment messages, for example negotiating settlements and parameters of various payment products. Since for communication all that is really needed is node pubkey, communicating using a different layer seems redundant and not very effective.

I propose creating a simple sendMessage, subscribeMessages (websocket?) with encryption and signature verification. This would greatly improve usability of lightning network besides of simple payment use-case.

jsarenik commented 2 years ago

We just spoke about WebSockets during this meeting and it is said to be working. Trying on my node now.

It requires following plugin: https://github.com/rbndg/c-lightning-events and its configured websocket-port can be straight proxied by Caddy2 like this:

(basic) {
        encode zstd gzip
}

wsl.bublina.eu.org {
        import basic
        reverse_proxy * 127.0.0.1:8524
}

EDIT: No plugin needed. See 80a47f111 and set experimental-websocket-port in the config file. Does not work with Caddy2 WSS proxy yet. Only unencrypted WebSocket (of course inside it the full LN authentication and encryption is being done, but that is not obvious to a browser accessing ws:// scheme).

@jb55 FYI

jb55 commented 2 years ago

You can acheive custom messaging between clightning nodes with plugins + custommsg hooks. You can also communicate with clightning nodes from anywhere with something like lnsocket and commando for clightning rpc access over lightning.

Once lnsocket is compiled to javascript/wasm, you should be able to talk to clightning nodes e2e in your browser with a websocket proxy as described above.