Good day steemians, here's the homework task for the advanced course by professor @sapwood
TASK
(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)
(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)
(3) How does the routing of payment through intermediate nodes(or peers) become trustless with HTLC? (within 300 words)
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)
(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)

image created by me with canva

(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?
With the era ushering in cryptocurrencies and blockchain technology in general especially in the area of Bitcoin. Decentralization has always been the major focus with its added advantages being top notch security. However, the problem of scalability especially in the first generation Proof of work Bitcoin has always been left untackled. This problem led to the innovation known as the lightning network.Lightning Network is a layer technology incorporated on a layer just above Bitcoin Technology for the purpose of tackling scalability and network congestion issues experienced in this network. The lightning network was developed to eradicate this issue following the creation of a secure channel amongst nodes to enable it to perform off-chain transactions. Here parties can move funds endlessly without alerting the main chain. This results in an advantage of increased throughput and transaction speed as the burden which would have been bestowed upon nodes by approval of transactions within the main chain are reduced.
Here smart contracts known as "Hashed Timelock Contract Protocol (HTLC)" are used to manage node transactions and transaction information only gets updated to the node for validators to validate and mine into a block when the last transaction is signed by all involved nodes.
Lightning nodes
Lightning nodes could simply be referred to as the participants in a lighting network. These nodes connect together with other nodes in a off-chain format and at the same time are connected to the blockchain in an on-chain format. These nodes work peer to peer and payments are routed through indirectly connected nodes from sender to receiver in a lightning network.
Lightning channel
A lightning channel is a pathway through which secure payments are routed by nodes in a network. In order to establish a channel on a lightning network, you'll be required to make a deposit known as funding transaction.
It is estimated that there are more than 12000 nodes across the blockchain connected by over 50000 channels.
In summary, the constituents of a lighting network are the lighting nodes and lightning channels.
The lightning network has proven to tackle scalability effectively however it's not completely free from issues. One basic issue confronting this network is the issue of high bandwidth and memory requirements as the users on the network grows larger.
Different uses of lightning network
- Macropayments
- Cross chain payments
- Exchange arbitrage ...e.t.c.
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?
The lightning network allows nodes to perform transactions without any fees using digital wallets and channels. Before any transaction can take place off-chain, a lightning channel has to be created and established by one of the parties with a funding transaction. Establishing a channel is done on-chain and this is when the cost will be incurred however after the channel has been created, transactions made between peers would incur no transaction fee as this is done off-chain with an end-to-end encryption so that authorized nodes can have access to the channel. These transactions are called commitment transactions and they would keep updating the channel state off-chain.
After the last commitment transaction has been made the channel would be closed and this final transaction is the settlement transaction. Details of this would be recorded on-chain.

3) How does the routing of payment through intermediate nodes(or peers) become trustless with HTLC?
As mentioned earlier, activities in the lightning network are managed by smart contracts known as Hashed Timelock Contract Protocol (HTLC)". This feature utilizes a time based escrow to reduce counterparty risks encountered in decentralized p2p Smart contracts.
Here a secret phase would be made known to both nodes would be required to validate hash transactions within the time specified.
The security of HTLC is top-notch. In the event when funds have been let out by the sender and the receiver fails to enter the correct unlock phrase within the specified time period. The refund would automatically be rerouted back to the sender therefore any attempt by one party to fool the other party would most likely invalidate the transaction.
Lighting network allows nodes to route payments trustlessly to one another even without a direct channel.
Let's take an illustration
John has a channel to Candice
Candice has a channel to Brad
Brad has a channel to doppley.

Image created by me with canva
A lightning network would make it possible for John to make payment to doppley by routing through Candice and Brad.
Here, doppley would create a Hashed secret and send it to John. A transaction would therefore be initiated by John with the hashed secret and a lock time (feature of HTLC) would be added to the transaction before routing through Candice and Brad. It's very safe since only doppley knows the hashed secret and therefore only doppley can unlock it.

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
In order to attempt this task. The use of a non-custodial wallet supporting lightning channel transactions is required. Some custodial wallet that fulfills this criterion are listed above namely: Electrum(trampoline node), Phoenix e.t.c
However, I'm more familiar with the electrum wallet so I'd go ahead and use it for this task
Setting up my channel
Firstly, I have to create a channel. To do this, I'd open the Electrum wallet and head over to tab marked channels and click on open channel as displayed below. after clicking on open channel, a pop up message will appear on screen. Click Yes to continue.


