Crypto Academy Season 3 | Advanced course - Task 7: Lightning Network By Prof @sapwood

in SteemitCryptoAcademy3 years ago

Hello class, my pleasure to participate in this weeks advance task.

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)

What is Lightning Network?

Lightning Network is an off-chain solution Smart contract that was borne out of necessity to ameliorate some of the bottlenecks seen in the overall process seen in the Bitcoin blockchain. Each time we talk about Bitcoin, we talk about Decentralization then the position of our mind at scalability throughput associated with the blockchain. Just as we have other off-chain protocols all designed for specific tasks in the blockchain technology (For example the Chainlink, Augur, Teller etc, which are all Oracle Applications that links and bridge the gap between the off-chain world and the On-chain world by supplying data), the Lightning network is specifically built on the Bitcoin blockchain to help improve scalability by de-congesting the process of validating transactions on the chain.

The Lightning Network helps in offloading micro-transactions off the chain that ordinarily would have been done in the Bitcoin blockchain which hence improves scalability and less congestion of the network. In doing this, only the Initial and Final transactions are seen to be recorded in the bitcoin blockchain network while taking into cognizance the privacy, decentralization, security and trustless nature of the Bitcoin technology. This process also maintains the peer to peer interaction seen in the bitcoin protocol and sometimes it goes with zero to low fee charges.

Lightening Channels

This is borne out of the Lightning Network which has the Lightening Channels as one of its components. The Lightening channel in its simplest term is a gateway whereby the originating peer connects the recipient peer by not necessarily having to pass through a merchant or another peer to help deliver to the recipient peer. In short, if Prof sapwood wants to send 10steem to xkool24, he can do this by looping this 10steem directly to xkool24 by creating a channel especially for this. sapwood does not need to pass through kinkyamiee who has close contact and range to xkool24 to send this 10steem.

In all of this, the gateway/link between sapwood and xkool24 is a Network channel, also the gateway between sapwood and kinkyamiee is a Network channel and the gateway linking kinkyamiee and xkool24 is also a network channel. Passing through that long loop from sapwood point to xkool24 point would not be cost-efficient vis-a-vis passing through kinkyamiee to xkool24 to deliver the 10steem.

Lightening Nodes

Just as explained above for Lightning Nodes has been the second component/leg that makes up the Lightning Network. it is simply those merchants or intermediaries seen within the Network channels that we may connect to reach our recipient peers rather than creating a loop directly to them. The Lightning nodes are shortcuts to connect the sender and the Receiver, and the path in which this connection happens is the Lightening Channel while the points of interceptions are the nodes.

The Lightning can be seen to interact with both the first layer_Bitcoin Network as well as the Second layer_ the LN. This sees it also interact with the Bitcoin nodes independently and in a trustless state which doesn't compromise the decentralization nature it upholds. The LN node also helps us to trace optimal routes which connect with distance peers with the ability to use the HTLC for a trustless engagement.

How to achieve a near-instant settlement, near-infinite scalability

The Lightning Network which comprises the Lightning Nodes and Channels are the second layer solution to the Bitcoin scalability issues with a propensity to achieve Lightening fast payments given to the number of validations sen be engaged nodes. Not all the nodes are involved while making these micro-payments in the lightning Network which makes transactions near-instant and scalability near-infinite.

Transactions in the First layer involves the confirmations from all available nodes in the network which makes scalability an issue and transaction seen to about 10minutes whereas only the engaged nodes in the second layer solution participate in the transaction done in its network which makes it highly scalable and near-instant.

Uses
  • Allows for micropayments (mBTC)
  • It is cost-efficient to use the mBTC compared to when dealing with the BTC token directly
  • E-commerce and other micro-unit transaction firms have received a boost with the use of LN

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)

The Lightning Network allows two peers to make a zero-fee transaction (or multiple transactions) off-chain network. All that is seen here is that either the sides who want to send or receive money is expected to bind up some amount of capital On-chain with a propensity to spend all or part of that amount while engaging with multiple transactions activities Off-chain using the Lightning Network void of any transaction fees/chargers.

