{"id":25005,"date":"2016-06-07T19:15:03","date_gmt":"2016-06-07T19:15:03","guid":{"rendered":"http:\/\/ci027cfe6a200e2697"},"modified":"2025-01-28T19:04:28","modified_gmt":"2025-01-28T19:04:28","slug":"understanding-the-lightning-network-part-creating-the-network-1465326903","status":"publish","type":"post","link":"https:\/\/bitcoinmagazine.com\/technical\/understanding-the-lightning-network-part-creating-the-network-1465326903","title":{"rendered":"Understanding the Lightning Network, Part 2: Creating the Network"},"content":{"rendered":"<div id=\"bsf_rt_marker\"><\/div><figure><img decoding=\"async\" src=\"https:\/\/bitcoinmagazine.com\/wp-content\/uploads\/2025\/01\/understanding-the-lightning-network.png\" title=\"\"><\/figure>\n<p>The Lightning Network is probably the most highly anticipated technological innovation to be deployed on top of Bitcoin. The payment layer, first proposed by Joseph Poon and Tadge Dryja about a year ago, promises to support a virtually unlimited number of off-chain transactions among users, at nearly no cost \u2013 while leveraging the security offered by Bitcoin.<\/p>\n<p>At least three companies \u2013 Poon and Dryja&#8217;s <a href=\"http:\/\/lightning.network\/\" target=\"_blank\" rel=\"noopener\">Lightning<\/a>, <a href=\"https:\/\/blockstream.com\/2015\/09\/01\/lightning-network\/\" target=\"_blank\" rel=\"noopener\">Blockstream<\/a> and <a href=\"https:\/\/www.blockchain.com\/thunder\/index.html\" target=\"_blank\" rel=\"noopener\">Blockchain<\/a> \u2013 are currently working on implementations of the technology. But few outside this small technological frontline fully grasp how the \u201cfuture of micropayments\u201d is set to boost Bitcoin\u2019s capabilities.<\/p>\n<p>In this three-part series, <em>Bitcoin Magazine<\/em> lays out the basic building blocks of the Lightning Network, and shows how they fit together to realize this upcoming protocol layer.<\/p>\n<p>The <a href=\"https:\/\/bitcoinmagazine.com\/articles\/understanding-the-lightning-network-part-building-a-bidirectional-payment-channel-1464710791\">first part<\/a> of this series covered basic building blocks, and explained how these are used to establish bidirectional payment channels. This second part explains how bidirectional payment channels are turned into a network.<\/p>\n<p><strong>The Network<\/strong><\/p>\n<p>In the previous article, Alice and Bob established a bidirectional payment channel. Now, Alice wants to pay one bitcoin to a third person, Carol.<\/p>\n<p>To do so, Alice and Carol could open up a payment channel between them. But they don&#8217;t actually need to. As it turns out, Bob and Carol already have a mutual channel, so Alice can simply pay Carol through Bob.<\/p>\n<p>Specifically, Alice can pay Bob one bitcoin, and Bob can pay Carol one bitcoin.<\/p>\n<p>However, Alice doesn&#8217;t really trust Bob \u2013 or Carol for that matter. She&#8217;s afraid that if she pays Bob, Bob will never actually pay Carol. Or perhaps Bob <em>will<\/em> pay Carol, but Carol will claim she never received the money, and Alice wouldn&#8217;t know whom to blame.<\/p>\n<p>Alice, therefore, wants to ensure that she only pays Bob one bitcoin, <em>if<\/em> he also pays Carol one bitcoin. This is accomplished (in part) with a simple cryptographic trick.<\/p>\n<p>When Alice wants to send Carol a bitcoin, she tells Carol to create a value (a random string of numbers) and send her the hash. Alice also tells Carol to exchange the original value with Bob for a bitcoin.<\/p>\n<p>Alice, meanwhile, takes the hash from Carol, turns to Bob, and tells Bob she will give him a bitcoin if he provides her the corresponding value (which only Carol has).<\/p>\n<p>So, Bob turns to Carol, and gives Carol one bitcoin in return for the value.<\/p>\n<p>Then, Bob turns back to Alice with the value. Alice knows Bob must have gotten the value from Carol in exchange for a bitcoin, and therefore concludes Carol got her bitcoin. So Alice can confidently give Bob a bitcoin.<\/p>\n<p>Everybody is happy.<\/p>\n<p>Well. .. <em>almost<\/em> everybody is happy.<\/p>\n<p>In this \u201cnaive\u201d scenario, middleman Bob still has to trust Alice and Carol. Bob has to trust Carol to really give him the value after he sent her a bitcoin, and Bob has to trust Alice to really give him a bitcoin once he presents her the value.<\/p>\n<p>The bitcoin-for-value trades must therefore be absolutely guaranteed along the network. More specifically: <em>if<\/em> Bob gives a bitcoin to Carol, he <em>must<\/em> be guaranteed to get a bitcoin back from Alice.<\/p>\n<p>That&#8217;s where Hash Time-Locked Contracts (HTLCs) come in.<\/p>\n<p><strong>Hash Time-Locked Contracts<\/strong><\/p>\n<p>So Alice and Bob want to exchange a bitcoin for the value through an HTLC. (And Bob and Carol also want to a bitcoin exchange for that same value &#8211; but never mind that for now.)<\/p>\n<p>To do so, rather than sending Bob a bitcoin straight up, Alice sends a bitcoin to a new (and, again: funky) multisig address. The bitcoins locked up on this address can be unlocked in two different ways.<\/p>\n<p>The first option is for Bob to include his signature <em>and<\/em> the value.<\/p>\n<p>The second option is for Alice to include her own signature. However, this option has a <a href=\"https:\/\/bitcoinmagazine.com\/articles\/checklocktimeverify-or-how-a-time-lock-patch-will-boost-bitcoin-s-potential-1446658530\">CLTV-timelock<\/a> on it: Alice can sign and broadcast the transaction only after \u2013 say \u2013 two weeks have gone by.<\/p>\n<p>This means that Bob has two weeks to create a subsequent transaction in which he includes his signature and the value, and broadcast it to send the bitcoin from the funky multisig address to himself. As such, this trade is guaranteed. Bob can <em>only<\/em> claim Alice&#8217;s bitcoin if he provides the value: broadcasting it over the Bitcoin network makes it publicly visible for Alice to see.<\/p>\n<p>And if Bob doesn\u2019t provide the value in time, there is a \u201ctime-out alternative\u201d for Alice to get her bitcoin back. Simple.<\/p>\n<p>Back to the network, as that\u2019s really why this HTLC setup is needed.<\/p>\n<p>As mentioned, not only Alice and Bob, but also Bob and Carol established an HTLC. So, <em>if<\/em> Carol claims her bitcoin from Bob, Bob <em>will<\/em> get the value in return; it will be visible on the blockchain.<\/p>\n<p>Therefore,<em> if<\/em> that happens, Bob is guaranteed to get a bitcoin from Alice as well. Bob can take the value that Carol made publicly visible on the blockchain, include it in his HTLC with Alice, and claim a bitcoin for himself, too. The two channels are effectively linked.<\/p>\n<p>As a final detail, it <em>is<\/em> important that Bob gets the value from Carol <em>before<\/em> Alice can reclaim her bitcoin from Bob. If Bob gets the value from Carol only <em>after<\/em> Alice already reclaimed hers back, Bob is stuck in the middle after all. The time-out in Bob and Carol\u2019s HTLC must therefore expire <em>before<\/em> the time-out in Alice and Bob\u2019s HTLC expires. (For example after exactly ten days, instead of two weeks. This is also why HTLCs need CheckLockTimeVerify (CLTV)&#8211;and not CheckSequenceVerify (CSV).)<\/p>\n<p>Lastly, there&#8217;s one more problem to solve: for the Lightning Network to be useful, all this must be accomplished off-chain. How this is done, is covered in the <a href=\"https:\/\/bitcoinmagazine.com\/articles\/understanding-the-lightning-network-part-completing-the-puzzle-and-closing-the-channel-1466178980\">third<\/a> and final article of this series.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Lightning Network is probably the most highly anticipated technological innovation to be deployed on top of Bitcoin. The payment layer, first proposed by Joseph Poon and Tadge Dryja about a year ago, promises to support a virtually unlimited number of off-chain transactions among users, at nearly no cost \u2013 while leveraging the security offered [&hellip;]<\/p>\n","protected":false},"author":2509,"featured_media":24975,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[35],"tags":[329,1313,1279,2525],"class_list":{"0":"post-25005","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-technical","8":"tag-cryptography","9":"tag-payment-channels","10":"tag-smart-contracts","11":"tag-timelock"},"author_data":{"id":2509,"name":"Aaron van Wirdum","nicename":"aaron-van-wirdum","avatar_url":"https:\/\/bitcoinmagazine.com\/wp-content\/uploads\/2024\/12\/aaron-van-wirdum-96x96.jpg"},"featured_image_url":"https:\/\/bitcoinmagazine.com\/wp-content\/uploads\/2024\/11\/understanding-the-lightning-network.png","_links":{"self":[{"href":"https:\/\/bitcoinmagazine.com\/wp-json\/wp\/v2\/posts\/25005","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bitcoinmagazine.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bitcoinmagazine.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bitcoinmagazine.com\/wp-json\/wp\/v2\/users\/2509"}],"replies":[{"embeddable":true,"href":"https:\/\/bitcoinmagazine.com\/wp-json\/wp\/v2\/comments?post=25005"}],"version-history":[{"count":0,"href":"https:\/\/bitcoinmagazine.com\/wp-json\/wp\/v2\/posts\/25005\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/bitcoinmagazine.com\/wp-json\/wp\/v2\/media\/24975"}],"wp:attachment":[{"href":"https:\/\/bitcoinmagazine.com\/wp-json\/wp\/v2\/media?parent=25005"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bitcoinmagazine.com\/wp-json\/wp\/v2\/categories?post=25005"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bitcoinmagazine.com\/wp-json\/wp\/v2\/tags?post=25005"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}