Homework post for @sapwood || Lightning network by @utsavsaxena11
Hello steemians how are you? I hope you all are doing well and you all are safe and healthy during this pandemic time. Hope we all soon get the vaccine.
Today I go through one of the best and simplest language explanation homework posts by @sapwood on Lightining network second layer solution of off-chain network. It's interesting to read the lecture post. Now I am Submitting my homework post to the professor.
HOMEWORK
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? (within 300 words)
ANSWER 1:
Lighting Network :
https://images.app.goo.gl/xspreDc5wfgPbP467
The two-layer payment protocol that is a decentralized network that allows an instant high volume of micro-payments that are fast, secure and cheap is known as a lightning network. It works on bitcoin that use micro-payments channels to make its blockchain more efficient. But why the user should use a lighting network? So if we use a lightning network other than the main blockchain network in the off-chain then we can reduce the crowd in the main blockchain and also can reduce our transaction fees. To maintain the privacy of transactions through the lighting network only the initial and final statements are recorded in the main blockchain. Because of the lthe lighting network, the scalability of bitcoin improves because nodes are connected and in contact in off-chain.
Uses of lighting network :
- It can be used in direct peer to peer transactions in off-chain transactions.
- It can also be used in Indirect peer transactions.
Lightning Node :
We all know the working of nodes in the blockchain, these are the devices that connect sender and receivers in the blockchain. Similarly, the Lightning node is the node that makes lightning channels that further make the complete lightning network. These nodes also work the same that connects the sender and receiver on the off-chain network. Lightning node is used to validate the transaction that is directly connected and calculate the transaction of nodes and these nodes are connected to the receivers node indirectly. By using HTLC protocol transactions are secured and only the reciver can claim their token reward.
Lightning Channel :
When two lightning nodes combine each other and interact together then they form a lightning channel. These channels are created on blockchain by adding funds to a wallet that is connected.
Near-instant settlement:
As we all know that to validate a transaction in on-chain main blockchain technology requires all nodes to participate in the validation of the block then this makes the process very slow and requires a lot of effort and time but in the Lightning network, only the Lightning channel is required to make transaction valid. In the thing channel, two nodes are connected and only those two nodes are valid to make transactions valid. This process is very much fast and hence off-chain works effectively. This process is known as Near-instant settlement.
Near- infinite scalable:
As we all know that to validate a transaction in on-chain main blockchain technology and complete a transaction ires all nodes to participate and also requires high transaction fees. This makes the process very slow and requires a lot of effort and time. Micro-payments can not be done through the blockchain because of high transaction fees but in lightning network transaction happens without staking or delegation also no transaction fees or very fewer fees required to complete can perform an infinite number of transactions. This process is called near-infinite scalable.
Uses of lightning network :
The main uses of lightning networks are :
Use to complete micro-payments by reducing transaction fees and make it highly scalable.
Lightning network can easily use as peer 2 peer transaction that means two nodes that are connected perform transactions.
If we use the lightning network to work with the e-commerce industry like amazon Flipkart then it will be a great success as it reduces transaction fees and makes decentralised success.
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? (within 200 words)
Answer 2 :
Lightning networks allow two peers to make a transaction or multiple transactions without any transaction in the off-chain network by this method: When a sender or receiver implementing a transaction in the off-chain network then it is important to add a few amounts of funds on-chain. By adding that one, sender and receiver must tend to spend it while making a transaction on an off-chain lightning network. Added funds on-chain spend as transaction fees on-chain. Since on off-chain lightning network no miners a, represent so it reduces mining fees that were also added in transaction fees only. Also, it reduces the time of complete transactions as only lightning nodes that make lightning channels confirm transactions and not every node is required.
When we work on transactions then if the receiver Peer is directly not connected to the sender peer. Then it creates a lightning channel between nodes for the sender and receiver by taking all the best nodes to make the channel on-chain. Then we can easily make transactions off-chain without any transaction fees.
All these transactions that are free of cost happen off-chain by adding small funds on-chain to make transactions easy. This is how we can perform free of cost transactions.
Question 3:
How does the routing of payment through intermediate nodes(or peers) become trustless with HTLC?(within 300 words)
Answer 3:
The lightning network off chain network transactions are secured by HTLC smart contract. It is secure and reliable in the same way as bitcoin block-chain is. Many lightning channels are created and each channel created in lightning channel are inter connected to each other. So sender can send money to reciver through any channel in trustless atmosphere. Let us take an example how HTLC smart contract uses Hash lock and time lock to routing of payment through intermediate nodes to make it trustless.
Let us consider that I(utsav) want to send funds to my friend(Krishna). Then in off-chain network i can use 2of2 multisig wallet to make payment. But if there is a situation occur where my friend lost it's key and passwords then all the funds will get stuck in the multisig wallet and can't retrieve. To solve this problem HTLC smart contract was developed.
How HTLC works :
Let us consider A,B,C and assume that A want to transfer funds to C with trustless HTLC smart contract. So we have to route the payment through intermediate node B which will also take part in payment initiation. Follow these steps to understand it more clearly:
A want to send funds to C then an intermediate node B was created. C will create a secret and create a hash of it. This payment has time limitations, if you initiates the payment in provided time then your payment will get complete otherwise it will be cancelled after time gets over. So C will send this secret hash to A and A will initiate the payment and want send HTLC funds to B. But remember that B is an intermediate node and don't have a secret hash. So first B initiate the payment and send it to C and create secret Hash and exchange it with C, it means that payment initiated in between B and C. Both of them exchange their secret Hash. Funds are received by C but still not released by A. Now B will take the secret Hash to A and exchange there hash. A will initiates the payment and the whole process will get complete with a transaction fees very less and compare to main on-chain. A initiate the payment because the secret hash send by B is same as C and both B and C received their payments.
This is how the routing of payment through intermediate nodes(or peers) become trustless with HTLC.
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)
Answer 4:
Now using Electrum wallet wei will going to create a channel and perform purchase of E-commerce available on website. Let us follow the steps one by one.
Creating Lightning channel on Electrum :
First create a standard electrum wallet with a secured password. It will take time to add funds in it. But soon it will get complete and your wallet become ready to use.
Now to create channel, first click on channel and then click on open channel. This option will help you to open your channel.
A confirmation block will get generate which ask you for your confirmation whether you want to create your first channel or not. Click yes and move further.
Now to open wallet a new block will generate named as open channel which is a lightning node block that is by default trampoline node. So trampoline option is by default filled with electrum trampoline. Now enter the amount you eant to add in your wallet. It will ask you to enter amount in mbtc. This conversion work as 1mbtc=0.001btc. After entering 2mbtc click ok and move further.
Now a new block will ask you to confirm your transaction by entering your password. Enter correct password and click on send button to move further.
Now finally in first attempt our channel is established and a new block is pop up with the information that our channel is established. Click on ok to move further.
Now our new channel is created in channel list but its short channel ID is not available till yet, as its status is opening. Once it get open then it will show Status as open and short channel ID with some number. The total capacity of channel is 2 and total mbtc added is 1.9626 .
Now since this value is added in on chain network so it will get listed in blockchain explorer. So right click the mouse and copy transaction ID. Paste it in blockchain explorer you can see your transaction history updated on main block-chain.
Now finally our channel is created and its status change to open status with with a short channel ID generated on the channel. This is how we have to create a channel on lightning network.
Finally our channel is established in Lightning network with the first deposit of 2mbtc. This is a valid channel as it is also available on blockchain explorer. Now we can perform off-chain network transactions without display them on blockchain explorer.
E-commerce purchasing using Lightning Network:
If we want to make a purchase with E-commerce then first we have to find a website that support lightning network technology and that website named as Bitrefill.
How to make purchase using Lightning network, let us see the steps that we have to follow :
Visit the official website of Bitrefill and click on browse the product option that is present on main interface.
Select the product or gift card you want to purchase from this website. You can also recharge your mobile phones through this website. I choose Airtel pre paid to recharge my mobile phone.
After selecting your desired product move further and enter the mobile number and choose the plan you want to purchase. I purchase a plan that worth rupees ₹199. After that click on purchase option it will move your process further.
Now it will ask you to purchase more or check out, simply click on checkout to confirm payment in futher.
Now enter the valid email to get notification once you complete your transaction. Then tick the option that I have read the terms and conditions and click continue.
Now choose the payment method to make your transaction complete. For this we are choosing lightning network. Click on it to move further.
Now you can see your order details and a QR code, just below QR code there is an option named as copy, click on it, it will open lightning invoice ID.
Copy that ID and go back to electrum wallet and click on send button to make payment in lightning network.
Enter the invoice ID of your order and click on pay button.
You will get a message of confirmation click yes and move your transaction forward, it will complete your payment instant or in fee seconds.
Finally you recieve a message and a order confirmation green tick on Bitrefill. Also we earn a small reward that we can claim when we login our ID on Bitrefill.
We can see the transaction history in Electrum wallet also that our transaction Is completed.We also created a payment for Paytm wallet of ₹100 that is also displayed on Electrum history.
Does it incur fees ?
The above to transactions are transacted with a very small transaction fees. This is the transaction fees for intermediate node to take secret hash and move transaction futher that help us to complete transaction under HTLC smart contract.
In both transaction the total fees that is used is provided below :
Product | transaction fees (mbtc) | transaction fees(SAT) |
---|---|---|
Airtel | 0.00003 | 3.0000 |
Paytm | 0.00003 | 3.0000 |
Does everything recorded on-chain :
The above two transactions that we have completed are not recorded on-chain. Since we have established a lightning channel then each transaction are now manage my off-chain network and are listed in Electrum history. But why all these transactions are off-chain? So to maintain stability of main chain and reduce nodes from main chain lightning nodes are created. It will increase scalability, transaction speed on main chain also. The only thing that are recorded on main chain that is on -chain is the amount deposit and channel closed details. It means that only initial and final transactions are listed in blockchain explorer and other transactions are recorded in off-chain lightning network.
Swap function:
The swap function available in lightning network is a very useful function that allow to send funds to the main block chain network without closing the channel created off-chain. Swapping don't effect channel and increase capabilities of sending and receiving funds. How to swap funds let us see the process:
Click on swap option available in channel option to swap funds from lightning network to block chain.
Enter the amount you want to swap from lightning network to block chain. I am sending 0.1mbtc as an example swapping.
Click on Ok button after entering the valid information in the submarine swap block. I am sending 0.1mbtc and I am receiving 0.08971mbtc.
- Now your funds are swapped and listed in history of Electrum wallet.
The main thing is that we are swapping funds from off-chain to on-chain so it will display on block explorer. Capabilities of both sending and receiving improve when swapping take place in between off-chain and on-chain network.
How to close channel?
Right-Click on channel and select the option close channel.
Now it will display Electrum-4 block where it want your confirmation to close channel. Click yes and move further.
An error block display where it shows that our channel is now closed.
Finally our channel is closed as we can see the status updated as CLOSED.
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? (Screenshots needed)
Answer 5:
How to Backup lightning up channel:
To backup lightning channel we have to follow basic steps. First visit channel option and then follow these steps:
Right-click on the created channel and click on Export back-up.
It will open a QR code with option as copy text copy image save close. Click on save button to save QR code.
Enter the name of the file with which you want to save file, and click on save button. Now your QR code is backed up and save in your computer.
But why do we need back up channel ?
This backup QR code help us to secure our self. If we lost your password then to close our channel we can use this backup QR code. When channel gets closed by backup files then we can easily receive our funds from off chain to main on chain block chain address.
Funding transaction :
Funding transaction is the initial stage in off chain network where we add fund in the Lightning network. The node In which I initiated my funding is the first history node. Right-click on it and click on view history. Copy transaction I'd and go to block explorer.
Paste the Transaction I'd on block explorer and check the main chain that our transaction is listed there with display of transaction Hash and amount of transaction.
This is the initial stage of off chain network that is also listed in on-chain network.
Commitment Transaction
The commitment transaction is the transaction that takes place in the lightning network off chain network. In this lightning channel nodes are connected directly and indirectly. When nodes are connected directly then no transaction fee is required but when nodes are connected in directly with intermediate node then there is a transaction fee awarded to the intermediate node as reward.
The two transactions in Airtel and paytm are are indirect payments and are commitment transactions. These transactions are not display on the main chain and only display in lightning network off chain.
To check it's details right click on the transaction history and click on view payment option.
You can see the transaction history and complete payment history with total amount of transaction fee reduced.
Because of commitment transaction recharge and other options become very fast.
Settlement transaction:
Settlement transaction happen when we close the channel. This transaction is the final transactions and as we said that transaction will display on main blockchain. All the off-chain transactions become valid by verification of only one settlement transaction. When channel get closed then all the funds available on channel will shift into main block chain.
How to close channel?
Right-Click on channel and select the option close channel.
Now it will display Electrum-4 block where it want your confirmation to close channel. Click yes and move further.
An error block display where it shows that our channel is now closed.
Finally our channel is closed as we can see the status updated as CLOSED.
To check settlement transaction that is the last transaction right click on closed channel and click view transaction. Now copy the transaction I'd and move to block explorer.
Open the block explorer and paste the Transaction ID in search bar you can see the transaction history of closing channel with transaction hash and amount.
This is how initial and final transaction are are listed in blockchain on-chain and intermediate transactions are listed off-chain.
Conclusion:
Is time to conclude our homework post in which we discuss about lightning network which is an off-chain network of bitcoin main chain that is useful and also use other than main chain to increase transaction speed, scalability in main block chain. Off chain is time saving as only a single lightning channel and validate the transaction. In direct node transaction no transaction fees required but in indirect transactions, transactions fee are required to give intermediate block reward. Using HTCL smart contract one can easily make transactions in off chain network and also it is highly secured. We can easily purchase goods, gift cards mobile recharges via lightning network from a provider who accept lightning network Wallet. Finally we purchased Airtel recharge and Paytm top up. There are three types of transactions, settlement, commitment and funding. Funding and settlement are the transactions that are also listed in main chain in block explorer but commitment transaction are only listed in block chain and not listed in on-chain.these transactions get valid when settlement transaction get valid by main chain. This is all about my home work post. Thankyou so much professor so such a great and wonderful lecture.
You have been upvoted by @sapwood, a Country Representative from INDIA. We are voting with the Steemit Community Curator @steemcurator07 account to support the newcomers coming into Steemit.
Engagement is essential to foster a sense of community. Therefore we would request our members to visit each other's posts and make insightful comments.
Thank you