When the other peer is seen not to be directly connected to the sender's peer, we can create a Lightening Channel for the recipients with the help of the Nodes who gets an optimal route all happening On-chain before we can now engage our Lightning Network and transact accordingly Off-chain without charges.

Off-chain transaction in the Lightning Network is without charges due to the absence of Miners who incurs mining fee and also saves time since there are no confirmations done as seen in the On-Chain Network.

Question 3

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

The use of HTLC in the Lightening Network became necessary due to issues emanating from fellow parties abandoning a 2of2 Mulitsig wallet collaboration done, funds get trapped until when both parties engage in this wallet again. Hence the emergence of the HTLC to ameliorate issues by the use of time lock contracts. The HTLC is a combination of the Time lock and Hash lock which are seen to route payments through intermediaries and still make them trustless.

The HTLC works in such a way that only the peer with the secret hash can redeem payments given to the defined Time Lock. In this scenario, secrets are created and hashed with a Time Lock and Hash Value all incorporated in the HTLC payment with access to whoever knows the secret to redeem it but within the defined Time Lock. If this is not done within the Time Lock, it invalidates the payment.

For Example; I will be using Agent-A, B, & C where B is the intermediary, A-Sender & C-Receiver

  • So if Agent-C will create the secret and Hash it, Then since Agent-C is in trade with Agent-A, Agent-C will send this hash to Agent-A. (Remember, only Agent-C the receiver of this fund knows the secret)
  • Agent-A will quickly generate the HTLC payment using the Network channel of Agent-B who is only has a direct connection with Agent-C but does not know the secret value.
  • Agent-B will receive this HTLC payment from Agent-A and re-initiate another HTLC payment to Agent-C but with a condition to redeem this payment if the secret value is disclosed.
  • Agent-C would redeem this payment by disclosing the secret value to Agent-B who redeems the HTLC payment from A which makes the transaction completed.
  • This claim is done within the Time Lock to avoid invalidating payment transactions done. Also, a very low transaction fee is paid to Agent B.
  • This process makes the HTLC a trustless one in the Network.

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)

Creating, Opening & Using the Lightening Channel

I already have the standard wallet from the last lessons on the use of the Electrum wallet. So I just need to fund it and continue this process. So, in creating a channel, we will have to open the Standard Electrum wallet, then go to the top screen and click on the Channels icon. But should in case it is not showing, kindly click on the VIEW tabs to launch it on the tools bar. So;

  • Click on the Channels Tab
  • Click on Open Channels
  • From the pop-up interface, click on the YES button

image.png
image.png

  • Input the amount of BTC to be used. (The minimum amount is 2mBTC or 0.002BTC)
  • Remember to leave the Nodes at Trampoline Nodes
  • Then click on the OK button

image.png

  • Enter your standard wallet Password and click on the SEND button
    Note: I can slide the ETA bar to adjust the fee to get something I can afford. -
  • As soon as I clicked on the SEND button, information prompts up to confirm that a channel has been confirmed. Click on OK to close the tab.

image.png
image.png

  • I will have an interface showing that SHORT CHANNEL ID is NOT YET AVAILABLE. I have to wait for few seconds to get the Short Channel ID updated.
    From here I have Capacity as 2, Can Send as 1.9638mBTC and Can Receive as 0.
    image.png

Thereafter the Short Channel Id was updated almost immediately.

image.png

Since my deposit to the Lightning Network was an On-chain Transaction, this can be tracked or conform from the Blockchain explorer by inputting the transaction ID. (To get the Transaction ID, quickly click on the History Tab, go to the Transaction done carrying the 2mBTC and then click on it. Copy the transaction ID on the top screen from the prompt interface in the display).

  • Input the Transaction ID in the search box (using blockchain.com)
  • This will show the whole transactions done.

image.png

Purchasing via E-commence using the Lightning Network

I have to visit any of the E-commerce websites to complete this task but for this post, I will be using Bitrefill to perform this task.

  • Open the Site
  • Click on the Browse Products on the top right side of the screen

