Crypto Academy Season 3 Week 7 - Homework Post for Professor @Sapwood on Lightening Network.

in hive-108451 •  4 years ago 

Hello Steemians, I welcome you all to the week 7 of the Steemit Crypto Academy. Today's lesson was delivered by professor @sapwood on Lightening Network. I will be attempting the homework task in this post.

photo_2021-08-14_22-36-14.jpg

20210706_121504.jpeg

(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)

D5zH9SyxCKd9GJ4T6rkBdeqZw1coQAaQyCUzUF4FozBvW7Jjayh99xW6MJGLfCRkezgmEdPaBroQpYNNRqAz3EESJbb2VH7UWD2VN7KjSCWYkJUUdc5qVu3r2CE6asBxa8M838.jpg

Lightning Network.

Lightning Network is an off-chain layer on the top of the bitcoin network that helps to solve the issues of scalability, micro-payments, recurring payments, and privacy. The lightning network does this by creating an off-chain link between nodes called channels and transactions done on the lightning network is verified between the nodes. Only the initial and final transaction is recorded on the main chain.

In the lightning network a node creates a channel by first depositing funds which are recorded on the bitcoin network (main-chain), this is called the funding transaction. All other subsequent transactions within the range of the deposited funds done on the lightning network between nodes are not recorded on the main-chain but verified between nodes. These transactions are called commitment transactions. The last transaction of the commitment transactions done is called the settlement transaction and this is recorded on the main chain with its details. All transactions on the lightning network are secured by the HTCL contract where transactions are timed and only the holder of the secret can access the transaction details.

Lightning Node

Lightning nodes are nodes (devices) on the lightning network that creates an off-chain link from the bitcoin network to the main-chain by connecting with other nodes whereby transactions are done between both nodes or indirectly connecting nodes and only the initial and final transaction is broadcast to the blockchain network

Lightning Channels

Lightning channels are the secure links created by connecting nodes in the lightning that allows the nodes to perform transactions. These channels are created when a node makes a deposit of funds on the bitcoin network but spends/makes payment on the lightning network to other nodes on the network creating a channel on the lightning network. Transactions on the lightning network can be done between two nodes not directly connected through intermediary nodes.

How does it achieve a near-instant settlement, near-infinite scalability?

All transactions done on the lightning network are validated by its immediate peer, meaning, unlike the bitcoin network it does not have to wait for the entire network to validates the transactions that take time. Since only the transacting nodes need to validate the transaction it makes the transaction be settled almost at an instant.

Unique nodes like Trampoline nodes help find the shortest and optimal routes for payments to reach the destination for indirect nodes transactions making the transaction quicker reducing congestion to creating a near-infinite scalable network.

What are the different uses

  • This can be used for peer to peer transactions between direct nodes, for instance Node A creates a channel with Node B and run transactions between both nodes and those transactions are validated by the immediate node without needing the whole network

  • It can be used for transactions between nodes not directly connected by involving an intermediary node. this is still done off-chain requiring aa little fee for the intermediary node for acting as a connecting link.

D5zH9SyxCKd9GJ4T6rkBdeqZw1coQAaQyCUzUF4FozBvW7Jjayh99xW6MJGLfCRkezgmEdPaBroQpYNNRqAz3EESJbb2VH7UWD2VN7KjSCWYkJUUdc5qVu3r2CE6asBxa8M838.jpg

(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)

In a lightning network a node makes an initial deposit of funds alerting the main chain, then creates a channel with a different node on the off-chain and subsequent transactions are done between them and only the final transaction is being broadcast to the bitcoin network just as the first.

The transaction(s) between the connected nodes on the off-chain is validated by connected nodes and done without cost because the transaction (multiple or recurring) is not known by the bitcoin network so no blocks have to be mined by miners for those transactions hence no transaction fee is needed making those transactions cost-free. These cost-free transactions are done on the off-chain.

D5zH9SyxCKd9GJ4T6rkBdeqZw1coQAaQyCUzUF4FozBvW7Jjayh99xW6MJGLfCRkezgmEdPaBroQpYNNRqAz3EESJbb2VH7UWD2VN7KjSCWYkJUUdc5qVu3r2CE6asBxa8M838.jpg

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

