lnworker: fix rebalance_channels
fixes https://github.com/spesmilo/electrum/issues/8468
This commit is contained in:
@@ -1269,7 +1269,11 @@ class Commands:
|
|||||||
from_channel = wallet.lnworker.get_channel_by_scid(from_scid)
|
from_channel = wallet.lnworker.get_channel_by_scid(from_scid)
|
||||||
dest_channel = wallet.lnworker.get_channel_by_scid(dest_scid)
|
dest_channel = wallet.lnworker.get_channel_by_scid(dest_scid)
|
||||||
amount_sat = satoshis(amount)
|
amount_sat = satoshis(amount)
|
||||||
success, log = await wallet.lnworker.rebalance_channels(from_channel, dest_channel, amount_sat * 1000)
|
success, log = await wallet.lnworker.rebalance_channels(
|
||||||
|
from_channel,
|
||||||
|
dest_channel,
|
||||||
|
amount_msat=amount_sat * 1000,
|
||||||
|
)
|
||||||
return {
|
return {
|
||||||
'success': success,
|
'success': success,
|
||||||
'log': [x.formatted_tuple() for x in log]
|
'log': [x.formatted_tuple() for x in log]
|
||||||
|
|||||||
@@ -1842,8 +1842,7 @@ class LNWallet(LNWorker):
|
|||||||
self._bolt11_cache[payment_hash] = pair
|
self._bolt11_cache[payment_hash] = pair
|
||||||
return pair
|
return pair
|
||||||
|
|
||||||
def create_payment_info(self, amount_sat: Optional[int], write_to_disk=True) -> bytes:
|
def create_payment_info(self, *, amount_msat: Optional[int], write_to_disk=True) -> bytes:
|
||||||
amount_msat = amount_sat * 1000 if amount_sat else None
|
|
||||||
payment_preimage = os.urandom(32)
|
payment_preimage = os.urandom(32)
|
||||||
payment_hash = sha256(payment_preimage)
|
payment_hash = sha256(payment_preimage)
|
||||||
info = PaymentInfo(payment_hash, amount_msat, RECEIVED, PR_UNPAID)
|
info = PaymentInfo(payment_hash, amount_msat, RECEIVED, PR_UNPAID)
|
||||||
@@ -2289,17 +2288,19 @@ class LNWallet(LNWorker):
|
|||||||
for chan, swap_recv_amount in suggestions:
|
for chan, swap_recv_amount in suggestions:
|
||||||
return (chan, swap_recv_amount)
|
return (chan, swap_recv_amount)
|
||||||
|
|
||||||
async def rebalance_channels(self, chan1, chan2, amount_msat):
|
async def rebalance_channels(self, chan1: Channel, chan2: Channel, *, amount_msat: int):
|
||||||
if chan1 == chan2:
|
if chan1 == chan2:
|
||||||
raise Exception('Rebalance requires two different channels')
|
raise Exception('Rebalance requires two different channels')
|
||||||
if self.uses_trampoline() and chan1.node_id == chan2.node_id:
|
if self.uses_trampoline() and chan1.node_id == chan2.node_id:
|
||||||
raise Exception('Rebalance requires channels from different trampolines')
|
raise Exception('Rebalance requires channels from different trampolines')
|
||||||
lnaddr, invoice = self.add_reqest(
|
payment_hash = self.create_payment_info(amount_msat=amount_msat)
|
||||||
|
lnaddr, invoice = self.get_bolt11_invoice(
|
||||||
|
payment_hash=payment_hash,
|
||||||
amount_msat=amount_msat,
|
amount_msat=amount_msat,
|
||||||
message='rebalance',
|
message='rebalance',
|
||||||
expiry=3600,
|
expiry=3600,
|
||||||
fallback_address=None,
|
fallback_address=None,
|
||||||
channels = [chan2]
|
channels=[chan2],
|
||||||
)
|
)
|
||||||
return await self.pay_invoice(
|
return await self.pay_invoice(
|
||||||
invoice, channels=[chan1])
|
invoice, channels=[chan1])
|
||||||
|
|||||||
@@ -262,7 +262,7 @@ class SwapManager(Logger):
|
|||||||
privkey = os.urandom(32)
|
privkey = os.urandom(32)
|
||||||
pubkey = ECPrivkey(privkey).get_public_key_bytes(compressed=True)
|
pubkey = ECPrivkey(privkey).get_public_key_bytes(compressed=True)
|
||||||
amount_msat = lightning_amount_sat * 1000
|
amount_msat = lightning_amount_sat * 1000
|
||||||
payment_hash = self.lnworker.create_payment_info(lightning_amount_sat)
|
payment_hash = self.lnworker.create_payment_info(amount_msat=amount_msat)
|
||||||
lnaddr, invoice = self.lnworker.get_bolt11_invoice(
|
lnaddr, invoice = self.lnworker.get_bolt11_invoice(
|
||||||
payment_hash=payment_hash,
|
payment_hash=payment_hash,
|
||||||
amount_msat=amount_msat,
|
amount_msat=amount_msat,
|
||||||
|
|||||||
@@ -2625,7 +2625,9 @@ class Abstract_Wallet(ABC, Logger, EventListener):
|
|||||||
address = address or None # converts "" to None
|
address = address or None # converts "" to None
|
||||||
exp_delay = exp_delay or 0
|
exp_delay = exp_delay or 0
|
||||||
timestamp = int(Request._get_cur_time())
|
timestamp = int(Request._get_cur_time())
|
||||||
payment_hash = self.lnworker.create_payment_info(amount_sat, write_to_disk=False) if self.has_lightning() else None
|
payment_hash = None # type: Optional[bytes]
|
||||||
|
if self.has_lightning():
|
||||||
|
payment_hash = self.lnworker.create_payment_info(amount_msat=amount_sat * 1000, write_to_disk=False)
|
||||||
outputs = [ PartialTxOutput.from_address_and_value(address, amount_sat)] if address else []
|
outputs = [ PartialTxOutput.from_address_and_value(address, amount_sat)] if address else []
|
||||||
height = self.adb.get_local_height()
|
height = self.adb.get_local_height()
|
||||||
req = Request(
|
req = Request(
|
||||||
|
|||||||
Reference in New Issue
Block a user