How does Lightning Network work?
Bitcoin transactions are much cheaper if we make them with other traditional payment systems. Likewise, sometimes you want to ship as quickly as possible and avoid these costs, as transactions must be mined and stored on the thousands of nodes each time they are issued.
Payment channels are the foundation of the Lightning Network.
Channels create a multi-signature transaction on the blockchain with at least one of them sending funds. Both issuer and payer have a private key, and each future transaction can be executed only if the keys of the two parties sign. The opening time of this channel is about 10 minutes or whatever it takes to mine the next block, but once opened, both can exchange assets between them instantly using the funds stored on that channel.
All transactions within these channels are not issued until both parties decide that these channels stop trading. It should be noted that, within the Bitcoin network, transactions are always valid when they are issued on the network and included in one of the mined blocks.
Application on the lightning network.
Example: There are two participants in an initial $20 transaction. $10 will be A and $10 B. What Lightning does is take the technology behind payment channels and create a network that makes them up using smart contracts.
A opens the pay channel next to B which in turn has a channel with C, which in turn has an open channel with D. Multiple channels are currently open. A wants to exchange with D, so you can send funds to B and C to finally reach D.
Due to the nature of the Lightning Network, A doesn't have to rely on B and C as cryptography is used to ensure that the funds D will receive will be exactly the same as the ones sent by A. Otherwise they will be automatically returned to A.
It is also possible to trust B and C because both act as nodes within the network (equivalent to miners within the Bitcoin network) and decentralizely process all transactions without having control of the funds they help move.
If B or C is disconnected, channel funds are not trapped, but within lightning protocol users can unilaterally close channels. And so he'll get his money back.
When one channel closes at a time after an indefinite number of exchanges have been made on it, the final funds of each party will be recorded on the blockchain in 10 minutes or whatever it takes for the next block of the network to appear.