HTLC (Hashed Timelock Contract) is a smart contract used in the lightning network to make it trustless by making time-bound cryptographic transactions. This is a hash lock and time lock meaning for any transaction to be completed the hash needs to be decoded before the time specified elapses.

In the HTCL smart contract, a secret is created and hashed by the receiver, the receiver gives the hashed secret to the sender to initiate the transaction through an intermediary node. This transaction with the hashed secret is sent through an intermediary node with a locked time condition for the receiver to decode the hash. The receiver has to decrypt the hash within the time set else the transaction becomes invalid.

The HTCL makes routing of transactions through an intermediate node trustless cause it ensures only the receiver of the transaction can access it..

D5zH9SyxCKd9GJ4T6rkBdeqZw1coQAaQyCUzUF4FozBvW7Jjayh99xW6MJGLfCRkezgmEdPaBroQpYNNRqAz3EESJbb2VH7UWD2VN7KjSCWYkJUUdc5qVu3r2CE6asBxa8M838.jpg

(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)

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

To open up a lightning channel I first open my Electrum wallet and click on channel, then click on open channel.

photo_2021-08-14_06-25-45.jpg

After I clicked on the open channel a pop-up warning message appears asking if I want to go ahead I clicked on Yes

photo_2021-08-14_06-25-50.jpg

After clicking on yes a page comes up, I input the number of funds I will be depositing (the initial transaction). the amount is 2 mBTC and the node is the default Electrum Trampoline and clicks on OK as shown below.

photo_2021-08-14_06-25-54.jpg

I input my password and clicked on Send

photo_2021-08-14_06-25-58.jpg

A pop-up message shows the channel is established and a Remote peer is indicated then I clicked on Ok. The transaction can be checked on the block explorer to know if it has been confirmed

photo_2021-08-14_06-26-02.jpg

The Short channel ID shows unconfirmed on the Electrum wallet and this will show the short channel ID after three confirmations of the transaction. The lightning node is the electrum trampoline, capacity is 2, can send 1.9271 can receive 0, and status is opening

photo_2021-08-14_06-26-12.jpg

To check if the initial transaction is confirmed we go to the blockchain explorer and input the transaction ID. This is also used to track the transaction.

photo_2021-08-14_07-05-00.jpg

The moment the transaction is confirmed the short channel ID on the Electrum wallet shows as Confirmed and the status is Open

photo_2021-08-14_07-12-11.jpg

The lightning channel is created and the funding transaction is confirmed. Now transactions can be done without broadcasting them on the blockchain network.

Making an eCommerce purchase(or a micro-Transaction) using Lightning Channel

To make an eCommerce purchase I visited the Bitrefill
An eCommerce site that supports lightning network transactions

photo_2021-08-14_07-26-32.jpg

After which I clicked on the product I wish to buy from the bitrefill site and clicked on it. The product I chose is Airtel a prepaid network service.

photo_2021-08-14_06-26-16.jpg

A page opens where I input my phone number and click on the purchase

photo_2021-08-14_06-26-20.jpg

A page with a list of payment methods to choose from, I chose the lightning BTC as shown below

photo_2021-08-14_06-26-28.jpg

After clicking on the lightning BTC as a mode of payment a page comes up with a QR code of the lightning invoice or Copy, I copied the lightning invoice

photo_2021-08-14_06-26-34.jpg

Back to the electrum wallet I click on send and input the copied lightning invoice on the pay to olumn. When I confirmed the details were correct I clicked Pay

photo_2021-08-14_06-26-42.jpg

A pop-up message confirming the transaction I clicked on yes

photo_2021-08-14_06-26-46.jpg

After clicking on Yes my number was credited in seconds and on the bitrefill site the order was completed. Completing the purchase.

photo_2021-08-14_06-26-50.jpg

On the Electrum wallet, the transaction is displayed as confirmed

photo_2021-08-14_06-26-53.jpg

Does it incur fees?

