Crypto Academy / Season 3 / Week 7 - Homework Post for Professor @sapwood

Hi everyone and Assalam U Alaikum,

Welcome to my homework post for Professor @sapwood which is about Lightning Network. I have gone through this outstanding lecture and learned all new things.

Q. 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?


Lightning Network.


Screenshot_2021-08-13-19-22-47-97_40deb401b9ffe8e1df2f1cc5ba480b12.jpg

Image Source

Lightning network is a term used for "layer 2" payment protocol that is built on top of original Blockchain network like Bitcoin. Lightning network is deemed to be a solution to the scalability problem of the Bitcoin blockchain network.

Lightning Network has been designed to make fast transactions between the practicing nodes. It is a decentralized network which offers instant micro-payments at a very high volume using security of smart contracts with very low fees.

Lightning Network is used by creating a lightning channel on the Layer 1 network, means a channel is used on Bitcoin blockchain and then any number of micro-payments are made off-blockchain between the participating nodes without recording these transactions on the Bitcoin blockchain. Only initial and final payments are recorded on the Bitcoin network, thus maintaining the privacy of transactions.

Lightning Node.


IMG_20210813_200905.png

Image Source

Lightning node is one of the essential component s of Lightning Network. The job of the Node is to make the transaction complete by connecting the Origin and Destination. When one participant is not connected directly with other participant, and an intermediary is required to complete the transaction, here comes the role of Node and it will help the participants to complete the transaction through this node.

Moreover, a node is used to validate a transaction on Blockchain network. Similarly on Lightning network, nodes connect the sender and receiver and validate the transaction between the participants.

Lightning Channel.

The other component of Lightning Network is Lightning channel along with Lightning node. When two nodes are connected, it creates a channel. Lightning channel is used to connect different nodes on the network. A channel is created by binding funds on Blockchain network using a connected wallet.


vM1pGHgNcyCXUWJECrZbvn1NMPj1oFGUo3gYfF3NNPRD9VDgFAK8nqsh9tsJgKSej5TjPYqXsEzaJhLF2KnqjFQFm9Z7ThtnjtQpVDzSxCyYTnFJXRWLDnvpUNaW2E8ohwkErES.png

Image Source

near-instant settlement.

Near-instant means that a thing is done instantly. As we all know that on Bitcoin blockchain, when a transaction is made, it is validated by the nodes connected to the network at first and then after confirmation of its validation, transaction is completed. It takes some time to complete the transaction. But in Lightning Network, transactions are settled instantly. Because the connected participants or nodes are the only validators, so it is completed instantly. Hence it can be said that by using Lightning Network, near-instant settlement can be achieved.

near-infinite scalability.

Lightning Network is intended to solve the scalability problem of Bitcoin network. So, there are limited number of participants in a channel and infinite number of micro-payment transactions can be made instantly. So this term is used for this function of Lightning Network because the participants can make as many transaction as they want. It means near-infinity scalability is achieved through lightning network.

Uses of lightning network.

Followings are some of the uses of Lightning Network.

  1. Used to make instant micro-payments with very low fees.

  2. An infinite number of transactions can be made using LN.

  3. LN can easily be used for P2P transactions.

  4. It can help in boosting E-commerce websites.


Q. 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)


Lightning Network allows two peers to make a transaction or recurring or multiple transaction without any transaction fee using off-chain environment. 2of2 multi-sig wallet is used to make peer to peer transactions by the Lightning Network.

Two participants can create channel where bidirectional payments can be made off-chain. A channel is required to be created on the Bitcoin blockchain network and the participant has to bind some amount of capital on the Blockchain with intention to spend all or part of it. Then the participants will make transactions off-chain without fee or very less fee. These transactions are completed instantly. Participants can make infinite number of transactions that can be micro-payments.

When the payment process is completed, any of the participants can close the channel and the final transaction will be recorded on Bitcoin blockchain. In this way, multiple or recurring transactions can be made instantly using Lightning Network without any fee or very less fee.


Q. 3. How does the routing of payment through intermediate nodes(or peers) become trustless with HTLC?(within 300 words)


In Lightning network, when a transaction is made between participants and sender sends the funds to the recipient but he does not collect the funds or disappears, it is not possible for the sender to withdraw money. Sender is unable to withdraw funds of the transaction. So HTLC was introduced which stands for Hash Lock and Time Lock.

