commit 5401b3f72d87f8bd0cef4d3c9fb3e51ec713e64d
parent 182c192558085adc665c5073f12d842b8e7b7ffa
Author: SomberNight <somber.night@protonmail.com>
Date: Fri, 19 Jun 2020 06:38:00 +0200
channel backups: try fixing force-close-trigger
Diffstat:
2 files changed, 21 insertions(+), 12 deletions(-)
diff --git a/electrum/lnpeer.py b/electrum/lnpeer.py
@@ -53,7 +53,7 @@ from .lnutil import ln_dummy_address
from .json_db import StoredDict
if TYPE_CHECKING:
- from .lnworker import LNWorker, LNGossip, LNWallet
+ from .lnworker import LNWorker, LNGossip, LNWallet, LNBackups
from .lnrouter import RouteEdge, LNPaymentRoute
from .transaction import PartialTransaction
@@ -64,7 +64,12 @@ LN_P2P_NETWORK_TIMEOUT = 20
class Peer(Logger):
LOGGING_SHORTCUT = 'P'
- def __init__(self, lnworker: Union['LNGossip', 'LNWallet'], pubkey:bytes, transport: LNTransportBase):
+ def __init__(
+ self,
+ lnworker: Union['LNGossip', 'LNWallet', 'LNBackups'],
+ pubkey: bytes,
+ transport: LNTransportBase
+ ):
self._sent_init = False # type: bool
self._received_init = False # type: bool
self.initialized = asyncio.Future()
@@ -425,9 +430,6 @@ class Peer(Logger):
first_blocknum=first_block,
number_of_blocks=num_blocks)
- def encode_short_ids(self, ids):
- return chr(1) + zlib.compress(bfh(''.join(ids)))
-
def decode_short_ids(self, encoded):
if encoded[0] == 0:
decoded = encoded[1:]
@@ -773,8 +775,8 @@ class Peer(Logger):
self.send_message(
"channel_reestablish",
channel_id=channel_id,
- next_local_commitment_number=0,
- next_remote_revocation_number=0,
+ next_commitment_number=0,
+ next_revocation_number=0,
your_last_per_commitment_secret=0,
my_current_per_commitment_point=latest_point)
diff --git a/electrum/lnworker.py b/electrum/lnworker.py
@@ -20,7 +20,7 @@ from concurrent import futures
import dns.resolver
import dns.exception
-from aiorpcx import run_in_thread
+from aiorpcx import run_in_thread, TaskGroup
from . import constants, util
from . import keystore
@@ -1413,7 +1413,6 @@ class LNBackups(Logger):
self.features = LnFeatures(0)
self.features |= LnFeatures.OPTION_DATA_LOSS_PROTECT_OPT
self.features |= LnFeatures.OPTION_STATIC_REMOTEKEY_OPT
- self.taskgroup = SilentTaskGroup()
self.lock = threading.RLock()
self.wallet = wallet
self.db = wallet.db
@@ -1443,6 +1442,12 @@ class LNBackups(Logger):
if chan.funding_outpoint.to_str() == txo:
return chan
+ def on_peer_successfully_established(self, peer: Peer) -> None:
+ pass
+
+ def channels_for_peer(self, node_id):
+ return {}
+
def start_network(self, network: 'Network'):
assert network
self.lnwatcher = LNWalletWatcher(self, network)
@@ -1483,10 +1488,12 @@ class LNBackups(Logger):
@log_exceptions
async def request_force_close(self, channel_id):
cb = self.channel_backups[channel_id].cb
+ # TODO also try network addresses from gossip db (as it might have changed)
peer_addr = LNPeerAddr(cb.host, cb.port, cb.node_id)
transport = LNTransport(cb.privkey, peer_addr,
proxy=self.network.proxy)
peer = Peer(self, cb.node_id, transport)
- await self.taskgroup.spawn(peer._message_loop())
- await peer.initialized
- await self.taskgroup.spawn(peer.trigger_force_close(channel_id))
+ async with TaskGroup() as group:
+ await group.spawn(peer._message_loop())
+ await group.spawn(peer.trigger_force_close(channel_id))
+ # TODO force-exit taskgroup, to clean-up