Yes, it incurred a fee because the transaction was done using an intermediary node, but the fee was very minimal as it cost only 0.00006 mBTC.

photo_2021-08-14_06-26-57.jpg

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

It does not record the transaction on the on-chain as this is a commitment transaction done on the off-chain (lightning network) and hence not broadcast on the bitcoin network. This helps to reduce congestion on the bitcoin network and improve scalability and transaction speed.

How Swap Function helps to improve sending and receiving capacity

The swap function helps in the exchange of funds between the lightning network and the bitcoin network (on-chain) without needing to close the channel.

The sending and receiving capacity is improved by this, when you swap funds from the on-chain for a lightning fund it improves the sending capacity and when you swap your lightning fund for the on-chain fund it improves your receiving capacity.

D5zH9SyxCKd9GJ4T6rkBdeqZw1coQAaQyCUzUF4FozBvW7Jjayh99xW6MJGLfCRkezgmEdPaBroQpYNNRqAz3EESJbb2VH7UWD2VN7KjSCWYkJUUdc5qVu3r2CE6asBxa8M838.jpg

(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 back up a wallet file or a channel I go to the channels o my electrum wallet and right-click on the Electrum Trampoline channel and a pop-up menu appears. I click on Export Backup

photo_2021-08-14_06-27-11.jpg

A page with a QR code and option to copy the image, copy text, save, or close. I click on save

photo_2021-08-14_06-27-15.jpg

After I clicked on save my file explorer comes up to save the file I changed the name of the file to my preferred choice and then click on save. The channel is backed up.

photo_2021-08-14_08-26-36.jpg

Why and when is it needed

Backing up a channel is necessary when you want to close your channel and send funds to the on-chain network. Though backing up your channel does not help restore your channel ii is only used to request channel closure.

Indicating the funding Transaction, Commitment Transaction, and Settlement Transaction both in your wallet and Block Explorer

Funding Transaction

This is the initial transaction initiated to open a channel and it is broadcast on the bitcoin network and can be traced on the blockchain explorer.

photo_2021-08-14_09-14-28.jpg

To check for this transaction on the blockchain network, I input the Hash on the blockchain explorer search tool and click on enter

Transaction ID
01ad8dd3823fb866a0d56b20d3ffe5f720b219627766d5983769179e6cbc0fe3

photo_2021-08-14_07-05-00.jpg

Commitment Transaction

These are the subsequent transactions done on the lightning network (off-chain) between two nodes. These transactions are not recorded on the blockchain network and can’t be traced on the blockchain explorer

The commitment transaction I initiated was the purchase made on the bitrefill sit as shown below

photo_2021-08-14_09-31-43.jpg

And the details of the lightning payment are shown below.

photo_2021-08-14_06-27-24.jpg

Settlement Transaction

This is the transaction done last when the channel was closed and it is recorded on the blockchain network.

photo_2021-08-14_09-47-19.jpg

photo_2021-08-14_06-27-31.jpg

The transaction ID can be traced on the blockchain explorer

Transaction ID 4ba1c3e3da52e9d44bdea3c6f5513929a452587972b31669ace8e53909f7abce

photo_2021-08-14_06-27-35.jpg

D5zH9SyxCKd9GJ4T6rkBdeqZw1coQAaQyCUzUF4FozBvW7Jjayh99xW6MJGLfCRkezgmEdPaBroQpYNNRqAz3EESJbb2VH7UWD2VN7KjSCWYkJUUdc5qVu3r2CE6asBxa8M838.jpg

Conclusion

Lightning network is an improvement to the blockchain network as it helps in its scalability issues by reducing the congestion on the network with its off-chain transactions. Only the funding transaction and settlement transaction is recorded on the bitcoin network every other subsequent transaction called the commitment transaction is done off-chain needing no validation from the on-chain.

Transactions on the lightning network are fast, secure, and cheap and allow transactions as small as 1 satoshi. Transactions between direct nodes are free, only transactions involving intermediary nodes require a very small transaction fee.

Thank you @sapwood for this wonderful lesson.

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  
Loading...