fedimint / fedimint

Federated E-Cash Mint
https://fedimint.org/
MIT License
536 stars 210 forks source link

Lightning gateway serves multiple federations #664

Closed justinmoon closed 4 months ago

justinmoon commented 1 year ago

Making a new issue based inspired by https://github.com/fedimint/fedimint/issues/613#issuecomment-1257633238

What needs to happen in order to support this usecase?

elsirion commented 1 year ago

Braindump:

okjodom commented 1 year ago

Add a hop to the route hint so that the route becomes [gateway, federation, user] where the user key is randomly generated by the user and the federation key is generated once by the gateway. This is important since the GW needs to be able to decrypt the onion that would be sent to the "federation" hop (but is just processed by the GW to determine from where to get the preimage). Any ideas where else to hide a few bits to select the federation welcome (hash/user pk grinding?)

Ack on this.

okjodom commented 1 year ago

The GW needs to maintain separate e-cash wallets per federation

Supported by #714 , by fact of the each registered federation getting a dedicated GatewayActor

okjodom commented 1 year ago

"Internal routing" can now happen between federations and becomes more complex

Semantics: We probably should distinguish between payments/routing by giving definitions for "internal payments", "external payments" and "self payments". My take on it is that:

  1. internal payments

    • happens between two clients of the same federation
    • implementation as discussed in #613 , fully scopes all interactions between clients and the federation they belong t
    • gateways are NOT involved in routing
  2. external payments

    • happens between a client in a federation, and some other lightning entity outside this federation
    • entity outside this federation might be in another federation, but it doesn't matter unless it's an "self payment" case, defined below
    • gateways are involved in routing
  3. self payments

    • special case of external payments
    • happens when a gateway serves two federations, between which two clients want to complete a transaction
    • self payment logic is fully scoped within the gateway

current issue is about external payments and self payments

okjodom commented 1 year ago

Add a hop to the route hint so that the route becomes [gateway, federation, user] where the user key is randomly generated by the user and the federation key is generated once by the gateway. This is important since the GW needs to be able to decrypt the onion that would be sent to the "federation" hop (but is just processed by the GW to determine from where to get the preimage). Any ideas where else to hide a few bits to select the federation welcome (hash/user pk grinding?)

Ack on this.

@okjodom taking up this task

justinmoon commented 1 year ago

Remember to fix this TODO when you close out this issue.

okjodom commented 1 year ago

This was a limitation of the old gateway architecture, from which we have fully migrated after #1718 The new gateway introduced to the test framework at #1717 supports multiple federations

justinmoon commented 1 year ago

Do we have a test for this, yet?

okjodom commented 1 year ago

Do we have a test for this, yet?

Reactivating, until we have automated tests

justinmoon commented 1 year ago

Update:

m1sterc001guy commented 1 year ago

LND might not work because LndClient.router().htlc_interceptor can't be called twice in our experience. But why not?

This should be fixed after https://github.com/fedimint/fedimint/pull/2161. We know only have one interceptor thread. Still need the test to confirm this works though.

justinmoon commented 1 year ago

Dope. I think we could use fedimint-bin-tests to make a test for this. We would just need something like this, but which runs 2 federations, and joins both gateways in each federation. Then make a bunch of payments testing that everything works.

elsirion commented 4 months ago

To which degree does this work now and how much is it tested? @m1sterc001guy @okjodom

m1sterc001guy commented 4 months ago

We have a few tests that utilize multi_federation_test helper function in our gateway test suite. The main test that covers the swap scenario between two connected federations in a gateway is called test_gateway_executes_swaps_between_connected_federations