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

in hive-108451 •  4 years ago  (edited)

untitleddesign_1_original-139.png

my line.png

LIGHTNING NETWORK, NODES AND CHANNELS

LIGHTNING NETWORK

Lightning network is a layer 2 off-chain solution built on the bitcoin network. Imagine the bitcoin network of interconnected nodes as the primary layer, then lightning network will be another network that allows different parties to carry out transactions that would have been done on the bitcoin network.

The transactions carried out on the lightning network are not only cheaper and faster, they are also all broadcasted to the bitcoin network at some point. This implies that the lightning network, though a different network, still connects to the bitcoin network. It is actually built on the bitcoin network as an off-chain second layer solution.

LIGHTNING NETWORK CHANNEL

Lightning network nodes are the softwares that connect together to make up the lightning network. They are the computing components of the network that facilitate the sending and receiving of bitcoins on the lightning network. It is imperative to say that they are the core components and the building blocks of the lightning network.

LIGHTNING NETWORK CHANNEL

A Lightning network channel is a transaction apparatus used to facilitate transactions between parties on the lightning network. It helps to consider the transacting parties to be situated at both ends with the channel in between.

The channel is open when a party locks in a unit of the asset (BTC) in an on-chain transaction, through lightning network. This becomes the channels opening balance. The user who locked in the funds can go ahead to spend the funds until it's exhausted.


untitleddesign_1_original-146.png

It is possible for a node to want to transact with another node they are not channelled to through another node. E.g Node A wants to transact with Node C through Node B but is not channelled to Node C.

The criteria for this possibility is that Node A must have a channel with Node B and Node B must have a channel with Node C. Node B will usually request a fee from Node A in such cases.

HOW LIGHTNING NETWORK ACHIEVES NEAR INSTANT SETTLEMENT AND NEAR INFINITE SCALABILITY

On lightning network, only the opening and closing balances of a channel are recorded on the bitcoin blockchain. Every other transaction on the channel is validated by the node immediate to the peer involved in the transaction unlike bitcoin blockchain transactions that must be verified by every node on the bitcoin network.

This enables the lightning network to carry out transactions faster and achieve near instant settlement. Near infinite scalability is also achieved as more and more nodes can join the network, making validation for more peers possible.

USES OF LIGHTNING NETWORK

LOW TRANSACTION FEES

On lightning network, the miner fee is non-existent. Thus, lightning network is used for bitcoin transactions where low transaction fees are desired

FAST TRANSACTIONS

Lightning network also facilitate fast transactions as just one node is enough to validate a transaction. Thus it can be used for bitcoin transactions where speed is required.

PRIVACY

On the lightning network, nodes don't whisper validated transactions to other nodes. This is enhanced and thus makes the network useful when enhanced privacy is desired.

SCALABILITY

The lightning network is used to achieve scalability on the bitcoin network as it facilitates fast and cheaper transactions and enables the bitcoin network to process more payments.

my line.png

HOW LIGHTNING NETWORK FACILITATES TRANSACTIONS BETWEEN PEERS

Lightning network facilitates transactions between peers via channels. Each channel is exactly a 2of2 multi-sig wallet and each transaction is validated by just one node on the lightning network.

MAKING A TRANSACTION WITHOUT FEES

A transaction is usually carried out when a channel is opened between two transacting peers. Any of the peer can open the channel by locking-in a certain amount on-chain (ie. on the bitcoin chain).

When this locking-in of the asset on-chain is done, the peer who locked-in the asset can spend it with the other peer or a merchant or an eCommerce store.

The transactions carried out is done with little or no transaction fee. The transaction could also be single, multiple or recurring transactions.

On the lightning network, only the initial locking in of the asset which opens the channel and the final balance of the channel is record on-chain (i.e on the bitcoin blockchain).

The first transaction that binds or locks in a capital on-chain is known as a Funding transaction while every transaction that takes place on the chain after the funding transaction is referred to as Commitment transaction. Usually, the channel is closed with the last commitment transaction which will also reflect the channel's final balance. This last commitment transaction is referred to as the Settlement transaction.

It is only the funding transaction and the last commitment transaction that is recorded on-chain, the rest of the commitment transactions are recorded and carried out off-chain, on the lightning network.

my line.png

HOW HTLC MAKES ROUTING PAYMENTS THROUGH INTERMEDIATE NODES TRUSTLESS

Lightning network permits transactions between peers through channels. In a case where a peer needs to transact with another peer they are not channelled to, such peer will need an intermediary node.

When using an intermediary node to transact with a distant peer, the transaction is kept trustless through Two mechanisms

  • Hash lock

  • Time lock

These two combine to form HTLC (Hashed Timelocked Contract).

