In this fourth installment of our blog post series on the Lightning Network for beginners, we will discuss what a Lightning channel is and how they work. In previous posts we have explained:
Anatomy of a Lightning channel
Lightning channels are what enables users on the Lightning Network to actually send and receive money to and from other users. You can think of them almost as money tubes that’s hooked up to each other, allowing payments to flow between users seamlessly.
All Lightning channels are between two nodes on the Lightning Network. In our case we will call them Alice and Bob. The channel has a Bitcoin balance for both Alice and Bob, keeping track of how much money they each have.
How are Lightning channels created?
Either Alice or Bob can open a Lightning channel by creating a Bitcoin transaction that’s designed to lock their funds on the Bitcoin blockchain, and unlock them on the Lighting Network. This ensures that money cannot be spent multiple places at the same time. To the users of the Bitcoin blockchain the transaction acts just like a normal Bitcoin transaction, with no real differences (except for a few technical ones) between the two. Keep in mind that all of this is done automagically by their Bitcoin wallet, and that regular users do not need to know the details.
When a Lighting channel is created, the creator must choose how much money he or she want to have available in that channel. An example: Alice could make a transaction on the Bitcoin blockchain that gave her 100,000 satoshis on the Lighting Network. That transaction would then lock down the same amount of satoshis on the Bitcoin blockchain, freeing them up on the Lightning Network.
How are Lightning channels used?
Once a Lightning channel is established, it’s owners can send and receive money through them. If Bob wants to send 1000 satoshis to Alice, he’ll need a Lightning invoice from Alice. You can read more on invoices in a previous blog post in this series. Using that invoice he can send a payment to Alice, increasing Alice’s balance by 1000 satoshis and decreasing his own by the same amount. Both parties to the channel keep track of each others balances, making sure the numbers add up.
Do I need to have a channel to everyone I want to pay? That sounds cumbersome
No! The beauty of the Lightning Network is that it is a network of channels stitched together. Let say Bob convinced his friend Carol to also join the Lightning Network. Alice has a channel with Bob, and Bob has a channel with Carol. Alice and Carol can then pay each other by “routing” through Bob. Through some pretty clever cryptographic tricks, Bob cannot steal the money while it’s passing through him.
When making a payment on the Lightning Network your node searches for a path of channels between you and your destination. This is what’s referred to as routing. This will be covered more in detail in a later blog post.
What if someone tries to cheat?
Both Bitcoin in itself as well as the Lightning Network are designed such that people acting maliciously won’t gain any benefit by doing so. If someone tries to submit an invalid transaction on the Lightning Network — for example claiming some of Alice’s money actually belongs to Bob, or by being dishonest about what’s happened in the channel- there’s a built in mechanism for punishing the attacker, where the victim of the attack can take money from the perpetrator. How this works in details is a somewhat complicated process, and is a potential topic for a future blog post.
How do I close Lightning channels?
To close a Lightning Channel, you also have to make a regular Bitcoin transaction on the blockchain. This transaction does the reverse of the initial one, removing the funds from the Lightning Network while unlocking them on the regular Bitcoin blockchain. After sending money back and forth, paying for APIs, Lightning bling and the odd beer or two you’ll most likely not end up with the same amount of money you started with. If you initially opened up a Lightning channel worth 100,000 satoshis and then spent 25,000 satoshis on high speed crypto exchange data, you’ll end up with 75,000 satoshis refunded in your channel-closing transaction.
Lightning channels are the lifeblood of the Lightning Network, allowing nodes on the network to communicate and have payments flowing freely between them. Without them, network nodes would sit all by themselves, not doing anything useful. Together they form the financial superhighway of the future, enabling radically new data distribution and business models.
If you’re interested in chatting more about Lightning Network technology or crypto tech, you can find us on Twitter @Suredbits or join our Suredbits Slack community.