Lightning network uses HTLC smart contract when off-chain network transactions are made. These off-chain transactions are secured by HTLC smart contract in the same way as transactions are secure on Bitcoin network. Sender can use any channel to make payment to the receiver in trust-less atmosphere using HTLC smart contract.

How HTLC works?

Now we will discuss with an example how HTLC works. A, B and C are assumed in which A wants to send funds to C but they have no direct connection. A uses an intermediary B to route payment to C. A is the sender and C is the receiver while B is intermediary to complete this transaction as A & C are not connected directly. Now to complete this transcation with HTLC smart contract, following steps will have to be taken.

  1. C, the Sender, will create a secret and hash it. Without this secret, payment cannot be redeemed. C will include timelock and hash value in the HTLC payment script. C will handover hash to A, which is direct party in the transaction. Secret is only with C and he is the only one who can unlock the HTLC payment.

  2. Now A will initiate the HTLC payment through the channel created by making B an intermediary. At this point, B is not the one who knows the secret, so he will not be able to unlock payment. B & C are directly connected and C is the final recipient, So another HTLC payment will be initiated by B to C with a condition. Condition will be that C can only claim the payment if the secret value is known to C and he discloses it.

  3. C knows the secret value and he will redeem the payment. Now the secret has been disclosed and B can also redeem the payment from A.

This is the process in which HTLC payment is processed and completed using intermediary node.


Q. 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)


Now I will use Phoenix wallet to create a channel and then perform a transaction (an eCommerce Purchase) available on the website.

Creating Lightning channel on Phoenix.

I installed the Phoenix wallet on my mobile phone and created account. I was asked to backup seed of my wallet and I kept it safe. Then I sent funds into the wallet that took some time and finally funds received and showed on the homepage.

IMG_20210814_130353.jpg

It can be seen that funds have received. It requires minimum 10000 sat to open a channel on Phoenix. Now click on Setting button in the left low corner, circled in the screenshot. Next interface will open as given below.

IMG_20210814_130416.jpg

Now click on Channel List, mentioned in the screenshot above and then the next interface will open as given below.

IMG_20210814_073340.jpg

The channel has been created automatically as Phoenix creates the channel automatically and you can see funds have been added to the channel. It is also showing the Capacity that is 57,232 sat.

To verify the transaction, click on the mentioned channel.

IMG_20210814_073340.jpg

The next interface will open as a pop-up message that is given below.

IMG_20210814_133334.jpg

Now click on Tx and the next interface will open as given below. This is the explorer which is showing that the transactions was added to the block. Time and date is also mentioned on it.

IMG_20210814_132508.jpg

Now finally the channel has been created on Phoenix wallet.

E-commerce purchase through Lightning Network.

In order to make a purchase on eCommerce site, I will have to find it and I am going to open Bitrefill and login to my account and it is showing the available products in Pakistan.

IMG_20210814_134820.jpg

I have chosen to top-up my jazz number that is available. I clicked on it and the next interface will open as given below.

IMG_20210814_135102.jpg

Here I entered the details of the transaction. I entered the amount and mobile number and then click on Purchase.

IMG_20210814_135244.jpg

Now I was asked to select the payment method and I selected Lightning BTC. I clicked on it.

IMG_20210814_135532.jpg

Now the QR code appeared and there is an option to Copy. I clicked on it and copied the data and then opened my Phoenix Wallet to complete the transaction. I clicked on Send button and pasted the payment link. It was pasted automatically from clipboard. Then click on Pay.

IMG_20210814_135814.jpg

In very short time, I received the message of successful payment.

IMG_20210814_140138.jpg

Payment has been completed and then I headed to website.

IMG_20210814_140249.jpg

It is showing that the transaction has been completed. In this way, using lightning network, transaction can be made with very low fee and instantly.

Does it incur fees ?

Yes, transaction fee is only 1 sat and it is nothing as compared to on-chain transaction fee. This is the feature of Lightning network that micro-payments can be made with very small fee or no fee. In fact this fee has been given to intermediate node for helping in completion of the transaction.

IMG_20210814_140138.jpg

Does everything recorded on-chain.

