breez / breez-sdk-greenlight

MIT License
244 stars 43 forks source link

Trampoline payments #1034

Closed JssDWt closed 3 months ago

JssDWt commented 4 months ago

This PR adds trampoline payment functionality to the SDK.

If a client sends a payment, normally the greenlight node will find routes through the gossip graph, and attempt to pay over those routes. If a route fails, it tries again. For every attempt there are multiple rounds where the greenlight node has to communicate with the signer. Trampoline payments have the advantage there will be only one outgoing payment attempt, and the LSP will do the retrying, therefore less communication rounds are necessary, hopefully improving payment performance. The tradeoff is the user may pay more fees for the route, and the user loses some privacy in the current setup, because the LSP will learn the payment destination. The initial default trampoline policy will be 0,5%.

This PR leans on the corresponding greenlight PR for trampoline payments, which is still a work in process: https://github.com/Blockstream/greenlight/pull/475

The LSP will need to run this plugin: https://github.com/breez/trampoline

Some notes about this PR:

TODO:

roeierez commented 4 months ago

Good points @dangeross . Regarding checking lsp liquidity since this check comes with some latency price for each payment and it is an edge case I would consider trying trampoline and if failing for liquidity fallback to regular payment. I think it should fail fast since the node plugin should check that before sending any htlcs

JssDWt commented 4 months ago

@dangeross @roeierez please check my last 7 commits. Instead of calling lsp_info (which is a network call) I added two changes:

With these two pieces of information we can check:

Next to that I added a flag in the SendPaymentRequest and LnurlPayRequest to signal the user doesn't want to use trampoline.

JssDWt commented 4 months ago

I had a case where the trampoline payment was not attempted. I don't think this mechanism is robust enough. Maybe the peer feature check has to be removed?

JssDWt commented 4 months ago

The status of this PR today is:

JssDWt commented 3 months ago
JssDWt commented 3 months ago

Re-requesting review from @roeierez and @dangeross

JssDWt commented 3 months ago

I imagine at some point people will ask about LSP trampoline fees. Maybe we should follow up at some point to add the fee rate to the LSP info?

Yes. The fee rate is currently not advertised in our custom protocol. That could be an additional feature. We assume a fixed fee of 0.5%.

JssDWt commented 3 months ago

@dangeross re-requesting review due to this added commit: 4a0a150457c1d191ae850badb7846571266a2b48

JssDWt commented 3 months ago

Bumped greenlight because https://github.com/Blockstream/greenlight/pull/475 was merged