1
0

LNWatcher refactoring:

- do not store non-breach transactions
 - send 'channel_open' and 'channel_closed' events
 - force-closed channels are handled by LNWorker
This commit is contained in:
ThomasV
2018-12-04 20:50:24 +01:00
parent 1b7a3c25d1
commit 729ddb8ec3
3 changed files with 122 additions and 113 deletions

View File

@@ -43,8 +43,7 @@ from .lnutil import HTLC_TIMEOUT_WEIGHT, HTLC_SUCCESS_WEIGHT
from .lnutil import funding_output_script, LOCAL, REMOTE, HTLCOwner, make_closing_tx, make_commitment_outputs
from .lnutil import ScriptHtlc, PaymentFailure, calc_onchain_fees, RemoteMisbehaving, make_htlc_output_witness_script
from .transaction import Transaction
from .lnsweep import (create_sweeptxs_for_our_latest_ctx, create_sweeptxs_for_their_latest_ctx,
create_sweeptxs_for_their_just_revoked_ctx)
from .lnsweep import create_sweeptxs_for_their_just_revoked_ctx
class ChannelJsonEncoder(json.JSONEncoder):
@@ -204,10 +203,10 @@ class Channel(PrintError):
for sub in (LOCAL, REMOTE):
self.log[sub].locked_in.update(self.log[sub].adds.keys())
# used in lnworker.on_channel_closed
self.local_commitment = self.current_commitment(LOCAL)
self.remote_commitment = self.current_commitment(REMOTE)
def set_state(self, state: str):
if self._state == 'FORCE_CLOSING':
assert state == 'FORCE_CLOSING', 'new state was not FORCE_CLOSING: ' + state
@@ -325,7 +324,7 @@ class Channel(PrintError):
htlcsigs.sort()
htlcsigs = [x[1] for x in htlcsigs]
self.process_new_offchain_ctx(pending_remote_commitment, ours=False)
self.remote_commitment = self.pending_commitment(REMOTE)
# we can't know if this message arrives.
# since we shouldn't actually throw away
@@ -390,7 +389,7 @@ class Channel(PrintError):
if self.constraints.is_initiator and self.pending_fee[FUNDEE_ACKED]:
self.pending_fee[FUNDER_SIGNED] = True
self.process_new_offchain_ctx(pending_local_commitment, ours=True)
self.local_commitment = self.pending_commitment(LOCAL)
def verify_htlc(self, htlc: UpdateAddHtlc, htlc_sigs: Sequence[bytes], we_receive: bool) -> int:
_, this_point, _ = self.points()
@@ -454,19 +453,6 @@ class Channel(PrintError):
next_point = secret_to_pubkey(int.from_bytes(next_secret, 'big'))
return last_secret, this_point, next_point
# TODO don't presign txns for non-breach close
def process_new_offchain_ctx(self, ctx: 'Transaction', ours: bool):
if not self.lnwatcher:
return
outpoint = self.funding_outpoint.to_str()
if ours:
encumbered_sweeptxs = create_sweeptxs_for_our_latest_ctx(self, ctx, self.sweep_address)
else:
encumbered_sweeptxs = create_sweeptxs_for_their_latest_ctx(self, ctx, self.sweep_address)
for prev_txid, encumbered_tx in encumbered_sweeptxs:
if encumbered_tx is not None:
self.lnwatcher.add_sweep_tx(outpoint, prev_txid, encumbered_tx.to_json())
def process_new_revocation_secret(self, per_commitment_secret: bytes):
if not self.lnwatcher:
return