|
| 1 | +# Loop Architecture |
| 2 | + |
| 3 | +Lightning Loop's architecture for orchestrating submarine swaps is based on a |
| 4 | +client/server concept. |
| 5 | + |
| 6 | +The client has a swap execution daemon `loopd` controlled by a CLI application |
| 7 | +`loop` which uses a gRPC API. The client daemon initiates swaps and handles |
| 8 | +their progress through swap phases. To manage keys and the connection to the |
| 9 | +LN/BTC network layers the client daemon connects to a local lnd wallet. |
| 10 | + |
| 11 | +Client daemons communicate with the Loop server daemon, which is opaque but |
| 12 | +operates in a similar way. The server is not a trusted component in this |
| 13 | +architecture; the client daemon validates that the terms of the swap are |
| 14 | +acceptable and the server cannot access the swap funds unless the swap enters |
| 15 | +the "complete" phase. |
| 16 | + |
| 17 | +## Loop Out Swap (off -> on-chain) |
| 18 | + |
| 19 | +Phases: |
| 20 | + |
| 21 | +1. Initiation: Client queries for terms of a swap |
| 22 | +2. Fee: Client sends a small fee HTLC that is unrestricted |
| 23 | +3. Funding: Client sends a funding HTLC locked to a preimage they generate |
| 24 | +4. Payment: Server sends the funds on-chain locked to the funding preimage hash |
| 25 | +5. Complete: Client uses the preimage to take the on-chain funds. |
| 26 | +6. Final: The server uses the on-chain-revealed preimage to claim funding HTLC |
| 27 | + |
| 28 | +``` |
| 29 | + loop out 500 |
| 30 | + | |
| 31 | + | |
| 32 | + v |
| 33 | + .-----------------------------. |
| 34 | + | Loop CLI | |
| 35 | + | ./cmd/loop | |
| 36 | + | | |
| 37 | + | | |
| 38 | + | .-------------------. | .--------------. .---------------. |
| 39 | + | | Loop Client (lib) | | | LND node | | Bitcoin node | |
| 40 | + | | ./ |<-------------| |-------------------| | |
| 41 | + | | | | | | on-chain | | |
| 42 | + | | |------------->| | htlc | | |
| 43 | + | | | | off-chain | | | | |
| 44 | + | '-------------------' | htlc '--------------' '---------------' |
| 45 | + '-----------------|-----------' | ^ |
| 46 | + | | | |
| 47 | + | v | |
| 48 | + | .--. .--. |
| 49 | + | _ -( )- _ _ -( )- _ |
| 50 | + | .--,( ),--. .--,( ),--. |
| 51 | + initiate| _.-( )-._ _.-( )-._ |
| 52 | + swap | ( LIGHTNING NETWORK ) ( BITCOIN NETWORK ) |
| 53 | + | '-._( )_.-' '-._( )_.-' |
| 54 | + | '__,( ),__' '__,( ),__' |
| 55 | + | - ._(__)_. - - ._(__)_. - |
| 56 | + | | ^ |
| 57 | + | | | |
| 58 | + v v | |
| 59 | + .--------------------. off-chain .--------------. .---------------. |
| 60 | + | Loop Server | htlc | LND node | | Bitcoin node | |
| 61 | + | |<-------------| | | | |
| 62 | + | | | | on-chain | | |
| 63 | + | | | | htlc | | |
| 64 | + | |--------------| |----------------->| | |
| 65 | + | | | | | | |
| 66 | + '--------------------' '--------------' '---------------' |
| 67 | +``` |
0 commit comments