Browse Source

add watchtower class, send encumbered tx as json

dependabot/pip/contrib/deterministic-build/ecdsa-0.13.3
ThomasV 6 years ago
parent
commit
e761f5b876
  1. 26
      electrum/daemon.py
  2. 4
      electrum/lnchan.py
  3. 6
      electrum/lnwatcher.py

26
electrum/daemon.py

@ -122,6 +122,23 @@ def get_rpc_credentials(config: SimpleConfig) -> Tuple[str, str]:
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):
@profiler
@ -147,8 +164,7 @@ class Daemon(DaemonThread):
self.server = None
if listen_jsonrpc:
self.init_server(config, fd)
if config.get('watchtower_host'):
self.init_watchtower()
self.watchtower = WatchTower(self.config, self.network.lnwatcher) if self.config.get('watchtower_host') else None
self.start()
def init_server(self, config: SimpleConfig, fd):
@ -176,12 +192,6 @@ class Daemon(DaemonThread):
server.register_function(getattr(self.cmd_runner, cmdname), cmdname)
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):
return True

4
electrum/lnchan.py

@ -343,7 +343,7 @@ class Channel(PrintError):
else:
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)
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):
if not self.lnwatcher:
@ -351,7 +351,7 @@ class Channel(PrintError):
outpoint = self.funding_outpoint.to_str()
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)
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):
"""

6
electrum/lnwatcher.py

@ -63,7 +63,8 @@ class LNWatcher(PrintError):
name, args, kwargs = await self.watchtower_queue.get()
func = getattr(self.watchtower, name)
try:
func(*args, **kwargs)
r = func(*args, **kwargs)
self.print_error("watchtower answer", r)
except:
self.print_error('could not reach watchtower, will retry in 5s', name, args)
await asyncio.sleep(5)
@ -179,7 +180,8 @@ class LNWatcher(PrintError):
return keep_watching_this
@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:
return
with self.lock:

Loading…
Cancel
Save