image.png

  • From the landing page, I can see all the mobile telecommunication logos in my country
  • I will be choosing the GLO to perform this task. So Click on the GLO

image.png

  • Enter the Amount
  • Enter your Mobile Number
  • Click on Purchase

image.png

  • Click on Checkout
  • Enter your email address
  • Click on Continue

image.png
image.png

  • From the payment method, click on the Lightening (BTC) option

  • Click on the QR or the copy option to copy your Invoice Lightening ID
    image.png
    image.png
    image.png

  • Then go back to your Ethereum Wallet and do the following
    a. Goto SEND tab
    b. Paste the copied Invoice number at the PAY TO column
    c. The description/Amount column would be updated automatically
    d. Then click on the PAY icon

  • Continue the prompt by clicking on YES
    image.png
    image.png

WOW...I immediately got a notification and value on my mobile. This simply complies with the fast lightning scalability which was what it is known for.

image.png

Does it Incur Fees

The cost seen in the transactional was quite infinitesimal. Just like we said before now, using the Off-chain Lightning channel has no/low fees. These low fees are mostly for the intermediaries nodes payment used during the transaction.
Fee charged here - 0.00006mBTC

image.png

Does it record the transaction on-chain

Just as mentioned earlier in my explanation of the Lightning Network, the transaction was not recorded On-chain. As soon as the channel was opened and established, every other microtransaction is aisoffloaded to the Off chain. This is one of the mainstays of the Lightning Network to de-congest the first layer (Bitcoin Blockchain) with only the Initial and Final transactions only recorded On the chain.

This also improves on the scalability of transactions done as well as saves time (Since there are no miners to validate with all the confirmations), hence it's relatively cheap (low fees) to transact on.

The Swap Function

This is another feature when we open the Lightening Channel. It allows users to move funds from the Lightening Channels to On-chain without really affecting the inbound capacity of the user. Hence it still maintains the channel initially established.

These swap activities are also beneficial to the user as it increases the Sending and Receiving Capacity of the user while using the Lightning Channels. Therefore, swapping increases the capacity of the channel generally.

Question 5

How do you back up a wallet file, why and when is it needed? Indicate the funding Transaction, Commitment Transaction, and Settlement Transaction both in your wallet and Block Explorer? (Screenshots needed

Backing up a Wallet File

This can be simply done by right-clicking on the Electrum Trampoline Option from the wallet

  • Right-click on the Electrum Trampoline
  • Click on Backup from the drop-down
  • Click on the SAVE option
  • Enter your filename and click on Save

image.png
image.png

image.png

Why and when is it needed
  • It helps users to close up their opened channels as well as send the funds to On-chain
  • It helps to import the Lightening Channel Transaction on the same wallet or device
  • It can be called up and used to close up the channel.
Indicating Funding Transaction

This is the transaction that establishes the Channel. We can see it from the transaction history with the description as an Open channel.

image.png

Blockchain Explorer Transaction Tracker

image.png

Indicating Commitment Transaction

These are transactions that involve activities that happened in the Lightning Network we purchased the mobile top-up. They are off Chain transactions with no fees if transacted directly but when done through intermediaries, there are low fee charges seen.

image.png
image.png

Indicating Settlement Transaction

This is the transaction that simply shows the transaction of a closed channel.

image.png

Blockchain Explorer Transaction Tracker

image.png

How to Close the Channel
  • Right-click on the Electrum Trampoline
  • Click on the close channel option
  • Confirm by clicking YES
    A confirmation will pop up showing that the channel has been closed.

image.png
image.png
image.png

Confirming if the Receiving address has the same Transaction value as executed.

image.png

Thank you respected Prof @sapwood for this task.

Written by: @xkool24

Sort:  
Loading...

Interestingly, I didn't know all this Lightening Network stuff. Thank you for sharing this information.

 3 years ago 

You're most welcome... Good to know I atleast shared some piece of knowledge via the task.

@xkool24 please what applicatiom do you use to edit your photos and arrows for your assignment

 3 years ago 

You can download imark for this purpose

Thanks so much