So "off chain" means LN holds the BTC in some other data structure then batches it up as one big transaction? Kinda like how a broker covers small retail trades until they hit enough volume to register an NYSE trade on the floor? Is that how it works? If so , this means lots of BTC is tied up in LN ... that seems dubious as heck.
It's not entirely off chain. It's hedged in that a transaction is created sending X BTC between us, we repeatedly update that transaction off chain every time we move small amounts of money between eachother, then after Y days we submit the final transaction to the blockchain to resolve the total amounts.
The idea being if one of us starts to be uncooperative, the other can just submit the transaction at its latest state so that we don't lose anything except that last update that we disagreed upon.
Most of the examples of Lightning that I've seen involve frequent transactions between small numbers of parties. How would this work in a retail transaction? For example, if I want to buy a cup of coffee from a shop that I visit infrequently?
My understanding is basically there's routing and there will be centralization of channels to some extent. One way to think of LN is that it is a wallet/debit card of sorts. You transfer some amount of BTC to a Lightning channel and that becomes your wallet. You can transact with that wallet quickly/cheaply but there's always the ability for that channel to be closed and put back on the chain with the last balance in the case of disputes etc..
But as you said, coffee shop needs some path to you to make that feasible. So then you get BTCVisa (c) or whatever, which is a channel provider that has built a network of channels open with lots of vendors. If you open a channel with them then you get to benefit from getting to use the wallet you already have. There is cross-channel routing of course so maybe that doesn't happen but it seems like a natural result.
LN is neat in concept, but I'm not sure I really see the point compared to Bitcoin cash or the like that just say scale on chain. I guess we'll see.
It forms a network, where transactions are routed between LN nodes/channels. You have to be in the same graph with the coffee shop. If there are small separate subgraphs, they can be connected by one common node, such as an exchange.
So, most likely the coffee shop has just one or a few channels open to popular exchanges or dedicated LN services. You open a channel either directly or indirectly to the same exchange / service.
You have onchain BTC, and you can decide to put them in a LN channel with another party (this causes an onchain transaction)
You and that party can now transact freely between each other with no fees, but if that other party is a gateway, it can route payments through it and through other gateways too, and each of them charge fees for routing.
Once any of the parties decide to close the channel, is when a new onchain transaction is created with the last balances state.
While the LN channel is open, only the parties involved know the current state of the balance.
Interesting. So it's like lots of little ledgers, each channel stays open until N number of transactions between two people complete, then the finally tally is pushed onchain when the channel closes. Am I wrong to thing this sounds a little risky? Like, that channel could be "lost" after the goods/services were exchanged, leaving the seller holding the bag. I don't understand what kind of recourse the seller has to LN if LN screws up? It's kinda like escrow, but escrow agents are heavily regulated whereas is LN "trustworthy"?
EDIT: ah, I think "nicpottier" explains a little more, below. about having an account on LN requires a certain amount of a deposit (like a debit account).
Each update to the channel is a new transaction that references the opening transaction, on each update, this transaction is replaced with a new one, so in practice only the last transaction is kept (old transactions become dangerous to publish)
The big difference is that bitcoin's scripting language is not turing complete. This is a security and scalability trade off that the bitcoin community isn't willing to compromise on, which drove people like Vitalik (started as a bitcoin dev) away to start Ethereum.
I haven't looked into this much, but there are projects like Rootstock, https://www.rsk.co/, that essentially recreate all of Ethereum's functionality as a bitcoin sidechain.
It has always had, it is just much limited than ethereum's.
But you can express things like "if X and Y cooperate they can spend this transaction or Y can spend after 1000 blocks or X can spend if it reveals the preimage of this hash ____"
These logics are what LN uses in its update-transactions
If what you want is a more technical answer of how the balances in a LN channel is trustlessly updated, then you should probably read a more in-depth resource, it's a complicated topic. But I'll try to give you some idea.
Every transaction in a LN channel is not a simple transaction, it's a smart contract transaction that, if broadcasted, closes the channel automatically but have multiple ways of spending it further, and one of those ways allows a party to get all the funds if he has proof that the counter party cheated (closed the channel using and old-state transaction).
So those transactions that are created are never published if both party cooperate, instead, they serve as a forced-closing mechanism if the other party is uncooperative
That was just a high level view of updating channels, but opening a channel and routing a payment is another story