Hello steemians, I'm here to submit my season 3 homework task 7. That carried by @sapwood.
Question.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?
The biggest problem with the bitcoin blockchain is its low scalability and high congestion because of the number of transactions to get validated.
To resolve this problem a new idea of a lightning network was put forward. Lightning network is the 2nd layer payment protocol that works under the bitcoin blockchain and in this nodes itself validate the transaction and only initial and last transactions are broadcasted to and validated by the main blockchain.
In a lightning network funds are secured with hashed time lock contract protocol which is a smart contract that allows only the receiver to unlock funds that too in the prescribed time. After this and only in this condition funds are refunded to the sender.
Lightning node- In a lightning network, nodes make the lightning network and validates the transaction. Another main purpose of a lightning node is to connect sender and receiver via shortest way with no or minimum node between. So that no or minimum transaction is levied.
Lightning channel- Sender or receivers in the lightning network are connected with each other through the lightning channel. The purpose of a node is to keep the channel shortest.
Different uses of lightning network- The main purpose of a lightning network is to keep the main blockchain less congestion and to increase its scalability. Another purpose of lightning networks is to make micropayment more popular because by using the bitcoin blockchain, micropayments become more expensive and take much time. By using a lightning network both of these problems can be resolved.
Question.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?
To create a lightning network between two nodes, first of all, funds are deposited in the lightning blockchain from the on-chain blockchain and this transaction is broadcasted to the main blockchain and thus can be traced using a block explorer. This is called funding transaction
After this, when transactions are made using the lightning network, these transactions are not broadcasted to the main blockchain instead of this these are validated by the nodes themselves.
These transactions are called commitment transactions.
And hundreds of transactions can be made between two nodes and the transaction fees are nill if the nodes are connected directly and fees are low if the nodes are connected indirectly.
After every commitment transaction, the balance is updated using a smart ledger in the wallet. And these transactions are signed by both parties.
These are commitment transactions are secured with HLTC protocol and can be unlocked using only a secret hash.
When this channel is to be closed last copy of transactions signed by both parties is sent to the main blockchain, all these commitment transactions are considered as a single transaction and broadcasted on the main blockchain.
Now as we discussed that in the lightning network, only the funding transaction which is made for the first time, and the last transaction when the channel is to be closed, are broadcasted to the main blockchain. Thus these transactions are on-chain transactions.
On the other hand, commitment transactions that are validated by the nodes themselves are done off-chain and are not broadcasted to the main blockchain.
Question.3
How does the routing of payment through intermediate nodes(or peers) become trustless with HTLC?
HTLC is an acronym for hash lock time lock contract. HTLC Smart contract is like security for transactions of the Lightning Channel. As we know, Lightning Channel is made up of two nodes joining together. And the Lightning Network is made up of many channels. So it is common that there are thousands of nodes of Lightning Network and all are connected to each other. And the same happens for channels, all channels are interconnected with each other. So One peer can transfer funds to any other peer through the payment channel.
And imagine, if a peer wants to transfer funds to a peer that is not connected to each other, is it possible? Yes, it is possible. In this situation, an intermediate peer will participate in the transaction and will charge some amount as fees as his share.
Let's say I (A) want to send some payment to another peer (C). But I am not directly connected to him. So there the Intermediate Peer (B) comes in. As I am connected to B and B is connected to C (another peer). So in this case there can be a transaction between A and C. But here in return B will charge some fee. However, this fee is very small, as this transaction is recorded off-chain.
For this, you can see a real example of Bitrefill. I purchased the product from Bitrefill but I was not directly connected to it. So here the Trampoline node acted as an intermediate peer. And charged 0.00003 mBTC as a fee which is negligible.
Question.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)
Steps to set up & open a Lightning Channel using Electrum
- To create a channel, go to the channel section and click on open channel.
- Now it will give you a warning type message that you really want to open your first channel. Click on ok.
- Now you can select for your node with which you want to open the channel. Or you can just set it to default. Also, enter the amount you want to add to your channel. The minimum amount is 2 mBTC. Enter the amount and click on ok.
- Now for confirmation, enter your password for confirmation. Enter the password and click on ok.
- Now you will see a pop-up stating that your channel is established. And you can see the same in the status option as opening
- After 3 confirmations, the Lightning channel is opened completely and usable. Now you can perform the off-chain transactions on it.
- As the initial translation that is funding transaction is done on-chain, you can see the details on the block explorer.
E-commerce purchasing using Lightning Network::-
To purchase using a lighting network go to an e-commerce website that supports the Lightning channel. For example, here I am visiting the bitrefill website.
- Go to bitrefill website and click on browse product
- Now select your product, here I am purchasing for my mobile prepaid plan (JIO). I clicked on that icon.
- Now Select the plan you want to purchase and you can also see the value in bitcoin here. Click on purchase.
- Enter your Email id on the next page to get the updates of the order.
- Now select the method using which you want to purchase. Here I select lighting bitcoin.
- It will show you a QR code to scan. Click on the copy below to copy the invoice as we have to paste the invoice we can't scan.
- Here copy the Lightning invoice and let's switch to electrum wallet.
- Now go to the pay section and paste the invoice you copied. And click on pay.
- It will ask for confirmation. Click on ok to give you assent.
- Now your order will be completed in no time. You can see the same in the history by clicking on the history section.
Does it incur fees ?:-
Yeah, it incurred fees as the nodes weren't directly connected with each other. But it was quite low. You can see how many fees were incurred by clicking on history and then clicking on history for the payment.
Here you can see for this transaction I was charged with 0.00006 mBTC which is quite low.
Does it record the transaction on-chain?
No this doesn't record on chain as this is a commitment transaction and these type of transaction are validated by the nodes itself not by the blockchain.
That's why we can't see it's TNX detail on block explorer.
Swap Function
As we know that only the last and initial transaction is recorded on main blockchain. But if we want to record the transaction anytime them closing channel isn't a Good option.
To do this we can use swapping.
Swapping means swap between the funds on chain and off chain. When on chain funds are swapped for off chain fund then it increases the sending capacity as we have more fund to send. On the other hand if off chain funds are swapped for on chain funds then it increases the receiving capacity.
Close the channel -
To close a channel
- Go to your channel by clicking on channel option.
- And then right click on channel you want to close.
- After that it will ask for confirmation, click on ok to confirm
- Now it will say that your channel is closed but status says that your channel is shutdown. This means it is still under process.
- After some time when status changes to closed the process is done
*As this is the last transaction and it is done on chain and recorded too you can seethe txn details on block explorer.
Txn information on Blockchain Explorer
Question.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?
Steps to export channel backup -
- Click on the Channel tab.
- Then right-click on the channel.
- Now Click on the Export Backup for backup the channel file.
- Now the next page will show you the QR code. Click on the Save button. Apart from this, you can also copy the image and text and store it offline.
- Now save it on your PC's Windows. Simply, click on the Save.
- Now Channel Backup will be exported successfully.
Why and when is backup needed?
Channel backup is required in case of losing the wallet file. One thing you can do with a backup has requested the channel to be closed. So that your funds are transferred off-chain to on-chain. This means that the funds will be sent from the LN channel to your Electrum's main wallet with the help of a Channel Backup. Remember that Channel cannot be restored with Channel Backup.
Funding Transaction -
Funding transaction occurs when we add funds to the channel to open the channel for the first time. This process is recorded on-chain. This transaction is completed after 3 confirmations and a fee is charged for this which is not specific.
To check this transaction on Blockchain Explorer,
- Click on the History tab.
- Then Right-click on the funding transaction (Open channel).
- Now four options appear, Click on the View Transaction.
- Now Copy the transaction I'd.
- Lastly, Paste the transaction I'd in the Blockchain Explorer.
- Now you can see all the information about Funding Transactions.
Commitment Transaction -
All the transactions performed on Lightning Channel are known as Commitment Transactions. As it involves Lightning Channel, all these transactions are recorded off-chain. This makes Commitment Transaction different from both the rest of the transactions (Funding & Settlement) because it charges a negligible fee compared to both the transactions.
To check details about this transaction,
- Click on the History tab.
- Then Right-click on the Commitment transaction (Bitrefill Transaction).
- Now three options appear, Click on the View Payment.
Settlement Transaction -
Settlement Transaction occurs when we close the channel itself. This transaction is directly related to the last transaction that reflects the closing balance. These transactions are stored on-chain and can be viewed on the blockchain. The closing balance is sent back to the wallet via the Change address.
To check this transaction on Blockchain Explorer,
- Click on the History tab.
- Then Right-click on the Settlement transaction (Close channel).
- Now four options appear, Click on the View Transaction.
- Now Copy the transaction I'd.
- Lastly, Paste the transaction I'd in the Blockchain Explorer.
- Now you can see all the information about Settlement Transaction.
Thank You