mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-09-04 04:45:16 +00:00
lnchannel: pass reference to lnworker
This commit is contained in:
parent
a8e2f79563
commit
3e443535a2
4 changed files with 16 additions and 31 deletions
|
@ -120,12 +120,9 @@ class Channel(PrintError):
|
||||||
except:
|
except:
|
||||||
return super().diagnostic_name()
|
return super().diagnostic_name()
|
||||||
|
|
||||||
def __init__(self, state, *, sweep_address=None, name=None,
|
def __init__(self, state, *, sweep_address=None, name=None, lnworker=None):
|
||||||
payment_completed: Optional[Callable[['Channel', Direction, UpdateAddHtlc], None]] = None):
|
self.lnworker = lnworker
|
||||||
if not payment_completed:
|
|
||||||
payment_completed = lambda this, x, y: None
|
|
||||||
self.sweep_address = sweep_address
|
self.sweep_address = sweep_address
|
||||||
self.payment_completed = payment_completed
|
|
||||||
assert 'local_state' not in state
|
assert 'local_state' not in state
|
||||||
self.config = {}
|
self.config = {}
|
||||||
self.config[LOCAL] = state["local_config"]
|
self.config[LOCAL] = state["local_config"]
|
||||||
|
@ -437,10 +434,11 @@ class Channel(PrintError):
|
||||||
|
|
||||||
received = self.hm.received_in_ctn(self.config[LOCAL].ctn)
|
received = self.hm.received_in_ctn(self.config[LOCAL].ctn)
|
||||||
sent = self.hm.sent_in_ctn(self.config[LOCAL].ctn)
|
sent = self.hm.sent_in_ctn(self.config[LOCAL].ctn)
|
||||||
for htlc in received:
|
if self.lnworker:
|
||||||
self.payment_completed(self, RECEIVED, htlc)
|
for htlc in received:
|
||||||
for htlc in sent:
|
self.lnworker.payment_completed(self, RECEIVED, htlc)
|
||||||
self.payment_completed(self, SENT, htlc)
|
for htlc in sent:
|
||||||
|
self.lnworker.payment_completed(self, SENT, htlc)
|
||||||
received_this_batch = htlcsum(received)
|
received_this_batch = htlcsum(received)
|
||||||
sent_this_batch = htlcsum(sent)
|
sent_this_batch = htlcsum(sent)
|
||||||
|
|
||||||
|
@ -616,11 +614,8 @@ class Channel(PrintError):
|
||||||
assert htlc_id not in log['settles']
|
assert htlc_id not in log['settles']
|
||||||
self.hm.send_settle(htlc_id)
|
self.hm.send_settle(htlc_id)
|
||||||
# save timestamp in LNWorker.preimages
|
# save timestamp in LNWorker.preimages
|
||||||
try:
|
if self.lnworker:
|
||||||
self.save_preimage(htlc.payment_hash, preimage, timestamp=int(time.time()))
|
self.lnworker.save_preimage(htlc.payment_hash, preimage, timestamp=int(time.time()))
|
||||||
except:
|
|
||||||
import traceback
|
|
||||||
traceback.print_exc()
|
|
||||||
|
|
||||||
def receive_htlc_settle(self, preimage, htlc_id):
|
def receive_htlc_settle(self, preimage, htlc_id):
|
||||||
self.print_error("receive_htlc_settle")
|
self.print_error("receive_htlc_settle")
|
||||||
|
@ -629,12 +624,8 @@ class Channel(PrintError):
|
||||||
assert htlc.payment_hash == sha256(preimage)
|
assert htlc.payment_hash == sha256(preimage)
|
||||||
assert htlc_id not in log['settles']
|
assert htlc_id not in log['settles']
|
||||||
self.hm.recv_settle(htlc_id)
|
self.hm.recv_settle(htlc_id)
|
||||||
try:
|
if self.lnworker:
|
||||||
self.save_preimage(htlc.payment_hash, preimage, timestamp=int(time.time()))
|
self.lnworker.save_preimage(htlc.payment_hash, preimage, timestamp=int(time.time()))
|
||||||
except AttributeError as e:
|
|
||||||
# save_preimage is not defined in the unit tests... this is ugly as hell. FIXME
|
|
||||||
import traceback
|
|
||||||
traceback.print_exc()
|
|
||||||
|
|
||||||
def fail_htlc(self, htlc_id):
|
def fail_htlc(self, htlc_id):
|
||||||
self.print_error("fail_htlc")
|
self.print_error("fail_htlc")
|
||||||
|
|
|
@ -376,10 +376,8 @@ class Peer(PrintError):
|
||||||
}
|
}
|
||||||
chan = Channel(chan_dict,
|
chan = Channel(chan_dict,
|
||||||
sweep_address=self.lnworker.sweep_address,
|
sweep_address=self.lnworker.sweep_address,
|
||||||
payment_completed=self.lnworker.payment_completed)
|
lnworker=self.lnworker)
|
||||||
chan.lnwatcher = self.lnwatcher
|
chan.lnwatcher = self.lnwatcher
|
||||||
chan.get_preimage = self.lnworker.get_preimage # FIXME hack.
|
|
||||||
chan.save_preimage = self.lnworker.save_preimage # FIXME hack.
|
|
||||||
sig_64, _ = chan.sign_next_commitment()
|
sig_64, _ = chan.sign_next_commitment()
|
||||||
self.send_message("funding_created",
|
self.send_message("funding_created",
|
||||||
temporary_channel_id=temp_channel_id,
|
temporary_channel_id=temp_channel_id,
|
||||||
|
@ -470,10 +468,8 @@ class Peer(PrintError):
|
||||||
}
|
}
|
||||||
chan = Channel(chan_dict,
|
chan = Channel(chan_dict,
|
||||||
sweep_address=self.lnworker.sweep_address,
|
sweep_address=self.lnworker.sweep_address,
|
||||||
payment_completed=self.lnworker.payment_completed)
|
lnworker=self.lnworker)
|
||||||
chan.lnwatcher = self.lnwatcher
|
chan.lnwatcher = self.lnwatcher
|
||||||
chan.get_preimage = self.lnworker.get_preimage # FIXME hack.
|
|
||||||
chan.save_preimage = self.lnworker.save_preimage # FIXME hack.
|
|
||||||
remote_sig = funding_created['signature']
|
remote_sig = funding_created['signature']
|
||||||
chan.receive_new_commitment(remote_sig, [])
|
chan.receive_new_commitment(remote_sig, [])
|
||||||
sig_64, _ = chan.sign_next_commitment()
|
sig_64, _ = chan.sign_next_commitment()
|
||||||
|
|
|
@ -157,7 +157,7 @@ def create_sweeptxs_for_our_latest_ctx(chan: 'Channel', ctx: Transaction,
|
||||||
def create_txns_for_htlc(htlc: 'UpdateAddHtlc', is_received_htlc: bool) -> Tuple[Optional[Transaction], Optional[Transaction]]:
|
def create_txns_for_htlc(htlc: 'UpdateAddHtlc', is_received_htlc: bool) -> Tuple[Optional[Transaction], Optional[Transaction]]:
|
||||||
if is_received_htlc:
|
if is_received_htlc:
|
||||||
try:
|
try:
|
||||||
preimage = chan.get_preimage(htlc.payment_hash)
|
preimage = chan.lnworker.get_preimage(htlc.payment_hash)
|
||||||
except UnknownPaymentHash as e:
|
except UnknownPaymentHash as e:
|
||||||
print_error(f'trying to sweep htlc from our latest ctx but getting {repr(e)}')
|
print_error(f'trying to sweep htlc from our latest ctx but getting {repr(e)}')
|
||||||
return None, None
|
return None, None
|
||||||
|
@ -260,7 +260,7 @@ def create_sweeptxs_for_their_latest_ctx(chan: 'Channel', ctx: Transaction,
|
||||||
def create_sweeptx_for_htlc(htlc: 'UpdateAddHtlc', is_received_htlc: bool) -> Optional[Transaction]:
|
def create_sweeptx_for_htlc(htlc: 'UpdateAddHtlc', is_received_htlc: bool) -> Optional[Transaction]:
|
||||||
if not is_received_htlc:
|
if not is_received_htlc:
|
||||||
try:
|
try:
|
||||||
preimage = chan.get_preimage(htlc.payment_hash)
|
preimage = chan.lnworker.get_preimage(htlc.payment_hash)
|
||||||
except UnknownPaymentHash as e:
|
except UnknownPaymentHash as e:
|
||||||
print_error(f'trying to sweep htlc from their latest ctx but getting {repr(e)}')
|
print_error(f'trying to sweep htlc from their latest ctx but getting {repr(e)}')
|
||||||
return None
|
return None
|
||||||
|
|
|
@ -78,9 +78,7 @@ class LNWorker(PrintError):
|
||||||
self.peers = {} # type: Dict[bytes, Peer] # pubkey -> Peer
|
self.peers = {} # type: Dict[bytes, Peer] # pubkey -> Peer
|
||||||
self.channels = {} # type: Dict[bytes, Channel]
|
self.channels = {} # type: Dict[bytes, Channel]
|
||||||
for x in wallet.storage.get("channels", []):
|
for x in wallet.storage.get("channels", []):
|
||||||
c = Channel(x, sweep_address=self.sweep_address, payment_completed=self.payment_completed)
|
c = Channel(x, sweep_address=self.sweep_address, lnworker=self)
|
||||||
c.get_preimage = self.get_preimage # FIXME hack.
|
|
||||||
c.save_preimage = self.save_preimage # FIXME hack.
|
|
||||||
self.channels[c.channel_id] = c
|
self.channels[c.channel_id] = c
|
||||||
c.set_remote_commitment()
|
c.set_remote_commitment()
|
||||||
c.set_local_commitment(c.current_commitment(LOCAL))
|
c.set_local_commitment(c.current_commitment(LOCAL))
|
||||||
|
|
Loading…
Add table
Reference in a new issue