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

in hive-108451 •  4 years ago 

This is Season 3 Week 7 of Steemit Crypto Academy and I'm writing Homework Task for Professor @sapwood

Steemit Crypto Academy 7th Task.png

Question. 1)


Lightning Network


Scalability is the biggest problem that bitcoin is still facing even ten years after its launch. Lightning network is a decentralized protocol that uses smart contracts feature on the bitcoin blockchain to address the biggest issue of scalability by allowing instant payment services to all the users connected to a network.

The protocol uses micropayment channels and is a second layer technology coated on the bitcoin blockchain to bring desirable improvements in the speed and scalability of the network. Therefore it is designed to handle transactions of bitcoin at lesser cost and consuming lesser time. Supporting the bitcoin network eradicates the need for central institutions. 


Lightning node


Like in bitcoin the lightning network is an aggregation of nodes. These nodes which create the payment channels and form the basis of the lightning network are called the lightning network nodes. On a lightning network a node is a responsible link between a sender and the receiver. They validate the transactions and thus they are responsible for routing payment from the parties to the lightning network or vice versa. The nodes are connected to each other through channels. Other than intra-node connections which are off-chain they also have an on-chain connection with the blockchain.

These nodes are designed to use the best and the shortest way to forward the transaction to the receiving node at a minimal cost. Due to these nodes, even Micropayments of 1 Satoshi (SAT) can be done within the network.


Lightning Channels


Lightning channels are the links through which the nodes are connected to one another. It is like a 2 of 2 Multisig wallets. These channels serve as the basis of instant coordinated actions by the nodes in case of exchange/send and receive operations. A lightning channel is created as soon as the funds are deposited on the network in specified wallets and the transactions are broadcasted. 

The channel closes once the last transaction is verified by the main network or the blockchain. These channels allow transactions to be done first off-chain for instant procedures and the main network is updated later.

The system of interconnected nodes and channels for allowing transactions to happen off-chain is the key to improving the issue of scalability and slow-speed transactions. But the same problem can happen with lightning networks when the number of nodes is increased. To settle this issue the network introduced nodes like the Rendezvous Routing nodes and Trampoline nodes. These nodes are responsible for taking responsibility for the network resources and taking a record of all the transactions forwarded and improving the speed of the network.


image.png

Different Uses of the lightning Network


Lightning network nodes allow p2p direct transactions between sending and receiving nodes. When the transactions are initiated a channel is set both the parties can perform a number of off-chain transactions and once they decide to close the channel they change the status of the latest transaction broadcast to get it validated from the main blockchain. All the off-chain transactions are protected and encrypted by the HTLC protocol.

In addition to that, the lightning network also allows for intermediary dependent transactions in which the two nodes are dependent on the third node to forward the transaction. Lightning network is aimed at making bitcoin transactions cost-friendly and fast. With off-chain transactions the users do not have to worry about confirmations from the block for each independent transaction.

image.png

Question .2)


The first process in the functioning of a lightning network is the creation of the lightning channel

  • The interested parties or nodes create a link on the bitcoin blockchain and deposit funds on the created link which is referred to as the funding of a transaction. They do not need to broadcast the transactions as only the last transaction is broadcasted during the time of closing of the channel.

  • They then share the access keys similar to what happens in a Multisig wallet. Only the key holders can access the link.

  • Both parties can perform instant transactions without broadcasting the transactions.  A transaction only proceeds when both parties digitally sign it.

  • The cosigners have the freedom of doing as many transactions through the settles link they want with no cost. The status of every transaction changes to confirm when it is confirmed and signed by both the parties and the public ledger and the balance is also updated accordingly.

  • The channel can be closed when one or both of the parties desire any of the two parties to broadcast the copy of the last transaction and forward it to the main blockchain for validation.

  • So here we see the blockchain is only involved in two of the many transactions decreasing its workload to a great extent.

image.png

Question .3)


HTLC is a combination of cryptographic hash functions and a Time-lock algorithm. It is used to confirm transactions between peers within a limited designated time using the security key. In short, it is applied to commitment transaction scripts. It is a set of security measures in case the transaction is sent to the wrong address. If the receiving node fails to enter the right security key within the designated time by the HTLC the transaction gets locked and is refunded to the sender.

source

HTLC ensures security not only for the sender but also for the receiver. It makes sure that the sender cannot reverse the transaction once it is initiated before the time of HTLC is over or is regarded invalidated due to an error.

In the peer or intermediary routing case the network involves an intermediary node to send or forward transactions to nodes not directly involved in the channel. This relation is also secured by the HTCL security protocol.

What happens is that the sender receives a designed hashed secret code from the receiver. The sender then initiates the transaction secured with time-lock algo and HTCL and sends it to the intermediary node. In this whole scenario, only the receiving node of the transaction knows the hashed code and only he can confirm the transaction.

Then the intermediary node initiates another HTLC transaction with a status of pending that requires the receiver to ensure that the initial transaction can be unlocked within the specified time. Once the receiver validates the transaction the intermediary unlocks the transaction from the sender through the hash code obtained from the receiver. This can be repeated for multiple receivers and senders. 

image.png

Question .4)

Create an eCommerce Purchase


To create an eCommerce purchase, open the Electrum wallet

Click on the channels option on the top bar and click on open channel

A warning dialogue box will appear click yes to continue

The smallest deposit you need to open a channel is 2mbtc

The next step is to enter password

Select the fee rate (the above screenshot is taken before adjusting fee rate) it should be kept to minimum. Click send

Our channel is established but it will be useable after 3 confirmations

Click okay to proceed. As soon as the short id will be available 

the short channel ID is now available however the status of the channel has not yet changed to open

The channel was the opened

E-commerce purchase:

I made my account and then continue

Click on custom the lowest possible amount was 110 pkr I added my mobile number, and then click on purchase as a gift

The next thing I had to ask was personal details and then click on Add to cart

The order was added to the cart click on the cart and then click checkout

Next, select the method of payment lightning BTC.

Now copy your lightning invoice and past it in the electrum wallet

Click on send add the lightning invoice and click on yes on the dialogue box

The minimal fees

The transaction costs a minimal fee that is redistributed to the intermediary as a reward for sending the transaction to the receiver for validation. it was around 0.0001 mBTC.

Now if you check the order page the transaction will be done in seconds and order will be confirmed

Now I will close the channel

Go to electrum wallet and open channels right click on the channel and click close

Click on yes

The channel will be closed and all the transactions will be done on-chain in the form of a single transaction

As soon as the channel was closed my balance was returned to the on-chain wallet


image.png

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? 

These transactions are not recorded on the blockchain. Only the initial and the last transaction are recorded on the blockchain. All the other transactions are confirmed and validated by the nodes within the network. This is done to bring down the load on the main blockchain and increase its scalability. In addition to that when lesser nodes are involved in validating transactions the cost is lower.

Let me show you

How does Swap Function help to improve sending and receiving capacity?

The swap function in the lightning network is the function that allows you to transfer funds between the blockchain and the network. the swapping does not affect the channel created nor does it close it.

The swapping however increases the sending capability of the wallet when you swap a fund in a blockchain for a lightning fund. On the contrary, it increases the receiving capability of your wallet when you swap lightning funds for the blockchain fund.

image.png

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)

  • Go to channel 

  • Right click on the channel

  • Click on backup and then save it

 

After clicking save, save it on your computer.

These backups prove useful when you want to load the transaction details later on this wallet for this channel. But in case you lost the wallet file you can only use the backup file to close the channel.

Funding Transaction

The funding transaction in the lightning network is the initial transaction in the form of a funds transfer while opening the channel that created the lightning channel in the first place. Below I have indicated my initial or funding transaction.

Commitment Transaction

Commitment transactions are the follow-up transactions we perform off-chain. During these transactions, the transaction is forward to the receiving node from the sending node with or without the involvement of the intermediary node. When the transaction is through an intermediary a minimal fee is charged otherwise it is free of cost.

Settlement Transaction

The last transaction after which the channel is closed is called the settlement node. This transaction is broadcasted on the blockchain and the block validators verify all the off-chain transactions as one transaction on-chain. Once validated, the channel is fully closed and the lightning network funds are transferred to the blockchain fund balance.

image.png

Conclusion

Lightning network is a very fast supportive layer for the bitcoin blockchain. With a large number of transactions happening off-chain at the lower coat and fast speed it surely acts to facilitate bitcoin users. The transactions are encrypted and protected and hence traders can trade freely. Creating a channel with Electrum was also very easy and comprehensive. Overall this week’s assignment was very informative.

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