Browse Source

channel backups: try fixing force-close-trigger

bip39-recovery
SomberNight 5 years ago
parent
commit
5401b3f72d
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 16
      electrum/lnpeer.py
  2. 17
      electrum/lnworker.py

16
electrum/lnpeer.py

@ -53,7 +53,7 @@ from .lnutil import ln_dummy_address
from .json_db import StoredDict from .json_db import StoredDict
if TYPE_CHECKING: if TYPE_CHECKING:
from .lnworker import LNWorker, LNGossip, LNWallet from .lnworker import LNWorker, LNGossip, LNWallet, LNBackups
from .lnrouter import RouteEdge, LNPaymentRoute from .lnrouter import RouteEdge, LNPaymentRoute
from .transaction import PartialTransaction from .transaction import PartialTransaction
@ -64,7 +64,12 @@ LN_P2P_NETWORK_TIMEOUT = 20
class Peer(Logger): class Peer(Logger):
LOGGING_SHORTCUT = 'P' 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._sent_init = False # type: bool
self._received_init = False # type: bool self._received_init = False # type: bool
self.initialized = asyncio.Future() self.initialized = asyncio.Future()
@ -425,9 +430,6 @@ class Peer(Logger):
first_blocknum=first_block, first_blocknum=first_block,
number_of_blocks=num_blocks) 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): def decode_short_ids(self, encoded):
if encoded[0] == 0: if encoded[0] == 0:
decoded = encoded[1:] decoded = encoded[1:]
@ -773,8 +775,8 @@ class Peer(Logger):
self.send_message( self.send_message(
"channel_reestablish", "channel_reestablish",
channel_id=channel_id, channel_id=channel_id,
next_local_commitment_number=0, next_commitment_number=0,
next_remote_revocation_number=0, next_revocation_number=0,
your_last_per_commitment_secret=0, your_last_per_commitment_secret=0,
my_current_per_commitment_point=latest_point) my_current_per_commitment_point=latest_point)

17
electrum/lnworker.py

@ -20,7 +20,7 @@ from concurrent import futures
import dns.resolver import dns.resolver
import dns.exception import dns.exception
from aiorpcx import run_in_thread from aiorpcx import run_in_thread, TaskGroup
from . import constants, util from . import constants, util
from . import keystore from . import keystore
@ -1413,7 +1413,6 @@ class LNBackups(Logger):
self.features = LnFeatures(0) self.features = LnFeatures(0)
self.features |= LnFeatures.OPTION_DATA_LOSS_PROTECT_OPT self.features |= LnFeatures.OPTION_DATA_LOSS_PROTECT_OPT
self.features |= LnFeatures.OPTION_STATIC_REMOTEKEY_OPT self.features |= LnFeatures.OPTION_STATIC_REMOTEKEY_OPT
self.taskgroup = SilentTaskGroup()
self.lock = threading.RLock() self.lock = threading.RLock()
self.wallet = wallet self.wallet = wallet
self.db = wallet.db self.db = wallet.db
@ -1443,6 +1442,12 @@ class LNBackups(Logger):
if chan.funding_outpoint.to_str() == txo: if chan.funding_outpoint.to_str() == txo:
return chan 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'): def start_network(self, network: 'Network'):
assert network assert network
self.lnwatcher = LNWalletWatcher(self, network) self.lnwatcher = LNWalletWatcher(self, network)
@ -1483,10 +1488,12 @@ class LNBackups(Logger):
@log_exceptions @log_exceptions
async def request_force_close(self, channel_id): async def request_force_close(self, channel_id):
cb = self.channel_backups[channel_id].cb 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) peer_addr = LNPeerAddr(cb.host, cb.port, cb.node_id)
transport = LNTransport(cb.privkey, peer_addr, transport = LNTransport(cb.privkey, peer_addr,
proxy=self.network.proxy) proxy=self.network.proxy)
peer = Peer(self, cb.node_id, transport) peer = Peer(self, cb.node_id, transport)
await self.taskgroup.spawn(peer._message_loop()) async with TaskGroup() as group:
await peer.initialized await group.spawn(peer._message_loop())
await self.taskgroup.spawn(peer.trigger_force_close(channel_id)) await group.spawn(peer.trigger_force_close(channel_id))
# TODO force-exit taskgroup, to clean-up

Loading…
Cancel
Save