mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-09-01 09:45:18 +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:
|
||||
return super().diagnostic_name()
|
||||
|
||||
def __init__(self, state, *, sweep_address=None, name=None,
|
||||
payment_completed: Optional[Callable[['Channel', Direction, UpdateAddHtlc], None]] = None):
|
||||
if not payment_completed:
|
||||
payment_completed = lambda this, x, y: None
|
||||
def __init__(self, state, *, sweep_address=None, name=None, lnworker=None):
|
||||
self.lnworker = lnworker
|
||||
self.sweep_address = sweep_address
|
||||
self.payment_completed = payment_completed
|
||||
assert 'local_state' not in state
|
||||
self.config = {}
|
||||
self.config[LOCAL] = state["local_config"]
|
||||
|
@ -437,10 +434,11 @@ class Channel(PrintError):
|
|||
|
||||
received = self.hm.received_in_ctn(self.config[LOCAL].ctn)
|
||||
sent = self.hm.sent_in_ctn(self.config[LOCAL].ctn)
|
||||
for htlc in received:
|
||||
self.payment_completed(self, RECEIVED, htlc)
|
||||
for htlc in sent:
|
||||
self.payment_completed(self, SENT, htlc)
|
||||
if self.lnworker:
|
||||
for htlc in received:
|
||||
self.lnworker.payment_completed(self, RECEIVED, htlc)
|
||||
for htlc in sent:
|
||||
self.lnworker.payment_completed(self, SENT, htlc)
|
||||
received_this_batch = htlcsum(received)
|
||||
sent_this_batch = htlcsum(sent)
|
||||
|
||||
|
@ -616,11 +614,8 @@ class Channel(PrintError):
|
|||
assert htlc_id not in log['settles']
|
||||
self.hm.send_settle(htlc_id)
|
||||
# save timestamp in LNWorker.preimages
|
||||
try:
|
||||
self.save_preimage(htlc.payment_hash, preimage, timestamp=int(time.time()))
|
||||
except:
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
if self.lnworker:
|
||||
self.lnworker.save_preimage(htlc.payment_hash, preimage, timestamp=int(time.time()))
|
||||
|
||||
def receive_htlc_settle(self, preimage, htlc_id):
|
||||
self.print_error("receive_htlc_settle")
|
||||
|
@ -629,12 +624,8 @@ class Channel(PrintError):
|
|||
assert htlc.payment_hash == sha256(preimage)
|
||||
assert htlc_id not in log['settles']
|
||||
self.hm.recv_settle(htlc_id)
|
||||
try:
|
||||
self.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()
|
||||
if self.lnworker:
|
||||
self.lnworker.save_preimage(htlc.payment_hash, preimage, timestamp=int(time.time()))
|
||||
|
||||
def fail_htlc(self, htlc_id):
|
||||
self.print_error("fail_htlc")
|
||||
|
|
|
@ -376,10 +376,8 @@ class Peer(PrintError):
|
|||
}
|
||||
chan = Channel(chan_dict,
|
||||
sweep_address=self.lnworker.sweep_address,
|
||||
payment_completed=self.lnworker.payment_completed)
|
||||
lnworker=self.lnworker)
|
||||
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()
|
||||
self.send_message("funding_created",
|
||||
temporary_channel_id=temp_channel_id,
|
||||
|
@ -470,10 +468,8 @@ class Peer(PrintError):
|
|||
}
|
||||
chan = Channel(chan_dict,
|
||||
sweep_address=self.lnworker.sweep_address,
|
||||
payment_completed=self.lnworker.payment_completed)
|
||||
lnworker=self.lnworker)
|
||||
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']
|
||||
chan.receive_new_commitment(remote_sig, [])
|
||||
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]]:
|
||||
if is_received_htlc:
|
||||
try:
|
||||
preimage = chan.get_preimage(htlc.payment_hash)
|
||||
preimage = chan.lnworker.get_preimage(htlc.payment_hash)
|
||||
except UnknownPaymentHash as e:
|
||||
print_error(f'trying to sweep htlc from our latest ctx but getting {repr(e)}')
|
||||
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]:
|
||||
if not is_received_htlc:
|
||||
try:
|
||||
preimage = chan.get_preimage(htlc.payment_hash)
|
||||
preimage = chan.lnworker.get_preimage(htlc.payment_hash)
|
||||
except UnknownPaymentHash as e:
|
||||
print_error(f'trying to sweep htlc from their latest ctx but getting {repr(e)}')
|
||||
return None
|
||||
|
|
|
@ -78,9 +78,7 @@ class LNWorker(PrintError):
|
|||
self.peers = {} # type: Dict[bytes, Peer] # pubkey -> Peer
|
||||
self.channels = {} # type: Dict[bytes, Channel]
|
||||
for x in wallet.storage.get("channels", []):
|
||||
c = Channel(x, sweep_address=self.sweep_address, payment_completed=self.payment_completed)
|
||||
c.get_preimage = self.get_preimage # FIXME hack.
|
||||
c.save_preimage = self.save_preimage # FIXME hack.
|
||||
c = Channel(x, sweep_address=self.sweep_address, lnworker=self)
|
||||
self.channels[c.channel_id] = c
|
||||
c.set_remote_commitment()
|
||||
c.set_local_commitment(c.current_commitment(LOCAL))
|
||||
|
|
Loading…
Add table
Reference in a new issue