(1) Explain what do you mean by Lightning Network, Lightning Node, Lightning Channels? How does it achieve a near-instant settlement, near-infinite scalability? What are the different uses?
What do you mean by Lightning Network?
Lightning Network is the second layer payment protocol on top of the first layer which is applied to Bitcoin or Litecoin Blockchain. These transactions are off-chain and not recorded on the Blockchain. This characteristic has boosted the speed and cost of paying transactions as no mining is required. Just like we can compare to the Bitcoin network, Lightning Network is also a combination of nodes. Transactions on a Lightning Network are private and stored just among members of the network. so I can say Lightning Network is about
- Privacy
- Speed
- Transaction throughput
Lightning Network transactions are done by relying on the Bitcoin blockchain, and the Bitcoin block only comes into play at the final settlement of the funds. I remember mentioning in one of my assignments the scalability problem of the Bitcoin network. Lightning Network is here to solve that problem, as a second layer is created on the main layer of the Bitcoin blockchain. This second layer is made up of multiple channels between the two bitcoin users.
What do you mean by Lightning Node?
Lightning Node's purpose is to monitor the Blockchain while holding the token for transacting between other Lightning Nodes in the Lightning network. The main reason for Lightning Node to monitor the blockchain is to make sure tokens get lost between peers. Like I mentioned, Lightning Nodes relate to each other in a Lightning Network(Peer-to-peer network). Let us not forget we have the blockchain peer-to-peer network and Lightning peer-to-peer network when talking about interaction in Lightning.
While Lightning's peer-to-peer network is about the token to be paid on the Lightning Network, Lightning Node is to make sure the token gets to the other Lightning Node in the Network. How this is done will be mentioned below when I talk about Lightning channels. Lightning Nodes don't go about verifying every transaction like a bitcoin node, they validate transactions that are directly related to the network.
Lightning Node is responsible for monitoring each other on the Network. A little illustration can be you getting into a bus for a road trip, and the bus driver collects your wallet for collateral. LOL, the driver only opens your wallet when you arrive at your destination. Here the speed kilometer board has been calculating your distance, acting like the Lightning Node. As you drop from the bus, the driver withdraws from your wallet, same as when leaving a Lightning Network channel, payment is validated on the blockchain.
What do you mean by Lightning Channels?
Lightning Channels is the route to send and receive a token on the Lightning Network between users. This channel can be seen as a pipe that allows water to flow from a supplied point to a consumer. Lightning Channel connects two Lightning Nodes in a Lightning Network. Lightning Channels can be created by either of the parties involved in the transaction to lock their token on the Bitcoin blockchain. It is to make sure that spending the token in multiple places on the network is avoided. Note that Lightning Channels are done in the background and not public like any normal Bitcoin transaction.
I will take a small example. For Ben and Rene to create Lightning Channels, whoever is creating must choose the amount to be available in the channel. Ben makes a transaction of 20 000 satoshis, and the same amount is locked up in the Bitcoin blockchain, opening up a Lightning Network. The presence of Lightning Channels between Ben and Rene makes it easy for them to send and receive tokens. All Rene needs from Ben is the Lightning invoice to send him a token. Here both Ben and Rene can watch each other balance and the maths of adding and subtracting figures.
Lightning Channels are categorically the existence of Lightning Network because, with the channel, Lightning Nodes will just be on their own. It is only with the Lightning Channels, that nodes execute payments freely.
(2) How does a Lightning network enable two peers to make a transaction or recurring or multiple transactions without any transaction fee? Does it happen off-chain or on-chain?
Like I was talking above Lightning network is about peers making transactions between them using their digital wallets at no or reasonably low cost. For the transaction to go through, the peers need to create a Channel, between them which is practically an off-chain transaction. These channels on the Lightning network can process payments between peers without any fees. Given that it is an off-chain transaction, the on-chain network is greatly improved in speed and time used to process a transaction.
(3) How does the routing of payment through intermediate nodes(or peers) become trustless with HTLC?
As mentioned in the course outline by the professor, Lightning Networks are secure and reliable. The transactions on the Lightning network are off-chain and work like the bitcoin blockchain. For these transactions to be secured, HTLC smart contracts play a major role. Lightning network is a 2 of 2 multi-wallet where users can send and receive using any of the channels Trustless. As I mentioned above, many Lightning channels are created in a transaction to connect the lightning nodes. During routing payment, the HTLC smart contract makes use of the Hash lock and Time Lock to make sure immediate nodes are trustless.
The main purpose of developing HTLC was to handle incomplete transactions due to missing keys or passwords. It was just too easy for peers not to lose tokens during transactions.
For example, Trustless HTLC smart contracts are probably used when peers want to do a transfer and have another peer in between. We have peer A, peer B, and peer C, and A wants to transfer to C.
Let me try to make a small illustration. A wants to transfer a token to C, note we have B in between A and C. For this go-through, C has created a secret and hash which will be sent to A. the transfer is time, so that if the transaction is complete, the transfer is canceled. A will only initiate transfer when A receives the secret hash from C. Now an HTLC transfer is sent to B, B will create a secret Hash and share it with C while initiating the transfer. C and B will exchange secret hash, at this point C will receive payment, but not from the initial source which is A. At this point, B gets the secret Hash and shares it with A, and A initiates the payment. It is just a complete simple circle with a low transaction fee since it is off-chain with limited resources. A has finally transferred to C with all the peers (ABC) receiving their payment.
(4) Set up Lighting Wallet(Create a standard wallet, then open a Channel), open a Lightning Channel using Electrum(Trampoline Node), Phoenix, or any other non-custodial wallet that supports Lightning Network, make an eCommerce purchase(or a micro-Transaction) using Lightning Channel, then close the Channel? Does it incur fees? Does it record the transaction on-chain? If yes, indicate it, if no, then tell us why it does not record the transaction on-chain? How does Swap Function help to improve sending and receiving capacity? (Screenshots needed)
I downloaded and created my standard wallet during the last assignment, so now I will be moving ahead to demonstrate how to open a channel.
Here is my wallet, I had to do a good number of transactions to be able to get to the minimum amount which I will need in creating my first channel.
My balance in my Electrum wallet
I click on the channel, it is one of the taps. if you don't find it among the tabs, click view and select show channel
Click open channel, and a small window will pop up, click yes
By default, the new block node is a trampoline node when opening a channel. You will have to enter the amount, I will enter 2 and click okay
Now a summary of the amount I enter and fee, pending my confirmation by putting in my password. I insert my password and click send.
The last pop-up, displaying information with the remote peer is notifying me that my channel has been established.
Done, my channel has been created with status OPENING, and note I don't have a short channel id yet.
I will want to check the status of my transaction since it was added on-chain network, right-click on the channel, and select view funding transaction to get the transaction id. Past the id in the search bar in blockchain explorer to follow the transaction updates.
Cool, my status has changed meaning the channel has been created, now you can find a short channel Id.
E-commerce purchasing using Lightning Network:
Let's get to doing business with Lightning Network technology. First, we will need an E-commerce platform that will support Lightning Network transactions. A good example is the Bitrefill website which Prof @sapwood demonstrated to us in the course outline. I will be using the Bitrefill website to demonstrate.
let visit the website Bitrefill
Click browser products, No I'm going to select the product. I see most of the products are offered by the telecom company in my country Cameroon. My mobile phone operator is MTN, so I will choose MTN to credit my phone.
I have selected MTN, to credit my phone, I select the amount I want to credit my mobile phone. Next, I fill in my phone number and click purchase.
Click check out to process the order details, enter your email to receive notification on completion of the transaction. Click to checkbox validating you have read the terms and conditions and click continue.
Now we have to choose a payment method, the essential for this was to pay with Lightning Network technology. So I will select Lightning (BTC)
Now we have our order information and click on copy to open the lightning invoice Id. Note we have a timer counting down.
I have copied my Invoice Id, go back to my Electrum wallet. Click sent, past the ID in Pay to, other sections are auto-filled. click pay
Click yes to confirm the transaction.
No, let go back to our Bitrefill platform, we automatically receive a confirmation of my transaction.
I can see the transaction history of my purchase for MTN credit in the history tab.
Does it incur fees?
Yeah, it did incur fees, but very small as compared to if it was an on-chain network.
Does everything recorded on-chain:
Like I mentioned, Lightning Network transactions are not recorded on-chain, they are off-chain transactions. Even though it is an off-chain network, it is still recorded on the Electrum history, mainly the stability of the main chain. It helps to give stability to the main chain and speed up on-chain transactions.
Swap function:
It is one of the functions on the lightning network which permits funds to be sent to the main blockchain network. This function makes sure that the off-chain channels created are not closing when sending the fund. Let demonstrate how this function works on the electrum wallet.
Let go to our channel list, far right you see the swap button.
I will be swapping funds from the lightning network to the blockchain. Click swap
I enter the amount I want to swap
Click ok.
Now in my electrum history, I can find that I have successfully swapped my fund from lightning network to blockchain.
Swap is displayed on the main chain and can be a check on the blockchain explorer by right-clicking and selecting view on the block explorer.
How to close the channel?
Let go back to the channel list, right-click on the channel you want to close, and select close the channel.
A small window will pop up for you to confirm if you want to close the channel. Click yes
The final window pops up, click ok, channel status has changed to shut down.
Status updated to Closed, meaning the channel is finally closed.
(5) How do you back up a wallet file(Channel Backup), why and when is it needed? Indicate the funding Transaction, Commitment Transaction, and Settlement Transaction both in your wallet and Block Explorer? (Screenshots needed)
How to Backup lightning up channel:
I will go through the steps, right-click and select an export backup.
Click on copy and click save
Name the file you are about to save and click save, now you have a backup of your QR code.
But why do we need a backup channel?
Backups are for security reasons, in case of loss of data. so this is just a security strategy in case you lost your password and want to close a channel. Note when we backup our channel, we can get our funds from an off-chain to the main chain network.
Funding transaction
It is the initial stage when funds are added to a Lightning Network. To get my funding transaction, I need to go to my Electrum wallet history. Click the first node to which I initiated my funding.
Right-click and select the view transaction to get the transaction ID. I will use the block explorer to view the main chain transaction, hash, and amount.
Commitment Transaction
It is the transaction that happens off-chain between nodes that are connected directly and indirectly. Nodes that are directly connected have no fees, while others not connected but have an intermediate node between, have transaction fees. The illustration is the transaction I did to purchase credit, which was a commitment transaction.
Settlement transaction
It is the point when we close the channel, it is the final transaction and will be recorded on the mainchain network. It is the point where you can confirm that all off-chain transactions are complete and validated. As soon as the Settlement transaction is validated, the channel can be closed and funded back to the main blockchain.
- How to close the channel?
Let go back to the channel list, right-click on the channel you want to close, and select closes channel
A small window will pop up for you to confirm if you want to close the channel. Click yes
The final window pops up, click ok, channel status has changed to shut down.
Status updated to Closed, meaning the channel is finally closed.
Let's check the settlement transaction, right-click on the closed channel and select the view transaction.
Copy the transaction ID past in our search bar in Blockchain explorer to view the details of the closed channel/
We have the initial and settlement transactions listed on the main blockchain.
Conclusion
This has been a deep learning course for me this week. It is my first time coming across the term Lightning network and knowing what happened in the background of Bitcoin transactions. For a transaction to be signed as completed it must have gone through the three stages. That funding which you can get details on the blockchain explorer, commitment which is off-chain and recorded in the Electrum wallet and settlement which finalize everything and if recorded on the main chain network and details can be viewed on the blockchain explorer. Most interesting was the Bitrefill platform, which I was able to recharge my phone.
cc: @sapwood
@tipu curate
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Upvoted 👌 (Mana: 2/4) Get profit votes with @tipU :)
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit