mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-29 16:31:29 +00:00
fix race between network and lnwatcher (network.add_job does not always work)
This commit is contained in:
parent
1e3a91964d
commit
7cbb186167
3 changed files with 9 additions and 3 deletions
|
@ -150,15 +150,17 @@ class Daemon(DaemonThread):
|
||||||
self.network = Network(config)
|
self.network = Network(config)
|
||||||
self.network._loop_thread = self._loop_thread
|
self.network._loop_thread = self._loop_thread
|
||||||
self.fx = FxThread(config, self.network)
|
self.fx = FxThread(config, self.network)
|
||||||
if self.network:
|
|
||||||
self.network.start([self.fx.run])
|
|
||||||
self.gui = None
|
self.gui = None
|
||||||
self.wallets = {} # type: Dict[str, Abstract_Wallet]
|
self.wallets = {} # type: Dict[str, Abstract_Wallet]
|
||||||
# Setup JSONRPC server
|
# Setup JSONRPC server
|
||||||
self.server = None
|
self.server = None
|
||||||
if listen_jsonrpc:
|
if listen_jsonrpc:
|
||||||
self.init_server(config, fd)
|
self.init_server(config, fd)
|
||||||
|
# server-side watchtower
|
||||||
self.watchtower = WatchTower(self.config, self.network.lnwatcher) if self.config.get('watchtower_host') else None
|
self.watchtower = WatchTower(self.config, self.network.lnwatcher) if self.config.get('watchtower_host') else None
|
||||||
|
# client-side
|
||||||
|
if self.network:
|
||||||
|
self.network.start([self.fx.run, self.network.lnwatcher.watchtower_task])
|
||||||
self.start()
|
self.start()
|
||||||
|
|
||||||
def init_server(self, config: SimpleConfig, fd):
|
def init_server(self, config: SimpleConfig, fd):
|
||||||
|
|
|
@ -138,6 +138,7 @@ def serialize_server(host: str, port: Union[str, int], protocol: str) -> str:
|
||||||
|
|
||||||
|
|
||||||
class Interface(PrintError):
|
class Interface(PrintError):
|
||||||
|
verbosity_filter = 'i'
|
||||||
|
|
||||||
def __init__(self, network: 'Network', server: str, config_path, proxy: dict):
|
def __init__(self, network: 'Network', server: str, config_path, proxy: dict):
|
||||||
self.ready = asyncio.Future()
|
self.ready = asyncio.Future()
|
||||||
|
|
|
@ -19,6 +19,7 @@ class LNWatcher(PrintError):
|
||||||
# TODO if verifier gets an incorrect merkle proof, that tx will never verify!!
|
# TODO if verifier gets an incorrect merkle proof, that tx will never verify!!
|
||||||
# similarly, what if server ignores request for merkle proof?
|
# similarly, what if server ignores request for merkle proof?
|
||||||
# maybe we should disconnect from server in these cases
|
# maybe we should disconnect from server in these cases
|
||||||
|
verbosity_filter = 'W'
|
||||||
|
|
||||||
def __init__(self, network):
|
def __init__(self, network):
|
||||||
self.network = network
|
self.network = network
|
||||||
|
@ -47,7 +48,6 @@ class LNWatcher(PrintError):
|
||||||
watchtower_url = self.config.get('watchtower_url')
|
watchtower_url = self.config.get('watchtower_url')
|
||||||
self.watchtower = jsonrpclib.Server(watchtower_url) if watchtower_url else None
|
self.watchtower = jsonrpclib.Server(watchtower_url) if watchtower_url else None
|
||||||
self.watchtower_queue = asyncio.Queue()
|
self.watchtower_queue = asyncio.Queue()
|
||||||
asyncio.run_coroutine_threadsafe(self.network.add_job(self.watchtower_task), self.network.asyncio_loop)
|
|
||||||
|
|
||||||
def with_watchtower(func):
|
def with_watchtower(func):
|
||||||
def wrapper(self, *args, **kwargs):
|
def wrapper(self, *args, **kwargs):
|
||||||
|
@ -59,8 +59,11 @@ class LNWatcher(PrintError):
|
||||||
@ignore_exceptions
|
@ignore_exceptions
|
||||||
@log_exceptions
|
@log_exceptions
|
||||||
async def watchtower_task(self):
|
async def watchtower_task(self):
|
||||||
|
self.print_error('watchtower task started')
|
||||||
while True:
|
while True:
|
||||||
name, args, kwargs = await self.watchtower_queue.get()
|
name, args, kwargs = await self.watchtower_queue.get()
|
||||||
|
if self.watchtower is None:
|
||||||
|
continue
|
||||||
func = getattr(self.watchtower, name)
|
func = getattr(self.watchtower, name)
|
||||||
try:
|
try:
|
||||||
r = func(*args, **kwargs)
|
r = func(*args, **kwargs)
|
||||||
|
|
Loading…
Add table
Reference in a new issue