electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit d7b853f2716acb2808278e552987bf598821a4e4
parent 887b643706c262eb05134a698fbed7fd79005dbf
Author: ThomasV <thomasv@electrum.org>
Date:   Tue,  5 May 2020 15:40:13 +0200

follow-up 8ba7e6806428a90ffe01293e2b0b8bd340d07c6b

Diffstat:
Melectrum/lnchannel.py | 46++++++++++++++++++++++++++++++++++++----------
Melectrum/lnworker.py | 1+
2 files changed, 37 insertions(+), 10 deletions(-)

diff --git a/electrum/lnchannel.py b/electrum/lnchannel.py @@ -34,7 +34,7 @@ import attr from . import ecc from . import constants, util -from .util import bfh, bh2u, chunks, TxMinedInfo +from .util import bfh, bh2u, chunks, TxMinedInfo, PR_PAID from .bitcoin import redeem_script_to_address from .crypto import sha256, sha256d from .transaction import Transaction, PartialTransaction @@ -972,16 +972,42 @@ class Channel(AbstractChannel): return error_bytes, failure_message def extract_preimage_from_htlc_tx(self, tx): - witness = tx.inputs()[0].witness_elements() - if len(witness) != 5: - return - preimage = witness[3] - payment_hash = sha256(preimage) - for direction, htlc in self.hm.get_htlcs_in_oldest_unrevoked_ctx(REMOTE): - if htlc.payment_hash == payment_hash: - self.logger.info(f'found preimage for {payment_hash.hex()} in tx witness') + for _input in tx.inputs(): + witness = _input.witness_elements() + if len(witness) == 5: + preimage = witness[3] + elif len(witness) == 3: + preimage = witness[1] + else: + continue + payment_hash = sha256(preimage) + for direction, htlc in self.hm.get_htlcs_in_oldest_unrevoked_ctx(REMOTE): + if htlc.payment_hash == payment_hash: + is_sent = direction == RECEIVED + break + else: + for direction, htlc in self.hm.get_htlcs_in_latest_ctx(REMOTE): + if htlc.payment_hash == payment_hash: + is_sent = direction == RECEIVED + break + else: + for direction, htlc in self.hm.get_htlcs_in_oldest_unrevoked_ctx(LOCAL): + if htlc.payment_hash == payment_hash: + is_sent = direction == SENT + break + else: + for direction, htlc in self.hm.get_htlcs_in_latest_ctx(LOCAL): + if htlc.payment_hash == payment_hash: + is_sent = direction == SENT + break + else: + continue + if self.lnworker.get_preimage(payment_hash) is None: + self.logger.info(f'found preimage for {payment_hash.hex()} in witness of length {len(witness)}') self.lnworker.save_preimage(payment_hash, preimage) - if direction == RECEIVED: + info = self.lnworker.get_payment_info(payment_hash) + if info is not None and info.status != PR_PAID: + if is_sent: self.lnworker.payment_sent(self, payment_hash) else: self.lnworker.payment_received(self, payment_hash) diff --git a/electrum/lnworker.py b/electrum/lnworker.py @@ -1110,6 +1110,7 @@ class LNWallet(LNWorker): return bfh(r) if r else None def get_payment_info(self, payment_hash: bytes) -> Optional[PaymentInfo]: + """returns None if payment_hash is a payment we are forwarding""" key = payment_hash.hex() with self.lock: if key in self.payments: