request_force_close_from_backup:
- for an onchain backups, if the channel is with a hardcoded trampoline, try first without gossip DB. - for imported backups, fallback to gossip DB if we fail to connect with the provided network address.
This commit is contained in:
@@ -2526,29 +2526,46 @@ class LNWallet(LNWorker):
|
|||||||
node_id = cb.node_id
|
node_id = cb.node_id
|
||||||
privkey = cb.privkey
|
privkey = cb.privkey
|
||||||
addresses = [(cb.host, cb.port, 0)]
|
addresses = [(cb.host, cb.port, 0)]
|
||||||
# TODO also try network addresses from gossip db (as it might have changed)
|
|
||||||
else:
|
else:
|
||||||
assert isinstance(cb, OnchainChannelBackupStorage)
|
assert isinstance(cb, OnchainChannelBackupStorage)
|
||||||
if not self.channel_db:
|
|
||||||
raise Exception('Enable gossip first')
|
|
||||||
node_id = self.network.channel_db.get_node_by_prefix(cb.node_id_prefix)
|
|
||||||
privkey = self.node_keypair.privkey
|
privkey = self.node_keypair.privkey
|
||||||
addresses = self.network.channel_db.get_node_addresses(node_id)
|
for pubkey, peer_addr in trampolines_by_id().items():
|
||||||
if not addresses:
|
if pubkey.startswith(cb.node_id_prefix):
|
||||||
raise Exception('Peer not found in gossip database')
|
node_id = pubkey
|
||||||
for host, port, timestamp in addresses:
|
addresses = [(peer_addr.host, peer_addr.port, 0)]
|
||||||
peer_addr = LNPeerAddr(host, port, node_id)
|
break
|
||||||
transport = LNTransport(privkey, peer_addr, proxy=self.network.proxy)
|
else:
|
||||||
peer = Peer(self, node_id, transport, is_channel_backup=True)
|
# we will try with gossip (see below)
|
||||||
try:
|
addresses = []
|
||||||
async with OldTaskGroup(wait=any) as group:
|
|
||||||
await group.spawn(peer._message_loop())
|
async def _request_fclose(addresses):
|
||||||
await group.spawn(peer.request_force_close(channel_id))
|
for host, port, timestamp in addresses:
|
||||||
return
|
peer_addr = LNPeerAddr(host, port, node_id)
|
||||||
except Exception as e:
|
transport = LNTransport(privkey, peer_addr, proxy=self.network.proxy)
|
||||||
self.logger.info(f'failed to connect {host} {e}')
|
peer = Peer(self, node_id, transport, is_channel_backup=True)
|
||||||
continue
|
try:
|
||||||
else:
|
async with OldTaskGroup(wait=any) as group:
|
||||||
|
await group.spawn(peer._message_loop())
|
||||||
|
await group.spawn(peer.request_force_close(channel_id))
|
||||||
|
return True
|
||||||
|
except Exception as e:
|
||||||
|
self.logger.info(f'failed to connect {host} {e}')
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
# try first without gossip db
|
||||||
|
success = await _request_fclose(addresses)
|
||||||
|
if success:
|
||||||
|
return
|
||||||
|
# try with gossip db
|
||||||
|
if not self.channel_db:
|
||||||
|
raise Exception(_('Please enable gossip'))
|
||||||
|
node_id = self.network.channel_db.get_node_by_prefix(cb.node_id_prefix)
|
||||||
|
addresses_from_gossip = self.network.channel_db.get_node_addresses(node_id)
|
||||||
|
if not addresses_from_gossip:
|
||||||
|
raise Exception('Peer not found in gossip database')
|
||||||
|
success = await _request_fclose(addresses_from_gossip)
|
||||||
|
if not success:
|
||||||
raise Exception('failed to connect')
|
raise Exception('failed to connect')
|
||||||
|
|
||||||
def maybe_add_backup_from_tx(self, tx):
|
def maybe_add_backup_from_tx(self, tx):
|
||||||
|
|||||||
Reference in New Issue
Block a user