What is Lightning Network?

What is Lightning Network?
(Picture from internet)

Today's Cobo small class, we invited our technical giant to share a cutting-edge technology - lightning network. I hope that after reading this article, you can have a preliminary understanding of the background of the lightning network, the problems that need to be solved, and the basic principles of lightning network implementation.

The background of the Lightning Network has evolved over the past 10 years, and today's Bitcoin has become an encrypted digital currency system with a total market capitalization of hundreds of billions of dollars. We can already buy a lot of things in Bitcoin, from a cup of coffee to a big investment property, but as the number of users grows, the drawbacks of the Bitcoin network in taking high-frequency payments are gradually exposed. Due to the original design, the Bitcoin network can support a lower transaction frequency and a longer transaction confirmation time, which cannot support the future high-frequency, real-time payment requirements.

In order to ensure the correctness and unchangeability of the transaction, the Bitcoin network needs to record the details of each transaction in the block, and in order to control the growth rate of the block data, the Bitcoin network limits the size of each block. At 1MB, the mining time of each block is controlled to about 10 minutes, so under ideal conditions, the number of transactions (TPS) that Bitcoin can process per second is about 7. In fact, the trading frequency of about 3 transactions per second has already filled the block of the Bitcoin network, so people often encounter the problem that the bitcoin transfer cannot be confirmed.

In addition, in order to ensure the unchangeable modification of the transaction, the Bitcoin network generally needs to wait for 5-6 blocks to confirm, and the payee only recognizes the transaction success, so the confirmation waiting time of one transaction takes about 1 hour, and the user experience is extremely low. it is good. Moreover, due to the increasing number of transactions to be confirmed, the handling fee for Bitcoin transfer is also getting higher and higher. At present, the handling fee for an ordinary transfer is 0.0001~0.001BTC, a few dollars to tens of blocks. The money is not equal. Therefore, the current bitcoin payment network is not suitable for small transactions. For the above problems of Bitcoin, there are already a lot of expansion plans in the community. For example, using the isolation test can reduce the size of each transaction data, in addition to the large block expansion plan, the original 1MB limit is raised to 32MB or even 128MB, but these solutions are all palliative, can only increase the payment capacity of the Bitcoin network several times, up to dozens of per second, compared with VISA or Alipay's million-per-second payment frequency. It seems trivial.

The lightning network was proposed in such a large background, and its goal is to enable Bitcoin networks to support high-frequency, real-time transactions.

The realization principle of lightning network

The Lightning Network is a Layer 2 protocol, like a viaduct on a highway, that makes multiple payments over a large two-way channel network, eliminating the need to record every transaction on the Bitcoin blockchain. In this way, the limitation of the bitcoin transaction rate is avoided, and the faster transaction speed and larger capacity can be enjoyed at a lower cost.

For the above picture, for example, each lightning network user is a blue point. A lightning network payment channel is a connection between two points. If there is enough connection, there is a line between every two points. The path is reachable, which enables high-frequency, real-time transactions between all users. 1. Establishing the channel We assume that user Alice and user Bob want to use the lightning network payment scheme to conduct transactions, then they first need to build a lightning network payment channel between them, and then each initiate a 2-2 multi-signal address. Trading on the chain, depositing a part of the BTC, this part of the BTC is equivalent to the deposit. Each transaction sent through this multi-sign address requires two people to sign. If Alice saves 1 BTC to the multi-sign address, the maximum amount Alice can send to Bob in this channel cannot exceed 1 BTC, which prevents cheating during the transaction. For example, in the real world banking system, Alice and Bob need to go to the bank to open a public account. Each of them will deposit a part of the money into the public account. The two will sign a contract with the bank, stipulating that two people need to be followed at the same time. The signed contract can operate this public account. In the lightning network, both Alice and Bob can't cheat. Once one party cheats, the other party can get all the money in the payment channel. 2. After the lightning transaction Alice and Bob establish a lightning network payment channel, they can be used for trading. These transactions require a digital signature of both and can be instantly arrived through the payment channel. We all know that the essence of Bitcoin trading is UTXO (Unspent Transaction Output). Each transaction on the chain requires transaction input (source of funds), and transaction output, which is UTXO. In the lightning network example, many transactions between Alice and Bob through the payment channel do not appear on the chain, but are displayed by public account balance allocation. In the end, only the transaction that closes the payment channel will be chained. Through this transaction, we can see the balance in the public address when the final channel is closed.

For example, if A and B first transferred to the public address to 1BTC, there were a lot of transactions between the two people, but when the payment channel was closed, A had only 0.5 BTC in the public address and B had 1.5 BTC. Then the transaction on the chain is shown as A to B transfer 0.5BTC. 3. Routing node

Of course, individual users cannot establish a lightning network channel with each one. As of January 19, 2019, the lightning network has a total of 24,000 channels. If the trading node does not have a direct connection, it can be traded by means of a routing node (equivalent to an intermediary), which of course requires some routing fees for these "intermediaries". Nowadays, many people have started the business of routing nodes, and hope to bring some liquidity to the lightning network through these nodes, and can charge a little for it. In addition, there are some e-commerce platforms that use lightning networks to provide life-like services, such as charging charges.