How can I send a payment to myself with lightening to rebalance 2 channels?

by user1035617   Last Updated August 13, 2019 12:27 PM - source

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?

Related Questions

How to send payment through a predefined route?

Updated February 07, 2019 14:27 PM

How to send a payment through a route saved in a json?

Updated February 11, 2019 11:27 AM

Minimum funds required in a channel in Lightning?

Updated November 05, 2018 18:27 PM