When a peer (let's say peer A) is sending a payment to a distant peer (let's say peer C) through an intermediate node (let's say node B), the funds committed to the transaction by peer A is secured by a hash lock and a time lock.

First, Peer A creates a secret and hashes it. Next, a time lock and the hash value generated is then included in the transaction's HTLC script. Only the peer who knows the secret value can redeem the payment and the redemption must be done within the set time lock.

Failure of the receiving peer to redeem the payment within the preset time will invalidate the payment. Also, the sender of the payment cannot retract it until the time lock is over. The sender can however redeem the payment after the time lock.

Thus, the HTLC (Hashed Timelocked Contract) ensure trustless transfer of funds between peers through an intermediate node.

my line.png

REAL TRANSACTION USING LIGHTNING CHANNEL ON MOBILE

I would have love to use my electrum wallet for this demonstration but..


Screenshot_20210813-172704.png

Lightning can't be used on my mobile version of electrum. I could fix this but I decided to go for another option. I'm choosing phoenix because it runs natively on lightning network.


Screenshot_20210813-173418.png

Once an account is opened on phoenix, there's no lightning network channel opened until you receive BTC in your wallet.

Once you receive BTC in your wallet, a lightning network channel automatically opens. E.g I received 0.00023659 BTC (23,659 sat) and I now have a channel opened with my capacity being 0.00049145 BTC (49,145 sat)


Screenshot_20210813-211843.png


Screenshot_20210813-220119.png

ECOMMERCE TRANSACTION

I decided to top up my airtime using bitrefill


Screenshot_20210813-222113.png

I simply enter the amount I want and proceed to checkout


Screenshot_20210813-222718.png


Screenshot_20210813-223003.png

I had to enter an email so as to be updated on the status of the transaction. Then I selected 'Lightning' as my preferred payment option


Screenshot_20210813-223751.png


Screenshot_20210813-223833.png

I click on 'pay in wallet' and them I'm automatically redirected to my phoenix wallet from my browser


Screenshot_20210813-223920.png


20210813223951.gif

From my wallet I completed the payment.


Screenshot_20210813-224157.png


Screenshot_20210813-224432.png

A short while later, the airtime arrived my mobile number


Screenshot_20210813-224647.png

The fee charged for this bitcoin transaction was 11 sat


Screenshot_20210813-224810.png

Now one significant part of this demonstration was that I went to check a block explorer with the hash of the transaction and with my wallet address but found nothing


Screenshot_20210813-232653.png


Screenshot_20210813-232504.png

Next I closed the channel


Screenshot_20210813-232920.png


Screenshot_20210813-233603.png


Screenshot_20210813-233701.png


Screenshot_20210813-233819.png

Closing the channel incurred fees and it is recorded on-chain. As can be seen below. The fee incurred was 0.00000343BTC.


Screenshot_20210814-002142.png


Screenshot_20210814-062640.png

However, take a closer look at the transaction details, you'll discover that more than my final balance of 0.00010223 BTC was sent.

Now, checking with my binance wallet which the receiving address (1N8pTrDKYbzrGRv7R3ZPjEnrZ6UYq6zGPk) belong to, I received the exact 0.00010223.


Screenshot_20210814-065056.png


Screenshot_20210814-065356.png


Screenshot_20210814-070139.png

This implies that, though the settlement transaction incurred a fee as it was done on-chain, I was excluded from paying the fee.

Note: The transaction where I bought airtime from bitrefill was not found on blockchain explorer. This is because the transaction was carried out of chain, on the lightning network.

SWAP FUNCTION

Swapping on Lightning network is the act of converting on-chain funds to Lightning funds and converting Lightning funds to on-chain funds. This is necessary because in-bound capacity during transactions can get bottlenecked for the merchant.

Also, when opening a channel especially for the first time, conversion from on-chain funds to Lightning funds is required and this is done by swapping.

When on-chain funds are converted to Lightning funds for use on the Lightning network, the sending capacity is improved. This means the user can send more funds or spend more at the ecommerce online store.

When Lightning funds are converted to on-chain funds, possibly to pay provider fees or foot some bills, the receiving capacity is improved. This means that when the user can receive more funds as payments or otherwise.

On phoenix wallet, the swap function is automatated.


Screenshot_20210813-203731.png

HOW SWAP FUNCTION IMPROVES CAPACITY

Converting on-chain funds to lightning funds provides funds to be used on the lightning network, thereby improving the sending capacity.

Converting lightning funds to on-chain funds reduces the in-bound capacity bottleneck thereby improving the receiving capacity.

my line.png

BACKING UP A WALLET FILE (CHANNEL BACKUP)

Channel backup on phoenix wallet is done automatically. The French company ACINQ who owns the wallet is always the funding peer in every phoenix transaction. They are a node on the lightning network and are always available as they always have assets at stake on the network. Whenever a user needs to restore their channel, all they need is to restore their wallet with their seed phrase and everything returns.


Screenshot_20210814-104436.png

Usually, Lightning channel backup is needed because if the wallet or the device in which the wallet is is lost, the channel opened and the funds in it will be lost.

Lightning channel backup is done when the channel is still on. For phoenix however, backup is done automatically and all the user needs to do is to restore their wallet.

FUNDING TRANSACTION, COMMITMENT TRANSACTION AND SETTLEMENT TRANSACTION

Below, is a screenshot of the funding, commitment and settlement transactions.

  • Funding transaction is pointed with a green arrow

  • Commitment transaction is pointed with a yellow arrow

  • Settlement transaction is pointed with a blue arrow


Screenshot_20210814-110145.png


FUNDING TRANSACTION IN PHOENIX AND IN BLOCKCHAIN EXPLORER


Screenshot_20210814-110551.png


Screenshot_20210814-110714.png


COMMITMENT TRANSACTION IN PHOENIX AND IN BLOCKCHAIN EXPLORER


Screenshot_20210814-111057.png


Screenshot_20210814-111229.png


Screenshot_20210814-111444.png


SETTLEMENT TRANSACTION IN PHOENIX AND IN BLOCKCHAIN EXPLORER


Screenshot_20210814-111530.png


Screenshot_20210814-111712.png


Screenshot_20210814-112157.png

my line.png

CONCLUSION

It's been a very interesting course beginning from the lecture on multi-sig wallet and now this - lightning network. I've learnt about phoenix wallet, a super easy non-custodial wallet that automates all the processes on the lightning network. You just use it as a normal wallet, the swapping and backing up is being done automatically.

With the lightning work, BTC transactions are not only super fast but also super cheap. These transactions, apart from the funding and settlement transaction are not done on-chain but off-chain, hence they are not accountedin the blockchain explorer. The funding and settlement transactions however are on-chain transactions.

Thanks for reading.

Cc:
@sapwood

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