<p>First of all, there are already scripts that automate this process. Check <a href="https://github.com/C-Otto/rebalance-lnd" rel="nofollow noreferrer">C-Otto's rebalance script</a>, for example.</p>

<p>Secondly, I wouldn't assume that finding a route via queryroute guarantees that the balances in the used channels could actually support your payment. I think it just means that the theoretical capacity in your nodes' view of the LN is sufficient. Knowing if the route actually works involves trying to route across it.</p>

<p>To address your concrete questions, I don't know if queryroute supports loops by now, but from glancing over the above script, it appears that it should. </p>

<p>As for your 2nd question, fees are always taken by the node forwarding a payment for sending across a channel, not the recipient in a channel. So if you try to route you-bitstamp-lpu-you, there are only two forwarding hops here, bitstamp and lpu. And they will require the fees that they have announced for the channel bitstamp-lpu (announced and collected by bitstamp) and lpu-you (announced and collected by lpu).</p>

CC BY-SA 4.0
2019-08-20T07:56:01.307Z
2019-08-20T07:56:01.307Z
stefanwouldgo
<p>I have an active channel with bitstamp with a balance on my side. Bitstamp has an active channel with lightening power users (lpu) with balance on their side (I checked this with <code>lncli queryroutes 0331f80652fb840239df8dc99205792bba2e559a05469915804c08420230e23c7c 70000</code>). Lpu has a channel with me with a balance on their side (I used their service to rent inbound liquidity).</p>

<p>Now since I rented liquidity from lpu only of a couple of days, I will lose inbound liquidity soon. I want to send a payment to myself like so: me -> bitstamp -> lpu -> me. This will result in keeping some inbound liquidity (in my channel with bitstamp) after lpu close our channel.</p>

<p>I suppose I need to use <code>lncli sendtoroute</code> to send payment over a specific route. For this, I need a payment hash and a route. I genereated a payment hash with <code>lncli addinvoice 70000</code> and copied the r_hash value. I tried to generate a route with <code>lncli queryroutes 0364f45ee43cd4b1d6db08972dfd6ab227e47adccee80ca7d76ae0bd107334c2aa 70000</code> (that is my pub_key) but I got a "unable to find a path to destination" error.</p>

<p>1st question: Is there a way to get the best route to me with queryroutes?</p>

<p>Then I tried to construct the queryroutes response by myself. I found a route with 3 hops and tried to reverse engineer how fees work. It seems that in hops only the recipient charges a fee. So the first hop is from me to bitstamp (bitstamp charges a fee), the second hop is from bitstamp to lpu (lpu charges a fee), the last hop is from lpu to me (I do not charge a fee to myself).</p>

<p>2nd question: Is the above fee logic correct?</p>

<p>Ok so with all that data I generated queryroutes response below</p>

<p><code>{
    "routes": [
        {
            "total_time_lock": 590112,
            "total_fees": "373",
            "total_amt": "70373",
            "hops": [
                {
                    "chan_id": "648038959352250368",
                    "chan_capacity": "100000",
                    "amt_to_forward": "70373",
                    "fee": "0",
                    "expiry": 590072,
                    "amt_to_forward_msat": "70373500",
                    "fee_msat": "70",
                    "pub_key": "02a04446caa81636d60d63b066f2814cbd3a6b5c258e3172cbdded7a16e2cfff4c"
                },
                {
                    "chan_id": "630596306830950400",
                    "chan_capacity": "2500000",
                    "amt_to_forward": "70360",
                    "fee": "360",
                    "expiry": 589928,
                    "amt_to_forward_msat": "70360000",
                    "fee_msat": "13500",
                    "pub_key": "0331f80652fb840239df8dc99205792bba2e559a05469915804c08420230e23c7c"
                },
                {
                    "chan_id": "648098333019668480",
                    "chan_capacity": "500000",
                    "amt_to_forward": "70000",
                    "fee": "360",
                    "expiry": 589928,
                    "amt_to_forward_msat": "70000000",
                    "fee_msat": "360000",
                    "pub_key": "0364f45ee43cd4b1d6db08972dfd6ab227e47adccee80ca7d76ae0bd107334c2aa"
                }
            ],
            "total_fees_msat": "373570",
            "total_amt_msat": "70373570"
        }
    ]
}</code></p>

<p>Then I try to send this with <code>cat my.route | lncli sendtoroute --pay_hash=hashIgenerated -</code> and get a <code>"payment_error": "FeeInsufficient...</code> error.</p>