The above transaction has not been recorded on Bitcoin blockchain because this transaction was completed using lightning network off-chain. This transaction is only recorded on Phoenix Wallet. The purpose of creating lightning channel is to reduce the number of nodes on-chain and the transaction off-chain are not recorded so that scalability problem of the Bitcoin network may be solved. By doing this, transaction speed and scalability of Bitcoin network can be improved. Amount deposit transaction as well as the closing of the channel transaction will be recorded on the main Bitcoin network.

Swap Function.

On Phoenix Wallet, I was unable to locate swap function. When I closed the channel, I was asked to transfer my sats to a bitcoin address. I gave the address of my Binance account and the funds were sent to that address.

How to Close channel.

Click on Setting button, a screenshot was uploaded above, and then click on the option Close all channels.

IMG_20210814_145641.jpg

Then it will ask you to enter Bitcoin address where your funds will be sent. I entered my bitcoin wallet address and funds were sent to it. This message was shown on the screen.

IMG_20210814_143939.jpg


Q. 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)


To backup lightning channel on Phoenix Wallet, Click on channel and a pop up message will appear. There is an option to copy. We can copy and save the channel details in any file. It is quite different from what we learned from the lecture because a different wallet is being used.

IMG_20210814_133334.jpg

Backup file of channel is needed in case we lose password and we want to close the channel. Then using the backup file, a channel can be closed and fund can be transferred to Bitcoin network.

Funding Transaction.

Funding transaction is the transaction that is made for the first time in the Lightning network. After installing Phoenix Wallet, Minimum of 10000 sat are required to be deposited in order to create a channel. Otherwise channel will not be created. This funding transaction is recorded on the main Bitcoin blockchain.

IMG_20210814_175834.jpg

I have mentioned the Funding transaction that is available in the history of Phoenix wallet. By clicking on this, the next interface will open as follows.

IMG_20210814_175936.jpg

You can see in this above screenshot that there is an option to Show in Explorer. Now click on this option and the next explorer will be opened where transaction details can be seen that have been recorded on the Bitcoin Network.

IMG_20210814_180130.jpg

IMG_20210814_180130-1.jpg

It shows that the funding transaction is recorded on Bitcoin blockchain and it can be found on explorer.

Commitment Transaction.

The off-chain network transactions that are made on Lightning network between the participants of lightning channel, are called commitment transactions. These transactions are not recorded on Bitcoin network because these transactions are made using off-chain environment. No fee is charged when participants are directly connected and a very low fee is charged when an intermediary node is used to complete the transaction.

I have made a commitment transaction and I am going to show this to you.

IMG_20210814_194823.jpg

This is the transaction which I made in order to purchase balance for my mobile phone. By clicking on it, the details of the transaction can be seen in the screenshot below.

IMG_20210814_180301.jpg

There is address of Bitrefill where i sent the payment. Below is an option "Show details" and I clicked on it.

IMG_20210814_180301-1.jpg

This transaction was made using off-chain network so there is no option to show it on explorer.

Settlement transaction.

When the channel is closed, and fund is returned to main blockchain, it is called settlement transaction. As we discussed earlier that initial and final transactions are recorded on Bitcoin blockchain. So settlement transaction is also recorded.

IMG_20210814_194905.jpg

click on the transaction and details of the transaction will be shown as given below.

IMG_20210814_180418.jpg

It can be seen in the description that it is payment for closing channel. Next is the option of Show details. Click on it and next interface will open as given below.

IMG_20210814_180453.jpg

In this screenshot, closing transaction is in link form and clicking on it will open explorer where we can see that this transaction has bee n recorded on the Bitcoin blockchain. Next is the screenshot showing the details of the transaction on the explorer.

IMG_20210814_180546.jpg


Conclusion.

We have learned about Lightning Network which a layer 2 network built on top of the main Bitcoin blockchian network. It is intended to increase the transaction speed with very low transaction fee. Transactions are made using off-chain network which are not recorded on the bitcoin blockchain. It also helps in increasing the speed of Bitcoin blockchain by reducing the number of nodes. Infinite number of micro-payments can be made using lightning network. Transactions privacy is also maintained by using off-chain network and only initial and final transactions are recorded on Bitcoin blockchian.

Thanks in anticipation.

Regards,

@mawattoo8

Sort:  
Loading...

Coin Marketplace

STEEM 0.20
TRX 0.13
JST 0.029
BTC 66599.03
ETH 3421.37
USDT 1.00
SBD 2.63