Image taken from Electrum wallet
Aftwerward I'll enter the amount. since the minimum amount is 2 mbtc. ill enter that and select the default node(electrum trampoline) and hit the ok button.

image taken from Electrum wallet
We see the transaction details on the next pop-up. Here amount to be sent is 2 mBtc with a mining fee of 0.00542 mBtc incurred.
Next click send to establish the channel.

image taken from Electrum wallet
Now the channel has been established with remote peer ID displayed.

We can view info about the channel status. The channel ID is displaying as not yet available, the node alias as Electrum trampoline, channel capacity is 2 mbtc of which I can send 1.94736 to another peer. My can receive status is 0 because I've not made transactions yet using this channel.

The transaction details can be tracked using the blockchain miner since it's an on chain transaction. To do this I'll make use of the transaction ID

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?
E-commerce purchase
To make a E-commerce purchase I'll be making use of the Bitrefill platform
On the homepage I'll click browse products.

image taken from Bitrefill platform
In the products options. I'll choose to top up my mobile credit so I'll choose my service provider [9-mobile]

After choosing the service provider, I'll go ahead and fill in my sim number and click the purchase button.

I chose to get my transaction details via email and next I check the terms and conditions and privacy boxes and click continue.

Next I check it select the payment option as lightning BTC and copy invoice



Next, I access the Electrum wallet, navigate towards the send tab and paste the copied invoice in the pay to box. The details of the transactions will be automatically updated. Next, I click on pay.

A message will be displayed notifying you of the transaction details and effect.

After clicking yes, I received the top up instantaneously. It got me surprised

Does it incur fees?
Yes the Operation incurs minimal fees. The transaction performed above incurred a fee of 0.00006 mBtc
Does it record transaction on chain
No, it doesn't record the transaction on-chain. Activities performed on an off-chain channel are managed and recorded off-chain. It doesn't record the entire transaction on-chain because this will only burden and increase the workload of the main chain and this is against the concept of the lightning network. However, the initial deposit and final state of the transaction are recorded on-chain.
How swap function helps to improve sending and receiving capacity
The swap function enables lightning nodes to route funds between the blockchain and the lightning network, this it does without closing the lightning channel created. As explained above, by the process of sending funds via the lightning channel your sending capacity increases. Also by swapping your off-chain fund for an on-chain fund your receiving capacity will be increased.

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
To back up a wallet file, right click on the channel status and clickexport backup

Copy the QR code or text generated or click save.

Rename the backup file to whatever you want and save it

why and when is it needed
It is needed to close a channel and send funds on-chain in the event of losing the wallet file.
Note: channel backups do not serve as a channel restore point.
Indicate the funding Transaction, Commitment Transaction, and Settlement Transaction both in your wallet and Block Explorer
Funding transaction
This is the initial deposit that created the network channel. My funding transaction detail is displayed below


Commitment transaction
The commitment transaction details are indicated below in the transaction where I received the hashed secret in the form of an invoice from Bitrefill and routed the funds via the intermediary electrum trampoline node to the receiver (Bitrefill). The transaction includes a payment hash, lighting invoice and preimage hash.


Settlement transaction
This is the opposite of the funding transaction. The settlement transaction is the final transaction that closes the channel. The channel was closed immediately the receiver received funds and the transaction got validated.

This could be seen in the channel status which now displays "closed".


image sources are listed below
Electrum wallet
Bitrefill
canva
Conclusion
I found this particular task a bit difficult at first, probably because I missed the last lesson on multi sign wallet. The tasks felt so intimidating but I really wanted to tackle it either way. I'm glad I got to learn something new, as this is the first time I've experienced or performed any transaction using the lightning network and ohh haha I got butchered by the network fees. Thanks for the lecture professor @sapwood 👍
Concerning the questions assigned and in accordance with the respective rules highlighted. I've done my research and tried to tackle the advanced course. I was able to learn new things through the course of this task. I'd leave the assessment to the professors.
Thanks to the steemit team for this wonderful learning opportunity once again. It's been nice so far, I'm forever grateful.
Thanks for reading my write up and thanks for your support
Thanks for curating my content :)