<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>lightning Archives - The Story of David Kaspar</title>
	<atom:link href="https://blog.davidkaspar.com/archives/tag/lightning/feed" rel="self" type="application/rss+xml" />
	<link>https://blog.davidkaspar.com/archives/tag/lightning</link>
	<description>Online journal and ponderings about the Internet, gadgets and photography.</description>
	<lastBuildDate>Sun, 26 Dec 2021 13:40:47 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9</generator>

<image>
	<url>https://blog.davidkaspar.com/wp-content/uploads/2020/05/chubby.gif</url>
	<title>lightning Archives - The Story of David Kaspar</title>
	<link>https://blog.davidkaspar.com/archives/tag/lightning</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Rebalancing lightning channels after a lightning liquidity swap</title>
		<link>https://blog.davidkaspar.com/archives/2021/12/rebalancing-lightning-channels-after-a-lightning-liquidity-swap.php</link>
					<comments>https://blog.davidkaspar.com/archives/2021/12/rebalancing-lightning-channels-after-a-lightning-liquidity-swap.php#respond</comments>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Sat, 25 Dec 2021 20:36:50 +0000</pubDate>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[bitcoin]]></category>
		<category><![CDATA[lightning]]></category>
		<category><![CDATA[tutorial]]></category>
		<guid isPermaLink="false">https://blog.davidkaspar.com/?p=474</guid>

					<description><![CDATA[<p>Well done, you have participated in a lightning liquidity swap and all channels are open (future post about how to actually do the swap and common problems). Now you should see a new incoming channel and a new outgoing channel. The incoming channel will have all the liquidity remotely and your outgoing channel will have &#8230; <a href="https://blog.davidkaspar.com/archives/2021/12/rebalancing-lightning-channels-after-a-lightning-liquidity-swap.php" class="more-link">Continue reading<span class="screen-reader-text"> "Rebalancing lightning channels after a lightning liquidity swap"</span></a></p>
<p>The post <a href="https://blog.davidkaspar.com/archives/2021/12/rebalancing-lightning-channels-after-a-lightning-liquidity-swap.php">Rebalancing lightning channels after a lightning liquidity swap</a> appeared first on <a href="https://blog.davidkaspar.com">The Story of David Kaspar</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Well done, you have participated in a lightning liquidity swap and all channels are open (future post about how to actually do the swap and common problems).</p>



<p>Now you should see a new incoming channel and a new outgoing channel. The incoming channel will have all the liquidity remotely and your outgoing channel will have all the liquidity locally.</p>



<p>This means that no lightning payments can be routed via you. You have to balance those channels to have 50% local and 50% remote liquidity.</p>



<p>In summary your will pay yourself half of the channel capacity and route the payment through all the swap participants. This will result in all channels in the swap to become 50/50 balanced.</p>



<p><img decoding="async" width="150" height="121" class="wp-image-481" style="width: 150px;" src="https://blog.davidkaspar.com/wp-content/uploads/2021/12/Screen-Shot-2021-12-25-at-15.21.05.png" alt="triangle swap" srcset="https://blog.davidkaspar.com/wp-content/uploads/2021/12/Screen-Shot-2021-12-25-at-15.21.05.png 321w, https://blog.davidkaspar.com/wp-content/uploads/2021/12/Screen-Shot-2021-12-25-at-15.21.05-300x243.png 300w" sizes="(max-width: 150px) 85vw, 150px" />Case 1: Now for a simple triangle swap, where there are only two other participants, you can use the plugin <a href="https://www.thunderhub.io/" target="_blank" rel="noreferrer noopener">Thunderhub</a> or <a href="https://github.com/Ride-The-Lightning/RTL" target="_blank" rel="noreferrer noopener">Ride The Lightning</a> (RTL) to perform this payment.</p>



<p>Select the node you connected to as Outgoing. You should see 100% blue bar, this means the balance is all on your side (local).</p>



<p>Select the node that connected to you as Incoming. You should see a 100% green bar, this means that the balance is all on the other side (remote).</p>



<figure class="wp-block-image size-full"><img fetchpriority="high" decoding="async" width="777" height="384" src="https://blog.davidkaspar.com/wp-content/uploads/2021/12/Screen-Shot-2021-12-25-at-15.22.26.png" alt="" class="wp-image-488" srcset="https://blog.davidkaspar.com/wp-content/uploads/2021/12/Screen-Shot-2021-12-25-at-15.22.26.png 777w, https://blog.davidkaspar.com/wp-content/uploads/2021/12/Screen-Shot-2021-12-25-at-15.22.26-300x148.png 300w, https://blog.davidkaspar.com/wp-content/uploads/2021/12/Screen-Shot-2021-12-25-at-15.22.26-768x380.png 768w" sizes="(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px" /><figcaption>Thunder Hub rebalance channel dialog</figcaption></figure>



<p>Set the fees to something you are comfortable with, perhaps 100 for each field.</p>



<pre class="wp-block-verse"> If your swap participants have done their job they have lowered all fees to 0 and the rebalance should be free.</pre>



<p>Set the amount to <strong>Fixed</strong> and half the channel size (or slightly less if you get liquidity problems).</p>



<p>Hit rebalance!</p>



<p><img decoding="async" width="150" height="123" class="wp-image-482" style="width: 150px;" src="https://blog.davidkaspar.com/wp-content/uploads/2021/12/Screen-Shot-2021-12-25-at-15.21.35.png" alt="Pentagram swap" srcset="https://blog.davidkaspar.com/wp-content/uploads/2021/12/Screen-Shot-2021-12-25-at-15.21.35.png 334w, https://blog.davidkaspar.com/wp-content/uploads/2021/12/Screen-Shot-2021-12-25-at-15.21.35-300x245.png 300w" sizes="(max-width: 150px) 85vw, 150px" />Case 2: For any more complicated swaps like a square (4 participants) or a pentagram (5 participants) you will have to build an exact payment route through all the participants to do the balancing correctly (and cheaply).</p>



<h2 class="wp-block-heading">You still want to pay yourself half the channel size but it has to go out to the node you connected to, then via each participant in the correct order, and then back in via the node that connected to you.</h2>



<p>You will have to use the <code>lncli</code> command after you SSH to your node to perform this more complicated payment.</p>



<p>Some swap sites like <a href="https://lightningnetwork.plus/" target="_blank" rel="noreferrer noopener">lightningnetwork.plus</a> will prepare the correct route for you already. Please start by running the provided command to test whether the route works correctly:</p>



<p><code>lncli buildroute --amt [AMOUNT] --hops 1a613234234116def5de68...,7243578234df738...,87827ea233...,014aea43432244...,0a34324445...</code></p>



<pre class="wp-block-verse">Replace the example hops with the actual <meta charset="utf-8">public keys of the nodes in your swap.</pre>



<p>If all is well you will get a json output with a prebuilt route and the cost for this transfer:</p>



<p><code>{<br>   "route": {<br>      "total_time_lock": 715773,<br>      "total_fees": "4",<br>      "total_amt": "1250004",<br>      "hops": [<br>        {…</code></p>



<pre class="wp-block-verse">If the fees seem too high then you should start a dialog with the other swap participants to lower their channel fees. Skill levels of the participants varies widely and you may need to assist them.</pre>



<p>You can now prepare an invoice which will be the payment to yourself since the routing appears to be successful:</p>



<p><code>lncli addinvoice --amt [AMOUNT]</code></p>



<p>This command will return you a PAYMENT_ADDR and a R_HASH that you have to use in the below step.</p>



<p>You can now run the command provided by your service that will in a single line build the route using <meta charset="utf-8"><code>lncli buildroute</code>,  add a multi-payment record (mpp) using the <code>jq</code> utility and then send the payment using <code>lncli sendtoroute</code>:</p>



<p><code>lncli buildroute --amt [AMOUNT] --hops 1a613234234116def5de68…,7243578234df738…,87827ea233…,014aea43432244…,0a34324445… | jq -r '(.route.hops[-1] | .mpp_record) |= {payment_addr:"[PAYMENT_ADDR]", total_amt_msat: "[AMOUNT]"}' | lncli sendtoroute --payment_hash=[R_HASH] -</code></p>



<pre class="wp-block-verse">You can also construct the hops manually by hand by starting with the node you connected to, traverse the participants one by one and finishing with the public key of your own node.</pre>



<p>If all goes well, you should get a SUCCESS result code and also information about the total fees paid.</p>



<p>Congratulations, you are now balanced!</p>



<p class="has-medium-font-size">Common problems with liquidity rebalancing</p>



<p class="has-normal-font-size"><img loading="lazy" decoding="async" width="10" height="19" class="wp-image-486" style="width: 10px;" src="https://blog.davidkaspar.com/wp-content/uploads/2021/12/119499525762661096tab_right.svg_.hi_.png" alt="" srcset="https://blog.davidkaspar.com/wp-content/uploads/2021/12/119499525762661096tab_right.svg_.hi_.png 318w, https://blog.davidkaspar.com/wp-content/uploads/2021/12/119499525762661096tab_right.svg_.hi_-157x300.png 157w" sizes="auto, (max-width: 10px) 85vw, 10px" /> Not all channels have been set up.</p>



<p>The swap participants are reporting that they all have opened channels but how can you be sure? The <meta charset="utf-8"><code>lncli buildroute</code> command is a quick way to test that the route is correctly set up. </p>



<p class="has-normal-font-size"><img loading="lazy" decoding="async" width="10" height="19" class="wp-image-486" style="width: 10px;" src="https://blog.davidkaspar.com/wp-content/uploads/2021/12/119499525762661096tab_right.svg_.hi_.png" alt="" srcset="https://blog.davidkaspar.com/wp-content/uploads/2021/12/119499525762661096tab_right.svg_.hi_.png 318w, https://blog.davidkaspar.com/wp-content/uploads/2021/12/119499525762661096tab_right.svg_.hi_-157x300.png 157w" sizes="auto, (max-width: 10px) 85vw, 10px" /> Private channels</p>



<p>If a swap participant accidentally created a private channel instead of a public one then the liquidity swap will not work. </p>



<p class="has-normal-font-size"><meta charset="utf-8"><img loading="lazy" decoding="async" width="10" height="19" class="wp-image-486" style="width: 10px;" src="https://blog.davidkaspar.com/wp-content/uploads/2021/12/119499525762661096tab_right.svg_.hi_.png" alt="" srcset="https://blog.davidkaspar.com/wp-content/uploads/2021/12/119499525762661096tab_right.svg_.hi_.png 318w, https://blog.davidkaspar.com/wp-content/uploads/2021/12/119499525762661096tab_right.svg_.hi_-157x300.png 157w" sizes="auto, (max-width: 10px) 85vw, 10px" /> Not enough liquidity in existing channels</p>



<p>A participant can accidentally crate a smaller channel than specified.</p>



<p>I have also seen cases where participants already had existing channels with the other participants so they didn&#8217;t feel like creating additional ones.</p>



<p>This will however break the swap as the liquidity in the swap is less than was specified. Rebalancing will not work for example.</p>



<p><meta charset="utf-8"><img loading="lazy" decoding="async" width="10" height="19" class="wp-image-486" style="width: 10px;" src="https://blog.davidkaspar.com/wp-content/uploads/2021/12/119499525762661096tab_right.svg_.hi_.png" alt="" srcset="https://blog.davidkaspar.com/wp-content/uploads/2021/12/119499525762661096tab_right.svg_.hi_.png 318w, https://blog.davidkaspar.com/wp-content/uploads/2021/12/119499525762661096tab_right.svg_.hi_-157x300.png 157w" sizes="auto, (max-width: 10px) 85vw, 10px" /> Remote node is down</p>



<p>You are unable to open the channel and you see errors like <code>503, 'FailedToSuccessfullyConnectToRemotePeer'</code>.</p>



<p>This is likely due to the remote node being down, having TOR configuration issues or other resource problems. A restart of the remote node often helps.</p>



<p>Divide the channel opening process into two steps: 1) connect to the peer first and 2) open the channel with the existing peer</p>



<p><meta charset="utf-8"><img loading="lazy" decoding="async" width="10" height="19" class="wp-image-486" style="width: 10px;" src="https://blog.davidkaspar.com/wp-content/uploads/2021/12/119499525762661096tab_right.svg_.hi_.png" alt="" srcset="https://blog.davidkaspar.com/wp-content/uploads/2021/12/119499525762661096tab_right.svg_.hi_.png 318w, https://blog.davidkaspar.com/wp-content/uploads/2021/12/119499525762661096tab_right.svg_.hi_-157x300.png 157w" sizes="auto, (max-width: 10px) 85vw, 10px" /> Node not accepting the specified channel size in the swap</p>



<p>A node can be misconfigured to only allow chanel size above a certain size&#8230; a size that is larger than the swap. Often this is due to am extra zero in the required channel size.</p>



<p><meta charset="utf-8"><img loading="lazy" decoding="async" width="10" height="19" class="wp-image-486" style="width: 10px;" src="https://blog.davidkaspar.com/wp-content/uploads/2021/12/119499525762661096tab_right.svg_.hi_.png" alt="" srcset="https://blog.davidkaspar.com/wp-content/uploads/2021/12/119499525762661096tab_right.svg_.hi_.png 318w, https://blog.davidkaspar.com/wp-content/uploads/2021/12/119499525762661096tab_right.svg_.hi_-157x300.png 157w" sizes="auto, (max-width: 10px) 85vw, 10px" /> Blockchain reorg</p>



<p>Luckily this hasn&#8217;t happened to me but there is a theoretical scenario where the open channel has only one confirmation and due to blockchain reorg that transaction becomes void. Wait for a few confirmations before using a newly open channel!</p>



<p><meta charset="utf-8"><img loading="lazy" decoding="async" width="10" height="19" class="wp-image-486" style="width: 10px;" src="https://blog.davidkaspar.com/wp-content/uploads/2021/12/119499525762661096tab_right.svg_.hi_.png" alt="" srcset="https://blog.davidkaspar.com/wp-content/uploads/2021/12/119499525762661096tab_right.svg_.hi_.png 318w, https://blog.davidkaspar.com/wp-content/uploads/2021/12/119499525762661096tab_right.svg_.hi_-157x300.png 157w" sizes="auto, (max-width: 10px) 85vw, 10px" /> You are using Umbrel and thus LND in a Docker container. You get the error &#8220;The input device is not a TTY&#8221;</p>



<p>Umbrel is popular Lightning node operating system. If uses docker container for many of the require services, such as lncli. This means you don&#8217;t have direct access to lcnli and linux &#8220;piping&#8221; between processes doesn&#8217;t work.</p>



<p>Split the routing command into two steps:</p>



<p><code>lncli buildroute --amt [AMOUNT] --hops 1a613234234116def5de68…,7243578234df738…,87827ea233…,014aea43432244…,0a34324445… | jq -r '(.route.hops[-1] | .mpp_record) |= {payment_addr:"<strong>[PAYMENT_ADDRESS]</strong>", total_amt_msat: "<strong>[AMOUNT]</strong>"}' &gt; path.txt</code></p>



<p><code>lncli sendtoroute --payment_hash=<strong>[R_HASH]</strong> --routes="$(cat path.txt)"</code></p>



<p><img loading="lazy" decoding="async" width="10" height="19" class="wp-image-486" style="width: 10px;" src="https://blog.davidkaspar.com/wp-content/uploads/2021/12/119499525762661096tab_right.svg_.hi_.png" alt="" srcset="https://blog.davidkaspar.com/wp-content/uploads/2021/12/119499525762661096tab_right.svg_.hi_.png 318w, https://blog.davidkaspar.com/wp-content/uploads/2021/12/119499525762661096tab_right.svg_.hi_-157x300.png 157w" sizes="auto, (max-width: 10px) 85vw, 10px" /> &#8220;not enough witness outputs to create funding transaction&#8221;</p>



<p>You are opening a channel and you have enough funds in your on-chain wallet but you still get this error.</p>



<p>Some of your utxo are probably unconfirmed and you cannot spend them even though they are showing in your total balance.</p>



<p>You probably have some chennels pending. There are unconfirmed payments to yourself as part of it. </p>



<p>Wait until all channels are confirmed and all funds should be available again for new channel opening!</p>
<p>The post <a href="https://blog.davidkaspar.com/archives/2021/12/rebalancing-lightning-channels-after-a-lightning-liquidity-swap.php">Rebalancing lightning channels after a lightning liquidity swap</a> appeared first on <a href="https://blog.davidkaspar.com">The Story of David Kaspar</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.davidkaspar.com/archives/2021/12/rebalancing-lightning-channels-after-a-lightning-liquidity-swap.php/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