<p>How should I construct the routes for this to work?</p>

<lightning-network><lightning-network-daemon><lightning-routing><ln-channel-balance-management>
How can I send a payment to myself with lightening to rebalance 2 channels?
user1035617
# How can I send a payment to myself with lightening to rebalance 2 channels?

(Asked by: username_0 on 2019-08-13)

I have an active channel with bitstamp with a balance on my side. Bitstamp has an active channel with lightening power users (lpu) with balance on their side (I checked this with `lncli queryroutes 0331f80652fb840239df8dc99205792bba2e559a05469915804c08420230e23c7c 70000`). Lpu has a channel with me with a balance on their side (I used their service to rent inbound liquidity).

Now since I rented liquidity from lpu only of a couple of days, I will lose inbound liquidity soon. I want to send a payment to myself like so: me -> bitstamp -> lpu -> me. This will result in keeping some inbound liquidity (in my channel with bitstamp) after lpu close our channel.

I suppose I need to use `lncli sendtoroute` to send payment over a specific route. For this, I need a payment hash and a route. I genereated a payment hash with `lncli addinvoice 70000` and copied the r\_hash value. I tried to generate a route with `lncli queryroutes 0364f45ee43cd4b1d6db08972dfd6ab227e47adccee80ca7d76ae0bd107334c2aa 70000` (that is my pub\_key) but I got a "unable to find a path to destination" error.

1st question: Is there a way to get the best route to me with queryroutes?

Then I tried to construct the queryroutes response by myself. I found a route with 3 hops and tried to reverse engineer how fees work. It seems that in hops only the recipient charges a fee. So the first hop is from me to bitstamp (bitstamp charges a fee), the second hop is from bitstamp to lpu (lpu charges a fee), the last hop is from lpu to me (I do not charge a fee to myself).

2nd question: Is the above fee logic correct?

Ok so with all that data I generated queryroutes response below

`{
"routes": [
{
"total_time_lock": 590112,
"total_fees": "373",
"total_amt": "70373",
"hops": [
{
"chan_id": "648038959352250368",
"chan_capacity": "100000",
"amt_to_forward": "70373",
"fee": "0",
"expiry": 590072,
"amt_to_forward_msat": "70373500",
"fee_msat": "70",
"pub_key": "02a04446caa81636d60d63b066f2814cbd3a6b5c258e3172cbdded7a16e2cfff4c"
},
{
"chan_id": "630596306830950400",
"chan_capacity": "2500000",
"amt_to_forward": "70360",
"fee": "360",
"expiry": 589928,
"amt_to_forward_msat": "70360000",
"fee_msat": "13500",
"pub_key": "0331f80652fb840239df8dc99205792bba2e559a05469915804c08420230e23c7c"
},
{
"chan_id": "648098333019668480",
"chan_capacity": "500000",
"amt_to_forward": "70000",
"fee": "360",
"expiry": 589928,
"amt_to_forward_msat": "70000000",
"fee_msat": "360000",
"pub_key": "0364f45ee43cd4b1d6db08972dfd6ab227e47adccee80ca7d76ae0bd107334c2aa"
}
],
"total_fees_msat": "373570",
"total_amt_msat": "70373570"
}
]
}`

Then I try to send this with `cat my.route | lncli sendtoroute --pay_hash=hashIgenerated -` and get a `"payment_error": "FeeInsufficient...` error.

How should I construct the routes for this to work?

**Tags:** lightning-network, lightning-network-daemon, lightning-routing, ln-channel-balance-management


---

## 1 answers

### Answer by username_1 on 2019-08-20. Score: 2 | Accepted answer

First of all, there are already scripts that automate this process. Check [C-Otto's rebalance script](https://github.com/C-Otto/rebalance-lnd), for example.

Secondly, I wouldn't assume that finding a route via queryroute guarantees that the balances in the used channels could actually support your payment. I think it just means that the theoretical capacity in your nodes' view of the LN is sufficient. Knowing if the route actually works involves trying to route across it.

To address your concrete questions, I don't know if queryroute supports loops by now, but from glancing over the above script, it appears that it should.

As for your 2nd question, fees are always taken by the node forwarding a payment for sending across a channel, not the recipient in a channel. So if you try to route you-bitstamp-lpu-you, there are only two forwarding hops here, bitstamp and lpu. And they will require the fees that they have announced for the channel bitstamp-lpu (announced and collected by bitstamp) and lpu-you (announced and collected by lpu).


---

