mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-30 17:01:34 +00:00
add watchtower class, send encumbered tx as json
This commit is contained in:
parent
4e8d019d8d
commit
1e3a91964d
3 changed files with 24 additions and 12 deletions
|
@ -118,6 +118,23 @@ def get_rpc_credentials(config: SimpleConfig) -> Tuple[str, str]:
|
||||||
return rpc_user, rpc_password
|
return rpc_user, rpc_password
|
||||||
|
|
||||||
|
|
||||||
|
class WatchTower(DaemonThread):
|
||||||
|
|
||||||
|
def __init__(self, config, lnwatcher):
|
||||||
|
DaemonThread.__init__(self)
|
||||||
|
self.config = config
|
||||||
|
self.lnwatcher = lnwatcher
|
||||||
|
self.start()
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
host = self.config.get('watchtower_host')
|
||||||
|
port = self.config.get('watchtower_port', 12345)
|
||||||
|
server = SimpleJSONRPCServer((host, port), logRequests=True)
|
||||||
|
server.register_function(self.lnwatcher.add_sweep_tx, 'add_sweep_tx')
|
||||||
|
server.timeout = 0.1
|
||||||
|
while self.is_running():
|
||||||
|
server.handle_request()
|
||||||
|
|
||||||
class Daemon(DaemonThread):
|
class Daemon(DaemonThread):
|
||||||
|
|
||||||
def __init__(self, config: SimpleConfig, fd=None, *, listen_jsonrpc=True):
|
def __init__(self, config: SimpleConfig, fd=None, *, listen_jsonrpc=True):
|
||||||
|
@ -141,8 +158,7 @@ class Daemon(DaemonThread):
|
||||||
self.server = None
|
self.server = None
|
||||||
if listen_jsonrpc:
|
if listen_jsonrpc:
|
||||||
self.init_server(config, fd)
|
self.init_server(config, fd)
|
||||||
if config.get('watchtower_host'):
|
self.watchtower = WatchTower(self.config, self.network.lnwatcher) if self.config.get('watchtower_host') else None
|
||||||
self.init_watchtower()
|
|
||||||
self.start()
|
self.start()
|
||||||
|
|
||||||
def init_server(self, config: SimpleConfig, fd):
|
def init_server(self, config: SimpleConfig, fd):
|
||||||
|
@ -170,12 +186,6 @@ class Daemon(DaemonThread):
|
||||||
server.register_function(getattr(self.cmd_runner, cmdname), cmdname)
|
server.register_function(getattr(self.cmd_runner, cmdname), cmdname)
|
||||||
server.register_function(self.run_cmdline, 'run_cmdline')
|
server.register_function(self.run_cmdline, 'run_cmdline')
|
||||||
|
|
||||||
def init_watchtower(self):
|
|
||||||
host = self.config.get('watchtower_host')
|
|
||||||
port = self.config.get('watchtower_port', 12345)
|
|
||||||
server = SimpleJSONRPCServer((host, port), logRequests=False)
|
|
||||||
server.register_function(self.network.lnwatcher, 'add_sweep_tx')
|
|
||||||
|
|
||||||
def ping(self):
|
def ping(self):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
|
@ -343,7 +343,7 @@ class Channel(PrintError):
|
||||||
else:
|
else:
|
||||||
their_cur_pcp = self.config[REMOTE].next_per_commitment_point
|
their_cur_pcp = self.config[REMOTE].next_per_commitment_point
|
||||||
encumbered_sweeptx = maybe_create_sweeptx_for_their_ctx_to_remote(self, ctx, their_cur_pcp, self.sweep_address)
|
encumbered_sweeptx = maybe_create_sweeptx_for_their_ctx_to_remote(self, ctx, their_cur_pcp, self.sweep_address)
|
||||||
self.lnwatcher.add_sweep_tx(outpoint, ctx.txid(), encumbered_sweeptx)
|
self.lnwatcher.add_sweep_tx(outpoint, ctx.txid(), encumbered_sweeptx.to_json())
|
||||||
|
|
||||||
def process_new_revocation_secret(self, per_commitment_secret: bytes):
|
def process_new_revocation_secret(self, per_commitment_secret: bytes):
|
||||||
if not self.lnwatcher:
|
if not self.lnwatcher:
|
||||||
|
@ -351,7 +351,7 @@ class Channel(PrintError):
|
||||||
outpoint = self.funding_outpoint.to_str()
|
outpoint = self.funding_outpoint.to_str()
|
||||||
ctx = self.remote_commitment_to_be_revoked
|
ctx = self.remote_commitment_to_be_revoked
|
||||||
encumbered_sweeptx = maybe_create_sweeptx_for_their_ctx_to_local(self, ctx, per_commitment_secret, self.sweep_address)
|
encumbered_sweeptx = maybe_create_sweeptx_for_their_ctx_to_local(self, ctx, per_commitment_secret, self.sweep_address)
|
||||||
self.lnwatcher.add_sweep_tx(outpoint, ctx.txid(), encumbered_sweeptx)
|
self.lnwatcher.add_sweep_tx(outpoint, ctx.txid(), encumbered_sweeptx.to_json())
|
||||||
|
|
||||||
def receive_revocation(self, revocation):
|
def receive_revocation(self, revocation):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -63,7 +63,8 @@ class LNWatcher(PrintError):
|
||||||
name, args, kwargs = await self.watchtower_queue.get()
|
name, args, kwargs = await self.watchtower_queue.get()
|
||||||
func = getattr(self.watchtower, name)
|
func = getattr(self.watchtower, name)
|
||||||
try:
|
try:
|
||||||
func(*args, **kwargs)
|
r = func(*args, **kwargs)
|
||||||
|
self.print_error("watchtower answer", r)
|
||||||
except:
|
except:
|
||||||
self.print_error('could not reach watchtower, will retry in 5s', name, args)
|
self.print_error('could not reach watchtower, will retry in 5s', name, args)
|
||||||
await asyncio.sleep(5)
|
await asyncio.sleep(5)
|
||||||
|
@ -179,7 +180,8 @@ class LNWatcher(PrintError):
|
||||||
return keep_watching_this
|
return keep_watching_this
|
||||||
|
|
||||||
@with_watchtower
|
@with_watchtower
|
||||||
def add_sweep_tx(self, funding_outpoint: str, ctx_txid: str, encumbered_sweeptx: EncumberedTransaction):
|
def add_sweep_tx(self, funding_outpoint: str, ctx_txid: str, sweeptx):
|
||||||
|
encumbered_sweeptx = EncumberedTransaction.from_json(sweeptx)
|
||||||
if encumbered_sweeptx is None:
|
if encumbered_sweeptx is None:
|
||||||
return
|
return
|
||||||
with self.lock:
|
with self.lock:
|
||||||
|
|
Loading…
Add table
Reference in a new issue