{"id":6847,"date":"2023-02-02T16:08:00","date_gmt":"2023-02-02T15:08:00","guid":{"rendered":"https:\/\/affidaty.io\/blog\/?p=6847"},"modified":"2023-08-07T17:00:46","modified_gmt":"2023-08-07T15:00:46","slug":"lightning-network-transactions","status":"publish","type":"post","link":"https:\/\/affidaty.io\/blog\/en\/2023\/02\/lightning-network-transactions\/","title":{"rendered":"Lightning Network: decentralized disintermediation of payments"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&#8220;A purely peer-to-peer version of electronic cash would allow online payments to be sent directly from one party to another without going through a financial institution.&#8221;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This is what is stated in the original Bitcoin whitepaper created by Satoshi Nakamoto. In other words, Bitcoin was originally designed to be a digital cash system that guarantees irreversible <strong>transactions<\/strong> without going through financial institutions.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">However, despite the fact that part of the original abstract has been fully respected (today, BTC is censorship-resistant), it cannot be said to be a widespread, convenient, and usable payment form.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The problem with the Bitcoin protocol is that it is not scalable. The block time (the time to &#8220;mine&#8221; a block) is approximately 10 minutes, and the maximum block size is 1 megabyte. As a result, on average, the Bitcoin network can handle only 3.7 tps (<strong>transactions<\/strong> per second), which is significantly &#8220;poor&#8221; for a system that originally hoped to be a global payment system.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Enter the &#8220;<strong>Lightning Network<\/strong>,&#8221; a scalability solution that allows bitcoin to be transferred at instant speed and with virtually no commission costs &#8211; ideal for using bitcoin as a payment system.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">But what is the <strong>Lightning Network<\/strong> in practice?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The <strong>Lightning Network<\/strong> is nothing more than an application of Bitcoin, a decentralized messaging system (broadcasting) where instead of sending messages, value is exchanged.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It is formed by a network of Bitcoin payment channels between nodes; the larger the network, the greater the number of <strong>transactions<\/strong>, so more channels and nodes mean more success in transaction events.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Unlike the Bitcoin protocol, on the <strong>Lightning Network<\/strong>, only two <strong>transactions<\/strong> are written on the blockchain: the funding transaction and the settlement transaction. All other <strong>transactions<\/strong> take place without touching the blockchain (commitment transaction).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">With Bitcoin&#8217;s off-chain <strong>transactions<\/strong> (Lightning), node operators on both sides of the channel keep track of the balance with the so-called &#8220;Channel State.&#8221;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Simplifying to the extreme, it is a peer-to-peer protocol for making off-chain <strong>transactions<\/strong> between a private channel between us and the recipient; this channel must first be opened and effectively funded with funds from both parties (funding transaction), which will then exchange value for the desired number of <strong>transactions<\/strong>, at zero cost, unlimitedly and instantly (commitment transaction).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Once the operations are completed, and it is decided to close the channel, the balance is finalized on-chain and officially updated, taking into account all the <strong>transactions<\/strong> carried out (settlement transaction). In summary, it is a sort of accounting ledger where at the end of the operations, the balances of the two operators are counted and updated, writing the final result of their balance net of the <strong>transactions<\/strong> carried out.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s see how it works:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Alice wants to open a 1M satoshi channel to Bob&#8217;s node (0.01 BTC).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">She needs to know Bob&#8217;s node URI (The URI is a unique parameter like a web URL). URI = PubKey Node @ IP (or onion address)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example: 02e74c09ca720c891221164424651f62176a4737a4b2fd4f75a5befee127e90b9e@170.75.160.17:9735<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Alice creates a pair of private\/public keys using her Bitcoin node and informs Bob&#8217;s node that she wants to open a channel via the open_channel message (message in the LN protocol).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In turn, Bob also creates a new pair of private\/public keys and gives consent to the channel that Alice is creating, sending his public key to Alice via the accept_channel message.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Alice now creates a funding transaction (from her Bitcoin wallet) that sends 1M satoshi to the multisig address obtained from the two public keys (on-chain multisig transaction).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Alice does not yet transmit this transaction to the Bitcoin network but sends the transaction ID to Bob in an LN message (funding_created), along with her signature to allow Bob to create his commitment transaction.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Both create their commitment transaction. This transaction uses the funds of the Funding transaction: in Alice&#8217;s case, it will return all the funds, in Bob&#8217;s case, it will return zero satoshi.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Alice and Bob do not exchange the <strong>transactions<\/strong> because each of them can build them independently, using the signature of both; they, therefore, exchange only signatures.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Bob, therefore, provides a signature for Alice&#8217;s commitment transaction and sends this message using funding_signed.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now that the signatures have been exchanged, Alice can transmit the funding transaction to the Bitcoin network. The channel between Alice and Bob is open.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Alice&#8217;s funds are now on the channel as a local balance\/outbound capacity.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Alice can spend but NOT receive. <br>Bob can receive but NOT spend.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If Alice wants to receive on that channel, she must spend funds first.<\/p>\n\n\n\n<div style=\"height:40px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" src=\"data:image\/gif;base64,R0lGODlhAQABAIAAAAAAAP\/\/\/yH5BAEAAAAALAAAAAABAAEAAAIBRAA7\" data-src=\"https:\/\/affidaty.io\/blog\/wp-content\/uploads\/2023\/02\/Schermata-2023-02-01-alle-10.08.26.png\" alt=\"\" class=\"wp-image-11641 lazyload\"><noscript><img decoding=\"async\" width=\"742\" height=\"347\" src=\"https:\/\/affidaty.io\/blog\/wp-content\/uploads\/2023\/02\/Schermata-2023-02-01-alle-10.08.26.png\" alt=\"\" class=\"wp-image-11641\" srcset=\"https:\/\/affidaty.io\/blog\/wp-content\/uploads\/2023\/02\/Schermata-2023-02-01-alle-10.08.26.png 742w, https:\/\/affidaty.io\/blog\/wp-content\/uploads\/2023\/02\/Schermata-2023-02-01-alle-10.08.26-560x262.png 560w, https:\/\/affidaty.io\/blog\/wp-content\/uploads\/2023\/02\/Schermata-2023-02-01-alle-10.08.26-150x70.png 150w\" sizes=\"(max-width: 742px) 100vw, 742px\" \/><\/noscript><\/figure>\n<\/div>\n\n\n<div style=\"height:40px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So how does Alice send funds?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For on-chain <strong>transactions<\/strong>, she needs a public Bitcoin address. <br>For Lightning <strong>transactions<\/strong>, Alice needs an Invoice (Bolt 11).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">lnbc1m1p0m4sj8pp5rq72jn0qjpvut36u9et2j70n0l7rdake5v052kae5skumgz6zldqdqqcqzpgxqrrsssp577msvl9cvekq8z90lcvk86mpr0ve83zzwde9srcg0kesddstjqq9qy9qsqc7lyx5pdpr9wx2rv0y3cewg8qjja40lx4l3t93y84tvuz4x6429qh6wdczm97urd5p45hx4uy8qhyel5xfqfp987cr48867fyuccvpspqpxwaq<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Bitcoin&#8217;s public address is static and offline; <br>it can send as many funds as it wants, whenever it wants. <br><br>However, invoices are &#8220;dynamic&#8221; (as per Bolt 11 standard) and &#8220;online&#8221;; <br><br>Alice must request the invoice from the recipient at a specific time in the future (there is a deadline) and for a specific amount. <br><br>It cannot send funds if the recipient&#8217;s node is offline, and the same applies when it has to receive funds.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The real potential of the <strong>Lightning Network<\/strong> lies in the fact that it allows the sending of funds not only from A to B and vice versa, but also to C, D, E&#8230; without these being directly connected to the sender. This is done using a smart contract system called Hash Time-Locked Contracts (<strong>HTLC<\/strong>).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>HTLC<\/strong> = hash verification (H) + time expiration verification. <br>H = Hash(R)<br>R = Secret (also known as the Preimage).<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" src=\"data:image\/gif;base64,R0lGODlhAQABAIAAAAAAAP\/\/\/yH5BAEAAAAALAAAAAABAAEAAAIBRAA7\" data-src=\"https:\/\/affidaty.io\/blog\/wp-content\/uploads\/2023\/02\/Schermata-2023-02-01-alle-10.10.16.png\" alt=\"\" class=\"wp-image-11648 lazyload\"><noscript><img decoding=\"async\" width=\"439\" height=\"407\" src=\"https:\/\/affidaty.io\/blog\/wp-content\/uploads\/2023\/02\/Schermata-2023-02-01-alle-10.10.16.png\" alt=\"\" class=\"wp-image-11648\" srcset=\"https:\/\/affidaty.io\/blog\/wp-content\/uploads\/2023\/02\/Schermata-2023-02-01-alle-10.10.16.png 439w, https:\/\/affidaty.io\/blog\/wp-content\/uploads\/2023\/02\/Schermata-2023-02-01-alle-10.10.16-150x139.png 150w\" sizes=\"(max-width: 439px) 100vw, 439px\" \/><\/noscript><\/figure>\n<\/div>\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">For instance, if Alice needs to pay Eric but does not have a direct channel:<br><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Eric creates a preimage (the secret R) and sends Alice the hash of this secret. <br>Only Eric knows the secret.<br><\/li>\n\n\n\n<li>Alice creates an <strong>HTLC<\/strong> containing the hash sent by Eric plus a timelock of N Bitcoin blocks. <br>Within this HTLC, Alice specifies how many bitcoins should be sent: <br>x bitcoins for Eric, y bitcoins for the participants in the payment chain as a commission for sending it. <br>For example, Alice must pay 1 bitcoin to Eric, so she locks 1.0003 bitcoins in the <strong>HTLC<\/strong>, with 1 bitcoin for Eric and 0.0003 for the chain participants.<br><\/li>\n\n\n\n<li>Alice sends this <strong>HTLC<\/strong> to Bob. <br>If Bob does not discover Eric&#8217;s secret R within N blocks set by Alice, she will regain the locked bitcoins. <br>Bob is incentivized to discover R to get the commissions.<br><\/li>\n\n\n\n<li>Bob creates an HTLC containing the hash given by Eric to Alice and a new timelock of N-1, sending it to Carol. <br>If Carol does not discover Eric&#8217;s secret R within N-1 blocks set by Bob, she will regain the locked bitcoins. <br>Carol is incentivized to discover R to get the remaining commissions. Bob specifies how many bitcoins should be sent within this <strong>HTLC<\/strong>: 1 bitcoin for Eric, 0.0002 for the chain participants. If the payment is successful, Bob will pocket 0.0001 bitcoins.<br><\/li>\n\n\n\n<li>Carol creates an HTLC containing the hash given by Eric to Alice and a new timelock of N-2, sending it to Diana. <br>If Diana does not discover Eric&#8217;s secret R within N-2 blocks set by Carol, she will regain the locked bitcoins. Diana is incentivized to discover R to get the remaining commissions. Carol specifies how many bitcoins should be sent within this <strong>HTLC<\/strong>: 1 bitcoin for Eric, 0.0001 for Diana. <br>If the payment is successful, Carol will pocket 0.0001 bitcoins sent by Bob.<br><\/li>\n\n\n\n<li>Finally, Diana creates an <strong>HTLC<\/strong> containing the hash given by Eric to Alice and a new timelock of N-3, sending it to Eric.<br>Eric has the secret R used to create the initial hash. <br>If Eric does not unlock the <strong>HTLC<\/strong> within N-3 blocks, he will not receive the payment, and the other participants will regain their locked funds. <br>Eric is incentivized to unlock the <strong>HTLC<\/strong> to receive the payment.<br><\/li>\n\n\n\n<li>Eric unlocks the HTLC by revealing the secret to Diana. <br>Diana finally cashes in on the fees by revealing the secret to Carol and unlocking her HTLC. <br>Carol knows R and unlocks Bob&#8217;s <strong>HTLC<\/strong> to collect the fees he sent. <br>Bob now knows R and unlocks Alice&#8217;s <strong>HTLC<\/strong> to collect the fees. <br>Alice sent 1 bitcoin to Eric and 0.0003 bitcoin to the participants, who split the fees.<br><br><\/li>\n<\/ul>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" src=\"data:image\/gif;base64,R0lGODlhAQABAIAAAAAAAP\/\/\/yH5BAEAAAAALAAAAAABAAEAAAIBRAA7\" data-src=\"https:\/\/affidaty.io\/blog\/wp-content\/uploads\/2023\/02\/Schermata-2023-02-01-alle-10.10.58.png\" alt=\"\" class=\"wp-image-11649 lazyload\"><noscript><img decoding=\"async\" width=\"762\" height=\"678\" src=\"https:\/\/affidaty.io\/blog\/wp-content\/uploads\/2023\/02\/Schermata-2023-02-01-alle-10.10.58.png\" alt=\"\" class=\"wp-image-11649\" srcset=\"https:\/\/affidaty.io\/blog\/wp-content\/uploads\/2023\/02\/Schermata-2023-02-01-alle-10.10.58.png 762w, https:\/\/affidaty.io\/blog\/wp-content\/uploads\/2023\/02\/Schermata-2023-02-01-alle-10.10.58-560x498.png 560w, https:\/\/affidaty.io\/blog\/wp-content\/uploads\/2023\/02\/Schermata-2023-02-01-alle-10.10.58-150x133.png 150w, https:\/\/affidaty.io\/blog\/wp-content\/uploads\/2023\/02\/Schermata-2023-02-01-alle-10.10.58-750x667.png 750w\" sizes=\"(max-width: 762px) 100vw, 762px\" \/><\/noscript><\/figure>\n<\/div>\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Final conclusions:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The <strong>Lightning Network <\/strong>has the potential to be the killer app that could truly eliminate third-party payment intermediaries forever. It is a distributed, decentralized, fast, efficient, and cost-effective system with a high degree of privacy that, with the advent of CBDCs (central bank digital currencies), would be a valid libertarian and independent alternative.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;A purely peer-to-peer version of electronic cash would allow online payments to be sent directly from one party to another without going through a financial institution.&#8221; This is what is stated in the original Bitcoin whitepaper created by Satoshi Nakamoto. In other words, Bitcoin was originally designed to be a digital cash system that guarantees [&hellip;]<\/p>\n","protected":false},"author":141,"featured_media":5159,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jnews-multi-image_gallery":[],"jnews_single_post":{"subtitle":"","format":"standard","video":"","gallery":"","source_name":"","source_url":"","via_name":"","via_url":"","override_template":"0","override":[{"template":"2","single_blog_custom":"","parallax":"1","fullscreen":"0","layout":"right-sidebar","sidebar":"default-sidebar","second_sidebar":"default-sidebar","sticky_sidebar":"1","share_position":"float","share_float_style":"share-normal","show_share_counter":"1","show_view_counter":"1","show_featured":"1","show_post_meta":"1","show_post_author":"1","show_post_author_image":"1","show_post_date":"1","post_date_format":"default","post_date_format_custom":"Y\/m\/d","show_post_category":"1","show_post_reading_time":"1","post_reading_time_wpm":"300","show_zoom_button":"1","zoom_button_out_step":"2","zoom_button_in_step":"3","show_post_tag":"1","show_prev_next_post":"0","show_popup_post":"1","number_popup_post":"1","show_author_box":"1","show_post_related":"1","show_inline_post_related":"0"}],"override_image_size":"0","image_override":[{"single_post_thumbnail_size":"crop-500","single_post_gallery_size":"crop-500"}],"trending_post":"0","trending_post_position":"meta","trending_post_label":"Trending","sponsored_post":"0","sponsored_post_label":"Sponsored by","sponsored_post_name":"","sponsored_post_url":"","sponsored_post_logo_enable":"0","sponsored_post_logo":"","sponsored_post_desc":"","disable_ad":"0"},"jnews_primary_category":{"id":"","hide":""},"jnews_social_meta":{"fb_title":"","fb_description":"","fb_image":"","twitter_title":"","twitter_description":"","twitter_image":""},"footnotes":""},"categories":[349,525],"tags":[794,800,170,62,183,830,177,844,147],"coauthors":[567],"class_list":["post-6847","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-educational-eng","category-real-applications-en","tag-ai-eng","tag-bitcoin-en","tag-blockchain-en","tag-ledger","tag-pos-en","tag-satoshi-nakamoto-en","tag-smart-contracts-en","tag-speed","tag-transaction"],"_links":{"self":[{"href":"https:\/\/affidaty.io\/blog\/wp-json\/wp\/v2\/posts\/6847","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/affidaty.io\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/affidaty.io\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/affidaty.io\/blog\/wp-json\/wp\/v2\/users\/141"}],"replies":[{"embeddable":true,"href":"https:\/\/affidaty.io\/blog\/wp-json\/wp\/v2\/comments?post=6847"}],"version-history":[{"count":0,"href":"https:\/\/affidaty.io\/blog\/wp-json\/wp\/v2\/posts\/6847\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/affidaty.io\/blog\/wp-json\/wp\/v2\/media\/5159"}],"wp:attachment":[{"href":"https:\/\/affidaty.io\/blog\/wp-json\/wp\/v2\/media?parent=6847"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/affidaty.io\/blog\/wp-json\/wp\/v2\/categories?post=6847"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/affidaty.io\/blog\/wp-json\/wp\/v2\/tags?post=6847"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/affidaty.io\/blog\/wp-json\/wp\/v2\/coauthors?post=6847"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}