Bitcoin Q&A: How do payment channels work?

Bitcoin Q&A: How do payment channels work?

“Can you explain the Lightning Network and how
payment channels with ‘locked’ funds work?” Yes. Let’s start with payment channels. Payment channels are [opened from]… transactions on the Bitcoin network that lock
funds in a 2-of-2 multi-signature address. If I have a payment channel with Alice, that has [bitcoin]
locked [in a multi-sig with one key from each of us]. I commit an [amount] of funds to the balance
of the channel. Let’s say I put in one bitcoin. Alice [also] puts in one bitcoin and we both
commit those [bitcoin] in a 2-of-2 multi-sig, where both of us [must] sign to
[spend or] release these funds. Once we have [opened a payment channel], we can sign
a [payment] that changes the balance [of the channel]. We [can] sign a [payment] whereby I reduce my
[share of the] balance in the channel to 0.9 bitcoin, [while] I increase Alice’s [share of
the] balance to 1.1 bitcoin, by simply… updating the multi-sig with a new signed transaction,
which updates the balance in the channel. That is [called] a payment channel because we don’t
[broadcast] that transaction to [the Bitcoin network]. We hold on to it [until we need to update
again, or if we settle the channel on-chain]. Once we have locked funds in the payment channel,
we can write [smaller payments] to each other. This is a real [payment using bitcoin],
which [updates the balance in the channel]. I [see that Alice and] I [each] used
to own one bitcoin in this channel. But I will sign a transaction that Alice could “cash in”
(settle) in the future, which gives her 1.1 bitcoin… and returns 0.9 bitcoin to me,
from this multi-sig address. I will [then] give [the signed transaction] to Alice.
Alice could [also] sign it and [settle it on-chain], at which point she gets 1.1 bitcoin and I get 0.9 bitcoin,
or hold on to it and wait [until after more payments]. If I want to do another [payment], I could sign another
transaction that reduces my balance to 0.8 bitcoin… and increases Alice’s [share] to 1.2 bitcoin. I sign it, give it to Alice, and now she has a new balance. If she [settled] that transaction, she would get 1.2 bitcoin
[from the multi-sig] and I would get 0.8 bitcoin. Effectively, we have transferred 0.2 bitcoin total to Alice.
But what if Alice wants to pay me back some money? Alice writes a transaction that changes the [channel]
balance to 0.9 bitcoin for me, and 1.1 bitcoin for Alice. Effectively, Alice has sent me 0.1 bitcoin,
[a payment] in the opposite direction. I just hold on to it. [Over time], back and forth we go,
signing and sending each other these transactions. Anytime we want, one of us or both of us collaboratively
could sign [a transaction to settle the channel balance], which is the [most] accurate and up-to-date
balance of our tab, like how you keep track… of when you are buying drinks at a bar and don’t
[use your] credit card until the end of the night. That would effectively “close the channel”
when you [authorize] the transaction. [When you] commit and update the balance, there
are a few complexities in there for security reasons. Obviously, I want some protection so Alice can’t sign
an older transaction which gives her a better balance. There are a couple of ways to [do that]. There is a built-in penalty mechanism where, if
Alice tries to cheat by signing an older transaction, [older payments will have revealed] a script that
allows me to take all of the money from the channel. Because [there is a] penalty for misuse, she can’t sign it prematurely or [rebroadcast an old
channel state unilaterally] without my agreement. I will penalize her by taking all the money in the channel. That tit-for-tat mechanism, as it is called in game theory,
is one of the security [measures in Lightning channels]. There are other mechanisms which
could be used. One of them is called L2. But that is the basic idea [of] payment channels. [In summary]: we lock some funds into a
shared multi-sig address, and then exchange… [a series of] signed transactions — which
we don’t [broadcast] to the Bitcoin network… [until we want to settle on-chain] — updating the balance to reflect payments we are sending to each other. When we are done sending payments to each other, we can [both sign] the last transaction, [broadcast it
to the Bitcoin network], and close the channel. That is one payment channel, but [it becomes more
interesting] when you can link [channels] together. Lightning is [a network of linked]
bi-directional payment channels. [I can have a bi-directional payment channel]
with Alice, [who also] has [a channel] with Carol. I [can] make a commitment to pay Alice, only if Alice
[then] pays Carol. As a result, I pay Carol through Alice. That is done through the exchange of a series of
transactions called hashed timelock contracts (HTLCs) It is rather complicated, but basically we use
Alice as an [intermediate routing node], so that… if I commit funds to Alice, Alice [must] commit [those]
funds to Carol, as if I committed to Carol [directly]. These channels can [continue for] quite a significant
length, [with] multiple hops of commitments. As soon as Carol is satisfied that she has a
commitment from Alice, she can signal back to me; I release my commitment to Alice, Alice releases
her commitment Carol, and everybody gets paid. Most importantly, in all of [hops], the system
is designed so that no one can cheat. Alice doesn’t get paid unless Carol has
[a commitment to be] paid [by Alice]; only once Alice has committed to Carol
is my commitment to Carol [released]. That way, we have security.
We don’t [need] to trust each other. If anybody disappears from the network, we all get
refunds [for bitcoin] we locked in commitments. Of course, this isn’t transmitted to the Bitcoin network,
even though it is [still] a bitcoin [payment]. The only times you use [an on-chain] bitcoin
transaction, is if [you want to cooperatively settle]… or there is a dispute / breakdown in the channel,
whereby somebody disappears or tries to cheat. [In that case] you [would] take the last valid transaction
you have and you send that to the Bitcoin network. That way, you get your money back, or
punish the cheater, and close the channel. You can’t be cheated, [as you are] effectively using
the [underlying] Bitcoin blockchain for security. almost like a court [in an instance where] you [bring them] the contract if [someone has tried to break it]. You wouldn’t take every contract you ever made, you only take a contract to court if there
has been an attempt to cheat you. In the Lightning Network, the vast majority of
the hundreds of thousands of [payments]… can happen without any problems. Everybody knows that if they disappear or attempt to
cheat, or if anything [else] goes wrong in the channel, any participant can take one of these already signed,
valid Bitcoin transactions, “cash it in” to the court… of the Bitcoin blockchain, and become whole. If you know someone can [settle the
balance] if you cheat, you don’t cheat, especially if there is a penalty included in the
transaction that will cost you [all of your bitcoin]. That is how Lightning Network works. There is another question: “Is the Lightning Network
a sidechain?” The answer is: No, it is not a sidechain. Lightning is an overlay network [made of] a series of
smart contracts with bitcoin that [enable] you to do… hundreds of thousands of [off-chain
payments between] you and other recipients [The payments are] that are private and fast with very
low cost, as the capacity of the [on-chain] network… is only used to open and close channels,
which does not need to happen very often. Therefore, you can scale the Bitcoin
blockchain to a much greater degree. It is only used as the “judge” [in settlement]. “Do these payment channels face scaling problems
if they [become] heavily loaded with [payments]?” Not really. The amount of computation you
need to calculate a hashed timelock contract… and route [through channels] is such that… If you have two Lightning nodes on a well-connected
network, and exchange transactions between them… as fast as possible, you [could] do hundreds
of thousands of [payments] per second. Transactions are only seen by
[the nodes involved in a channel]. There could be another two nodes [nearby] doing
a hundred thousand [payments] per second. There could be a hundred thousand nodes, each doing
a hundred thousand transactions to each other. [Activity between two nodes in one channel]
doesn’t really affect the rest of the network, so it decentralizes scaling. The Lightning Network is not only much
more private, because these payments… on payment channels are not seen by
anyone other than participating nodes, but it is much harder to censor because you don’t
need a miner [to confirm them until settlement]. [Lightning is] also much faster and lower cost. “In order to be Lightning compatible, each chain
must execute SegWit, correct?” Not really. You could [make a Lightning implementation] without
SegWit, it would just be [a lot] more complicated… because of the transaction malleability bug;
both chains [must] have a transaction malleability fix. It doesn’t [need] to be SegWit, however.
It could be a different transaction malleability fix. It is very difficult to implement Lightning securely on
a chain that has a transaction malleability problem. SegWit fixed it on Bitcoin and Litecoin.
On another chain, you might have a different fix. That would make Lightning possible. “Is the Lightning Network also for
altcoins?” That is a great question. Yes, the Lightning Network can run on any blockchain
system that has certain fundamental capabilities. It must have the ability to do multi-
signature [schemes] and timelocks. If it has the ability to do those two things,
[and has a transaction malleability fix], you can probably [make a Lightning implementation]… that is in compliance with the current Lightning Network
specifications: Basis of Lightning Technology (BOLT). The BOLT specifications are not specific to Bitcoin; the Lightning Network already operates on
both Bitcoin and Litecoin simultaneously. Here is [what is] really amazing. You can send a Lightning payment in bitcoin,
have an intermediate [routing] node exchange it… [through payment channels in both bitcoin
and litecoin], and the recipient gets litecoin, [even though] you sent bitcoin. The Lightning Network is not just portable to [other]
blockchains, but it can run multiple currencies. where even a single routed payment can
[be an exchange] for other cryptocurrencies. “Who keeps Lightning nodes?” I am running a
Lightning node. You can run a Lightning node. The requirements to run a
Lightning node are fairly light. If you are already running a Bitcoin node,
adding a Lightning node to it is very easy. It takes very few additional resources. [In terms of]
the incentives, if you decide to route payments, you will earn a tiny fee for each payment. If you run a Lightning node full-time, you
will probably [earn] a few cents per month. It is very cheap, but it is also very easy
to run, and usable across the internet. These lightning payments can be transmitted all around
the world; payment channels cross network boundaries. There is no geographic limitation
as to where a Lightning node can be. A payment can be routed globally in a
matter of seconds or even milliseconds. At this stage, one of the fascinating things about
Lightning as we [are tracking and looking at its size] [as it is] growing, as nodes are [joining], advertising
their presence and the channels they have opened, [Nodes also] advertise how much
capacity [in bitcoin] their channels have. Some nodes do not advertise their presence or channels
to anyone, other than [participants] of the channel. You can have secret channels on Lightning. The bigger the Lightning Network [becomes],
the harder it is for us to see how big it is. It becomes more invisible. All [payments] are routed
using onion routing, where each node doesn’t know… where the payment [came from] or where it is going. The bigger Lightning grows,
the more private it [becomes], the less we know about where payments are going
and how many payments are happening. Gradually, it becomes harder
and harder to collect statistics. Over time, we will have less visibility into Lightning. We will know it is out there and lots of things are
happening on it, but the level of privacy is such… that we will know less and less about it.


  1. When Alice closes the channel, sending the transaction to get her 1.1 btc, does that mean Bob's 0.9 btc transaction is also sent on chain, or can his channel stay open and redeem it later?

  2. Tone Vays has stated, Bitcoin will not become mainstream until all "shitcoins" go to zero, including Etherium. Is he correct?

  3. Andreas, You travel alot, receive your speaking fees in Bitcoin as often as possible, and pay for as much as you can with Bitcoin. What percentage of your Bitcoin transactions do you do on the Lightning Network? My main query is at the fact that you, as a major Bitcoin user and among the top technology people in the space is capable of and should be doing a larger number of Lightning Network transactions and should have a larger number of channels going than anyone else (especially grandpa and grandma which I remember you saying their usage was a goal of Bitcoin).

  4. Payment channels clearly are an impressive solution for P2P payments and exchanges: self-managed, off the grid, lightning fast.
    Next step: Get these payment channels to run on Satellite beams rather than Internet-only.

  5. Maybe a way to understand this is: what if all people in the world were 100% honest? How could we deal with transactions?
    We would probably all keep tabs and rarely actually send the money.
    LN is what forces everyone to be honest.
    Makes sense?

  6. can I open such channel with any exchange? if not, how exactly would it benefit an average user? how can I participate in this system? it only applicable to huge services, banks and exchanges, yes maybe bitcoins will 'flow' fast between them, but it only centralizes things, if I want to send or receive on my personal wallet it would still be painfully slow, and maybe such payments to private individuals would not be even impossible in the future. in the end we will get just banks 2.0

  7. So did I get this right: Andreas is this Bob guy I heart so much about? πŸ˜€

    But I also have a question, what are your thoughts on the complexity of node discovery and routing in a network with potentially millions of channels, especially for LN wallets on smartphones? Will the LN be able to scale in this regard if it becomes popular?

  8. routing problem much ? lol
    cant do big tx ..
    needs channel opening and closing time and fees.
    how absurd can this get?.
    just do micropayments on mainchain with some other coin that also can do big payments ..

  9. I probably will get downvoted for this, but the routing between LN channels actually is quite similar to the credit network in the Ripple Blockchain.

  10. can you do those kind of videos with some graphics, Andreas? That would be awesome!😁
    Keep it up!
    You're one of the best guys in the Bitcoin-sphere!!! Thanks for your contribution!

  11. Lightning is an overlay network, NOT a sidechain. nice explanation. Lightning is essentially a smart contract settled onchain. Brilliant!

  12. Nicely put! What I could not find (yet) is the easy way Andreas mentions to set up a Lightning Node. I've been running a BTC core node for at least a year, that was straightforward. But the few tutorials I've seen on how to set up a Lightning Node were ultra-technical.

  13. It spuds like lightning network was originated at a bar after having too many drinks. It is like a lot of shit and not enough bull πŸ˜†

  14. How would this work in a retail setting where only 1 transaction is needed?
    What if a payment channel is signed prematurely on accident?

  15. i have always been quite pessimistic about LN but this time my mind clicked. I always thought that "locking" funds was just very bad I wouldn't want to do that. Now I realised that its actually the good thing. The fact that these "locked funds" can propagate is amazing and that's what clicked my mind to think that bitcoin might actually work.

    AFAIK the LN capacity is now 500 BTC and it seems that a good UX is the only thing resisting adoption. Wallets are still migrating to segwit so it seems lighting support will take some time.

  16. So when the network scales, and these lightning nodes need to suddenly start settling large amounts of BTC and the fees become expensive again will the node owners loose money? How will they know what to charge users based on future fees? Some risk there?

  17. Let’s say a complex web of transactions happens on the lightning network. If one node in the web closes his channel or cheats, does that cascade to the rest of the channels in the web that he has transacted with indirectly? Or is the settlement localized?

  18. In case if you are reading this, I have a question. When a new balance transaction is created/exchanged, the users are supposed to exchange revocation keys which make sure no older balance transaction can be committed on-chain. What stops malicious party to not send their revocation key on the network level at the moment of exchange? I mean no network txs are atomic and parties send receive network packets few milliseconds apart, should be enough time to "drop" the connection in a hypothetical malicious client.

  19. It's never going to work. Everyday people aren't going to get all this. Use stable coins to spend & BTC for savings. There's your killer dapp!

Add a Comment

Your email address will not be published. Required fields are marked *